def add_editor_control(self, var, label, syntax=False): """ Adds a QProgEdit that is linked to a variable. arguments: var: The associated variable. label: The label text. keywords: syntax: A boolean indicating whether Python syntax highlighting should be activated. returns: A QProgEdit widget. """ from QProgEdit import QTabManager if syntax: lang = u'python' else: lang = u'text' qprogedit = QTabManager(cfg=cfg) qprogedit.focusLost.connect(self.apply_edit_changes) qprogedit.handlerButtonClicked.connect(self.apply_edit_changes) qprogedit.addTab(label).setLang(lang) if var is not None: self.auto_editor[var] = qprogedit self.edit_vbox.addWidget(qprogedit) self.set_focus_widget(qprogedit) return qprogedit
def add_editor_control(self, var, label, syntax=False, tooltip=None, \ default=None): """ Adds a QProgEdit 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: A QProgEdit widget. """ from QProgEdit import QTabManager if syntax: lang = u'python' else: lang = u'text' qprogedit = QTabManager(cfg=cfg) qprogedit.focusLost.connect(self.apply_edit_changes) qprogedit.handlerButtonClicked.connect(self.apply_edit_changes) qprogedit.addTab(_(label, context=self.name)).setLang(lang) if var is not None: self.auto_editor[var] = qprogedit self.edit_vbox.addWidget(qprogedit) self.set_focus_widget(qprogedit) return qprogedit
def init_script_widget(self): """Build the script tab""" from QProgEdit import QTabManager self.script_qprogedit = QTabManager(handler= \ self.apply_script_and_close, defaultLang=u'OpenSesame', \ handlerButtonText=_(u'Apply and close script editor'), \ focusOutHandler=self.apply_script_changes, cfg=cfg) self.script_qprogedit.addTab(u'Script') hbox = QtGui.QHBoxLayout() hbox.addWidget(self.experiment.label_image(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.script_qprogedit) self._script_widget = QtGui.QWidget() self._script_widget.setLayout(vbox) self._script_widget.__script_item__ = self.name
def main(): """Runs a simple QProgEdit demonstration.""" print(u'API: %s' % os.environ[u'QT_API']) validate.addPythonBuiltins([u'builtin_var']) validate.setPyFlakesFilter(lambda msg: msg.message == u'undefined name %r') app = QtWidgets.QApplication(sys.argv) treeWidgetItem1 = QtWidgets.QTreeWidgetItem([u'Tab 1']) treeWidgetItem3 = QtWidgets.QTreeWidgetItem([u'Tab 3']) symbolTree = QtWidgets.QTreeWidget() symbolTree.addTopLevelItem(treeWidgetItem1) symbolTree.addTopLevelItem(treeWidgetItem3) symbolTree.itemActivated.connect(activateSymbolTree) tabManager = QTabManager(handlerButtonText=u'apply', runButton=True) tabManager.setWindowIcon(QtGui.QIcon.fromTheme(u'accessories-text-editor')) tabManager.setWindowTitle(u'QProgEdit') tabManager.resize(800, 600) tabManager.cursorRowChanged.connect(cursorRowChanged) tabManager.focusLost.connect(focusLost) tabManager.focusReceived.connect(focusReceived) tabManager.handlerButtonClicked.connect(handlerButtonClicked) tabManager.execute.connect(runSelectedText) tab = tabManager.addTab(u'Tab 1') tab.setLang(u'Python') tab.setSymbolTree(treeWidgetItem1) tab.setText(open(__file__).read()) tab = tabManager.addTab(u'Tab 2') tab.setText(u'Some plain text') tab = tabManager.addTab(u'Tab 3') tab.setLang(u'Python') tab.setSymbolTree(treeWidgetItem3) if os.path.exists(u'content.txt'): tab.setText(open(u'content.txt').read()) layout = QtWidgets.QHBoxLayout() layout.addWidget(symbolTree) layout.addWidget(tabManager) container = QtWidgets.QWidget() container.setLayout(layout) container.show() res = app.exec_() open(u'content.txt', u'w').write(tab.text()) sys.exit(res)
def __init__(self, main_window): """ desc: Constructor. arguments: main_window: A qtopensesame object. """ from QProgEdit import QTabManager super(general_script_editor, self).__init__(main_window, ui=u'widgets.general_script_editor') self.ui.qprogedit = QTabManager(handlerButtonText=u'Apply', cfg=cfg) self.ui.qprogedit.handlerButtonClicked.connect(self._apply) self.ui.qprogedit.addTab(u'General script').setLang(u'OpenSesame') self.ui.layout_vbox.addWidget(self.ui.qprogedit) self.tab_name = u'__general_script__'
def init_edit_widget(self): """Constructs the GUI controls.""" from QProgEdit import QTabManager qtitem.qtitem.init_edit_widget(self, False) self.qprogedit = QTabManager(handler=self.apply_edit_changes, \ defaultLang=u'Python', cfg=cfg, focusOutHandler= \ self.apply_edit_changes) self.qprogedit.addTab(u'Prepare') self.qprogedit.addTab(u'Run') # Switch to the run phase, unless there is only content for the prepare # phase. if self._run == u'' and self._prepare != u'': self.qprogedit.setCurrentIndex(0) else: self.qprogedit.setCurrentIndex(1) self.edit_vbox.addWidget(self.qprogedit)
def init_edit_widget(self): """See qtitem.""" from QProgEdit import QTabManager super(inline_script, self).init_edit_widget(stretch=False) self.qprogedit = QTabManager(cfg=cfg) self.qprogedit.handlerButtonClicked.connect(self.apply_edit_changes) self.qprogedit.focusLost.connect(self.apply_edit_changes) self.qprogedit.cursorRowChanged.connect(self.apply_edit_changes) self.qprogedit.addTab(u'Prepare').setLang(u'Python') self.qprogedit.addTab(u'Run').setLang(u'Python') # Switch to the run phase, unless there is only content for the prepare # phase. if self._run == u'' and self._prepare != u'': self.qprogedit.setCurrentIndex(0) else: self.qprogedit.setCurrentIndex(1) self.edit_vbox.addWidget(self.qprogedit)
def init_edit_widget(self): """See qtitem.""" from QProgEdit import QTabManager qtplugin.init_edit_widget(self, stretch=False) self.qprogedit = QTabManager(cfg=cfg, runButton=True) self.qprogedit.execute.connect(self.main_window.console.execute) self.qprogedit.handlerButtonClicked.connect(self.apply_edit_changes) self.qprogedit.focusLost.connect(self.apply_edit_changes) self.qprogedit.cursorRowChanged.connect(self.apply_edit_changes) self.qprogedit.addTab(_(u'Prepare')).setLang(u'Python') self.qprogedit.addTab(_(u'Run')).setLang(u'Python') # Switch to the run phase, unless there is only content for the prepare # phase. if self.var._run == u'' and self.var._prepare != u'': self.qprogedit.setCurrentIndex(0) else: self.qprogedit.setCurrentIndex(1) self.edit_vbox.addWidget(self.qprogedit)
def __init__(self, main_window): """ Constructor Arguments: main_window -- the main window """ from QProgEdit import QTabManager self.main_window = main_window QtGui.QWidget.__init__(self, main_window) self.ui = Ui_widget_general_script_editor() self.ui.setupUi(self) self.ui.qprogedit = QTabManager(handler=self._apply, defaultLang= \ u'OpenSesame', handlerButtonText=u'Apply', cfg=cfg) self.ui.qprogedit.addTab(u'General script') self.ui.layout_vbox.addWidget(self.ui.qprogedit) self.main_window.theme.apply_theme(self) self.tab_name = '__general_script__'
def settings_widget(self): """ desc: returns the QProgEdit settings widget. returns: type: QWidget """ # Create a temporary QProgEdit instance, add one tab, and wrap the # preferences widget for this tab in a group box. from QProgEdit import QTabManager tm = QTabManager(cfg=cfg) tm.addTab() w = tm.tab(0).prefs w.show() w.refresh() group = QtGui.QGroupBox(_(u'Editor preferences (QProgEdit)'), self.main_window) layout = QtGui.QHBoxLayout(group) layout.addWidget(w) group.setLayout(layout) return group
def init_edit_widget(self, stretch=True): """ desc: Builds the UI. keywords: stretch: desc: Indicates whether a vertical stretch should be added to the bottom of the controls. This is necessary if the controls don't expand. type: bool """ # Header widget self.header = header_widget.header_widget(self) self.header_hbox = QtWidgets.QHBoxLayout() self.header_item_icon = self.theme.qlabel(self.item_icon()) self.header_hbox.addWidget(self.header_item_icon) self.header_hbox.addWidget(self.header) self.header_hbox.setContentsMargins(0, 0, 0, 0) self.header_hbox.setSpacing(12) # Maximize button self.button_toggle_maximize = QtWidgets.QPushButton( self.theme.qicon(u'view-fullscreen'), u'') self.button_toggle_maximize.setToolTip(_(u'Toggle pop-out')) self.button_toggle_maximize.setIconSize(QtCore.QSize(16, 16)) self.button_toggle_maximize.clicked.connect(self.toggle_maximize) self.header_hbox.addWidget(self.button_toggle_maximize) # View button self.button_view = item_view_button(self) self.header_hbox.addWidget(self.button_view) # Help button self.button_help = QtWidgets.QPushButton(self.theme.qicon(u"help"), u"") self.button_help.setToolTip( _(u"Tell me more about the %s item") % self.item_type) self.button_help.setIconSize(QtCore.QSize(16, 16)) self.button_help.clicked.connect(self.open_help_tab) self.header_hbox.addWidget(self.button_help) self.header_widget = QtWidgets.QWidget() self.header_widget.setLayout(self.header_hbox) # The edit_grid is the layout that contains the actual controls for the # items. self.edit_grid = QtWidgets.QFormLayout() if self.label_align == u'right': self.edit_grid.setLabelAlignment(QtCore.Qt.AlignRight) self.edit_grid.setFieldGrowthPolicy( QtWidgets.QFormLayout.FieldsStayAtSizeHint) self.edit_grid.setContentsMargins(0, 0, 0, 0) self.edit_grid.setVerticalSpacing(6) self.edit_grid.setHorizontalSpacing(12) self.edit_grid_widget = QtWidgets.QWidget() self.edit_grid_widget.setLayout(self.edit_grid) # The edit_vbox contains the edit_grid and the header widget self.edit_vbox = QtWidgets.QVBoxLayout() self.edit_vbox.addWidget(self.edit_grid_widget) self.edit_vbox.setContentsMargins(0, 0, 0, 0) self.edit_vbox.setSpacing(12) if stretch: self.edit_vbox.addStretch() self._edit_widget = QtWidgets.QWidget() self._edit_widget.setWindowIcon(self.theme.qicon(self.item_type)) self._edit_widget.setLayout(self.edit_vbox) # The _script_widget contains the script editor from QProgEdit import QTabManager self._script_widget = QTabManager( handlerButtonText=_(u'Apply and close'), cfg=cfg) self._script_widget.focusLost.connect(self.apply_script_changes) self._script_widget.cursorRowChanged.connect(self.apply_script_changes) self._script_widget.handlerButtonClicked.connect( self.apply_script_changes_and_switch_view) self._script_widget.addTab(u'Script').setLang(u'OpenSesame') # The container_widget is the top-level widget that is actually inserted # into the tab widget. self.splitter = qtitem_splitter(self) if self.initial_view == u'controls': self.set_view_controls() elif self.initial_view == u'script': self.set_view_script() elif self.initial_view == u'split': self.set_view_split() else: debug.msg(u'Invalid initial_view: %s' % self.initial_view, reason=u'warning') self.set_view_controls() self.splitter.splitterMoved.connect(self.splitter_moved) self.container_vbox = QtWidgets.QVBoxLayout() self.container_vbox.setContentsMargins(12, 12, 12, 12) self.container_vbox.setSpacing(18) self.container_vbox.addWidget(self.header_widget) self.container_vbox.addWidget(self.splitter) self.container_widget = QtWidgets.QWidget() self.container_widget.setLayout(self.container_vbox) self.container_widget.on_activate = self.show_tab self.container_widget.__item__ = self.name
def init_edit_widget(self, stretch=True): """ desc: Builds the UI. keywords: stretch: desc: Indicates whether a vertical stretch should be added to the bottom of the controls. This is necessary if the controls don't expand. type: bool """ # Header widget self.header = header_widget.header_widget(self) self.user_hint_widget = user_hint_widget.user_hint_widget( self.experiment.main_window, self) self.header_hbox = QtGui.QHBoxLayout() self.header_item_icon = self.experiment.label_image(self.item_icon()) self.header_hbox.addWidget(self.header_item_icon) self.header_hbox.addWidget(self.header) self.header_hbox.setContentsMargins(0, 5, 0, 10) # Maximize button self.button_toggle_maximize = QtGui.QPushButton( self.theme.qicon(u'view-fullscreen'), u'') self.button_toggle_maximize.setToolTip(_(u'Toggle pop-out')) self.button_toggle_maximize.setIconSize(QtCore.QSize(16, 16)) self.button_toggle_maximize.clicked.connect(self.toggle_maximize) self.header_hbox.addWidget(self.button_toggle_maximize) # View button self.button_view = item_view_button(self) self.header_hbox.addWidget(self.button_view) # Help button self.button_help = QtGui.QPushButton(self.experiment.icon(u"help"), u"") self.button_help.setToolTip( _(u"Tell me more about the %s item") % self.item_type) self.button_help.setIconSize(QtCore.QSize(16, 16)) self.button_help.clicked.connect(self.open_help_tab) self.header_hbox.addWidget(self.button_help) self.header_widget = QtGui.QWidget() self.header_widget.setLayout(self.header_hbox) # The edit_grid is the layout that contains the actual controls for the # items. self.edit_grid = QtGui.QGridLayout() self.edit_grid.setColumnStretch(2, 2) self.edit_grid_widget = QtGui.QWidget() self.edit_grid.setMargin(0) self.edit_grid_widget.setLayout(self.edit_grid) # The edit_vbox contains the edit_grid and the header widget self.edit_vbox = QtGui.QVBoxLayout() self.edit_vbox.setMargin(5) self.edit_vbox.addWidget(self.user_hint_widget) self.edit_vbox.addWidget(self.edit_grid_widget) if stretch: self.edit_vbox.addStretch() self._edit_widget = QtGui.QWidget() self._edit_widget.setWindowIcon(self.experiment.icon(self.item_type)) self._edit_widget.setLayout(self.edit_vbox) # The _script_widget contains the script editor from QProgEdit import QTabManager self._script_widget = QTabManager( handlerButtonText=_(u'Apply and close'), cfg=cfg) self._script_widget.focusLost.connect(self.apply_script_changes) self._script_widget.handlerButtonClicked.connect( self.set_view_controls) self._script_widget.addTab(u'Script').setLang(u'OpenSesame') # The container_widget is the top-level widget that is actually inserted # into the tab widget. self.splitter = qtitem_splitter(self) if self.initial_view == u'controls': self.set_view_controls() elif self.initial_view == u'script': self.set_view_script() elif self.initial_view == u'split': self.set_view_split() else: debug.msg(u'Invalid initial_view: %s' % self.initial_view, reason=u'warning') self.set_view_controls() self.splitter.splitterMoved.connect(self.splitter_moved) self.container_vbox = QtGui.QVBoxLayout() self.container_vbox.addWidget(self.header_widget) self.container_vbox.addWidget(self.splitter) self.container_widget = QtGui.QWidget() self.container_widget.setLayout(self.container_vbox) self.container_widget.on_activate = self.show_tab