本文整理汇总了Python中QProgEdit.QTabManager类的典型用法代码示例。如果您正苦于以下问题:Python QTabManager类的具体用法?Python QTabManager怎么用?Python QTabManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTabManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_editor_control
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
示例2: add_editor_control
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
示例3: main
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)
示例4: main
def main():
"""Runs a simple QProgEdit demonstration."""
validate.addPythonBuiltins(['builtin_var'])
app = QtGui.QApplication(sys.argv)
treeWidgetItem1 = QtGui.QTreeWidgetItem([u'Tab 1'])
treeWidgetItem3 = QtGui.QTreeWidgetItem([u'Tab 3'])
symbolTree = QtGui.QTreeWidget()
symbolTree.addTopLevelItem(treeWidgetItem1)
symbolTree.addTopLevelItem(treeWidgetItem3)
symbolTree.itemActivated.connect(activateSymbolTree)
tabManager = QTabManager(handlerButtonText=u'apply')
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)
tab = tabManager.addTab(u'Tab 1')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem1)
tab.setText(open(__file__).read())
print tab.symbols()
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().decode(u'utf-8'))
print tab.symbols()
layout = QtGui.QHBoxLayout()
layout.addWidget(symbolTree)
layout.addWidget(tabManager)
container = QtGui.QWidget()
container.setLayout(layout)
container.show()
res = app.exec_()
open(u'content.txt', u'w').write(tab.text().encode(u'utf-8'))
sys.exit(res)
示例5: init_script_widget
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'), callHandlerOnFocusOut=False,
cfg=cfg)
self.script_qprogedit.addTab(u'Script')
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.experiment.label_image(u"%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.script_qprogedit)
self._script_widget = QtGui.QWidget()
self._script_widget.setLayout(vbox)
self._script_widget.__script_item__ = self.name
示例6: init_edit_widget
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)
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)
示例7: init_edit_widget
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)
示例8: inline_script
class inline_script(inline_script_runtime, qtplugin):
"""The inline_script GUI controls"""
def __init__(self, name, experiment, string=None):
"""See item."""
inline_script_runtime.__init__(self, name, experiment, string)
qtplugin.__init__(self)
def apply_edit_changes(self):
"""See qtitem."""
super(inline_script, self).apply_edit_changes(self)
sp = self.qprogedit.text(index=0)
sr = self.qprogedit.text(index=1)
self.var._prepare = sp
self.var._run = sr
self.update_item_icon()
def set_focus(self):
"""
desc:
Allows the item to focus the most important widget.
"""
self.qprogedit.setFocus()
def item_icon(self):
"""
desc:
Determines the icon, based on whether the scripts are syntactically
correct.
returns:
desc: An icon name.
type: unicode
"""
status = max(
self.experiment.python_workspace.check_syntax(
self.var.get(u'_prepare', _eval=False)),
self.experiment.python_workspace.check_syntax(
self.var.get(u'_run', _eval=False)))
if status == 2:
return u'os-inline_script-syntax-error'
if status == 1:
return u'os-inline_script-syntax-warning'
return u'os-inline_script'
def build_item_tree(self, toplevel=None, items=[], max_depth=-1,
extra_info=None):
"""See qtitem."""
widget = tree_inline_script_item(self, extra_info=extra_info,
symbols=(max_depth < 0 or max_depth > 1))
items.append(self.name)
if toplevel is not None:
toplevel.addChild(widget)
return widget
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, 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 edit_widget(self):
"""See qtitem."""
super(inline_script, self).edit_widget()
self.qprogedit.tab(0).setText(safe_decode(self.var._prepare))
self.qprogedit.tab(1).setText(safe_decode(self.var._run))
def get_ready(self):
"""See qtitem."""
if self.qprogedit.isAnyModified():
#.........这里部分代码省略.........
示例9: qtitem
#.........这里部分代码省略.........
# View button
self.button_view = item_view_button(self)
self.header_hbox.addWidget(self.button_view)
# Help button
self.button_help = QtGui.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 = 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_widget.setLayout(self.edit_grid)
# The edit_vbox contains the edit_grid and the header widget
self.edit_vbox = QtGui.QVBoxLayout()
self.edit_vbox.addWidget(self.user_hint_widget)
self.edit_vbox.addWidget(self.edit_grid_widget)
self.edit_vbox.setContentsMargins(0, 0, 0, 0)
self.edit_vbox.setSpacing(0)
if stretch:
self.edit_vbox.addStretch()
self._edit_widget = QtGui.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.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.setContentsMargins(4, 0, 4, 4)
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
self.container_widget.__item__ = self.name
def splitter_moved(self, pos, index):
"""
示例10: init_edit_widget
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.theme.qlabel(self.item_icon())
self.header_hbox.addWidget(self.header_item_icon)
self.header_hbox.addWidget(self.header)
self.header_hbox.setContentsMargins(0, 2, 0, 0)
# 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.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 = 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_widget.setLayout(self.edit_grid)
# The edit_vbox contains the edit_grid and the header widget
self.edit_vbox = QtGui.QVBoxLayout()
self.edit_vbox.addWidget(self.user_hint_widget)
self.edit_vbox.addWidget(self.edit_grid_widget)
self.edit_vbox.setContentsMargins(0, 0, 0, 0)
self.edit_vbox.setSpacing(0)
if stretch:
self.edit_vbox.addStretch()
self._edit_widget = QtGui.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.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.setContentsMargins(4, 0, 4, 4)
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
self.container_widget.__item__ = self.name
示例11: inline_script
class inline_script(libopensesame.inline_script.inline_script, qtitem.qtitem):
"""The inline_script GUI controls"""
def __init__(self, name, experiment, string=None):
"""
Constructor.
Arguments:
name -- The item name.
experiment -- The experiment object.
Keywords arguments:
string -- A definition string. (default=None)
"""
libopensesame.inline_script.inline_script.__init__(self, name, \
experiment, string)
qtitem.qtitem.__init__(self)
self.lock = False
self._var_info = None
def apply_edit_changes(self, **args):
"""
Applies the controls.
Keywords arguments:
args -- A dictionary to accept unused keyword arguments.
"""
qtitem.qtitem.apply_edit_changes(self, False)
sp = self.qprogedit.text(index=0)
sr = self.qprogedit.text(index=1)
self.set(u'_prepare', sp)
self.set(u'_run', sr)
self.lock = True
self._var_info = None
self.experiment.main_window.refresh(self.name)
self.lock = False
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)
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 edit_widget(self):
"""
Updates the GUI controls.
Returns:
The control QWidget.
"""
qtitem.qtitem.edit_widget(self, False)
if not self.lock:
self.qprogedit.setText(self._prepare, index=0)
self.qprogedit.setText(self._run, index=1)
return self._edit_widget
def get_ready(self):
"""Applies pending script changes."""
if self.qprogedit.isModified():
debug.msg(u'applying pending script changes')
self.apply_edit_changes(catch=False)
return True
return qtitem.qtitem.get_ready(self)
示例12: qtitem
#.........这里部分代码省略.........
self.experiment.items[item].from_string(script)
except Exception as e:
self.experiment.notify(unicode(e))
return
else:
self.experiment.items[item].from_string(script)
self.experiment.items[item].name = self.name
# Replace the current item
self.experiment.items[self.name] = self.experiment.items[item]
del self.experiment.items[item]
self.experiment.items[self.name].init_script_widget()
self.experiment.main_window.dispatch.event_script_change.emit(self.name)
def strip_script_line(self, s):
"""
Strips unwanted characters from a line of script
Arguments:
s -- a line of script
Returns:
A stripped line of script
"""
if len(s) > 0 and s[0] == u"\t":
return s[1:] + u"\n"
return s + u"\n"
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'), callHandlerOnFocusOut=False,
cfg=cfg)
self.script_qprogedit.addTab(u'Script')
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.experiment.label_image(u"%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.script_qprogedit)
self._script_widget = QtGui.QWidget()
self._script_widget.setLayout(vbox)
self._script_widget.__script_item__ = self.name
def script_widget(self):
"""
Update the script tab
Returns:
The QWidget containing the script tab
"""
self.script_header.setText( \
示例13: qtitem
#.........这里部分代码省略.........
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
self.container_widget.__item__ = self.name
def splitter_moved(self, pos, index):
"""
desc:
示例14: qtitem
#.........这里部分代码省略.........
_(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
示例15: init_edit_widget
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
#.........这里部分代码省略.........