本文整理汇总了Python中spyderlib.qt.QtGui.QMenu类的典型用法代码示例。如果您正苦于以下问题:Python QMenu类的具体用法?Python QMenu怎么用?Python QMenu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMenu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent):
QTableView.__init__(self, parent)
self._model = None
# Setting up actions
self.date_dayfirst_action = create_action(
self, "dayfirst", triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=True)
)
self.date_monthfirst_action = create_action(
self, "monthfirst", triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=False)
)
self.perc_action = create_action(self, "perc", triggered=ft_partial(self.parse_to_type, atype="perc"))
self.acc_action = create_action(self, "account", triggered=ft_partial(self.parse_to_type, atype="account"))
self.str_action = create_action(self, "unicode", triggered=ft_partial(self.parse_to_type, atype="unicode"))
self.int_action = create_action(self, "int", triggered=ft_partial(self.parse_to_type, atype="int"))
self.float_action = create_action(self, "float", triggered=ft_partial(self.parse_to_type, atype="float"))
# Setting up menus
self.date_menu = QMenu()
self.date_menu.setTitle("Date")
add_actions(self.date_menu, (self.date_dayfirst_action, self.date_monthfirst_action))
self.parse_menu = QMenu(self)
self.parse_menu.addMenu(self.date_menu)
add_actions(self.parse_menu, (self.perc_action, self.acc_action))
self.parse_menu.setTitle("String to")
self.opt_menu = QMenu(self)
self.opt_menu.addMenu(self.parse_menu)
add_actions(self.opt_menu, (self.str_action, self.int_action, self.float_action))
示例2: __init__
def __init__(self, parent, actions=None, menu=None,
corner_widgets=None, menu_use_tooltips=False):
QTabWidget.__init__(self, parent)
self.setUsesScrollButtons(True)
# To style tabs on Mac
if sys.platform == 'darwin':
self.setObjectName('plugin-tab')
self.corner_widgets = {}
self.menu_use_tooltips = menu_use_tooltips
if menu is None:
self.menu = QMenu(self)
if actions:
add_actions(self.menu, actions)
else:
self.menu = menu
# Corner widgets
if corner_widgets is None:
corner_widgets = {}
corner_widgets.setdefault(Qt.TopLeftCorner, [])
corner_widgets.setdefault(Qt.TopRightCorner, [])
self.browse_button = create_toolbutton(self,
icon=ima.icon('browse_tab'),
tip=_("Browse tabs"))
self.browse_tabs_menu = QMenu(self)
self.browse_button.setMenu(self.browse_tabs_menu)
self.browse_button.setPopupMode(self.browse_button.InstantPopup)
self.browse_tabs_menu.aboutToShow.connect(self.update_browse_tabs_menu)
corner_widgets[Qt.TopLeftCorner] += [self.browse_button]
self.set_corner_widgets(corner_widgets)
示例3: __init__
def __init__(self, parent, actions=None, menu=None,
corner_widgets=None, menu_use_tooltips=False):
QTabWidget.__init__(self, parent)
self.setUsesScrollButtons(True)
self.corner_widgets = {}
self.menu_use_tooltips = menu_use_tooltips
if menu is None:
self.menu = QMenu(self)
if actions:
add_actions(self.menu, actions)
else:
self.menu = menu
# Corner widgets
if corner_widgets is None:
corner_widgets = {}
corner_widgets.setdefault(Qt.TopLeftCorner, [])
corner_widgets.setdefault(Qt.TopRightCorner, [])
self.browse_button = create_toolbutton(self,
icon=get_icon("browse_tab.png"),
tip=_("Browse tabs"))
self.browse_tabs_menu = QMenu(self)
self.browse_button.setMenu(self.browse_tabs_menu)
self.browse_button.setPopupMode(self.browse_button.InstantPopup)
self.browse_tabs_menu.aboutToShow.connect(self.update_browse_tabs_menu)
corner_widgets[Qt.TopLeftCorner] += [self.browse_button]
self.set_corner_widgets(corner_widgets)
示例4: get_plugin_actions
def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
quit_action = create_action(self, _("&Quit"),
icon=ima.icon('exit'),
tip=_("Quit"),
triggered=self.quit)
self.register_shortcut(quit_action, "_", "Quit", "Ctrl+Q")
run_action = create_action(self, _("&Run..."), None,
ima.icon('run_small'),
_("Run a Python script"),
triggered=self.run_script)
environ_action = create_action(self,
_("Environment variables..."),
icon=ima.icon('environ'),
tip=_("Show and edit environment variables"
" (for current session)"),
triggered=self.show_env)
syspath_action = create_action(self,
_("Show sys.path contents..."),
icon=ima.icon('syspath'),
tip=_("Show (read-only) sys.path"),
triggered=self.show_syspath)
buffer_action = create_action(self,
_("Buffer..."), None,
tip=_("Set maximum line count"),
triggered=self.change_max_line_count)
exteditor_action = create_action(self,
_("External editor path..."), None, None,
_("Set external editor executable path"),
triggered=self.change_exteditor)
wrap_action = create_action(self,
_("Wrap lines"),
toggled=self.toggle_wrap_mode)
wrap_action.setChecked(self.get_option('wrap'))
calltips_action = create_action(self, _("Display balloon tips"),
toggled=self.toggle_calltips)
calltips_action.setChecked(self.get_option('calltips'))
codecompletion_action = create_action(self,
_("Automatic code completion"),
toggled=self.toggle_codecompletion)
codecompletion_action.setChecked(self.get_option('codecompletion/auto'))
codecompenter_action = create_action(self,
_("Enter key selects completion"),
toggled=self.toggle_codecompletion_enter)
codecompenter_action.setChecked(self.get_option(
'codecompletion/enter_key'))
option_menu = QMenu(_('Internal console settings'), self)
option_menu.setIcon(ima.icon('tooloptions'))
add_actions(option_menu, (buffer_action, wrap_action,
calltips_action, codecompletion_action,
codecompenter_action, exteditor_action))
plugin_actions = [None, run_action, environ_action, syspath_action,
option_menu, None, quit_action]
# Add actions to context menu
add_actions(self.shell.menu, plugin_actions)
return plugin_actions
示例5: contextMenuEvent
def contextMenuEvent(self, event):
menu = QMenu(self)
add_actions( menu, (self.pageAction(QWebPage.Back),
self.pageAction(QWebPage.Forward), None,
self.pageAction(QWebPage.SelectAll),
self.pageAction(QWebPage.Copy), None,
self.pageAction(QWebPage.Reload), None,
self.zoom_in_action, self.zoom_out_action) )
menu.popup(event.globalPos())
event.accept()
示例6: BreakpointTableView
class BreakpointTableView(QTableView):
def __init__(self, parent, data):
QTableView.__init__(self, parent)
self.model = BreakpointTableModel(self, data)
self.setModel(self.model)
self.delegate = BreakpointDelegate(self)
self.setItemDelegate(self.delegate)
self.setup_table()
def setup_table(self):
"""Setup table"""
self.horizontalHeader().setStretchLastSection(True)
self.adjust_columns()
self.columnAt(0)
# Sorting columns
self.setSortingEnabled(False)
self.sortByColumn(0, Qt.DescendingOrder)
def adjust_columns(self):
"""Resize three first columns to contents"""
for col in range(3):
self.resizeColumnToContents(col)
def mouseDoubleClickEvent(self, event):
"""Reimplement Qt method"""
index_clicked = self.indexAt(event.pos())
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
line_number_str = self.model.breakpoints[index_clicked.row()][1]
self.emit(SIGNAL("edit_goto(QString,int,QString)"), filename, int(line_number_str), "")
def contextMenuEvent(self, event):
index_clicked = self.indexAt(event.pos())
actions = []
self.popup_menu = QMenu(self)
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
lineno = int(self.model.breakpoints[index_clicked.row()][1])
clear_breakpoint_action = create_action(
self,
_("Clear this breakpoint"),
triggered=lambda filename=filename, lineno=lineno: self.emit(
SIGNAL("clear_breakpoint(QString,int)"), filename, lineno
),
)
actions.append(clear_breakpoint_action)
clear_all_breakpoints_action = create_action(
self, _("Clear breakpoints in all files"), triggered=lambda: self.emit(SIGNAL("clear_all_breakpoints()"))
)
actions.append(clear_all_breakpoints_action)
add_actions(self.popup_menu, actions)
self.popup_menu.popup(event.globalPos())
event.accept()
示例7: contextMenuEvent
def contextMenuEvent(self, event):
menu = QMenu(self)
actions = [self.pageAction(QWebPage.Back),
self.pageAction(QWebPage.Forward), None,
self.pageAction(QWebPage.SelectAll),
self.pageAction(QWebPage.Copy), None,
self.zoom_in_action, self.zoom_out_action]
if DEV:
settings = self.page().settings()
settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
actions += [None, self.pageAction(QWebPage.InspectElement)]
add_actions(menu, actions)
menu.popup(event.globalPos())
event.accept()
示例8: context_menu_requested
def context_menu_requested(self, event):
""" """
pos = QPoint(event.x(), event.y())
menu = QMenu(self)
actions = []
action_title = create_action(self, _('Go to step: '), icon=QIcon())
action_title.setDisabled(True)
actions.append(action_title)
# actions.append(create_action(self, _(': '), icon=QIcon()))
add_actions(menu, actions)
menu.popup(self.mapToGlobal(pos))
示例9: setup_context_menu
def setup_context_menu(self):
"""Setup shell context menu"""
self.menu = QMenu(self)
self.cut_action = create_action(self, _("Cut"),
shortcut=keybinding('Cut'),
icon=ima.icon('editcut'),
triggered=self.cut)
self.copy_action = create_action(self, _("Copy"),
shortcut=keybinding('Copy'),
icon=ima.icon('editcopy'),
triggered=self.copy)
paste_action = create_action(self, _("Paste"),
shortcut=keybinding('Paste'),
icon=ima.icon('editpaste'),
triggered=self.paste)
save_action = create_action(self, _("Save history log..."),
icon=ima.icon('filesave'),
tip=_("Save current history log (i.e. all "
"inputs and outputs) in a text file"),
triggered=self.save_historylog)
self.delete_action = create_action(self, _("Delete"),
shortcut=keybinding('Delete'),
icon=ima.icon('editdelete'),
triggered=self.delete)
selectall_action = create_action(self, _("Select All"),
shortcut=keybinding('SelectAll'),
icon=ima.icon('selectall'),
triggered=self.selectAll)
add_actions(self.menu, (self.cut_action, self.copy_action,
paste_action, self.delete_action, None,
selectall_action, None, save_action) )
示例10: contextMenuEvent
def contextMenuEvent(self, event):
index_clicked = self.indexAt(event.pos())
actions = []
self.popup_menu = QMenu(self)
clear_all_breakpoints_action = create_action(
self, _("Clear breakpoints in all files"), triggered=lambda: self.clear_all_breakpoints.emit()
)
actions.append(clear_all_breakpoints_action)
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
lineno = int(self.model.breakpoints[index_clicked.row()][1])
clear_breakpoint_action = create_action(
self,
_("Clear this breakpoint"),
triggered=lambda filename=filename, lineno=lineno: self.clear_breakpoint.emit(filename, lineno),
)
actions.insert(0, clear_breakpoint_action)
edit_breakpoint_action = create_action(
self,
_("Edit this breakpoint"),
triggered=lambda filename=filename, lineno=lineno: (
self.edit_goto.emit(filename, lineno, ""),
self.set_or_edit_conditional_breakpoint.emit(),
),
)
actions.append(edit_breakpoint_action)
add_actions(self.popup_menu, actions)
self.popup_menu.popup(event.globalPos())
event.accept()
示例11: setup
def setup(self, name_filters=["*.py", "*.pyw"], show_all=False):
"""Setup tree widget"""
self.setup_view()
self.set_name_filters(name_filters)
self.show_all = show_all
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions()
示例12: setup
def setup(self, name_filters=['*.py', '*.pyw'],
valid_types= ('.py', '.pyw'), show_all=False):
"""Setup tree widget"""
self.setup_view()
self.set_name_filters(name_filters)
self.valid_types = valid_types
self.show_all = show_all
# Setup context menu
self.menu = QMenu(self)
self.common_actions = self.setup_common_actions()
示例13: __init__
def __init__(self, parent):
QTreeWidget.__init__(self, parent)
self.setItemsExpandable(True)
self.setColumnCount(1)
self.itemActivated.connect(self.activated)
self.itemClicked.connect(self.clicked)
# Setup context menu
self.menu = QMenu(self)
self.collapse_all_action = None
self.collapse_selection_action = None
self.expand_all_action = None
self.expand_selection_action = None
self.common_actions = self.setup_common_actions()
self.__expanded_state = None
self.itemSelectionChanged.connect(self.item_selection_changed)
self.item_selection_changed()
示例14: contextMenuEvent
def contextMenuEvent(self, event):
index_clicked = self.indexAt(event.pos())
actions = []
self.popup_menu = QMenu(self)
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
lineno = int(self.model.breakpoints[index_clicked.row()][1])
clear_breakpoint_action = create_action(
self,
_("Clear this breakpoint"),
triggered=lambda filename=filename, lineno=lineno: self.emit(
SIGNAL("clear_breakpoint(QString,int)"), filename, lineno
),
)
actions.append(clear_breakpoint_action)
clear_all_breakpoints_action = create_action(
self, _("Clear breakpoints in all files"), triggered=lambda: self.emit(SIGNAL("clear_all_breakpoints()"))
)
actions.append(clear_all_breakpoints_action)
add_actions(self.popup_menu, actions)
self.popup_menu.popup(event.globalPos())
event.accept()
示例15: contextMenuEvent
def contextMenuEvent(self, event):
index_clicked = self.indexAt(event.pos())
actions = []
self.popup_menu = QMenu(self)
clear_all_breakpoints_action = create_action(self,
_("Clear breakpoints in all files"),
triggered=lambda: self.clear_all_breakpoints.emit())
actions.append(clear_all_breakpoints_action)
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
lineno = int(self.model.breakpoints[index_clicked.row()][1])
# QAction.triggered works differently for PySide and PyQt
if not API == 'pyside':
clear_slot = lambda _checked, filename=filename, lineno=lineno: \
self.clear_breakpoint.emit(filename, lineno)
edit_slot = lambda _checked, filename=filename, lineno=lineno: \
(self.edit_goto.emit(filename, lineno, ''),
self.set_or_edit_conditional_breakpoint.emit())
else:
clear_slot = lambda filename=filename, lineno=lineno: \
self.clear_breakpoint.emit(filename, lineno)
edit_slot = lambda filename=filename, lineno=lineno: \
(self.edit_goto.emit(filename, lineno, ''),
self.set_or_edit_conditional_breakpoint.emit())
clear_breakpoint_action = create_action(self,
_("Clear this breakpoint"),
triggered=clear_slot)
actions.insert(0,clear_breakpoint_action)
edit_breakpoint_action = create_action(self,
_("Edit this breakpoint"),
triggered=edit_slot)
actions.append(edit_breakpoint_action)
add_actions(self.popup_menu, actions)
self.popup_menu.popup(event.globalPos())
event.accept()