def add_editor_control(self, var, label, syntax=False, tooltip=None, \ default=None): """ Adds a texteditor control (an extended QPlainTextEdit) that is linked to a variable. Arguments: var -- Name of the associated variable. label -- Label text. Keyword arguments: syntax -- A boolean indicating whether Python syntax highlighting should be activated. (default=False) tooltip -- A tooltip text. (default=None) default -- DEPRECATED Returns: An inline_editor widget. """ label = QtGui.QLabel(label) if syntax: editor = inline_editor.inline_editor(self.experiment, \ syntax="python") else: editor = inline_editor.inline_editor(self.experiment) editor.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(editor.edit, QtCore.SIGNAL('focusLost'), \ self.apply_edit_changes) if var != None: self.auto_editor[var] = editor self.edit_vbox.addWidget(label) self.edit_vbox.addWidget(editor) return editor
def add_editor_control(self, var, label, syntax=False, tooltip=None, \ default=None): """ Adds a texteditor control (an extended QPlainTextEdit) Arguments: var -- name of the associated variable label -- a label Keyword arguments: syntax -- a boolean indicating whether Python syntax highlighting should be activated (default=False) tooltip -- a tooltip (default=None) default -- a default value (default=None) """ label = QtGui.QLabel(label) if syntax: editor = inline_editor.inline_editor(self.experiment, \ syntax="python") else: editor = inline_editor.inline_editor(self.experiment) editor.setText(str(self.get_check(var, ""))) editor.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(editor.edit, QtCore.SIGNAL("focusLost"), \ self.apply_edit_changes) if var != None: self.auto_editor[var] = editor self.edit_vbox.addWidget(label) self.edit_vbox.addWidget(editor)
def init_edit_widget(self): """Construct the GUI controls""" qtitem.qtitem.init_edit_widget(self, False) tabwidget_script = QtGui.QTabWidget(self._edit_widget) py_ver = "Python %d.%d.%d" % (sys.version_info[0], \ sys.version_info[1], sys.version_info[2]) # Construct prepare editor self.textedit_prepare = inline_editor.inline_editor(self.experiment, \ notification=py_ver, syntax="python") self.textedit_prepare.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_prepare.edit, QtCore.SIGNAL( \ "focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_prepare) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon("inline_script"), \ _("Prepare phase")) # Construct run editor self.textedit_run = inline_editor.inline_editor(self.experiment, \ notification=py_ver, syntax="python") self.textedit_run.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_run.edit, QtCore.SIGNAL( \ "focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_run) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon("inline_script"), \ _("Run phase")) # Switch to the run script by default, unless there is only content for # the prepare script. if self._run == "" and self._prepare != "": tabwidget_script.setCurrentIndex(0) else: tabwidget_script.setCurrentIndex(1) # Add the tabwidget to the controls self.edit_vbox.addWidget(tabwidget_script)
def init_edit_widget(self): """Constructs the GUI controls.""" qtitem.qtitem.init_edit_widget(self, False) tabwidget_script = QtGui.QTabWidget(self._edit_widget) py_ver = u'Python %d.%d.%d' % (sys.version_info[0], \ sys.version_info[1], sys.version_info[2]) # Construct prepare editor self.textedit_prepare = inline_editor.inline_editor(self.experiment, \ notification=py_ver, syntax=u'python') self.textedit_prepare.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_prepare.edit, QtCore.SIGNAL( \ "focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_prepare) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon( \ u'inline_script'), _(u'Prepare phase')) # Construct run editor self.textedit_run = inline_editor.inline_editor(self.experiment, \ notification=py_ver, syntax=u'python') self.textedit_run.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_run.edit, QtCore.SIGNAL( \ "focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_run) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon( \ u'inline_script'), _(u'Run phase')) # Switch to the run script by default, unless there is only content for # the prepare script. if self._run == u'' and self._prepare != u'': tabwidget_script.setCurrentIndex(0) else: tabwidget_script.setCurrentIndex(1) # Add all widgets to the edit_vbox self.edit_vbox.addWidget(tabwidget_script)
def __init__(self, main_window): """ Constructor Arguments: main_window -- the main window """ self.main_window = main_window QtGui.QWidget.__init__(self, main_window) self.ui = Ui_widget_general_script_editor() self.ui.setupUi(self) self.ui.edit = inline_editor(self.main_window.experiment) self.ui.edit.applied.connect(self._apply) self.ui.layout_vbox.addWidget(self.ui.edit) self.main_window.theme.apply_theme(self) self.tab_name = '__general_script__'
def init_script_widget(self): """Build the script tab""" self.edit_script = inline_editor.inline_editor( \ self.experiment, syntax="opensesame") script = "" for s in self.to_string().split("\n")[1:]: script += self.strip_script_line(s) self.edit_script.edit.setPlainText(script, set_modified=False) self.edit_script.apply.clicked.connect(self.apply_script_changes) QtCore.QObject.connect(self.edit_script.edit, QtCore.SIGNAL( \ "focusLost"), self.apply_script_changes) button = QtGui.QPushButton(self.experiment.icon("apply"), \ _("Apply and close")) button.setToolTip(_("Apply changes and resume normal editing")) button.setIconSize(QtCore.QSize(16, 16)) button.clicked.connect(self.apply_script_and_close) self.edit_script.toolbar_hbox.addWidget(button) button = QtGui.QPushButton(self.experiment.icon("close"), \ _("Forget changes and close")) button.setToolTip(_("Ignore changes and resume normal editing")) button.setIconSize(QtCore.QSize(16, 16)) button.clicked.connect(self.ignore_script_and_close) self.edit_script.toolbar_hbox.addWidget(button) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.experiment.label_image("%s" % self.item_type)) hbox.addWidget(QtGui.QLabel(_("Editing script for <b>%s</b> - %s") % \ (self.name, self.item_type))) hbox.addStretch() hbox.setContentsMargins(0,0,0,0) hwidget = QtGui.QWidget() hwidget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(hwidget) vbox.addWidget(self.edit_script) self._script_widget = QtGui.QWidget() self._script_widget.setLayout(vbox) self._script_widget.__script_item__ = self.name
def init_script_widget(self): """Build the script tab""" self.edit_script = inline_editor.inline_editor( \ self.experiment, syntax="opensesame") script = "" for s in self.to_string().split("\n")[1:]: script += self.strip_script_line(s) self.edit_script.edit.setPlainText(script, set_modified=False) self.edit_script.apply.clicked.connect(self.apply_script_changes) button = QtGui.QPushButton(self.experiment.icon("apply"), \ _("Apply and close")) button.setToolTip(_("Apply changes and resume normal editing")) button.setIconSize(QtCore.QSize(16, 16)) button.clicked.connect(self.apply_script_and_close) self.edit_script.toolbar_hbox.addWidget(button) button = QtGui.QPushButton(self.experiment.icon("close"), \ _("Forget changes and close")) button.setToolTip(_("Ignore changes and resume normal editing")) button.setIconSize(QtCore.QSize(16, 16)) button.clicked.connect(self.ignore_script_and_close) self.edit_script.toolbar_hbox.addWidget(button) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.experiment.label_image("%s" % self.item_type)) self.script_header = QtGui.QLabel() hbox.addWidget(self.script_header) hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hwidget = QtGui.QWidget() hwidget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(hwidget) vbox.addWidget(self.edit_script) self._script_widget = QtGui.QWidget() self._script_widget.setLayout(vbox) self._script_widget.__script_item__ = self.name
def __init__(self, parent=None): """ Constructor Keywords arguments: parent -- the parent QWidget """ self.main_window = parent QtGui.QWidget.__init__(self) # Set the header, with the icon, label and script button self.header_widget = general_header_widget(self.main_window.experiment) button_help = QtGui.QPushButton(self.main_window.experiment.icon( \ "help"), "") button_help.setIconSize(QtCore.QSize(16, 16)) button_help.clicked.connect(self.open_help_tab) button_help.setToolTip("Tell me more about OpenSesame!") header_hbox = QtGui.QHBoxLayout() header_hbox.addWidget(self.main_window.experiment.label_image( \ "experiment")) header_hbox.addWidget(self.header_widget) header_hbox.addStretch() header_hbox.addWidget(button_help) header_hbox.setContentsMargins(0, 0, 0, 16) header_widget = QtGui.QWidget() header_widget.setLayout(header_hbox) # The rest of the controls from the UI file w = QtGui.QWidget() self.ui = general_widget_ui.Ui_Form() self.ui.setupUi(w) self.main_window.theme.apply_theme(self) # The foeground and background widgets get a special treatment self.ui.edit_foreground = color_edit.color_edit( \ self.main_window.experiment) self.ui.edit_background = color_edit.color_edit( \ self.main_window.experiment) self.ui.edit_foreground.setSizePolicy(QtGui.QSizePolicy.Fixed, \ QtGui.QSizePolicy.Fixed) self.ui.edit_background.setSizePolicy(QtGui.QSizePolicy.Fixed, \ QtGui.QSizePolicy.Fixed) self.ui.layout_general_properties.addWidget(self.ui.edit_foreground, \ 4, 3) self.ui.layout_general_properties.addWidget(self.ui.edit_background, \ 5, 3) QtCore.QObject.connect(self.ui.edit_foreground, QtCore.SIGNAL( \ "set_color"), self.apply_changes) QtCore.QObject.connect(self.ui.edit_background, QtCore.SIGNAL( \ "set_color"), self.apply_changes) # Connect the rest self.ui.combobox_start.currentIndexChanged.connect(self.apply_changes) self.ui.spinbox_width.editingFinished.connect(self.apply_changes) self.ui.spinbox_height.editingFinished.connect(self.apply_changes) self.ui.group_script.toggled.connect(self.toggle_script_editor) self.ui.group_backend_settings.toggled.connect( \ self.toggle_backend_settings) self.ui.label_opensesame.setText(unicode( \ self.ui.label_opensesame.text()).replace("[version]", \ misc.version).replace("[codename]", misc.codename)) self.ui.label_website.mousePressEvent = self.open_website self.ui.label_facebook.mousePressEvent = self.open_facebook self.ui.label_twitter.mousePressEvent = self.open_twitter # Set the backend combobox for backend in openexp.backend_info.backend_list: desc = openexp.backend_info.backend_list[backend]["description"] icon = openexp.backend_info.backend_list[backend]["icon"] self.ui.combobox_backend.addItem(self.main_window.theme.qicon( \ icon), self.backend_format % (backend, desc)) self.ui.combobox_backend.currentIndexChanged.connect(self.apply_changes) # Script editor self.edit_script = inline_editor.inline_editor( \ self.main_window.experiment, syntax="opensesame") self.edit_script.apply.clicked.connect(self.apply_script) self.ui.layout_script.addWidget(self.edit_script) vbox = QtGui.QVBoxLayout() vbox.addWidget(header_widget) vbox.addWidget(w) self.setLayout(vbox) self.general_tab = True self.toggle_script_editor() self.toggle_backend_settings()
def init_edit_widget(self): """Construct the GUI controls""" qtitem.qtitem.init_edit_widget(self, False) tabwidget_script = QtGui.QTabWidget(self._edit_widget) py_ver = "Python %d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]) self.textedit_prepare = inline_editor.inline_editor( self.experiment, notification=py_ver, syntax="python") self.textedit_prepare.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_prepare.edit, QtCore.SIGNAL("focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_prepare) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon("inline_script"), "Prepare phase") self.textedit_run = inline_editor.inline_editor(self.experiment, notification=py_ver, syntax="python") self.textedit_run.apply.clicked.connect(self.apply_edit_changes) QtCore.QObject.connect(self.textedit_run.edit, QtCore.SIGNAL("focusLost"), self.apply_edit_changes) hbox = QtGui.QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox_widget = QtGui.QWidget() hbox_widget.setLayout(hbox) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.textedit_run) vbox.addWidget(hbox_widget) widget = QtGui.QWidget() widget.setLayout(vbox) tabwidget_script.addTab(widget, self.experiment.icon("inline_script"), "Run phase") # Switch to the run script by default, unless there is only content for # the prepare script. if self._run == "" and self._prepare != "": tabwidget_script.setCurrentIndex(0) else: tabwidget_script.setCurrentIndex(1) self.edit_vbox.addWidget(tabwidget_script)