def change_language(self): """Toggle the language and save to settings.""" current = self.view.button_language.text() new = TCL if current == PY else PY self.view.button_language.setText(new) self.settings["language"] = new model.save(self.settings)
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 load_stack(self): """Load stack or show window to create a new stack.""" new_stack_index = self.view.combo_stack.findText(NEW_STACK) if self.view.combo_stack.currentIndex() == new_stack_index: # We need to make this global in here otherwise Nuke won't show the # window. global NEW_STACK_VIEW # pylint: disable=global-statement NEW_STACK_VIEW = view.NewStack(self.view) NEW_STACK_VIEW.raise_() NEW_STACK_VIEW.show() NewStackController(NEW_STACK_VIEW) else: new_stack = self.view.combo_stack.currentText() self.settings["current_stack"] = new_stack model.save(self.settings) self.populate_scripts_table()
def toggle_command_widgets(self, show=None): """Show/ hide the command inputs and update settings. Args: show (bool, default is None): If True force the command widgets to show, otherwise hide them. """ command_widgets = (self.view.button_language, self.view.input_command) # We need indeed to check for 'is not None' explicitly in here because # this value might explicitly be set to False which would otherwise # evaluate to the second term instead. visibility = (show if show is not None else not command_widgets[0].isVisible()) for widget in command_widgets: widget.setVisible(visibility) self.view.adjustSize() self.settings["show_command_widgets"] = visibility model.save(self.settings)
def save_and_close_settings(self): """Update settings and close setting section.""" panel = self.view.settings_panel self.settings["tooltips"] = \ panel.check_tooltips.isChecked() self.settings["command_tooltips"] = \ panel.check_command_tooltips.isChecked() self.settings["auto_clear_command"] = \ panel.check_auto_clear_command.isChecked() self.settings["auto_close_script"] = \ panel.check_auto_close_script.isChecked() self.settings["auto_close_command"] = \ panel.check_auto_close_command.isChecked() self.settings["default_language_new_commands"] = \ panel.combo_lang_new_commands.currentText() self.settings["command_size"] = \ panel.combo_command_size.currentText() stack_root_temp = self.settings["stack_root"] self.settings["stack_root"] = panel.input_stack_root.text() self.settings = model.save(self.settings) self.toggle_settings() # Refresh the scripts table only when the stack root directory has # changed. Always refreshing is kind of an overkill. if stack_root_temp != self.settings["stack_root"]: self.scanner = scanner.Scanner(self.settings["stack_root"], self) self.setup_view_widgets(add_new_command=False) self.refresh() self.view.combo_stack.setCurrentIndex(0)
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)