def load_current_setting_values(self): self.view.prompt_save_on_close.setChecked( bool(CONF.get(self.PROMPT_SAVE_ON_CLOSE))) self.view.prompt_save_editor_modified.setChecked( bool(CONF.get(self.PROMPT_SAVE_EDITOR_MODIFIED))) self.view.prompt_deleting_workspaces.setChecked( bool(CONF.get(self.PROMPT_ON_DELETING_WORKSPACE))) # compare lower-case, because MantidPlot will save it as lower case, # but Python will have the bool's first letter capitalised pr_enabled = ("true" == ConfigService.getString( self.PR_RECOVERY_ENABLED).lower()) pr_time_between_recovery = int( ConfigService.getString(self.PR_TIME_BETWEEN_RECOVERY)) pr_number_checkpoints = int( ConfigService.getString(self.PR_NUMBER_OF_CHECKPOINTS)) use_notifications_setting = ("on" == ConfigService.getString( self.USE_NOTIFICATIONS).lower()) crystallography_convention = ( "Crystallography" == ConfigService.getString( self.CRYSTALLOGRAPY_CONV)) use_open_gl = ("on" == ConfigService.getString(self.OPENGL).lower()) self.view.project_recovery_enabled.setChecked(pr_enabled) self.view.time_between_recovery.setValue(pr_time_between_recovery) self.view.total_number_checkpoints.setValue(pr_number_checkpoints) self.view.use_notifications.setChecked(use_notifications_setting) self.view.crystallography_convention.setChecked( crystallography_convention) self.view.use_open_gl.setChecked(use_open_gl)
def __init__(self, parent, font=None): super(MultiFileEditor, self).__init__(parent) if not font: font = text_font() completion_enabled = True if CONF.has(ENABLE_COMPLETION_KEY): completion_enabled = CONF.get(ENABLE_COMPLETION_KEY) # layout self.editors = MultiPythonFileInterpreter( font=font, default_content=DEFAULT_SCRIPT_CONTENT, parent=self, completion_enabled=completion_enabled) layout = QVBoxLayout() layout.addWidget(self.editors) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.setAcceptDrops(True) # attributes self.tabs_open_on_closing = None self.editors_zoom_level = None
def action_font_selected(self, font): font_string = "" if CONF.has(GeneralProperties.FONT.value): font_string = CONF.get(GeneralProperties.FONT.value) if font_string != font.toString(): CONF.set(GeneralProperties.FONT.value, font.toString()) if self.settings_presenter is not None: self.settings_presenter.register_change_needs_restart("Main Font Selection")
def action_main_font_button_clicked(self): font = None if CONF.has(GeneralProperties.FONT.value): font_string = CONF.get(GeneralProperties.FONT.value).split(',') if len(font_string) > 2: font = QFontDatabase().font(font_string[0], font_string[-1], int(font_string[1])) font_dialog = self.view.create_font_dialog(self.parent, font) font_dialog.fontSelected.connect(self.action_font_selected)
def save_settings_to_file(filepath, settings): with open(filepath, 'w') as file: for setting in settings: if CONF.has(setting): if setting != GeneralProperties.USER_LAYOUT.value: value = CONF.get(setting, type=str) else: value = ConfigService.getString(setting) file.write(setting + '=' + str(value) + '\n')
def save_layout(self): filename = self.view.new_layout_name.text() if filename != "": layout_dict = self.get_layout_dict() layout_dict[filename] = self.parent.saveState() CONF.set(self.USER_LAYOUT, layout_dict) self.view.new_layout_name.clear() self.fill_layout_display() self.parent.populate_layout_menu()
def delete_layout(self): item = self.view.layout_display.currentItem() if hasattr(item, "text"): layout = item.text() layout_dict = self.get_layout_dict() layout_dict.pop(layout, None) CONF.set(GeneralProperties.USER_LAYOUT.value, layout_dict) self.fill_layout_display() self.parent.populate_layout_menu()
def save_layout(self): filename = self.view.new_layout_name.text() if filename != "": layout_dict = self.get_layout_dict() layout_dict[filename] = self.parent.saveState(SAVE_STATE_VERSION) CONF.set(GeneralProperties.USER_LAYOUT.value, layout_dict) self.view.new_layout_name.clear() self.fill_layout_display() self.parent.populate_layout_menu()
def load_current_setting_values(self): self.view.prompt_save_on_close.setChecked(CONF.get(self.PROMPT_SAVE_ON_CLOSE)) self.view.prompt_save_editor_modified.setChecked(CONF.get(self.PROMPT_SAVE_EDITOR_MODIFIED)) # compare lower-case, because MantidPlot will save it as lower case, # but Python will have the bool's first letter capitalised pr_enabled = ("true" == ConfigService.getString(self.PR_RECOVERY_ENABLED).lower()) pr_time_between_recovery = int(ConfigService.getString(self.PR_TIME_BETWEEN_RECOVERY)) pr_number_checkpoints = int(ConfigService.getString(self.PR_NUMBER_OF_CHECKPOINTS)) self.view.project_recovery_enabled.setChecked(pr_enabled) self.view.time_between_recovery.setValue(pr_time_between_recovery) self.view.total_number_checkpoints.setValue(pr_number_checkpoints)
def get_layout_dict(self): try: layout_list = CONF.get(GeneralProperties.USER_LAYOUT.value, type=dict) except (KeyError, TypeError): layout_list = {} return layout_list
def setup_general_group(self): self.view.window_behaviour.addItems(self.WINDOW_BEHAVIOUR) window_behaviour = CONF.get(GeneralProperties.WINDOW_BEHAVIOUR.value) if window_behaviour in self.WINDOW_BEHAVIOUR: self.view.window_behaviour.setCurrentIndex(self.view.window_behaviour.findText(window_behaviour)) self.view.window_behaviour.currentTextChanged.connect(self.action_window_behaviour_changed) self.view.main_font.clicked.connect(self.action_main_font_button_clicked)
def load_current_setting_values(self): self.view.prompt_save_on_close.setChecked( CONF.get(self.PROMPT_SAVE_ON_CLOSE)) self.view.prompt_save_editor_modified.setChecked( CONF.get(self.PROMPT_SAVE_EDITOR_MODIFIED)) # compare lower-case, because MantidPlot will save it as lower case, # but Python will have the bool's first letter capitalised pr_enabled = ("true" == ConfigService.getString( self.PR_RECOVERY_ENABLED).lower()) pr_time_between_recovery = int( ConfigService.getString(self.PR_TIME_BETWEEN_RECOVERY)) pr_number_checkpoints = int( ConfigService.getString(self.PR_NUMBER_OF_CHECKPOINTS)) self.view.project_recovery_enabled.setChecked(pr_enabled) self.view.time_between_recovery.setValue(pr_time_between_recovery) self.view.total_number_checkpoints.setValue(pr_number_checkpoints)
def load_settings_from_file(filepath, settings): with open(filepath, 'r') as file: line = file.readline() while line: setting = line.rstrip('\n').split('=', 1) prop = setting[0].strip() if prop in settings: if CONF.has(prop) or prop.find('/') != -1: if prop == GeneralProperties.USER_LAYOUT.value: pass elif prop == GeneralProperties.FONT.value and not setting[1]: # if the font setting is empty removing it will make workbench use the default CONF.remove(prop) else: try: value = ast.literal_eval(setting[1]) except (SyntaxError, ValueError): value = setting[1] CONF.set(setting[0].strip(), value) else: ConfigService.setString(prop, setting[1]) line = file.readline()
def _get_scripts_from_settings(): scripts = [] try: scripts = CONF.get(RECENT_SCRIPTS_KEY) except KeyError: # Happens quite often and should fail silently. pass except TypeError: # Happens when garbage data is found in the QSettings .ini file logger.error( "Recently Opened Scripts were lost during save, and workbench has recovered from an error." ) CONF.set(RECENT_SCRIPTS_KEY, []) def sort_key(sub_list): return sub_list[0] scripts.sort(key=sort_key) # strip scripts of it's extra data and overwrite the list for index, script in enumerate(scripts): scripts[index] = script[1] return scripts
def populate_layout_menu(self): self.view_menu_layouts.clear() try: layout_dict = CONF.get("MainWindow/user_layouts") except KeyError: layout_dict = {} layout_keys = sorted(layout_dict.keys()) layout_options = [] for item in layout_keys: layout_options.append(self.create_load_layout_action(item, layout_dict[item])) layout_options.append(None) action_settings = create_action( self, "Settings", on_triggered=self.open_settings_layout_window) layout_options.append(action_settings) add_actions(self.view_menu_layouts, layout_options)
def _get_scripts_from_settings(): scripts = [] try: scripts = CONF.get(RECENT_SCRIPTS_KEY) except KeyError: # Happens quite often and should fail silently. pass def sort_key(sub_list): return sub_list[0] scripts.sort(key=sort_key) # strip scripts of it's extra data and overwrite the list for index, script in enumerate(scripts): scripts[index] = script[1] return scripts
def action_prompt_deleting_workspace(self, state): CONF.set(GeneralProperties.PROMPT_ON_DELETING_WORKSPACE.value, bool(state)) if self.settings_presenter is not None: self.settings_presenter.register_change_needs_restart( "Prompt when deleting workspaces")
def action_prompt_save_editor_modified(self, state): CONF.set(GeneralProperties.PROMPT_SAVE_EDITOR_MODIFIED.value, bool(state))
def action_prompt_save_on_close(self, state): CONF.set(GeneralProperties.PROMPT_SAVE_ON_CLOSE.value, bool(state))
def action_completion_enabled_modified(self, state): CONF.set(GeneralProperties.COMPLETION_ENABLED.value, bool(state))
def action_window_behaviour_changed(self, text): CONF.set(GeneralProperties.WINDOW_BEHAVIOUR.value, text)
def get_layout_dict(self): try: layout_list = CONF.get(GeneralProperties.USER_LAYOUT.value) except KeyError: layout_list = {} return layout_list
def action_prompt_deleting_workspace(self, state): CONF.set(GeneralProperties.PROMPT_ON_DELETING_WORKSPACE.value, bool(state))
def action_prompt_save_editor_modified(self, state): CONF.set(self.PROMPT_SAVE_EDITOR_MODIFIED, bool(state))
def get_layout_dict(self): try: layout_list = CONF.get(self.USER_LAYOUT) except KeyError: layout_list = {} return layout_list
def action_prompt_deleting_workspace(self, state): CONF.set(self.PROMPT_ON_DELETING_WORKSPACE, bool(state))
def action_font_selected(self, font): CONF.set(GeneralProperties.FONT.value, font.toString())
def action_prompt_save_on_close(self, state): CONF.set(self.PROMPT_SAVE_ON_CLOSE, bool(state))
def action_font_selected(self, font): CONF.set(self.FONT, font.toString())
def _store_scripts_to_settings(scripts): # Add an index to a tuple in the script for index, script in enumerate(scripts): scripts[index] = (index, script) CONF.set(RECENT_SCRIPTS_KEY, scripts)
def setup(self): # menus must be done first so they can be filled by the # plugins in register_plugin self.create_menus() # widgets # Log message display must be imported first self.set_splash("Loading message display") from workbench.plugins.logmessagedisplay import LogMessageDisplay self.messagedisplay = LogMessageDisplay(self) # this takes over stdout/stderr self.messagedisplay.register_plugin() self.widgets.append(self.messagedisplay) self.set_splash("Loading Algorithm Selector") from workbench.plugins.algorithmselectorwidget import AlgorithmSelector self.algorithm_selector = AlgorithmSelector(self) self.algorithm_selector.register_plugin() self.widgets.append(self.algorithm_selector) self.set_splash("Loading Plot Selector") from workbench.plugins.plotselectorwidget import PlotSelector self.plot_selector = PlotSelector(self) self.plot_selector.register_plugin() self.widgets.append(self.plot_selector) self.set_splash("Loading code editing widget") from workbench.plugins.editor import MultiFileEditor self.editor = MultiFileEditor(self) self.messagedisplay.display.setActiveScript( self.editor.editors.current_tab_filename) self.editor.register_plugin() self.widgets.append(self.editor) self.editor.editors.sig_code_exec_start.connect( self.messagedisplay.script_executing) self.editor.editors.sig_file_name_changed.connect( self.messagedisplay.file_name_modified) self.editor.editors.sig_current_tab_changed.connect( self.messagedisplay.current_tab_changed) self.set_splash("Loading IPython console") from workbench.plugins.jupyterconsole import JupyterConsole self.ipythonconsole = JupyterConsole(self) self.ipythonconsole.register_plugin() self.widgets.append(self.ipythonconsole) from workbench.plugins.workspacewidget import WorkspaceWidget self.workspacewidget = WorkspaceWidget(self) self.workspacewidget.register_plugin() prompt = CONF.get('project/prompt_on_deleting_workspace') self.workspacewidget.workspacewidget.enableDeletePrompt(bool(prompt)) self.widgets.append(self.workspacewidget) # set the link between the algorithm and workspace widget self.algorithm_selector.algorithm_selector.set_get_selected_workspace_fn( self.workspacewidget.workspacewidget.getSelectedWorkspaceNames) # Set up the project, recovery and interface manager objects self.project = Project(GlobalFigureManager, find_all_windows_that_are_savable) self.project_recovery = ProjectRecovery( globalfiguremanager=GlobalFigureManager, multifileinterpreter=self.editor.editors, main_window=self) self.interface_executor = PythonCodeExecution() self.interface_executor.sig_exec_error.connect( lambda errobj: logger.warning(str(errobj))) self.interface_manager = InterfaceManager() # uses default configuration as necessary self.setup_default_layouts() self.create_actions() self.readSettings(CONF) self.config_updated()