def __init__(self, view_window): """Initialize the Controller instance. Args: view_window (scripter.view.ScripterView): View to drive. """ self.view = view_window self.icons = helper.get_session_icons() self.create_signals() self.settings = model.load() self.scanner = scanner.Scanner(self.settings["stack_root"], self) self.history_current_item = 0 # Save the stack that was previously opened before closing the scripter # window because the current stack will be changed once we populate # the combo_stack with elements. startup_stack = self.settings["current_stack"] self.setup_view_widgets() self.populate_scripts_table() # We need set the current stack in here so that we resume with the # last stack that we had open when we closed the scripter window. self.view.combo_stack.setCurrentIndex( self.view.combo_stack.findText(startup_stack)) self.setup_settings_widgets() if self.settings["tooltips"]: self.create_tooltips() helper.load_tooltips(self.view, "smartScripter") helper.load_tooltips(self.view, "settings")
def assemble_command_path(command_name): """Assemble command path from current settings and command name.""" settings = model.load() stack_root = settings["stack_root"] current_stack = settings["current_stack"] return os.path.join(stack_root, current_stack, command_name)
def clear_history(): """Clear all history commands from the settings file. Returns: dict: Updated hostory with empty history list. """ settings = model.load() del settings["history"][:] model.save(settings) return settings
def get_all_stacks(): """Get all stack folders. Returns: list: Names of all stack folders. """ settings = model.load() stack_root = settings["stack_root"] return [ name for name in os.listdir(stack_root) if os.path.isdir(os.path.join(stack_root, name)) ]
def __init__(self, view_window, command): """Initialize the RegisterCommandController instance. Args: view_window (scripter.widgets.RegisterCommandPanel): RegisterCommand instance to drive. command (str): Command to store. Can be edited in the text area of this widget. """ self.view = view_window self.command = command self.settings = model.load() self.create_signals() self.setup_view() self.setup_from_command_widget() self.detect_nk_snippet()
def create_new_stack(self): """Create new stack.""" self.settings = model.load() stack_name = self.view.input_stack_name.text() if not stack_name: return stack_path = os.path.join(self.settings["stack_root"], stack_name) if os.path.isdir(stack_path): message = ("The stack name '{}' already exists. Please choose " "a different name.".format(stack_name)) dialogs.show_message_box(self.view, message) return os.makedirs(stack_path) self.view.scripter_view.combo_stack.addItem(stack_name) self.view.scripter_view.combo_stack.setCurrentIndex( self.view.scripter_view.combo_stack.findText(stack_name)) self.view.close()
def add_to_history(command): """Add the given command to the history. Args: command (str): Command to add to the history. Returns: dict: The settings using the updated history. """ settings = model.load() # Remove the command from the history in case it already exists so that # we don't add up with duplicated commands in our history. If we execute # once command, then another and then again the first command, then we # want to add this command to the top. try: settings["history"].remove(command) except ValueError: pass settings["history"].append(command) return model.save(settings)
def refresh(self): """Reload scripts table.""" self.settings = model.load() self.scanner = scanner.Scanner(self.settings["stack_root"], self) self.populate_scripts_table()