def focusInEvent(self, e): """Refresh the layout on a focus in event""" # Only update the layout if the config is outdated if self.cfg_ver != get_config("cfg_ver"): self.set_layout() self.cfg_ver = get_config("cfg_ver") QsciScintilla.focusInEvent(self, e)
def plugin_disabled(plugin): """ Checks if a plugin has been disabled. If the config module cannot be loaded the return value is False. Arguments: plugin -- the plugin to check Returns: True if the plugin has been disabled, False otherwise """ try: from libqtopensesame import config return plugin in config.get_config("disabled_plugins").split(";") except: return False
def __init__(self, parent=None, syntax=None): """ Constructor Keywords arguments: parent -- parent QWidget syntax -- the syntax highlighter 'python', 'opensesame' or None (default=None) """ self._parent = parent QsciScintilla.__init__(self, parent) self.syntax = syntax self.textChanged.connect(self.parent().setModified) self.refresh_layout = True self.cfg_ver = get_config("cfg_ver") self.setUtf8(True)
def set_layout(self): """Initialize the editor layout""" if self._parent.experiment.debug: print "scintilla.set_layout(): resetting the scintilla layout" if get_config("scintilla_custom_font"): font_family = get_config("scintilla_font_family") elif os.name == "posix": font_family = "mono" else: font_family = "courier" font = QtGui.QFont(font_family) font.setFixedPitch(True) if get_config("scintilla_custom_font"): font.setPointSize(get_config("scintilla_font_size")) fm = QtGui.QFontMetrics(font) self.setFont(font) self.setMarginsFont(font) self.setTabWidth(4) # Set line numbers self.setMarginWidth(0, fm.width( "0000" )) self.setMarginLineNumbers(0, get_config("scintilla_line_numbers")) # Set the right margin self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) # Disable scrollbar self.setEdgeColumn(80) if get_config("scintilla_right_margin"): self.setEdgeMode(QsciScintilla.EdgeLine) else: self.setEdgeMode(QsciScintilla.EdgeNone) # Set EOL visibility self.setEolVisibility(get_config("scintilla_eol_visible")) # Set whitespace visibility if get_config("scintilla_whitespace_visible"): self.setWhitespaceVisibility(QsciScintilla.WsVisible) else: self.setWhitespaceVisibility(QsciScintilla.WsInvisible) # Set indentation guides self.setIndentationGuides(get_config("scintilla_indentation_guides")) # Set auto indent self.setAutoIndent(get_config("scintilla_auto_indent")) # Set folding if get_config("scintilla_folding"): self.setFolding(QsciScintilla.BoxedTreeFoldStyle) else: self.setFolding(QsciScintilla.NoFoldStyle) # Set brace matching if get_config("scintilla_brace_match"): self.setBraceMatching(QsciScintilla.SloppyBraceMatch) else: self.setBraceMatching(QsciScintilla.NoBraceMatch) # Set syntax highlightinh if get_config("scintilla_syntax_highlighting") and (self.syntax == "python" or self.syntax == "opensesame"): self.setLexer(python_lexer(font)) for i in range(16): # There are 16 properties that need to be forced self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, i, font.family()) self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, i, font.pointSize()) else: self.setLexer(None) self.SendScintilla(QsciScintilla.SCI_CLEARDOCUMENTSTYLE)
def set_controls(self): """Update the controls""" if self.lock: return self.lock = True if self.main_window.experiment.debug: print "preferences_widget.set_controls(): setting controls" self.ui.checkbox_immediately_rename.setChecked(self.main_window.immediate_rename) self.ui.checkbox_autoresponse.setChecked(self.main_window.experiment.auto_response) self.ui.checkbox_show_random_tips.setChecked(self.main_window.show_startup_tip) self.ui.checkbox_toolbar_text.setChecked(self.main_window.ui.toolbar_main.toolButtonStyle() == QtCore.Qt.ToolButtonTextUnderIcon) self.ui.checkbox_enable_autosave.setChecked(self.main_window.autosave_interval > 0) self.ui.spinbox_autosave_interval.setValue(self.main_window.autosave_interval / 60000) # Show in minutes, not milliseconds self.ui.spinbox_autosave_max_age.setValue(self.main_window.autosave_max_age) self.ui.checkbox_auto_update_check.setChecked(self.main_window.auto_check_update) self.ui.checkbox_opensesamerun.setChecked(self.main_window.opensesamerun) self.ui.checkbox_auto_opensesamerun_exec.setChecked(self.main_window.opensesamerun_exec == "") self.ui.edit_opensesamerun_exec.setText(self.main_window.opensesamerun_exec) self.ui.checkbox_new_experiment_dialog.setChecked(config.get_config("new_experiment_dialog")) self.ui.checkbox_scintilla_auto_indent.setChecked(config.get_config("scintilla_auto_indent")) self.ui.checkbox_scintilla_brace_match.setChecked(config.get_config("scintilla_brace_match")) self.ui.checkbox_scintilla_custom_font.setChecked(config.get_config("scintilla_custom_font")) self.ui.checkbox_scintilla_eol_visible.setChecked(config.get_config("scintilla_eol_visible")) self.ui.checkbox_scintilla_folding.setChecked(config.get_config("scintilla_folding")) self.ui.checkbox_scintilla_indentation_guides.setChecked(config.get_config("scintilla_indentation_guides")) self.ui.checkbox_scintilla_line_numbers.setChecked(config.get_config("scintilla_line_numbers")) self.ui.checkbox_scintilla_right_margin.setChecked(config.get_config("scintilla_right_margin")) self.ui.checkbox_scintilla_auto_indent.setChecked(config.get_config("scintilla_auto_indent")) self.ui.checkbox_scintilla_syntax_highlighting.setChecked(config.get_config("scintilla_syntax_highlighting")) self.ui.checkbox_scintilla_whitespace_visible.setChecked(config.get_config("scintilla_whitespace_visible")) self.ui.font_scintilla_font_family.setCurrentFont(QtGui.QFont(config.get_config("scintilla_font_family"))) self.ui.spinbox_scintilla_font_size.setValue(config.get_config("scintilla_font_size")) # Disable some of the controls, if they depend on other controls if self.main_window.autosave_interval <= 0: self.ui.spinbox_autosave_interval.setDisabled(True) if not self.main_window.opensesamerun: self.ui.checkbox_auto_opensesamerun_exec.setDisabled(True) self.ui.edit_opensesamerun_exec.setDisabled(True) self.ui.label_opensesamerun_exec.setDisabled(True) if self.main_window.opensesamerun_exec == "": self.ui.edit_opensesamerun_exec.setDisabled(True) self.ui.label_opensesamerun_exec.setDisabled(True) i = 0 if self.main_window.style == "": self.ui.combobox_style.addItem("[Default]") self.ui.combobox_style.setCurrentIndex(i) i += 1 for style in QtGui.QStyleFactory.keys(): self.ui.combobox_style.addItem(style) if self.main_window.style == str(style): self.ui.combobox_style.setCurrentIndex(i) i += 1 # Set the plugin status for plugin in plugins.list_plugins(filter_disabled=False): self.checkbox_plugins[plugin].setChecked(not plugins.plugin_disabled(plugin)) self.lock = False