本文整理汇总了Python中QProgEdit.QTabManager.addTab方法的典型用法代码示例。如果您正苦于以下问题:Python QTabManager.addTab方法的具体用法?Python QTabManager.addTab怎么用?Python QTabManager.addTab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProgEdit.QTabManager
的用法示例。
在下文中一共展示了QTabManager.addTab方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_editor_control
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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: inline_script
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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():
#.........这里部分代码省略.........
示例6: qtitem
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
#.........这里部分代码省略.........
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):
"""
desc:
Is called when the splitter handle is manually moved.
arguments:
pos:
desc: The splitter-handle position.
示例7: inline_script
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
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)
示例8: qtitem
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
#.........这里部分代码省略.........
debug.msg(u"%s (#%s)" % (self.name, hash(self)))
# Switch to edit mode and close the script tab if it was open
self.edit_mode = u"edit"
for i in range(self.experiment.ui.tabwidget.count()):
w = self.experiment.ui.tabwidget.widget(i)
if hasattr(w, u"__script_item__") and w.__script_item__ == \
self.name:
self.experiment.ui.tabwidget.removeTab(i)
if index == None:
index = i
break
# Focus the edit tab, instead of reopening, if it was already open
for i in range(self.experiment.ui.tabwidget.count()):
w = self.experiment.ui.tabwidget.widget(i)
if hasattr(w, u"__edit_item__") and w.__edit_item__ == self.name:
index = i
# Refresh the controls on the tab. In debug mode don't catch any errors
if debug.enabled:
widget = self.edit_widget()
else:
try:
widget = self.edit_widget()
except Exception as e:
self.experiment.notify(_(u"%s (Edit the script to fix this)") \
% e)
self.open_script_tab()
return
# Open the tab or focus the tab if it was already open
if index == None:
self.edit_tab_index = self.experiment.ui.tabwidget.addTab(widget, \
self.experiment.icon(self.item_type), u"%s" % self.name)
else:
self.experiment.ui.tabwidget.insertTab(index, widget, \
self.experiment.icon(self.item_type), u"%s" % self.name)
self.edit_tab_index = index
if focus:
self.experiment.ui.tabwidget.setCurrentIndex(self.edit_tab_index)
def apply_script_and_close(self):
"""Applies script changes and opens the edit tab"""
self.apply_script_changes()
self.experiment.main_window.select_item(self.name)
def apply_script_changes(self, rebuild=True, catch=True):
"""
Apply changes to the script, by regenerating the item from the script
Keywords arguments:
rebuild -- specifies whether the overview area (item list) should be
rebuild (default=True)
catch -- indicates if exceptions should be caught and shown in a
notification dialog (True) or not be caught (False)
(default=True)
"""
debug.msg(self.name)
script = self.script_qprogedit.text()
# Create a new item and make it a clone of the current item
item = self.experiment.main_window.add_item(self.item_type, False, \
示例9: qtitem
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
#.........这里部分代码省略.........
_(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:
Is called when the splitter handle is manually moved.
arguments:
pos:
desc: The splitter-handle position.
示例10: qtitem
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import addTab [as 别名]
#.........这里部分代码省略.........
# 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 splitter_moved(self, pos, index):
"""
desc:
Is called when the splitter handle is manually moved.
arguments: