本文整理汇总了Python中PyQt5.Qt.QToolBar.addAction方法的典型用法代码示例。如果您正苦于以下问题:Python QToolBar.addAction方法的具体用法?Python QToolBar.addAction怎么用?Python QToolBar.addAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QToolBar
的用法示例。
在下文中一共展示了QToolBar.addAction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupEditActions
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
def setupEditActions(self):
tb = QToolBar(self)
tb.setWindowTitle("Edit Actions")
self.addToolBar(tb)
menu = QMenu("&Edit", self)
self.menuBar().addMenu(menu)
self.actionUndo = QAction("&Undo", self, shortcut=QKeySequence.Undo)
tb.addAction(self.actionUndo)
menu.addAction(self.actionUndo)
self.actionRedo = QAction("&Redo", self, priority=QAction.LowPriority, shortcut=QKeySequence.Redo)
tb.addAction(self.actionRedo)
menu.addAction(self.actionRedo)
menu.addSeparator()
self.actionCut = QAction("Cu&t", self, priority=QAction.LowPriority, shortcut=QKeySequence.Cut)
tb.addAction(self.actionCut)
menu.addAction(self.actionCut)
self.actionCopy = QAction("&Copy", self, priority=QAction.LowPriority, shortcut=QKeySequence.Copy)
tb.addAction(self.actionCopy)
menu.addAction(self.actionCopy)
self.actionPaste = QAction("&Paste", self, priority=QAction.LowPriority,
shortcut=QKeySequence.Paste, enabled=(len(QApplication.clipboard().text()) != 0))
tb.addAction(self.actionPaste)
menu.addAction(self.actionPaste)
示例2: setupFileActions
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
def setupFileActions(self):
tb = QToolBar(self)
tb.setWindowTitle("File Actions")
self.addToolBar(tb)
menu = QMenu("&File", self)
self.menuBar().addMenu(menu)
self.actionNew = QAction("&New", self, priority=QAction.LowPriority,
shortcut=QKeySequence.New, triggered=self.fileNew)
tb.addAction(self.actionNew)
menu.addAction(self.actionNew)
self.actionOpen = QAction("&Open...", self, shortcut=QKeySequence.Open,
triggered=self.fileOpen)
tb.addAction(self.actionOpen)
menu.addAction(self.actionOpen)
menu.addSeparator()
self.actionSave = QAction("&Save", self, shortcut=QKeySequence.Save,
triggered=self.fileSave, enabled=False)
tb.addAction(self.actionSave)
menu.addAction(self.actionSave)
self.actionSaveAs = QAction("Save &As...", self, priority=QAction.LowPriority,
shortcut=Qt.CTRL + Qt.SHIFT + Qt.Key_S, triggered=self.fileSaveAs)
menu.addAction(self.actionSaveAs)
menu.addSeparator()
self.actionQuit = QAction("&Quit", self, shortcut=QKeySequence.Quit, triggered=self.close)
menu.addAction(self.actionQuit)
示例3: setupRunActions
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
def setupRunActions(self):
tb = QToolBar(self)
tb.setWindowTitle("Run Actions")
self.addToolBar(tb)
menu = QMenu("Run", self)
self.menuBar().addMenu(menu)
self.actionRun = QAction(
"&Run", self, shortcut=Qt.CTRL + Qt.Key_R)
tb.addAction(self.actionRun)
menu.addAction(self.actionRun)
self.comboScannoFile = QComboBox(tb)
self.comboScannoFile.setObjectName("comboScannoFile")
tb.addWidget(self.comboScannoFile)
self.comboScannoFile.setEditable(True)
self.comboLogFile= QComboBox(tb)
self.comboLogFile.setObjectName("comboLogFile")
self.comboLogFile.setEditable(True)
tb.addWidget(self.comboLogFile)
示例4: Category
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
class Category(QWidget): # {{{
plugin_activated = pyqtSignal(object)
def __init__(self, name, plugins, gui_name, parent=None):
QWidget.__init__(self, parent)
self._layout = QVBoxLayout()
self.setLayout(self._layout)
self.label = QLabel(gui_name)
self.sep = QFrame(self)
self.bf = QFont()
self.bf.setBold(True)
self.label.setFont(self.bf)
self.sep.setFrameShape(QFrame.HLine)
self._layout.addWidget(self.label)
self._layout.addWidget(self.sep)
self.plugins = plugins
self.bar = QToolBar(self)
self.bar.setStyleSheet(
'QToolBar { border: none; background: none }')
lh = QApplication.instance().line_height
self.bar.setIconSize(QSize(2*lh, 2*lh))
self.bar.setMovable(False)
self.bar.setFloatable(False)
self.bar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self._layout.addWidget(self.bar)
self.actions = []
for p in plugins:
target = partial(self.triggered, p)
ac = self.bar.addAction(QIcon(p.icon), p.gui_name.replace('&', '&&'), target)
ac.setToolTip(textwrap.fill(p.description))
ac.setWhatsThis(textwrap.fill(p.description))
ac.setStatusTip(p.description)
self.actions.append(ac)
w = self.bar.widgetForAction(ac)
w.setCursor(Qt.PointingHandCursor)
if hasattr(w, 'setAutoRaise'):
w.setAutoRaise(True)
w.setMinimumWidth(100)
def triggered(self, plugin, *args):
self.plugin_activated.emit(plugin)
示例5: Editor
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
class Editor(QWidget): # {{{
def __init__(self, parent=None, one_line_toolbar=False):
QWidget.__init__(self, parent)
self.toolbar1 = QToolBar(self)
self.toolbar2 = QToolBar(self)
self.toolbar3 = QToolBar(self)
for i in range(1, 4):
t = getattr(self, 'toolbar%d'%i)
t.setIconSize(QSize(18, 18))
self.editor = EditorWidget(self)
self.set_html = self.editor.set_html
self.tabs = QTabWidget(self)
self.tabs.setTabPosition(self.tabs.South)
self.wyswyg = QWidget(self.tabs)
self.code_edit = QPlainTextEdit(self.tabs)
self.source_dirty = False
self.wyswyg_dirty = True
self._layout = QVBoxLayout(self)
self.wyswyg.layout = l = QVBoxLayout(self.wyswyg)
self.setLayout(self._layout)
l.setContentsMargins(0, 0, 0, 0)
if one_line_toolbar:
tb = QHBoxLayout()
l.addLayout(tb)
else:
tb = l
tb.addWidget(self.toolbar1)
tb.addWidget(self.toolbar2)
tb.addWidget(self.toolbar3)
l.addWidget(self.editor)
self._layout.addWidget(self.tabs)
self.tabs.addTab(self.wyswyg, _('N&ormal view'))
self.tabs.addTab(self.code_edit, _('&HTML Source'))
self.tabs.currentChanged[int].connect(self.change_tab)
self.highlighter = Highlighter(self.code_edit.document())
self.layout().setContentsMargins(0, 0, 0, 0)
# toolbar1 {{{
self.toolbar1.addAction(self.editor.action_undo)
self.toolbar1.addAction(self.editor.action_redo)
self.toolbar1.addAction(self.editor.action_select_all)
self.toolbar1.addAction(self.editor.action_remove_format)
self.toolbar1.addAction(self.editor.action_clear)
self.toolbar1.addSeparator()
for x in ('copy', 'cut', 'paste'):
ac = getattr(self.editor, 'action_'+x)
self.toolbar1.addAction(ac)
self.toolbar1.addSeparator()
self.toolbar1.addAction(self.editor.action_background)
# }}}
# toolbar2 {{{
for x in ('', 'un'):
ac = getattr(self.editor, 'action_%sordered_list'%x)
self.toolbar2.addAction(ac)
self.toolbar2.addSeparator()
for x in ('superscript', 'subscript', 'indent', 'outdent'):
self.toolbar2.addAction(getattr(self.editor, 'action_' + x))
if x in ('subscript', 'outdent'):
self.toolbar2.addSeparator()
self.toolbar2.addAction(self.editor.action_block_style)
w = self.toolbar2.widgetForAction(self.editor.action_block_style)
w.setPopupMode(w.InstantPopup)
self.toolbar2.addAction(self.editor.action_insert_link)
# }}}
# toolbar3 {{{
for x in ('bold', 'italic', 'underline', 'strikethrough'):
ac = getattr(self.editor, 'action_'+x)
self.toolbar3.addAction(ac)
self.toolbar3.addSeparator()
for x in ('left', 'center', 'right', 'justified'):
ac = getattr(self.editor, 'action_align_'+x)
self.toolbar3.addAction(ac)
self.toolbar3.addSeparator()
self.toolbar3.addAction(self.editor.action_color)
# }}}
self.code_edit.textChanged.connect(self.code_dirtied)
self.editor.page().contentsChanged.connect(self.wyswyg_dirtied)
def set_minimum_height_for_editor(self, val):
self.editor.setMinimumHeight(val)
@dynamic_property
def html(self):
def fset(self, v):
self.editor.html = v
def fget(self):
self.tabs.setCurrentIndex(0)
return self.editor.html
return property(fget=fget, fset=fset)
def change_tab(self, index):
#.........这里部分代码省略.........
示例6: Preview
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
class Preview(QWidget):
sync_requested = pyqtSignal(object, object)
split_requested = pyqtSignal(object, object, object)
split_start_requested = pyqtSignal()
link_clicked = pyqtSignal(object, object)
refresh_starting = pyqtSignal()
refreshed = pyqtSignal()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QVBoxLayout()
self.setLayout(l)
l.setContentsMargins(0, 0, 0, 0)
self.view = WebView(self)
self.view.page().sync_requested.connect(self.request_sync)
self.view.page().split_requested.connect(self.request_split)
self.view.page().loadFinished.connect(self.load_finished)
self.inspector = self.view.inspector
self.inspector.setPage(self.view.page())
l.addWidget(self.view)
self.bar = QToolBar(self)
l.addWidget(self.bar)
ac = actions['auto-reload-preview']
ac.setCheckable(True)
ac.setChecked(True)
ac.toggled.connect(self.auto_reload_toggled)
self.auto_reload_toggled(ac.isChecked())
self.bar.addAction(ac)
ac = actions['sync-preview-to-editor']
ac.setCheckable(True)
ac.setChecked(True)
ac.toggled.connect(self.sync_toggled)
self.sync_toggled(ac.isChecked())
self.bar.addAction(ac)
self.bar.addSeparator()
ac = actions['split-in-preview']
ac.setCheckable(True)
ac.setChecked(False)
ac.toggled.connect(self.split_toggled)
self.split_toggled(ac.isChecked())
self.bar.addAction(ac)
ac = actions['reload-preview']
ac.triggered.connect(self.refresh)
self.bar.addAction(ac)
actions['preview-dock'].toggled.connect(self.visibility_changed)
self.current_name = None
self.last_sync_request = None
self.refresh_timer = QTimer(self)
self.refresh_timer.timeout.connect(self.refresh)
parse_worker.start()
self.current_sync_request = None
self.search = HistoryLineEdit2(self)
self.search.initialize('tweak_book_preview_search')
self.search.setPlaceholderText(_('Search in preview'))
self.search.returnPressed.connect(partial(self.find, 'next'))
self.bar.addSeparator()
self.bar.addWidget(self.search)
for d in ('next', 'prev'):
ac = actions['find-%s-preview' % d]
ac.triggered.connect(partial(self.find, d))
self.bar.addAction(ac)
def find(self, direction):
text = unicode(self.search.text())
self.view.findText(text, QWebPage.FindWrapsAroundDocument | (
QWebPage.FindBackward if direction == 'prev' else QWebPage.FindFlags(0)))
def request_sync(self, tagname, href, lnum):
if self.current_name:
c = current_container()
if tagname == 'a' and href:
if href and href.startswith('#'):
name = self.current_name
else:
name = c.href_to_name(href, self.current_name) if href else None
if name == self.current_name:
return self.view.page().go_to_anchor(urlparse(href).fragment, lnum)
if name and c.exists(name) and c.mime_map[name] in OEB_DOCS:
return self.link_clicked.emit(name, urlparse(href).fragment or TOP)
self.sync_requested.emit(self.current_name, lnum)
def request_split(self, loc, totals):
if self.current_name:
self.split_requested.emit(self.current_name, loc, totals)
def sync_to_editor(self, name, sourceline_address):
self.current_sync_request = (name, sourceline_address)
QTimer.singleShot(100, self._sync_to_editor)
def _sync_to_editor(self):
if not actions['sync-preview-to-editor'].isChecked():
#.........这里部分代码省略.........
示例7: Preferences
# 需要导入模块: from PyQt5.Qt import QToolBar [as 别名]
# 或者: from PyQt5.Qt.QToolBar import addAction [as 别名]
class Preferences(QMainWindow):
run_wizard_requested = pyqtSignal()
def __init__(self, gui, initial_plugin=None, close_after_initial=False):
QMainWindow.__init__(self, gui)
self.gui = gui
self.must_restart = False
self.committed = False
self.close_after_initial = close_after_initial
self.resize(930, 720)
nh, nw = min_available_height()-25, available_width()-10
if nh < 0:
nh = 800
if nw < 0:
nw = 600
nh = min(self.height(), nh)
nw = min(self.width(), nw)
self.resize(nw, nh)
self.esc_action = QAction(self)
self.addAction(self.esc_action)
self.esc_action.setShortcut(QKeySequence(Qt.Key_Escape))
self.esc_action.triggered.connect(self.esc)
geom = gprefs.get('preferences_window_geometry', None)
if geom is not None:
self.restoreGeometry(geom)
# Center
if islinux:
self.move(gui.rect().center() - self.rect().center())
self.setWindowModality(Qt.WindowModal)
self.setWindowTitle(__appname__ + ' - ' + _('Preferences'))
self.setWindowIcon(QIcon(I('config.png')))
self.status_bar = StatusBar(self)
self.setStatusBar(self.status_bar)
self.stack = QStackedWidget(self)
self.cw = QWidget(self)
self.cw.setLayout(QVBoxLayout())
self.cw.layout().addWidget(self.stack)
self.bb = QDialogButtonBox(QDialogButtonBox.Close)
self.wizard_button = self.bb.addButton(_('Run welcome wizard'),
self.bb.ActionRole)
self.wizard_button.setIcon(QIcon(I('wizard.png')))
self.wizard_button.clicked.connect(self.run_wizard,
type=Qt.QueuedConnection)
self.cw.layout().addWidget(self.bb)
self.bb.button(self.bb.Close).setDefault(True)
self.bb.rejected.connect(self.close, type=Qt.QueuedConnection)
self.setCentralWidget(self.cw)
self.browser = Browser(self)
self.browser.show_plugin.connect(self.show_plugin)
self.stack.addWidget(self.browser)
self.scroll_area = QScrollArea(self)
self.stack.addWidget(self.scroll_area)
self.scroll_area.setWidgetResizable(True)
self.setContextMenuPolicy(Qt.NoContextMenu)
self.bar = QToolBar(self)
self.addToolBar(self.bar)
self.bar.setVisible(False)
self.bar.setIconSize(QSize(ICON_SIZE, ICON_SIZE))
self.bar.setMovable(False)
self.bar.setFloatable(False)
self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.apply_action = self.bar.addAction(QIcon(I('ok.png')), _('&Apply'),
self.commit)
self.cancel_action = self.bar.addAction(QIcon(I('window-close.png')),
_('&Cancel'), self.cancel)
self.bar_title = BarTitle(self.bar)
self.bar.addWidget(self.bar_title)
self.restore_action = self.bar.addAction(QIcon(I('clear_left.png')),
_('Restore &defaults'), self.restore_defaults)
for ac, tt in [('apply', _('Save changes')),
('cancel', _('Cancel and return to overview'))]:
ac = getattr(self, ac+'_action')
ac.setToolTip(tt)
ac.setWhatsThis(tt)
ac.setStatusTip(tt)
for ch in self.bar.children():
if isinstance(ch, QToolButton):
ch.setCursor(Qt.PointingHandCursor)
ch.setAutoRaise(True)
self.stack.setCurrentIndex(0)
if initial_plugin is not None:
category, name = initial_plugin
plugin = get_plugin(category, name)
if plugin is not None:
self.show_plugin(plugin)
def run_wizard(self):
self.close()
self.run_wizard_requested.emit()
#.........这里部分代码省略.........