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 != config.get_config("cfg_ver"): self.set_layout() self.cfg_ver = config.get_config("cfg_ver") QsciScintilla.focusInEvent(self, e)
def build(self, dummy=None): """ Populate the toolbar with items (core and plugins) Keywords arguments: dummy -- a dummy argument (default=None) """ # Only do something if the main_window has been attached if self.main_window == None: return # Remove old items self.clear() if self.orientation() == QtCore.Qt.Vertical: self.addWidget(toolbar_label("<small>Commonly used</small>")) # Add the core items content = [] for item in self.main_window.experiment.core_items: content.append(widget_item(self.main_window.theme.qpixmap(item, \ size=config.get_config("toolbar_size")), item, \ self.main_window)) self.add_content(content) # Create a dictionary of plugins by category. We also maintain a list # to preserve the order of the categories. cat_list = [] cat_dict = {} for plugin in libopensesame.plugins.list_plugins(): cat = libopensesame.plugins.plugin_category(plugin) if cat not in cat_dict: cat_dict[cat] = [] cat_list.append(cat) cat_dict[cat].append(plugin) # Add the plugins for cat in cat_list: self.addSeparator() if self.orientation() == QtCore.Qt.Vertical: self.addWidget(toolbar_label("<small>%s</small>" % cat)) content = [] for plugin in cat_dict[cat]: debug.msg("adding plugin '%s'" % plugin) if config.get_config("toolbar_size") == 16: pixmap = QtGui.QPixmap( \ libopensesame.plugins.plugin_icon_small(plugin)) else: pixmap = QtGui.QPixmap( \ libopensesame.plugins.plugin_icon_large(plugin)) content.append(widget_item(pixmap, plugin, self.main_window)) self.add_content(content)
def toggle_onetabmode(self): """Toggles onetabmode""" config.set_config(u"onetabmode", \ self.main_window.ui.action_onetabmode.isChecked()) if config.get_config(u"onetabmode"): self.close_other() self.setTabsClosable(not config.get_config(u"onetabmode")) self.main_window.ui.action_close_other_tabs.setEnabled(not \ config.get_config(u"onetabmode"))
def get_logfile(self, quick=False, subject_nr=0): """ Gets the logfile for the current session, either by falling back to a default value ('quickrun.csv') or through a pop-up dialogue. Keyword arguments: quick -- Indicates whether we are quickrunning the experiment. (default=False) subject_nr -- Indicates the subject number, which is used to suggest a logfile. (default=0) Returns: A pathname for the logfile or None if no logfile was chosen (i.e. the dialogue was cancelled). """ if quick: logfile = os.path.join(config.get_config( \ u'default_logfile_folder'), config.get_config( \ u'quick_run_logfile')) else: # Suggested filename suggested_path = os.path.join(config.get_config( \ u'default_logfile_folder'), u'subject-%d.csv' % subject_nr) # Get the data file csv_filter = u'Comma-separated values (*.csv)' logfile = unicode(QtGui.QFileDialog.getSaveFileName( \ self.main_window.ui.centralwidget, \ _(u"Choose location for logfile (press 'escape' for default location)"), \ suggested_path, filter=csv_filter)) # An empty string indicates that the dialogue was cancelled, in # which case we fall back to a default location. if logfile == u'': logfile = os.path.join(config.get_config( \ 'default_logfile_folder'), u'defaultlog.csv') # If a logfile was provided, but it did not have a proper extension, # we add a `.csv` extension. else: if os.path.splitext(logfile)[1].lower() not in \ self.valid_logfile_extensions: logfile += self.default_logfile_extension # If the logfile is not writable, inform the user and cancel. try: open(logfile, u'w').close() except: self.main_window.experiment.notify( \ _(u"The logfile '%s' is not writable. Please choose another location for the logfile.") \ % logfile) return None # Remember the logfile folder for the next run # Remember the location of the logfile config.set_config('default_logfile_folder', os.path.dirname(logfile)) return logfile
def __init__(self, main_window, theme=None): """ Constructor Arguments: main_window -- the main_window object Keyword arguments: theme -- the theme to be used or None to use config (default=None) """ self.main_window = main_window if theme == None: self.theme = config.get_config(u"theme") else: self.theme = theme self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) debug.msg(u"theme = '%s' (%s)" % (self.theme, self.theme_folder)) if self.theme_folder == None or not os.path.exists(self.theme_folder): debug.msg(u"theme '%s' does not exist, using 'default'" % theme, \ reason=u"warning") self.theme = u"default" self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) self.theme_info = os.path.join(self.theme_folder, u"__theme__.py") if os.path.exists(self.theme_info): info = imp.load_source(self.theme, self.theme_info) self._qss = path = \ open(os.path.join(self.theme_folder, info.qss)).read() self._icon_map = info.icon_map self._icon_theme = info.icon_theme self.load_icon_map() self.apply_theme(self.main_window)
def toggle_onetabmode(self): """Toggles onetabmode""" config.set_config(u"onetabmode", self.main_window.ui.action_onetabmode.isChecked()) if config.get_config(u"onetabmode"): self.close_other() self.tabBar().setVisible(False) else: self.tabBar().setVisible(True) self.setTabsClosable(not config.get_config(u"onetabmode")) self.main_window.ui.action_close_all_tabs.setEnabled( not config.get_config(u"onetabmode")) self.main_window.ui.action_close_current_tab.setEnabled( not config.get_config(u"onetabmode")) self.main_window.ui.action_close_other_tabs.setEnabled( not config.get_config(u"onetabmode"))
def apply(self): """Apply the controls""" if self.lock: return self.lock = True debug.msg() self.experiment.auto_response = \ self.ui.checkbox_autoresponse.isChecked() self.main_window.ui.action_enable_auto_response.setChecked( self.ui.checkbox_autoresponse.isChecked()) if self.ui.checkbox_toolbar_text.isChecked(): self.main_window.ui.toolbar_main.setToolButtonStyle( QtCore.Qt.ToolButtonTextUnderIcon) else: self.main_window.ui.toolbar_main.setToolButtonStyle( QtCore.Qt.ToolButtonIconOnly) old_size = config.get_config(u'toolbar_size') if self.ui.checkbox_small_toolbar.isChecked(): new_size = 16 else: new_size = 32 if old_size != new_size: config.set_config(u"toolbar_size", new_size) self.theme.set_toolbar_size(config.get_config("toolbar_size")) from libqtopensesame import runners for runner in runners.runner_list: if runner in self.ui.combobox_runner.currentText(): config.set_config(u'runner', runner) config.set_config(u'theme', unicode(self.ui.combobox_theme.currentText())) config.set_config(u'style', unicode(self.ui.combobox_style.currentText())) self.main_window.save_state() self.lock = False
def set_controls(self): """ desc: Updates the controls. """ if self.lock: return self.lock = True debug.msg() self.ui.checkbox_autoresponse.setChecked( self.experiment.auto_response) self.ui.checkbox_toolbar_text.setChecked( self.main_window.ui.toolbar_main.toolButtonStyle() == \ QtCore.Qt.ToolButtonTextUnderIcon) self.ui.checkbox_small_toolbar.setChecked( config.get_config(u"toolbar_size") == 16) self.ui.combobox_runner.setCurrentIndex( self.ui.combobox_runner.findText(config.get_config(u'runner'), flags=QtCore.Qt.MatchContains)) # Set the style combobox i = 0 if config.get_config(u'style') == u'': self.ui.combobox_style.addItem(u"[Default]") self.ui.combobox_style.setCurrentIndex(i) i += 1 for style in QtGui.QStyleFactory.keys(): self.ui.combobox_style.addItem(style) if config.get_config(u'style') == unicode(style): self.ui.combobox_style.setCurrentIndex(i) i += 1 # Set the theme combobox i = 0 for _theme in theme.available_themes: self.ui.combobox_theme.addItem(_theme) if config.get_config(u'theme') == _theme: self.ui.combobox_theme.setCurrentIndex(i) i += 1 self.lock = False
def index_changed(self, index): """ Monitors tab index changes, closing other tabs if onetabmode is enabled Arguments: index -- the index of the new tab """ if config.get_config(u"onetabmode"): self.close_other() w = self.currentWidget() if hasattr(w, u'on_activate'): w.on_activate()
def set_controls(self): """ desc: Updates the controls. """ if self.lock: return self.lock = True debug.msg() self.ui.checkbox_autoresponse.setChecked(self.experiment.auto_response) self.ui.checkbox_toolbar_text.setChecked( self.main_window.ui.toolbar_main.toolButtonStyle() == \ QtCore.Qt.ToolButtonTextUnderIcon) self.ui.checkbox_small_toolbar.setChecked( config.get_config(u"toolbar_size") == 16) self.ui.combobox_runner.setCurrentIndex( self.ui.combobox_runner.findText(config.get_config(u'runner'), flags=QtCore.Qt.MatchContains)) # Set the style combobox i = 0 if config.get_config(u'style') == u'': self.ui.combobox_style.addItem(u"[Default]") self.ui.combobox_style.setCurrentIndex(i) i += 1 for style in QtGui.QStyleFactory.keys(): self.ui.combobox_style.addItem(style) if config.get_config(u'style') == unicode(style): self.ui.combobox_style.setCurrentIndex(i) i += 1 # Set the theme combobox i = 0 for _theme in theme.available_themes: self.ui.combobox_theme.addItem(_theme) if config.get_config(u'theme') == _theme: self.ui.combobox_theme.setCurrentIndex(i) i += 1 self.lock = False
def apply(self): """Apply the controls""" if self.lock: return self.lock = True self.experiment.auto_response = \ self.ui.checkbox_autoresponse.isChecked() self.main_window.ui.action_enable_auto_response.setChecked( self.ui.checkbox_autoresponse.isChecked()) if self.ui.checkbox_toolbar_text.isChecked(): self.main_window.ui.toolbar_main.setToolButtonStyle( QtCore.Qt.ToolButtonTextUnderIcon) else: self.main_window.ui.toolbar_main.setToolButtonStyle( QtCore.Qt.ToolButtonIconOnly) old_size = config.get_config(u'toolbar_size') if self.ui.checkbox_small_toolbar.isChecked(): new_size = 16 else: new_size = 32 if old_size != new_size: config.set_config(u"toolbar_size", new_size) self.theme.set_toolbar_size(config.get_config("toolbar_size")) from libqtopensesame import runners for runner in runners.runner_list: if runner in self.ui.combobox_runner.currentText(): config.set_config(u'runner', runner) config.set_config(u'theme', str(self.ui.combobox_theme.currentText())) config.set_config(u'style', str(self.ui.combobox_style.currentText())) self.main_window.save_state() self.lock = False
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. """ from libqtopensesame.misc import config return plugin in config.get_config(u'disabled_plugins').split(u';')
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 = config.get_config("cfg_ver") self.setUtf8(True)
def plugin_disabled(plugin, _type=u'plugins'): """ 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. """ from libqtopensesame.misc import config if plugin_property(plugin, u'disabled', _type=_type): return True if plugin in config.get_config(u'disabled_%s' % _type).split(u';'): return True return False
def __init__(self, main_window, theme=None): """ Constructor Arguments: main_window -- the main_window object Keyword arguments: theme -- the theme to be used or None to use config (default=None) """ self.main_window = main_window self.fallback_icon = QtGui.QIcon( os.path.join(misc.resource(u"theme"), u"fallback.png")) if theme is None: self.theme = config.get_config(u"theme") else: self.theme = theme self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) debug.msg(u"theme = '%s' (%s)" % (self.theme, self.theme_folder)) # The theme folder must exist, and contain a file called __theme__.py, # if not, we fall back to the default theme, which is assumed to always # exist. if self.theme_folder is None or not os.path.exists( os.path.join(self.theme_folder, u'__theme__.py')): debug.msg(u"theme '%s' does not exist, using 'default'" % theme, \ reason=u"warning") self.theme = u"default" self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) self.theme_info = os.path.join(self.theme_folder, u"__theme__.py") if os.path.exists(self.theme_info): info = imp.load_source( self.theme, safe_str(self.theme_info, enc=misc.filesystem_encoding())) with safe_open(os.path.join(self.theme_folder, info.qss)) as fd: self._qss = fd.read() self._icon_map = info.icon_map self._icon_theme = info.icon_theme self.load_icon_map() self.apply_theme(self.main_window)
def __init__(self, main_window, theme=None): """ Constructor Arguments: main_window -- the main_window object Keyword arguments: theme -- the theme to be used or None to use config (default=None) """ self.main_window = main_window self.fallback_icon = QtGui.QIcon(os.path.join(misc.resource(u"theme"), u"fallback.png")) if theme is None: self.theme = config.get_config(u"theme") else: self.theme = theme self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) debug.msg(u"theme = '%s' (%s)" % (self.theme, self.theme_folder)) # The theme folder must exist, and contain a file called __theme__.py, # if not, we fall back to the default theme, which is assumed to always # exist. if self.theme_folder is None or not os.path.exists( os.path.join(self.theme_folder, u'__theme__.py')): debug.msg(u"theme '%s' does not exist, using 'default'" % theme, \ reason=u"warning") self.theme = u"default" self.theme_folder = misc.resource(os.path.join(u"theme", \ self.theme)) self.theme_info = os.path.join(self.theme_folder, u"__theme__.py") if os.path.exists(self.theme_info): info = imp.load_source(self.theme, safe_str(self.theme_info, enc=misc.filesystem_encoding())) with open(os.path.join(self.theme_folder, info.qss)) as fd: self._qss = fd.read() self._icon_map = info.icon_map self._icon_theme = info.icon_theme self.load_icon_map() self.apply_theme(self.main_window)
def plugin_disabled(plugin, _type=u'plugins'): """ 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. """ from libqtopensesame.misc import config if plugin_property(plugin, u'disabled', _type=_type): return True # Check if disabled_plugins is not empty in which case it is a # QPyNullVariant which does not have split() method disabled_plugins = config.get_config(u'disabled_%s' % _type) if hasattr(disabled_plugins, u"split") and plugin in disabled_plugins.split(u';'): return True return False
def open_twitter(self, dummy=None): """Open Twitter page""" misc.open_url(config.get_config("url_twitter"))
def open_facebook(self, dummy=None): """Open Facebook page""" misc.open_url(config.get_config("url_facebook"))
def open_website(self, dummy=None): """Open the main website""" misc.open_url(config.get_config("url_website"))
def set_controls(self): """Update the controls""" if self.lock: return self.lock = True debug.msg() 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_small_toolbar.setChecked( \ config.get_config("toolbar_size") == 16) 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
def set_controls(self): """Update the controls""" if self.lock: return self.lock = True debug.msg() self.ui.checkbox_immediately_rename.setChecked( \ config.get_config('immediate_rename')) self.ui.checkbox_autoresponse.setChecked( \ self.main_window.experiment.auto_response) self.ui.checkbox_toolbar_text.setChecked( \ self.main_window.ui.toolbar_main.toolButtonStyle() == \ QtCore.Qt.ToolButtonTextUnderIcon) self.ui.checkbox_small_toolbar.setChecked( \ config.get_config("toolbar_size") == 16) self.ui.checkbox_enable_autosave.setChecked( \ config.get_config('autosave_interval') > 0) self.ui.spinbox_autosave_interval.setValue( \ config.get_config('autosave_interval') / 60000) # Show in minutes self.ui.spinbox_autosave_max_age.setValue( \ config.get_config('autosave_max_age')) self.ui.checkbox_auto_update_check.setChecked(config.get_config( \ 'auto_update_check')) self.ui.checkbox_opensesamerun.setChecked( \ config.get_config('opensesamerun')) self.ui.checkbox_auto_opensesamerun_exec.setChecked( \ config.get_config('opensesamerun_exec') == '') self.ui.edit_opensesamerun_exec.setText( \ config.get_config('opensesamerun_exec')) 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 config.get_config('autosave_interval') <= 0: self.ui.spinbox_autosave_interval.setDisabled(True) if not config.get_config('opensesamerun'): self.ui.checkbox_auto_opensesamerun_exec.setDisabled(True) self.ui.edit_opensesamerun_exec.setDisabled(True) self.ui.label_opensesamerun_exec.setDisabled(True) if config.get_config('opensesamerun_exec') == '': self.ui.edit_opensesamerun_exec.setDisabled(True) self.ui.label_opensesamerun_exec.setDisabled(True) # Set the style combobox i = 0 if config.get_config('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 config.get_config('style') == unicode(style): self.ui.combobox_style.setCurrentIndex(i) i += 1 # Set the theme combobox i = 0 for _theme in theme.available_themes: self.ui.combobox_theme.addItem(_theme) if config.get_config('theme') == _theme: self.ui.combobox_theme.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
def set_controls(self): """Updates the controls.""" if self.lock: return self.lock = True debug.msg() self.ui.checkbox_immediately_rename.setChecked( \ config.get_config(u'immediate_rename')) self.ui.checkbox_autoresponse.setChecked( \ self.main_window.experiment.auto_response) self.ui.checkbox_toolbar_text.setChecked( \ self.main_window.ui.toolbar_main.toolButtonStyle() == \ QtCore.Qt.ToolButtonTextUnderIcon) self.ui.checkbox_small_toolbar.setChecked( \ config.get_config(u"toolbar_size") == 16) self.ui.checkbox_enable_autosave.setChecked( \ config.get_config(u'autosave_interval') > 0) self.ui.spinbox_autosave_interval.setValue( \ config.get_config(u'autosave_interval') / 60000) # Show in minutes self.ui.spinbox_autosave_max_age.setValue( \ config.get_config(u'autosave_max_age')) self.ui.checkbox_auto_update_check.setChecked(config.get_config( \ u'auto_update_check')) self.ui.combobox_runner.setCurrentIndex( \ self.ui.combobox_runner.findText(config.get_config(u'runner'), \ flags=QtCore.Qt.MatchContains)) # Disable some of the controls, if they depend on other controls if config.get_config(u'autosave_interval') <= 0: self.ui.spinbox_autosave_interval.setDisabled(True) # Set the style combobox i = 0 if config.get_config(u'style') == u'': self.ui.combobox_style.addItem(u"[Default]") self.ui.combobox_style.setCurrentIndex(i) i += 1 for style in QtGui.QStyleFactory.keys(): self.ui.combobox_style.addItem(style) if config.get_config(u'style') == unicode(style): self.ui.combobox_style.setCurrentIndex(i) i += 1 # Set the theme combobox i = 0 for _theme in theme.available_themes: self.ui.combobox_theme.addItem(_theme) if config.get_config(u'theme') == _theme: self.ui.combobox_theme.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
def apply(self): """Apply the controls""" if self.lock: return self.lock = True debug.msg() config.set_config(u'immediate_rename', \ self.ui.checkbox_immediately_rename.isChecked()) self.main_window.experiment.auto_response = \ self.ui.checkbox_autoresponse.isChecked() self.main_window.ui.action_enable_auto_response.setChecked( \ self.ui.checkbox_autoresponse.isChecked()) if self.ui.checkbox_toolbar_text.isChecked(): self.main_window.ui.toolbar_main.setToolButtonStyle( \ QtCore.Qt.ToolButtonTextUnderIcon) else: self.main_window.ui.toolbar_main.setToolButtonStyle( \ QtCore.Qt.ToolButtonIconOnly) old_size = config.get_config(u'toolbar_size') if self.ui.checkbox_small_toolbar.isChecked(): new_size = 16 else: new_size = 32 if old_size != new_size: config.set_config(u"toolbar_size", new_size) self.main_window.theme.set_toolbar_size(config.get_config( \ "toolbar_size")) if self.ui.checkbox_enable_autosave.isChecked(): config.set_config(u'autosave_interval', 60000 * \ self.ui.spinbox_autosave_interval.value()) else: config.set_config(u'autosave_interval', 0) config.set_config(u'autosave_max_age', \ self.ui.spinbox_autosave_max_age.value()) self.main_window.start_autosave_timer() config.set_config(u'auto_update_check', \ self.ui.checkbox_auto_update_check.isChecked()) from libqtopensesame import runners for runner in runners.runner_list: if runner in self.ui.combobox_runner.currentText(): config.set_config(u'runner', runner) config.set_config(u'theme', unicode( \ self.ui.combobox_theme.currentText())) # Create a semicolon-separated list of disabled plugins l = [] for plugin in plugins.list_plugins(filter_disabled=False): if not self.checkbox_plugins[plugin].isChecked(): l.append(plugin) config.set_config(u"disabled_plugins", ";".join(l)) config.set_config(u'style', unicode( \ self.ui.combobox_style.currentText())) self.main_window.save_state() self.lock = False
def execute(self): """See base_runner.execute().""" import subprocess import tempfile try: # Temporary file for the standard output and experiment self.stdout = tempfile.mktemp(suffix=u".stdout") if self.experiment.experiment_path is None: raise osexception(u"Please save your experiment first, before running it using opensesamerun") self.path = os.path.join(self.experiment.experiment_path, ".opensesamerun-tmp.opensesame.tar.gz") self.experiment.save(self.path, True) debug.msg(u"experiment saved as '%s'" % self.path) # Determine the name of the executable if config.get_config(u"opensesamerun_exec") == u"": if os.name == u"nt": self.cmd = [u"opensesamerun.exe"] else: self.cmd = [u"opensesamerun"] else: self.cmd = config.get_config(u"opensesamerun_exec").split() self.cmd += [ self.path, u"--logfile=%s" % self.experiment.logfile, u"--subject=%s" % self.experiment.subject_nr, ] if debug.enabled: self.cmd.append(u"--debug") if self.experiment.fullscreen: self.cmd.append(u"--fullscreen") if u"--pylink" in sys.argv: self.cmd.append(u"--pylink") debug.msg(u"spawning opensesamerun as a separate process") # Call opensesamerun and wait for the process to complete try: p = subprocess.Popen(self.cmd, stdout=open(self.stdout, u"w")) except Exception as e: try: os.remove(self.path) os.remove(self.stdout) except: pass return e # Wait for OpenSesame run to complete, process events in the meantime, # to make sure that the new process is shown (otherwise it will crash # on Windows). retcode = None while retcode is None: retcode = p.poll() QtGui.QApplication.processEvents() time.sleep(1) debug.msg(u"opensesamerun returned %d" % retcode) print print(open(self.stdout, u"r").read()) print # Clean up the temporary file try: os.remove(self.path) os.remove(self.stdout) except: pass return None except Exception as e: return e
def apply(self): """Apply the controls""" if self.lock: return self.lock = True debug.msg() self.main_window.immediate_rename = self.ui.checkbox_immediately_rename.isChecked() self.main_window.show_startup_tip = self.ui.checkbox_show_random_tips.isChecked() self.main_window.experiment.auto_response = self.ui.checkbox_autoresponse.isChecked() self.main_window.ui.action_enable_auto_response.setChecked(self.ui.checkbox_autoresponse.isChecked()) if self.ui.checkbox_toolbar_text.isChecked(): self.main_window.ui.toolbar_main.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) else: self.main_window.ui.toolbar_main.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) if self.ui.checkbox_small_toolbar.isChecked(): config.set_config("toolbar_size", 16) else: config.set_config("toolbar_size", 32) self.main_window.theme.set_toolbar_size(config.get_config( \ "toolbar_size")) if self.ui.checkbox_enable_autosave.isChecked(): self.main_window.autosave_interval = 60000 * self.ui.spinbox_autosave_interval.value() else: self.main_window.autosave_interval = 0 self.main_window.autosave_max_age = self.ui.spinbox_autosave_max_age.value() self.main_window.start_autosave_timer() self.main_window.auto_check_update = self.ui.checkbox_auto_update_check.isChecked() self.main_window.opensesamerun = self.ui.checkbox_opensesamerun.isChecked() self.ui.edit_opensesamerun_exec.setEnabled(self.ui.checkbox_opensesamerun.isChecked() and not self.ui.checkbox_auto_opensesamerun_exec.isChecked()) self.ui.label_opensesamerun_exec.setEnabled(self.ui.checkbox_opensesamerun.isChecked() and not self.ui.checkbox_auto_opensesamerun_exec.isChecked()) if self.ui.checkbox_auto_opensesamerun_exec.isChecked(): self.main_window.opensesamerun_exec = "" self.ui.edit_opensesamerun_exec.setText("") else: if self.ui.edit_opensesamerun_exec.text() == "": if os.name == "nt": self.ui.edit_opensesamerun_exec.setText("opensesamerun.exe") else: self.ui.edit_opensesamerun_exec.setText("opensesamerun") self.main_window.opensesamerun_exec = str(self.ui.edit_opensesamerun_exec.text()) config.set_config("new_experiment_dialog", self.ui.checkbox_new_experiment_dialog.isChecked()) config.set_config("scintilla_auto_indent", self.ui.checkbox_scintilla_auto_indent.isChecked()) config.set_config("scintilla_brace_match", self.ui.checkbox_scintilla_brace_match.isChecked()) config.set_config("scintilla_custom_font", self.ui.checkbox_scintilla_custom_font.isChecked()) config.set_config("scintilla_eol_visible", self.ui.checkbox_scintilla_eol_visible.isChecked()) config.set_config("scintilla_folding", self.ui.checkbox_scintilla_folding.isChecked()) config.set_config("scintilla_indentation_guides", self.ui.checkbox_scintilla_indentation_guides.isChecked()) config.set_config("scintilla_line_numbers", self.ui.checkbox_scintilla_line_numbers.isChecked()) config.set_config("scintilla_right_margin", self.ui.checkbox_scintilla_right_margin.isChecked()) config.set_config("scintilla_syntax_highlighting", self.ui.checkbox_scintilla_syntax_highlighting.isChecked()) config.set_config("scintilla_whitespace_visible", self.ui.checkbox_scintilla_whitespace_visible.isChecked()) config.set_config("scintilla_font_family", str(self.ui.font_scintilla_font_family.currentFont().family())) config.set_config("scintilla_font_size", self.ui.spinbox_scintilla_font_size.value()) # Create a semicolon-separated list of disabled plugins l = [] for plugin in plugins.list_plugins(filter_disabled=False): if not self.checkbox_plugins[plugin].isChecked(): l.append(plugin) config.set_config("disabled_plugins", ";".join(l)) self.main_window.style = self.ui.combobox_style.currentText() self.main_window.set_style() self.main_window.save_state() self.lock = False
def set_layout(self): """Initialize the editor layout""" if self._parent.experiment.debug: print "scintilla.set_layout(): resetting the scintilla layout" if config.get_config("scintilla_custom_font"): font_family = config.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 config.get_config("scintilla_custom_font"): font.setPointSize(config.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, config.get_config( \ "scintilla_line_numbers")) # Set the right margin self.setEdgeColumn(80) if config.get_config("scintilla_right_margin"): self.setEdgeMode(QsciScintilla.EdgeLine) else: self.setEdgeMode(QsciScintilla.EdgeNone) # Set EOL visibility self.setEolVisibility(config.get_config("scintilla_eol_visible")) # Set whitespace visibility if config.get_config("scintilla_whitespace_visible"): self.setWhitespaceVisibility(QsciScintilla.WsVisible) else: self.setWhitespaceVisibility(QsciScintilla.WsInvisible) # Set indentation guides self.setIndentationGuides(config.get_config( \ "scintilla_indentation_guides")) # Set auto indent self.setAutoIndent(config.get_config("scintilla_auto_indent")) # Set folding if config.get_config("scintilla_folding"): self.setFolding(QsciScintilla.BoxedTreeFoldStyle) else: self.setFolding(QsciScintilla.NoFoldStyle) # Set brace matching if config.get_config("scintilla_brace_match"): self.setBraceMatching(QsciScintilla.SloppyBraceMatch) else: self.setBraceMatching(QsciScintilla.NoBraceMatch) # Set syntax highlightinh if config.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 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 get_logfile(self, quick=False, subject_nr=0): """ Gets the logfile for the current session, either by falling back to a default value ('quickrun.csv') or through a pop-up dialogue. Keyword arguments: quick -- Indicates whether we are quickrunning the experiment. (default=False) subject_nr -- Indicates the subject number, which is used to suggest a logfile. (default=0) Returns: A pathname for the logfile or None if no logfile was chosen (i.e. the dialogue was cancelled). """ remember_logfile = True if quick: logfile = os.path.join(config.get_config( \ u'default_logfile_folder'), config.get_config( \ u'quick_run_logfile')) try: open(logfile, u'w').close() except: import tempfile from libopensesame import misc debug.msg(u'Failed to open %s' % logfile) logfile = os.path.join(tempfile.gettempdir().decode( misc.filesystem_encoding()), tempfile.gettempprefix() \ .decode(misc.filesystem_encoding())+u'quickrun.csv') debug.msg(u'Using temporary file %s' % logfile) remember_logfile = False else: # Suggested filename suggested_path = os.path.join(config.get_config( \ u'default_logfile_folder'), u'subject-%d.csv' % subject_nr) # Get the data file csv_filter = u'Comma-separated values (*.csv)' logfile = unicode(QtGui.QFileDialog.getSaveFileName( \ self.main_window.ui.centralwidget, \ _(u"Choose location for logfile (press 'escape' for default location)"), \ suggested_path, filter=csv_filter)) # An empty string indicates that the dialogue was cancelled, in # which case we fall back to a default location. if logfile == u'': logfile = os.path.join(config.get_config( \ 'default_logfile_folder'), u'defaultlog.csv') # If a logfile was provided, but it did not have a proper extension, # we add a `.csv` extension. else: if os.path.splitext(logfile)[1].lower() not in \ self.valid_logfile_extensions: logfile += self.default_logfile_extension # If the logfile is not writable, inform the user and cancel. try: open(logfile, u'w').close() except: self.main_window.experiment.notify( \ _(u"The logfile '%s' is not writable. Please choose another location for the logfile.") \ % logfile) return None if remember_logfile: # Remember the logfile folder for the next run config.set_config('default_logfile_folder', os.path.dirname(logfile)) return logfile
def get_logfile(self, quick=False, subject_nr=0): """ Gets the logfile for the current session, either by falling back to a default value ('quickrun.csv') or through a pop-up dialogue. Keyword arguments: quick -- Indicates whether we are quickrunning the experiment. (default=False) subject_nr -- Indicates the subject number, which is used to suggest a logfile. (default=0) Returns: A pathname for the logfile or None if no logfile was chosen (i.e. the dialogue was cancelled). """ remember_logfile = True if quick: logfile = os.path.join( config.get_config(u"default_logfile_folder"), config.get_config(u"quick_run_logfile") ) try: open(logfile, u"w").close() except: import tempfile from libopensesame import misc debug.msg(u"Failed to open %s" % logfile) logfile = os.path.join( tempfile.gettempdir().decode(misc.filesystem_encoding()), tempfile.gettempprefix().decode(misc.filesystem_encoding()) + u"quickrun.csv", ) debug.msg(u"Using temporary file %s" % logfile) remember_logfile = False else: # Suggested filename suggested_path = os.path.join(config.get_config(u"default_logfile_folder"), u"subject-%d.csv" % subject_nr) # Get the data file csv_filter = u"Comma-separated values (*.csv)" logfile = unicode( QtGui.QFileDialog.getSaveFileName( self.main_window.ui.centralwidget, _(u"Choose location for logfile (press 'escape' for default location)"), suggested_path, filter=csv_filter, ) ) # An empty string indicates that the dialogue was cancelled, in # which case we fall back to a default location. if logfile == u"": logfile = os.path.join(config.get_config("default_logfile_folder"), u"defaultlog.csv") # If a logfile was provided, but it did not have a proper extension, # we add a `.csv` extension. else: if os.path.splitext(logfile)[1].lower() not in self.valid_logfile_extensions: logfile += self.default_logfile_extension # If the logfile is not writable, inform the user and cancel. try: open(logfile, u"w").close() except: self.main_window.experiment.notify( _(u"The logfile '%s' is not writable. Please choose another location for the logfile.") % logfile ) return None if remember_logfile: # Remember the logfile folder for the next run config.set_config("default_logfile_folder", os.path.dirname(logfile)) return logfile
def execute(self): """See base_runner.execute().""" import subprocess import tempfile try: # Temporary file for the standard output and experiment self.stdout = tempfile.mktemp(suffix=u".stdout") if self.experiment.experiment_path is None: raise osexception( \ u"Please save your experiment first, before running it using opensesamerun") self.path = os.path.join(self.experiment.experiment_path, \ '.opensesamerun-tmp.opensesame.tar.gz') self.experiment.save(self.path, True) debug.msg(u"experiment saved as '%s'" % self.path) # Determine the name of the executable if config.get_config(u'opensesamerun_exec') == u'': if os.name == u"nt": self.cmd = [u"opensesamerun.exe"] else: self.cmd = [u"opensesamerun"] else: self.cmd = config.get_config(u'opensesamerun_exec').split() self.cmd += [self.path, u"--logfile=%s" % self.experiment.logfile, \ u"--subject=%s" % self.experiment.subject_nr] if debug.enabled: self.cmd.append(u"--debug") if self.experiment.fullscreen: self.cmd.append(u"--fullscreen") if u"--pylink" in sys.argv: self.cmd.append(u"--pylink") debug.msg(u"spawning opensesamerun as a separate process") # Call opensesamerun and wait for the process to complete try: p = subprocess.Popen(self.cmd, stdout=open(self.stdout, u"w")) except Exception as e: try: os.remove(self.path) os.remove(self.stdout) except: pass return e # Wait for OpenSesame run to complete, process events in the meantime, # to make sure that the new process is shown (otherwise it will crash # on Windows). retcode = None while retcode == None: retcode = p.poll() QtGui.QApplication.processEvents() time.sleep(1) debug.msg(u"opensesamerun returned %d" % retcode) print print open(self.stdout, u"r").read() print # Clean up the temporary file try: os.remove(self.path) os.remove(self.stdout) except: pass return None except Exception as e: return e