本文整理汇总了Python中PyQt4.QtGui.QMenu.show方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.show方法的具体用法?Python QMenu.show怎么用?Python QMenu.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.show方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Main
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class Main(plugin.Plugin):
" Main Class "
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
if linux_distribution():
self.menu = QMenu('Open with')
self.menu.aboutToShow.connect(self.build_submenu)
self.ex_locator = self.locator.get_service('explorer')
self.ex_locator.add_project_menu(self.menu, lang='all')
def build_submenu(self):
''' build sub menu on the fly based on file path '''
self.menu.clear()
if self.ex_locator.get_current_project_item().isFolder is not True:
filenam = self.ex_locator.get_current_project_item().get_full_path()
entry = xdg_query('default', guess_type(filenam, strict=False)[0])
if entry:
app = entry.replace('.desktop', '')
self.menu.addActions([
QAction(QIcon.fromTheme(app), app, self,
triggered=lambda: Popen([app, filenam])),
QAction(QIcon.fromTheme('folder-open'), 'File Manager',
self, triggered=lambda: Popen(['xdg-open',
path.dirname(filenam)]))])
self.menu.show()
示例2: Main
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class Main(plugin.Plugin):
" Main Class "
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
self.menu = QMenu('Convert Image')
self.menu.aboutToShow.connect(self.build_submenu)
self.ex_locator = self.locator.get_service('explorer')
self.ex_locator.add_project_menu(self.menu, lang='all')
def build_submenu(self):
''' build sub menu on the fly based on file path '''
self.menu.clear()
if self.ex_locator.get_current_project_item().isFolder is not True:
filenam = self.ex_locator.get_current_project_item().get_full_path()
# pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
exten = ('bmp', 'cur', 'gbr', 'gif', 'ico', 'jfif', 'jpeg', 'pbm',
'pcx', 'pgm', 'png', 'ppm', 'psd', 'tga', 'tiff', 'xbm', 'xpm')
conditional = path.splitext(filenam)[1][1:].strip().lower() in exten
if conditional:
self.menu.addActions([
QAction('{} to WEBP'.format(path.basename(filenam)[:50]),
self, triggered=lambda: self.convert_img('WEBP')),
QAction('{} to JPG'.format(path.basename(filenam)[:50]),
self, triggered=lambda: self.convert_img('JPEG')),
QAction('{} to PNG'.format(path.basename(filenam)[:50]),
self, triggered=lambda: self.convert_img('PNG')), ])
self.menu.show()
def convert_img(self, fmt):
""" convert image to desired format """
filenam = self.ex_locator.get_current_project_item().get_full_path()
im = Image.open(filenam).convert("RGB")
im.save(path.splitext(filenam)[0] + ".{}".format(fmt.lower()), fmt)
示例3: Main
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class Main(plugin.Plugin):
" Main Class "
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
if linux_distribution():
self.menu = QMenu('Open with')
self.menu.aboutToShow.connect(self.build_submenu)
self.ex_locator = self.locator.get_service('explorer')
self.ex_locator.add_project_menu(self.menu, lang='all')
def build_submenu(self):
''' build sub menu on the fly based on file path '''
self.menu.clear()
if self.ex_locator.get_current_project_item().isFolder is not True:
filenam = self.ex_locator.get_current_project_item().get_full_path()
entry = xdg_query('default', guess_type(filenam, strict=False)[0])
if entry:
app = entry.replace('.desktop', '')
actions = [
QAction(QIcon.fromTheme(app), app, self,
triggered=lambda: Popen([app, filenam])),
QAction(QIcon.fromTheme('folder-open'), 'File Manager',
self, triggered=lambda: Popen(['xdg-open', path.dirname(filenam)]))]
#QAction(QIcon.fromTheme('Sublime Text 2'), 'Sublime',
# self, triggered=lambda: Popen(['sublime-text', filenam])),
#QAction(QIcon.fromTheme('Sqliteman'), 'Sqliteman',
# self, triggered=lambda: Popen(['sqliteman', filenam])),
#QAction(QIcon.fromTheme('Google Chrome'), 'Google Chrome',
# self, triggered=lambda: Popen(['google-chrome', filenam]))
for key in usersettings.commands.keys():
action = QAction(QIcon.fromTheme(key), key,
self, triggered=lambda: Popen([usersettings.commands[key], filenam]))
actions.append(action)
self.menu.addActions(actions)
self.menu.show()
示例4: Main
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class Main(plugin.Plugin):
" Main Class "
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
self.menu1 = QMenu('Compress')
self.menu1.aboutToShow.connect(self.build_submenu)
self.ex_locator = self.locator.get_service('explorer')
self.ex_locator.add_project_menu(self.menu1, lang='all')
if not version_info[0] < 3:
self.menu2 = QMenu('Extract')
self.menu2.aboutToShow.connect(self.build_submenu)
self.ex_locator.add_project_menu(self.menu2, lang='all')
def build_submenu(self):
''' build sub menu on the fly based on file path '''
self.menu1.clear()
if self.ex_locator.get_current_project_item().isFolder is True:
folder = self.ex_locator.get_current_project_item().get_full_path()
self.menu1.addActions([
QAction('To ZIP', self, triggered=lambda:
make_archive(folder, 'zip', folder)),
QAction('To TAR', self, triggered=lambda:
make_archive(folder, 'tar', folder)),
QAction('To BZ2', self, triggered=lambda:
make_archive(folder, 'bztar', folder))])
self.menu1.show()
elif not version_info[0] < 3:
self.menu2.clear()
filenam = self.ex_locator.get_current_project_item().get_full_path()
exten = ('zip', 'tar', 'bz2', 'bztar', 'gztar')
conditional = path.splitext(filenam)[1][1:].strip().lower() in exten
if conditional:
self.menu2.addAction(QAction('From {}'.format(
path.splitext(filenam)[1].upper()), self, triggered=lambda:
unpack_archive(filenam, path.dirname(filenam))))
self.menu2.show()
示例5: PythonConsoleWidget
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class PythonConsoleWidget(QDockWidget):
"""
original code pulled from:
http://stackoverflow.com/questions/31380457/add-right-click-functionality-to-listwidget-in-pyqt4
http://stackoverflow.com/questions/20951660/creating-a-syntax-highlighter-in-pythonpyqt4
http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt
"""
def __init__(self, parent):
self.parent = parent
super(PythonConsoleWidget, self).__init__('Python Console', parent=parent)
#super(QDockWidget, self).__init__('Python Console', parent=parent) # I think this works by accident in qt4/5
self.listMenu = QMenu()
self.execute_python_button = QPushButton('Execute')
self.execute_and_clear_python_button = QPushButton('Execute and Clear')
if is_pygments and is_scintilla:
#self.enter_data = QSyntaxHighlighting()
self.enter_data = SimplePythonEditorWidget()
else:
self.enter_data = QTextEdit()
font = QFont()
font.setFamily('Courier')
self.enter_data.setFont(font)
self.setup_connections()
self.layout()
def layout(self):
vbox = QVBoxLayout()
hbox = QHBoxLayout()
vbox.addWidget(self.enter_data)
hbox.addWidget(self.execute_python_button)
hbox.addWidget(self.execute_and_clear_python_button)
vbox.addLayout(hbox)
vbox_widget = QWidget()
vbox_widget.setLayout(vbox)
self.setWidget(vbox_widget)
def setup_connections(self):
if qt_version == 4:
self.connect(self.execute_python_button, QtCore.SIGNAL('clicked()'),
self.on_execute_python_button)
self.connect(self.execute_and_clear_python_button, QtCore.SIGNAL('clicked()'),
self.on_execute_and_clear_python_button)
else:
self.execute_python_button.clicked.connect(self.on_execute_python_button)
self.execute_and_clear_python_button.clicked.connect(
self.on_execute_and_clear_python_button)
#self.on_rig
# TODO: enables the right click menu
# messes up the previous right click menu
#self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
#self.connect(self, QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
# self.listItemRightClicked)
menu_item1 = self.listMenu.addAction("Properties...")
menu_item2 = self.listMenu.addAction("Select All...")
menu_item3 = self.listMenu.addAction("Copy...")
menu_item1.triggered.connect(self.menuItemClicked_1)
menu_item2.triggered.connect(self.menuItemClicked_2)
menu_item3.triggered.connect(self.menuItemClicked_3)
#self.connect(menu_item1, QtCore.SIGNAL("triggered()"), self.menuItemClicked_1)
#self.connect(menu_item2, QtCore.SIGNAL("triggered()"), self.menuItemClicked_2)
#self.connect(menu_item3, QtCore.SIGNAL("triggered()"), self.menuItemClicked_3)
# we have to create a QWidget to put the console vbox into vbox_widget because
# self.setLayout(vbox)
# is not supported in a QDockWidget
def on_execute_and_clear_python_button(self):
self.parent._on_execute_python_button(clear=True)
def on_execute_python_button(self):
self.parent._on_execute_python_button(clear=False)
def listItemRightClicked(self, QPos):
"""
TDOO: not done...
"""
return
parentPosition = self.mapToGlobal(QtCore.QPoint(0, 0))
self.listMenu.move(parentPosition + QPos)
self.listMenu.show()
def menuItemClicked_1(self):
print(1)
def menuItemClicked_2(self):
print(2)
def menuItemClicked_3(self):
print(3)
示例6: MenuManager
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class MenuManager(QWidget, Ui_nodeActions):
def __init__(self, selection, listmodel):
super(QWidget, self).__init__()
self.setupUi(self)
self.processusManager = ProcessusManager()
self.loader = loader.loader()
self.lmodules = self.loader.modules
self.taskmanager = TaskManager()
self.mainwindow = QApplication.instance().mainWindow
self.createActions()
self.checkedSelection = selection
self.selection = None
self.model = listmodel
self.bookManager = BookmarkManager(self.model)
def createActions(self):
self.extractor = Extractor(self.mainwindow)
self.connect(self.extractor, SIGNAL("filled"), self.launchExtract)
self.actionOpen.setParent(self.mainwindow)
self.actionOpen_in_new_tab.setParent(self.mainwindow)
self.connect(self.actionOpen, SIGNAL("triggered()"), self.openDefault)
self.connect(self.actionOpen_in_new_tab, SIGNAL("triggered()"), self.openAsNewTab)
self.connect(self.actionOpen_parent_folder, SIGNAL("triggered()"), self.openParentFolder)
self.connect(self.actionHex_viewer, SIGNAL("triggered()"), self.launchHexedit)
self.connect(self.actionExtract, SIGNAL("triggered()"), self.extractNodes)
self.connect(self.actionBookmark, SIGNAL("triggered()"), self.bookmark)
def createMenu(self):
nodeclicked = self.model.currentNode()
self.mainmenu = QMenu(self.mainwindow)
self.selection = self.model.currentNode()
self.setOpenRelevant()
self.setOpenWith()
self.mainmenu.addAction(self.actionOpen)
self.mainmenu.addAction(self.actionOpen_with)
self.mainmenu.addAction(self.actionOpen_in_new_tab)
self.mainmenu.addAction(self.actionOpen_parent_folder)
if nodeclicked.isDir() or nodeclicked.hasChildren():
self.actionOpen_parent_folder.setVisible(False)
self.actionOpen_parent_folder.setEnabled(False)
self.actionOpen_in_new_tab.setVisible(True)
self.actionOpen_in_new_tab.setEnabled(True)
else:
self.actionOpen_in_new_tab.setVisible(False)
self.actionOpen_in_new_tab.setEnabled(False)
self.actionOpen_parent_folder.setVisible(True)
self.actionOpen_parent_folder.setEnabled(True)
self.mainmenu.addSeparator()
selection = selectionMenu(self, self.model)
self.mainmenu.addMenu(selection)
tags = tagMenu(self, self.mainwindow, self.model)
self.actionTags.setMenu(tags)
self.mainmenu.addAction(self.actionTags)
self.mainmenu.addAction(self.actionBookmark)
self.bookseparator = self.mainmenu.addSeparator()
self.mainmenu.addAction(self.actionHex_viewer)
self.mainmenu.addAction(self.actionExtract)
self.mainmenu.popup(QCursor.pos())
self.mainmenu.show()
def setOpenRelevant(self):
if self.selection != None:
node = self.selection
modules = node.compatibleModules()
if len(modules):
relevant = QMenu()
for modname in modules:
module = self.loader.modules[modname]
relevant.addAction(newAction(self, self.mainwindow, modname, module.tags, module.icon))
self.actionOpen.setMenu(relevant)
def setOpenWith(self):
owmenu = QMenu()
setags = Utils.getSetTags()
selist = list(setags)
selist.sort()
owmenu.addAction(self.mainwindow.actionBrowse_modules)
owmenu.addSeparator()
for tags in selist:
if not tags == "builtins":
action = QAction(QString(tags), self.mainwindow)
menu = self.getMenuFromModuleTag(tags)
action.setMenu(menu)
owmenu.addAction(action)
self.actionOpen_with.setMenu(owmenu)
def getMenuFromModuleTag(self, tagname):
menu = QMenu()
modules = self.loader.modules
for mod in modules :
m = modules[mod]
try :
if m.tags == tagname:
menu.addAction(newAction(self, self.mainwindow, mod, tagname, m.icon))
# actions.append(newAction(self, self.__mainWindow, mod, self.tags, m.icon))
except AttributeError, e:
pass
return menu
示例7: Main
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import show [as 别名]
class Main(plugin.Plugin):
" Main Class "
def initialize(self, *args, **kwargs):
" Init Main Class "
super(Main, self).initialize(*args, **kwargs)
self.infile = QLineEdit(path.expanduser("~"))
self.infile.setPlaceholderText(' /full/path/to/file ')
self.infile.returnPressed.connect(self.run)
self.completer, self.dirs = QCompleter(self), QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setCompletionMode(QCompleter.PopupCompletion)
self.infile.setCompleter(self.completer)
self.menu = QMenu('Base64')
self.menu.aboutToShow.connect(self.build_submenu)
self.ex_locator = self.locator.get_service('explorer')
self.ex_locator.add_project_menu(self.menu, lang='all')
self.open = QPushButton(QIcon.fromTheme("folder-open"), 'Open')
self.open.setCursor(QCursor(Qt.PointingHandCursor))
self.open.clicked.connect(lambda: self.infile.setText(str(
QFileDialog.getOpenFileName(self.dock, "Open a File to Encode...",
path.expanduser("~"), ';;'.join(['{}(*.{})'.format(e.upper(), e)
for e in ['*', 'jpg', 'png', 'webp', 'svg', 'gif', 'webm']])))))
self.chckbx1 = QCheckBox('Use basic Caesar Cipher (ROT13)')
self.chckbx1.setToolTip('Use "string".decode("rot13") to Decipher ! ')
self.chckbx2 = QCheckBox('Use "data:type/subtype;base64,..."')
self.chckbx2.setChecked(True)
self.chckbx3 = QCheckBox('Copy encoded output to Clipboard')
self.chckbx4 = QCheckBox('Use URL-Safe Base64 Encoder')
self.combo1 = QComboBox()
self.combo1.addItems(['Do Not Generate Code', 'Generate CSS embed Code',
'Generate Python Embed Code', 'Generate HTML embed Code',
'Generate JS embed Code', 'Generate QML embed Code'])
self.combo1.currentIndexChanged.connect(self.combo_changed)
self.output = QTextEdit('''
We can only see a short distance ahead,
but we can see plenty there that needs to be done.
- Alan Turing ''')
self.output.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.button = QPushButton(QIcon.fromTheme("face-cool"), 'Encode BASE64')
self.button.setCursor(QCursor(Qt.PointingHandCursor))
self.button.setMinimumSize(100, 50)
self.button.clicked.connect(self.run)
glow = QGraphicsDropShadowEffect(self)
glow.setOffset(0)
glow.setBlurRadius(99)
glow.setColor(QColor(99, 255, 255))
self.button.setGraphicsEffect(glow)
glow.setEnabled(True)
class TransientWidget(QWidget):
' persistant widget thingy '
def __init__(self, widget_list):
' init sub class '
super(TransientWidget, self).__init__()
vbox = QVBoxLayout(self)
for each_widget in widget_list:
vbox.addWidget(each_widget)
tw = TransientWidget((QLabel('<i>Encode file as plain text string</i>'),
QLabel('<b>File to Encode:'), self.infile, self.open, self.chckbx2,
self.chckbx3, self.chckbx1, self.chckbx4,
QLabel('<b>Embedding Template Code:'), self.combo1,
QLabel(' <b>Base64 String Output: '), self.output,
QLabel('<center><small><i>' + ''.join((__doc__, __version__,
__license__, 'by', __author__))), self.button
))
self.scrollable, self.dock = QScrollArea(), QDockWidget()
self.scrollable.setWidgetResizable(True)
self.scrollable.setWidget(tw)
self.dock.setWindowTitle(__doc__)
self.dock.setStyleSheet('QDockWidget::title{text-align: center;}')
self.dock.setWidget(self.scrollable)
ExplorerContainer().addTab(self.dock, "Base64")
self.guimode = QComboBox(self.dock)
self.guimode.addItems(['Full Mode', 'Simple Mode'])
self.guimode.currentIndexChanged.connect(self.guimode_change)
def guimode_change(self):
""" Change from Simple Mode to Full Mode by Hide or Show Widgets """
if self.guimode.currentIndex() is 0:
self.chckbx1.show()
self.chckbx2.show()
self.chckbx3.show()
self.chckbx4.show()
else:
self.chckbx1.hide()
self.chckbx2.hide()
self.chckbx3.hide()
self.chckbx4.hide()
self.chckbx1.setChecked(False)
self.chckbx2.setChecked(True)
self.chckbx3.setChecked(False)
self.chckbx4.setChecked(False)
#.........这里部分代码省略.........