本文整理汇总了Python中qtpy.QtWidgets.QAction.setShortcut方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setShortcut方法的具体用法?Python QAction.setShortcut怎么用?Python QAction.setShortcut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.setShortcut方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_action
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
toggled=None, triggered=None, data=None, menurole=None,
context=Qt.WindowShortcut):
"""Create a QAction"""
action = QAction(text, parent)
if triggered is not None:
action.triggered.connect(triggered)
if toggled is not None:
action.toggled.connect(toggled)
action.setCheckable(True)
if icon is not None:
if is_text_string(icon):
icon = get_icon(icon)
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if data is not None:
action.setData(to_qvariant(data))
if menurole is not None:
action.setMenuRole(menurole)
#TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
# (this will avoid calling shortcuts from another dockwidget
# since the context thing doesn't work quite well with these widgets)
action.setShortcutContext(context)
return action
示例2: create_action
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
toggled=None, triggered=None, data=None, menurole=None,
context=Qt.WindowShortcut):
"""Create a QAction"""
action = QAction(text, parent)
if triggered is not None:
action.triggered.connect(triggered)
if toggled is not None:
action.toggled.connect(toggled)
action.setCheckable(True)
if icon is not None:
if is_text_string(icon):
icon = get_icon(icon)
action.setIcon(icon)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if data is not None:
action.setData(to_qvariant(data))
if menurole is not None:
action.setMenuRole(menurole)
# Workround for Mac because setting context=Qt.WidgetShortcut
# there doesn't have any effect
if sys.platform == 'darwin':
action._shown_shortcut = None
if context == Qt.WidgetShortcut:
if shortcut is not None:
action._shown_shortcut = shortcut
else:
# This is going to be filled by
# main.register_shortcut
action._shown_shortcut = 'missing'
else:
if shortcut is not None:
action.setShortcut(shortcut)
action.setShortcutContext(context)
else:
if shortcut is not None:
action.setShortcut(shortcut)
action.setShortcutContext(context)
return action
示例3: create_menus
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def create_menus(self):
exit_action = QAction('&Exit', self)
# exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.setStatusTip('Exit application')
exit_action.triggered.connect(qApp.quit)
menubar = self.menuBar()
file_menu = menubar.addMenu('&File')
open_menu = file_menu.addMenu('&Open')
open_file_action = QAction('&File', self)
open_file_action.triggered.connect(self.openFile)
open_dir_action = QAction('&Directory', self)
open_dir_action.triggered.connect(self.openDirDialog)
open_menu.addAction(open_file_action)
open_menu.addAction(open_dir_action)
file_menu.addAction(exit_action)
示例4: __init__
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self, *args, **kwargs):
QMainWindow.__init__(self, *args, **kwargs)
QtGuiApplication.__init__(self, self)
QtUI.__init__(self, self)
self.menubar = self.menuBar()
self.fileMenu = self.menubar.addMenu('&File')
openAction = QAction(QIcon('open.png'), '&Open...', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open...')
openAction.triggered.connect(self.actionOpen)
exitAction = QAction("&Exit", self, shortcut='Ctrl+Q', statusTip='Exit', triggered=app.exit)
self.fileMenu.addAction(openAction)
self.fileMenu.addSeparator()
sep = self.fileMenu.addSeparator()
self.fileMenu.addAction(exitAction)
self.recentInMenu = RecentInMenu(self, self.fileMenu, self.open, sep)
self.show()
示例5: __init__
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def __init__(self, parent=None):
super(ManiWindow, self).__init__(parent)
self.canvas = qtViewer3d(self)
# self.setWindowTitle("pythonOCC-%s 3d viewer" % VERSION)
self.canvas.InitDriver()
bar = self.menuBar()
file = bar.addMenu("&File")
_new = QAction(QIcon('icons/exit.png'), '&New', self)
_new.setStatusTip("New application")
_new.triggered.connect(self.my_process)
# self.connect(_new, SIGNAL("triggered()"), self.my_process)
file.addAction(_new)
_exit = QAction(QIcon('icons/exit.png'), '&Exit', self)
_exit.setShortcut('Ctrl+Q')
_exit.setStatusTip('Exit application')
_exit.triggered.connect(qApp.quit)
file.addAction(_exit)
self.statusBar()
self.setCentralWidget(self.canvas)
self.resize(800, 600)
示例6: create_action
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def create_action(parent, text, on_triggered=None, shortcut=None,
shortcut_context=None, icon_name=None):
"""Create a QAction based on the give properties
:param parent: The parent object
:param text: Text string to display
:param on_triggered: An optional slot to call on the triggered signal
:param shortcut: An optional shortcut
:param shortcut_context: An optional context for the supplied shortcut.
Only applies if a shortcut has been given
:param icon_name: The name of the qt awesome uri for an icon.
:return: A new QAction object
"""
action = QAction(text, parent)
if on_triggered is not None:
action.triggered.connect(on_triggered)
if shortcut is not None:
action.setShortcut(shortcut)
if shortcut_context is not None:
action.setShortcutContext(shortcut_context)
if icon_name is not None:
action.setIcon(get_icon(icon_name))
return action
示例7: ObjectExplorer
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
class ObjectExplorer(QTreeView):
nodevalue_changed = pyqtSignal(AbstractJsonItem)
nodeproperty_changed = pyqtSignal(AbstractJsonItem)
def __init__(self, rootnode: JsonNode, parent):
super().__init__(parent)
self.mainwindow = parent
self.setModel(JsonDataModel(rootnode, self.mainwindow))
self.model().dataChanged.connect(self.data_changed)
self.setItemDelegate(MyItemDelegate())
self.setDragDropMode(QTreeView.DragDrop)
self.setDragEnabled(True)
self.setAcceptDrops(True)
self.setDropIndicatorShown(True)
self.doubleClicked.connect(self.double_clicked)
# context menu
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_contextmenu)
# actions
# properties action
self.propertiesAction = QAction(self.tr("properties"), self)
self.propertiesAction.setIcon(QIcon(pixmap("document_properties.png")))
self.propertiesAction.triggered.connect(self.show_properties)
# edit action
self.editAction = QAction(self.tr("edit value"), self)
self.editAction.setShortcut("F2")
self.editAction.setIcon(QIcon(pixmap("edit.png")))
self.editAction.triggered.connect(self.edit_value)
# edit key action
self.editkeyAction = QAction(self.tr("edit key"), self)
self.editkeyAction.setIcon(QIcon(pixmap("kgpg_key1_kgpg.png")))
self.editkeyAction.triggered.connect(self.edit_key)
# insert item action
self.insertitemAction = QAction(self.tr("insert item"), self)
self.insertitemAction.setIcon(QIcon(pixmap("list_add.png")))
self.insertitemAction.triggered.connect(self.insert_item)
# insert node action
self.insertnodeAction = QAction(self.tr("insert node"), self)
self.insertnodeAction.setIcon(QIcon(pixmap("list_add.png")))
self.insertnodeAction.triggered.connect(self.insert_node)
# remove item action
self.removeitemAction = QAction(self.tr("remove"), self)
self.removeitemAction.setIcon(QIcon(pixmap("list_remove")))
self.removeitemAction.triggered.connect(self.remove_item)
def data_changed(self, topleft, bottomright, *args):
node = topleft.internalPointer()
if node is not None and isinstance(node, JsonItem):
self.nodevalue_changed.emit(node)
def double_clicked(self, *args, **kwargs):
index = self.currentIndex()
if not index.isValid():
return
column = self.model().columns[index.column()]
if column.name == "value":
self.edit_value()
else:
self.show_properties()
def edit_key(self):
index = self.currentIndex()
if index.isValid():
node = index.internalPointer()
key, b = QInputDialog.getText(
self, "Edit Json item", "Insert new key for item:",
text=node.key
)
if not b:
return
node.key = key
try: # PyQt5
self.model().dataChanged.emit(index, index, [Qt.DisplayRole])
except TypeError: # PyQt4, PySide
self.model().dataChanged.emit(index, index)
def edit_value(self):
index = self.currentIndex()
if not index.isValid():
return
i = self.model().index(index.row(), 2, index.parent())
self.edit(i)
def insert_item(self):
index = self.currentIndex()
if index.isValid():
#.........这里部分代码省略.........
示例8: _update_file_menu
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
def _update_file_menu(self):
"""
Set up the File menu and update the menu with recent files
"""
self.file_menu.clear()
newAction = QAction("&New Reduction...", self)
newAction.setShortcut("Ctrl+N")
newAction.setStatusTip("Start a new reduction")
newAction.triggered.connect(self._new)
openAction = QAction("&Open...", self)
openAction.setShortcut("Ctrl+O")
openAction.setStatusTip("Open an XML file containing reduction parameters")
openAction.triggered.connect(self._file_open)
saveAsAction = QAction("Save as...", self)
saveAsAction.setStatusTip("Save the reduction parameters to XML")
saveAsAction.triggered.connect(self._save_as)
saveAction = QAction("&Save...", self)
saveAction.setShortcut("Ctrl+S")
saveAction.setStatusTip("Save the reduction parameters to XML")
saveAction.triggered.connect(self._save)
exportAction = QAction("&Export...", self)
exportAction.setShortcut("Ctrl+E")
exportAction.setStatusTip("Export to python script for Mantid")
exportAction.triggered.connect(self._export)
quitAction = QAction("&Quit", self)
quitAction.setShortcut("Ctrl+Q")
quitAction.triggered.connect(self.close)
self.file_menu.addAction(newAction)
self.file_menu.addAction(openAction)
self.file_menu.addAction(saveAction)
self.file_menu.addAction(saveAsAction)
self.file_menu.addAction(exportAction)
self.file_menu.addSeparator()
if self.general_settings.debug:
clearAction = QAction("&Clear settings and quit", self)
clearAction.setStatusTip("Restore initial application settings and close the application")
clearAction.triggered.connect(self._clear_and_close)
self.file_menu.addAction(clearAction)
self.file_menu.addAction(quitAction)
# TOOLS menu
instrAction = QAction("Change &instrument...", self)
instrAction.setShortcut("Ctrl+I")
instrAction.setStatusTip("Select a new instrument")
instrAction.triggered.connect(self._change_instrument)
debug_menu_item_str = "Turn debug mode ON"
if self.general_settings.debug:
debug_menu_item_str = "Turn debug mode OFF"
debugAction = QAction(debug_menu_item_str, self)
debugAction.setStatusTip(debug_menu_item_str)
debugAction.triggered.connect(self._debug_mode)
self.tools_menu.clear()
self.tools_menu.addAction(instrAction)
self.tools_menu.addAction(debugAction)
recent_files = []
for fname in self._recent_files:
if fname != self._filename and QFile.exists(fname) and fname not in recent_files:
recent_files.append(fname)
if len(recent_files)>0:
self.file_menu.addSeparator()
for i, fname in enumerate(recent_files):
action = QAction("&%d %s" % (i+1, QFileInfo(fname).fileName()), self)
action.setData(fname)
action.triggered.connect(self.open_file)
self.file_menu.addAction(action)
示例9: MainWindow
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.recording_enabled = False
self.serial = serial.Serial()
self.rootnode = JsonNode('')
self._connected = False
self._dirty = False
self._filename = None
# settings
self.settings = QSettingsManager()
set_default_settings(self.settings)
# Controller Settings
self.settingsDialog = None
# object explorer
self.objectexplorer = ObjectExplorer(self.rootnode, self)
self.objectexplorer.nodevalue_changed.connect(self.send_serialdata)
self.objectexplorer.nodeproperty_changed.connect(self.set_dirty)
self.objectexplorerDockWidget = QDockWidget(self.tr("object explorer"),
self)
self.objectexplorerDockWidget.setObjectName(
"objectexplorer_dockwidget")
self.objectexplorerDockWidget.setWidget(self.objectexplorer)
# plot widget
self.plot = PlotWidget(self.rootnode, self.settings, self)
# plot settings
self.plotsettings = PlotSettingsWidget(self.settings, self.plot, self)
self.plotsettingsDockWidget = QDockWidget(self.tr("plot settings"),
self)
self.plotsettingsDockWidget.setObjectName("plotsettings_dockwidget")
self.plotsettingsDockWidget.setWidget(self.plotsettings)
# log widget
self.loggingWidget = LoggingWidget(self)
self.loggingDockWidget = QDockWidget(self.tr("logger"), self)
self.loggingDockWidget.setObjectName("logging_dockwidget")
self.loggingDockWidget.setWidget(self.loggingWidget)
# record widget
self.recordWidget = RecordWidget(self.rootnode, self)
self.recordDockWidget = QDockWidget(self.tr("data recording"), self)
self.recordDockWidget.setObjectName("record_dockwidget")
self.recordDockWidget.setWidget(self.recordWidget)
# actions and menus
self._init_actions()
self._init_menus()
# statusbar
statusbar = self.statusBar()
statusbar.setVisible(True)
self.connectionstateLabel = QLabel(self.tr("Not connected"))
statusbar.addPermanentWidget(self.connectionstateLabel)
statusbar.showMessage(self.tr("Ready"))
# layout
self.setCentralWidget(self.plot)
self.addDockWidget(Qt.LeftDockWidgetArea,
self.objectexplorerDockWidget)
self.addDockWidget(Qt.LeftDockWidgetArea, self.plotsettingsDockWidget)
self.addDockWidget(Qt.BottomDockWidgetArea, self.loggingDockWidget)
self.addDockWidget(Qt.BottomDockWidgetArea, self.recordDockWidget)
self.load_settings()
def _init_actions(self):
# Serial Dialog
self.serialdlgAction = QAction(self.tr("Serial Settings..."), self)
self.serialdlgAction.setShortcut("F6")
self.serialdlgAction.setIcon(QIcon(pixmap("configure.png")))
self.serialdlgAction.triggered.connect(self.show_serialdlg)
# Connect
self.connectAction = QAction(self.tr("Connect"), self)
self.connectAction.setShortcut("F5")
self.connectAction.setIcon(QIcon(pixmap("network-connect-3.png")))
self.connectAction.triggered.connect(self.toggle_connect)
# Quit
self.quitAction = QAction(self.tr("Quit"), self)
self.quitAction.setShortcut("Alt+F4")
self.quitAction.setIcon(QIcon(pixmap("window-close-3.png")))
self.quitAction.triggered.connect(self.close)
# Save Config as
self.saveasAction = QAction(self.tr("Save as..."), self)
self.saveasAction.setShortcut("Ctrl+Shift+S")
self.saveasAction.setIcon(QIcon(pixmap("document-save-as-5.png")))
self.saveasAction.triggered.connect(self.show_savecfg_dlg)
# Save file
self.saveAction = QAction(self.tr("Save"), self)
self.saveAction.setShortcut("Ctrl+S")
self.saveAction.setIcon(QIcon(pixmap("document-save-5.png")))
#.........这里部分代码省略.........
示例10: MainWindow
# 需要导入模块: from qtpy.QtWidgets import QAction [as 别名]
# 或者: from qtpy.QtWidgets.QAction import setShortcut [as 别名]
class MainWindow(QMainWindow):
"""OpenBurn's main window"""
title = "OpenBurn"
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle(self.title)
self.setGeometry(100, 100, 800, 600)
self.setWindowIcon(QIcon(RESOURCE_PATH + "icons/nakka-finocyl.gif"))
self.create_default_widgets()
self.setup_ui()
def create_default_widgets(self):
"""Creates static widgets such as menubar and statusbar"""
def create_menubar():
"""Create menu bar and populate it with sub menu actions"""
def file_menu():
"""Create a file submenu"""
self.file_sub_menu = self.menubar.addMenu('File')
self.open_action = QAction('Open File', self)
self.open_action.setStatusTip('Open a new design')
self.open_action.setShortcut('CTRL+O')
# self.open_action.triggered.connect(self.open_file)
self.exit_action = QAction('Exit', self)
self.exit_action.setStatusTip('Exit the application.')
self.exit_action.setShortcut('CTRL+Q')
self.exit_action.triggered.connect(QApplication.quit)
self.file_sub_menu.addAction(self.open_action)
self.file_sub_menu.addAction(self.exit_action)
def edit_menu():
self.edit_dub_menu = self.menubar.addMenu('Edit')
def tools_menu():
self.edit_dub_menu = self.menubar.addMenu('Tools')
def help_menu():
"""Create help submenu"""
self.help_sub_menu = self.menubar.addMenu('Help')
self.about_action = QAction('About', self)
self.about_action.setStatusTip('About the application.')
self.about_action.setShortcut('CTRL+H')
self.about_action.triggered.connect(self.about_dialog.exec_)
self.help_sub_menu.addAction(self.about_action)
self.menubar = QMenuBar(self)
file_menu()
edit_menu()
tools_menu()
help_menu()
def create_statusbar():
self.statusbar = QStatusBar(self)
self.statusbar.showMessage("Ready", 0)
self.about_dialog = AboutDialog(self)
create_menubar()
self.setMenuBar(self.menubar)
create_statusbar()
self.setStatusBar(self.statusbar)
def setup_ui(self):
"""setup the tab widget UI"""
self.tab_widget = QTabWidget()
self.tab_widget.addTab(DesignTab(), "Design")
self.tab_widget.addTab(QWidget(), "Simulation")
self.tab_widget.addTab(QWidget(), "Propellants")
self.layout = QVBoxLayout()
self.layout.addWidget(self.tab_widget)
self.frame = QFrame()
self.frame.setLayout(self.layout)
self.setCentralWidget(self.frame)