forked from samytichadou/Auto_Reload_Blender_addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.py
72 lines (58 loc) · 2.37 KB
/
operators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import bpy
import os
import time
from .functions import reload_images, get_modification_times
from .addon_prefs import get_addon_preferences
class Reload_reload_all(bpy.types.Operator):
bl_idname = "reload.reload_all"
bl_label = "Reload all Images"
bl_description = "Reload all Images in the blend."
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
reload_images()
get_modification_times()
print("Auto Reload Images --- All images reloaded")
return {"FINISHED"}
class Reload_reload_timer(bpy.types.Operator):
bl_idname = "reload.reload_timer"
bl_label = "Reload Images timer"
_timer = None
oldtimer : bpy.props.FloatProperty()
@classmethod
def poll(cls, context):
return not bpy.data.window_managers['WinMan'].reload_modal
def __init__(self):
print("Auto Reload Images --- Reload Images timer started")
bpy.data.window_managers['WinMan'].reload_modal=True
def modal(self, context, event):
if bpy.data.window_managers['WinMan'].reload_modal==False:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
if self.oldtimer!=self._timer.time_duration:
chk=0
for i in bpy.data.images:
path=os.path.abspath(bpy.path.abspath(i.filepath))
try:
if i.modification_time!=str(os.path.getmtime(path)):
chk=1
except FileNotFoundError:
if i.modification_time!="missing":
chk=1
if chk==1:
reload_images()
get_modification_times()
print("Auto Reload Images --- Modified images reloaded")
self.oldtimer=self._timer.time_duration
return {'PASS_THROUGH'}
def execute(self, context):
addon_preferences = get_addon_preferences()
freq=addon_preferences.check_frequency
wm = context.window_manager
self._timer = wm.event_timer_add(freq, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
wm.event_timer_remove(self._timer)
print("Auto Reload Images --- Reload Images timer ended")