MCPcopy Create free account
hub / github.com/coldtype/st2 / ST2SourceWatcher

Class ST2SourceWatcher

ST2/operations.py:317–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315
316
317class ST2SourceWatcher(bpy.types.Operator):
318 bl_idname = "wm.st2_source_watcher"
319 bl_label = "ST2 Source Watcher"
320
321 _timer = None
322 _force = False
323
324 _sources = {}
325
326 def modal(self, context, event):
327
328 st2 = context.scene.st2
329
330 def cancel(force=False):
331 print("CANCELLING")
332 self._force = force
333 self.cancel(context)
334 return {"FINISHED"}
335
336 if not st2.script_watch:
337 return cancel(force=True)
338
339 if event.type == 'ESC':
340 return cancel(force=True)
341
342 if event.type == 'TIMER':
343
344 for obj in search.find_st2_editables(context):
345 data = obj.st2
346 if data.script_file and data.script_enabled:
347 if data.script_file not in self._sources:
348 stat = Path(data.script_file).stat()
349 self._sources[data.script_file] = stat.st_mtime
350
351 for src, last_mtime in self._sources.items():
352 stat = Path(src).stat()
353 if stat.st_mtime > last_mtime:
354 self._sources[src] = stat.st_mtime
355 print("save detected:", src)
356 bpy.ops.st2.refresh_settings()
357
358 return {'PASS_THROUGH'}
359
360 def execute(self, context):
361 wm = context.window_manager
362 self._timer = wm.event_timer_add(0.25, window=context.window)
363 wm.modal_handler_add(self)
364
365 return {'RUNNING_MODAL'}
366
367 def cancel(self, context):
368 wm = context.window_manager
369 wm.event_timer_remove(self._timer)
370 self._force = False
371 print('timer removed')
372
373
374classes = [

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected