def modal(self, context, event): # First frame initialization: if PlayPanel.init_play: ModalTimerOperator._uuid = mu.rand_letters(5) self.limits = bpy.context.scene.frame_current if not PlayPanel.is_playing: return {'PASS_THROUGH'} if event.type in {'RIGHTMOUSE', 'ESC'} or self.limits > bpy.context.scene.play_to: plot_something(self, context, bpy.context.scene.play_to, ModalTimerOperator._uuid) print('Stop!') self.limits = bpy.context.scene.play_from PlayPanel.is_playing = False bpy.context.scene.update() self.cancel(context) return {'PASS_THROUGH'} if event.type == 'TIMER': # print(time.time() - self._time) if time.time() - self._time > bpy.context.scene.play_time_step: bpy.context.scene.frame_current = self.limits # print(self.limits, time.time() - self._time) self._time = time.time() try: plot_something(self, context, self.limits, ModalTimerOperator._uuid) except: print(traceback.format_exc()) print('Error in plotting at {}!'.format(self.limits)) self.limits = self.limits - bpy.context.scene.play_dt if PlayPanel.play_reverse else \ self.limits + bpy.context.scene.play_dt bpy.context.scene.frame_current = self.limits return {'PASS_THROUGH'}
def modal(self, context, event): # First frame initialization: if PlayPanel.init_play: ModalTimerOperator._uuid = mu.rand_letters(5) self.limits = bpy.context.scene.frame_current if not PlayPanel.is_playing: return {'PASS_THROUGH'} if event.type in {'RIGHTMOUSE', 'ESC'} or self.limits > bpy.context.scene.play_to: plot_something(self, context, bpy.context.scene.play_to, ModalTimerOperator._uuid) print('Stop!') self.limits = bpy.context.scene.play_from PlayPanel.is_playing = False bpy.context.scene.update() self.cancel(context) return {'PASS_THROUGH'} if event.type == 'TIMER': # print(time.time() - self._time) if time.time() - self._time > bpy.context.scene.play_time_step: bpy.context.scene.frame_current = self.limits # print(self.limits, time.time() - self._time) self._time = time.time() try: plot_something(self, context, self.limits, ModalTimerOperator._uuid) except: print(traceback.format_exc()) print('Error in plotting at {}!'.format(self.limits)) self.limits = self.limits - bpy.context.scene.play_dt if PlayPanel.play_reverse else \ self.limits + bpy.context.scene.play_dt bpy.context.scene.frame_current = self.limits return {'PASS_THROUGH'}
def run_faulthandler(): import faulthandler logs = op.join(mmvt_utils.get_user_fol(), 'logs') mmvt_utils.make_dir(logs) fault_handler = open( op.join(logs, 'faulthandler_{}.txt'.format(mmvt_utils.rand_letters(5))), 'w') faulthandler.enable(fault_handler)
class ExportGraph(bpy.types.Operator): bl_idname = "mmvt.export_graph" bl_label = "mmvt export_graph" bl_options = {"UNDO"} uuid = mu.rand_letters(5) @staticmethod def invoke(self, context, event=None): capture_graph() return {"FINISHED"}
def run_faulthandler(): try: import faulthandler logs = op.join(mmvt_utils.get_user_fol(), 'logs') mmvt_utils.make_dir(logs) fault_handler = open(op.join(logs, 'faulthandler_{}.txt'.format(mmvt_utils.rand_letters(5))), 'w') faulthandler.enable(fault_handler) except: print('Cannot create faulthandler log!') mmvt_utils.print_last_error_line()
class ExportGraph(bpy.types.Operator): bl_idname = "mmvt.export_graph" bl_label = "mmvt export_graph" bl_options = {"UNDO"} uuid = mu.rand_letters(5) @staticmethod def invoke(self, context, event=None): # image_fol = op.join(mu.get_user_fol(), 'images', ExportGraph.uuid) capture_graph() return {"FINISHED"}
class InflatingMovie(bpy.types.Operator): bl_idname = "mmvt.inflating_movie" bl_label = "mmvt inflating movie" bl_options = {"UNDO"} uuid = mu.rand_letters(5) @staticmethod def invoke(self, context, event=None): if bpy.context.scene.play_miscs == 'inflating': inflating_movie() elif bpy.context.scene.play_miscs == 'slicing': slicing_movie() return {"FINISHED"}
class ModalTimerOperator(bpy.types.Operator): """Operator which runs its self from a timer""" bl_idname = "wm.modal_timer_operator" bl_label = "Modal Timer Operator" # limits = bpy.props.IntProperty(default=bpy.context.scene.play_from) limits = bpy.context.scene.play_from _timer = None _time = time.time() _uuid = mu.rand_letters(5) def modal(self, context, event): # First frame initialization: if PlayPanel.init_play: ModalTimerOperator._uuid = mu.rand_letters(5) self.limits = bpy.context.scene.frame_current if not PlayPanel.is_playing: return {'PASS_THROUGH'} if event.type in {'RIGHTMOUSE', 'ESC' } or self.limits > bpy.context.scene.play_to: plot_something(self, context, bpy.context.scene.play_to, ModalTimerOperator._uuid) print('Stop!') self.limits = bpy.context.scene.play_from PlayPanel.is_playing = False bpy.context.scene.update() self.cancel(context) return {'PASS_THROUGH'} if event.type == 'TIMER': # print(time.time() - self._time) if time.time() - self._time > bpy.context.scene.play_time_step: rotate_while_playing() # if bpy.context.scene.rotate_brain_while_playing and ( # bpy.context.scene.render_movie or bpy.context.scene.save_images): # _addon().camera_mode('ORTHO') # _addon().rotate_brain() # _addon().camera_mode('CAMERA') # elif bpy.context.scene.rotate_brain_while_playing: # _addon().rotate_brain() bpy.context.scene.frame_current = self.limits # print(self.limits, time.time() - self._time) self._time = time.time() try: plot_something(self, context, self.limits, ModalTimerOperator._uuid) except: print(traceback.format_exc()) print('Error in plotting at {}!'.format(self.limits)) self.limits = self.limits - bpy.context.scene.play_dt if PlayPanel.play_reverse else \ self.limits + bpy.context.scene.play_dt bpy.context.scene.frame_current = self.limits return {'PASS_THROUGH'} def execute(self, context): # ModalTimerOperator._timer = wm.event_timer_add(time_step=bpy.context.scene.play_time_step, window=context.window) wm = context.window_manager # if ModalTimerOperator._timer: # print('timer is already running!') # print('last tick {}'.format(time.time() - self._time)) # else: self.cancel(context) ModalTimerOperator._timer = wm.event_timer_add(time_step=0.05, window=context.window) self._time = time.time() wm.modal_handler_add(self) return {'RUNNING_MODAL'} def cancel(self, context): # if ModalTimerOperator._timer: if ModalTimerOperator._timer: wm = context.window_manager wm.event_timer_remove(ModalTimerOperator._timer)