def set_lisnter_state_for_built_in(cls, value): if value: lx.eval("!!macro.record true") replay.Macro().start_track_insertions(True) cls._cmd_listner.layoutCreateOrClose = lx.eval( "user.value replay_record_layoutCreateOrClose ?") cls._cmd_listner.set_state(value) else: anyRecordedCommand = cls._cmd_listner.recording_session_data.lastCommand( ) is not None cls._cmd_listner.layoutCreateOrClose = lx.eval( "user.value replay_record_layoutCreateOrClose ?") cls._cmd_listner.set_state(value) lx.eval("!!macro.record false") if anyRecordedCommand: file_path = lx.eval( 'query platformservice alias ? {kit_mecco_replay:}') file_path = os.path.join(file_path, "Replay_built_in.LXM") lx.eval("!!macro.saveRecorded {%s}" % file_path) replay.Macro().start_track_insertions(False) replay.Macro().merge_with_build_in(file_path) replay.Macro().rebuild_view() notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): """Saves the current Macro() object to the destination stored in its `file_path` property. If `file_path` is `None`, prompt for a destination. Unlike `replay.fileSave` this command can save in multiple formats.""" # Stop recording lx.eval('replay.record stop') macro = replay.Macro() format_val = self.commander_arg_value(0) file_path = self.commander_arg_value(1) if file_path is None: file_path = modo.dialogs.customFile( dtype='fileSave', title=message("MECCO_REPLAY", "EXPORT_DIALOG_TITLE"), names=macro.export_format_names, unames=macro.export_format_unames, ext=macro.export_format_extensions, path=self._path) if file_path is None: return self.__class__._path = file_path format_val = lx.eval('dialog.fileSaveFormat ?') replay.Macro().render(format_val, file_path)
def selected_args(self): for node in replay.Macro().selected_commands: for arg in node.args: yield arg for arg in replay.Macro().selected_args: yield arg
def basic_Enable(self, msg): if lx.eval('replay.record query:?'): return False if replay.Macro().primary is not None and not replay.Macro( ).primary.can_insert_after(): return False return True
def basic_Enable(self, msg): if lx.eval('replay.record query:?'): return False if len(replay.Macro().selected_descendants) == 0: return False for command in replay.Macro().selected_descendants: if not command.can_copy(): return False return True
def commander_arguments(self): return [{ 'name': 'format', 'datatype': 'string', 'default': replay.Macro().export_format_names, 'values_list_type': 'popup', 'values_list': replay.Macro().export_format_names, 'flags': ['optional'] }, { 'name': 'destination', 'datatype': 'string', 'flags': ['optional'] }]
def reorder(self, indices): """Reorder indices of marco.children for each index pair in indices""" macro = replay.Macro() # change indices for from_idx, to_idx in indices: macro.children[from_idx].index = to_idx # Rebuild view macro.rebuild_view() replay.Macro().unsaved_changes = True notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def apply(self, actions): """Change colors for each item in actions""" macro = replay.Macro() # Change color of selected nodes for path, color in actions: macro.node_for_path(path).row_color = color # Rebuild view macro.rebuild_view() replay.Macro().unsaved_changes = True notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): # Stop recording lx.eval('replay.record stop') macro = replay.Macro() # Hack to fix crash bug. macro.select_event_treeview() if not macro.file_path: return if not macro.unsaved_changes: return if modo.dialogs.yesNo(message("MECCO_REPLAY", "REVERT_DIALOG_TITLE"), message("MECCO_REPLAY", "REVERT_FILE_MSG")) == 'yes': # No unsaved changes macro.unsaved_changes = False # Reload saved data macro.parse('open', macro.file_path) # Rebuild treeview macro.rebuild_view() notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): lxm = pyperclip.paste() if len(lxm.strip()) == 0: return # Register Undo object performing operation and apply it undo_svc = lx.service.Undo() macro = replay.Macro() if macro.primary is None: path = [0] old_primary = None else: path = list(macro.primary.path) old_primary = list(path) path[-1] += 1 if undo_svc.State() != lx.symbol.iUNDO_INVALID: paste = UndoPaste(lxm, path, old_primary) try: paste.undo_Forward() except: return undo_svc.Record(paste)
def commander_execute(self, msg, flags): macro = replay.Macro() idx = -1 if macro.primary is None: # If there's no primary node, insert at zero idx = len(macro.children) else: # If there's a primary node, insert right after it node = macro.primary while not node.can_insert_after(): node = node.parent idx = node.index + 1 cache = replay.RecordingCache() if len(cache.commands) == 0: return if len(cache.commands) == 1: macro.add_command(command=cache.commands[0], index=idx) if len(cache.commands) > 1: macro.add_block(block=cache.commands, name="", index=idx) macro.unsaved_changes = True idx += 1 macro.select(idx - 1) macro.rebuild_view() notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def toggle(self): """Toggle suppress for each item in paths""" macro = replay.Macro() # Toggle suppress flag of selected nodes for path in self.m_paths: macro.node_for_path( path).direct_suppress = False if macro.node_for_path( path).direct_suppress else True # Rebuild view macro.rebuild_view() replay.Macro().unsaved_changes = True notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): # Copy selection lxm = replay.Macro().render_LXM_selected() pyperclip.copy(lxm) lx.eval("replay.lineDelete")
def commander_execute(self, msg, flags): # Stop recording lx.eval('replay.record stop') macro = replay.Macro() if macro.file_path: lx.eval('cmds.mapKey command:{replay.runScript {%s}}' % macro.file_path) else: default_path = lx.eval('query platformservice alias ? {scripts:}') # Get the path from the user, if not given as argument: file_path = modo.dialogs.customFile( dtype='fileOpen', title=message("MECCO_REPLAY", "KEY_MAPPING_SCRIPT"), names=macro.import_format_names, unames=macro.import_format_unames, patterns=macro.import_format_patterns, path=default_path) if file_path is None: return lx.eval('cmds.mapKey command:{@{%s}}' % file_path)
def finalize_command(self, macro): """Does common command finalizing operations""" macro.rebuild_view() replay.Macro().unsaved_changes = True notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): file_path = lx.eval( 'query platformservice alias ? {kit_mecco_replay:}') file_path = os.path.join(file_path, "Replay_TempFile.LXM") file_format = "lxm" replay.Macro().render(file_format, file_path) lx.eval('@{%s}' % file_path)
def commander_execute(self, msg, flags): # Get script script = self.commander_arg_value(0).replace("\q", "?") ButtonName = self.commander_arg_value(1) macro = replay.Macro() path = None if macro.primary is None: # If there's no primary node, insert at end path = macro.root.path + [len(macro.children)] else: # If there's a primary node, insert right after it path = macro.primary.path while not macro.node_for_path(path).can_insert_after(): path = path[:-1] path[-1] += 1 lineInsert = UndoLineInsert(script, ButtonName, path) if self.cmd_Flags() & lx.symbol.fCMD_UNDO != 0: # Register Undo object performing operation and apply it undo_svc = lx.service.Undo() if undo_svc.State() != lx.symbol.iUNDO_INVALID: undo_svc.Apply(lineInsert) else: lineInsert.undo_Forward()
def undo_Forward(self): macro = replay.Macro() self.m_added_nodes = macro.parse_and_insert_string( self.m_lxm, list(self.m_path)) macro.select(self.m_path) self.finalize_command()
def arg_info(self, argIndex): """Returns sTYPE_INTEGER, sTYPE_FLOAT, or sTYPE_STRING depending on the datatype stored in the `MacroCommandArg` object. You'd think this would be straightforward, but no. This is MODO.""" argName = self.commander_args()['argName'] asString = self.asString() types = set() # Loop over all command args with name argName for command, argIndex in self.commands_by_argName(argName): arg = command.args[argIndex] # Get type coming from meta hints = None default = None argTypeName = None if asString or command.markedAsString(argIndex): argTypeName = lx.symbol.sTYPE_STRING default = command.args[argIndex].value hints = None else: attrs = command.attributes() argTypeName = attrs.arg(argIndex).type_name( lx.symbol.sTYPE_STRING) default = attrs.arg(argIndex).value_as_string( command.args[argIndex].value) hints_ = attrs.arg(argIndex).hints(None) if hints_ is None: hints = None else: hints = list() for idx, name in hints_: if idx >= 0: hints.append((idx, name)) if argTypeName: types.add((argTypeName, None if hints is None else tuple(hints), default)) # If we have more than one type no need to continue. Return 'string' if len(types) > 1: break if len(types) == 1: # If all argument types are identical return it arg_info = list(types)[0] # Nasty bug: if we edit a color, we must reset the color # else crash. if arg_info[0] == lx.symbol.sTYPE_COLOR: replay.Macro().reset_color_on_select = True return arg_info else: # If args doesn't have type or have many use string return (lx.symbol.sTYPE_STRING, None, "")
def undo_Reverse(self): for node in self.m_added_nodes: node.delete() macro = replay.Macro() if self.m_old_primary_path is not None: macro.select(self.m_old_primary_path) self.finalize_command()
def undo_Reverse(self): macro = replay.Macro() # Undo of executed operation will revert the modifications # so we only need to move primary node one step up macro.node_for_path(self.m_prev_path).selected = True macro.node_for_path(self.m_next_path).selected = False macro.refresh_view() notifier = replay.Notifier() notifier.Notify(lx.symbol.fCMDNOTIFY_CHANGE_ALL)
def commander_execute(self, msg, flags): # Collect selected paths paths = list() for line in replay.Macro().selected_descendants: paths.append(line.path) # Register Undo object performing operation and apply it undo_svc = lx.service.Undo() if undo_svc.State() != lx.symbol.iUNDO_INVALID: undo_svc.Apply(UndoLineSuppress(paths))
def commander_execute(self, msg, flags): # Stop recording lx.eval('replay.record stop') file_path = replay.Macro().file_path if file_path is None: lx.eval('replay.saveAs') try: file_path = replay.Macro().file_path lx.eval('!!file.open {%s}' % file_path) lx.eval('replay.fileClose') except: modo.dialogs.alert( message("MECCO_REPLAY", "OPEN_FILE_FAIL"), message("MECCO_REPLAY", "OPEN_FILE_FAIL_MSG", basename(file_path)))
def undo_Forward(self): macro = replay.Macro() del self.m_deleted_commands[:] # delete selected paths and store them in json form to be able to undo for path in self.m_paths: child = macro.node_for_path(path) self.m_deleted_commands.append((path, child.render_json())) child.delete() self.finalize_command(macro)
def commander_execute(self, msg, flags): # collect list of selected paths paths = list() for node in replay.Macro().selected_descendants: if isinstance(node, replay.MacroCommandArg): paths.append(node.path) # Register Undo object performing operation and apply it undo_svc = lx.service.Undo() if undo_svc.State() != lx.symbol.iUNDO_INVALID: undo_svc.Apply(UndoArgClear(paths))
def commander_execute(self, msg, flags): color_name = self.commander_arg_value(0, 'none') # Add actions needed to undo and redo this command actionList = ColorActionList() for line in replay.Macro().selected_descendants: actionList.append(line.path, line.row_color, color_name) # Register Undo object performing operation and apply it undo_svc = lx.service.Undo() if undo_svc.State() != lx.symbol.iUNDO_INVALID: undo_svc.Apply(UndoLineColor(actionList))
def undo_Reverse(self): macro = replay.Macro() # Sort paths in ascending order for undo operation # Default list comparision working in our case self.m_deleted_commands.sort(key=lambda x: x[0]) # Restore deleted commands for removed_path, json in self.m_deleted_commands: macro.add_json_command_or_block(json, path=removed_path) macro.node_for_path(removed_path).selected = True self.finalize_command(macro)
def undo_Forward(self): macro = replay.Macro() del self.m_cleared_values[:] # Save values in m_cleared_values and clear them for path in self.m_paths: child = macro.node_for_path(path) self.m_cleared_values.append( (child.value, child.parent.markedAsString(path[-1]))) child.value = None child.parent.markArgumentAsString(path[-1], False) self.finalize_command(macro)
def undo_Reverse(self): macro = replay.Macro() # Iterate all selected indices and remove previously added comments for path_idx in xrange(0, len(self.m_paths)): # Get path of selected item path = self.m_paths[path_idx] # Get count of lines in comment before adding new ones line_count_before = self.m_line_counts_before[path_idx] # Cat comment to restore previous state macro.node_for_path( path).user_comment_before = macro.node_for_path( path).user_comment_before[:line_count_before] self.finalize_command(macro)
def commander_execute(self, msg, flags): # Register Undo object performing operation and apply it macro = replay.Macro() if macro.all_suppressed(): modo.dialogs.alert(message("MECCO_REPLAY", "EMPTY_MACRO"), message("MECCO_REPLAY", "EMPTY_MACRO_MSG"), dtype='warning') return undo_svc = lx.service.Undo() if undo_svc.State() != lx.symbol.iUNDO_INVALID: step = UndoStep() try: step.undo_Forward() except: return undo_svc.Record(step)