本文整理汇总了Python中python_qt_binding.QtGui.QMenu.addMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.addMenu方法的具体用法?Python QMenu.addMenu怎么用?Python QMenu.addMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.addMenu方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_context_menu_for_tag
# 需要导入模块: from python_qt_binding.QtGui import QMenu [as 别名]
# 或者: from python_qt_binding.QtGui.QMenu import addMenu [as 别名]
def _create_context_menu_for_tag(self):
if isinstance(self.hl, XmlHighlighter):
tag = self.hl.get_tag_of_current_block(self.textCursor().block(), self.textCursor().positionInBlock())
if tag:
try:
menu = QMenu("ROS <%s>" % tag, self)
menu.triggered.connect(self._context_activated)
# create a menu with attributes
menu_attr = QMenu("attributes", menu)
attributes = sorted(list(set(XmlHighlighter.LAUNCH_ATTR[tag])))
for attr in attributes:
action = menu_attr.addAction(attr.rstrip('='))
action.setData('%s""' % attr)
menu.addMenu(menu_attr)
# create a menu with tags
tags = sorted(XmlHighlighter.LAUNCH_CHILDS[tag])
if tags:
menu_tags = QMenu("tags", menu)
for tag in tags:
data = '<%s></%s>' % (tag, tag) if XmlHighlighter.LAUNCH_CHILDS[tag] else '<%s/>' % tag
action = menu_tags.addAction(tag)
action.setData(data)
menu.addMenu(menu_tags)
return menu
except:
import traceback
print traceback.format_exc(1)
return None
return None
示例2: __init__
# 需要导入模块: from python_qt_binding.QtGui import QMenu [as 别名]
# 或者: from python_qt_binding.QtGui.QMenu import addMenu [as 别名]
def __init__(self, timeline, event, menu_topic):
super(TimelinePopupMenu, self).__init__()
self.parent = timeline
self.timeline = timeline
if menu_topic is not None:
self.setTitle(menu_topic)
self._menu_topic = menu_topic
else:
self._menu_topic = None
self._reset_timeline = self.addAction('Reset Timeline')
self._play_all = self.addAction('Play All Messages')
self._play_all.setCheckable(True)
self._play_all.setChecked(self.timeline.play_all)
self.addSeparator()
self._renderers = self.timeline._timeline_frame.get_renderers()
self._thumbnail_actions = []
# create thumbnail menu items
if menu_topic is None:
submenu = self.addMenu('Thumbnails...')
self._thumbnail_show_action = submenu.addAction('Show All')
self._thumbnail_hide_action = submenu.addAction('Hide All')
submenu.addSeparator()
for topic, renderer in self._renderers:
self._thumbnail_actions.append(submenu.addAction(topic))
self._thumbnail_actions[-1].setCheckable(True)
self._thumbnail_actions[-1].setChecked(self.timeline._timeline_frame.is_renderer_active(topic))
else:
self._thumbnail_show_action = None
self._thumbnail_hide_action = None
for topic, renderer in self._renderers:
if menu_topic == topic:
self._thumbnail_actions.append(self.addAction("Thumbnail"))
self._thumbnail_actions[-1].setCheckable(True)
self._thumbnail_actions[-1].setChecked(self.timeline._timeline_frame.is_renderer_active(topic))
# create view menu items
self._topic_actions = []
self._type_actions = []
if menu_topic is None:
self._topics = self.timeline._timeline_frame.topics
view_topics_menu = self.addMenu('View (by Topic)')
for topic in self._topics:
datatype = self.timeline.get_datatype(topic)
# View... / topic
topic_menu = QMenu(topic, self)
viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
# View... / topic / Viewer
for viewer_type in viewer_types:
tempaction = topic_menu.addAction(viewer_type.name)
tempaction.setData(viewer_type)
self._topic_actions.append(tempaction)
view_topics_menu.addMenu(topic_menu)
view_type_menu = self.addMenu('View (by Type)')
self._topics_by_type = self.timeline._timeline_frame._topics_by_datatype
for datatype in self._topics_by_type:
# View... / datatype
datatype_menu = QMenu(datatype, self)
datatype_topics = self._topics_by_type[datatype]
viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
for topic in [t for t in self._topics if t in datatype_topics]: # use timeline ordering
topic_menu = QMenu(topic, datatype_menu)
# View... / datatype / topic / Viewer
for viewer_type in viewer_types:
tempaction = topic_menu.addAction(viewer_type.name)
tempaction.setData(viewer_type)
self._topic_actions.append(tempaction)
datatype_menu.addMenu(topic_menu)
view_type_menu.addMenu(datatype_menu)
else:
view_menu = self.addMenu("View")
datatype = self.timeline.get_datatype(menu_topic)
viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
for viewer_type in viewer_types:
tempaction = view_menu.addAction(viewer_type.name)
tempaction.setData(viewer_type)
self._topic_actions.append(tempaction)
self.addSeparator()
# create publish menu items
self._publish_actions = []
if menu_topic is None:
submenu = self.addMenu('Publish...')
self._publish_all = submenu.addAction('Publish All')
self._publish_none = submenu.addAction('Publish None')
#.........这里部分代码省略.........
示例3: _rightclick_menu
# 需要导入模块: from python_qt_binding.QtGui import QMenu [as 别名]
# 或者: from python_qt_binding.QtGui.QMenu import addMenu [as 别名]
def _rightclick_menu(self, event):
"""
Dynamically builds the rightclick menu based on the unique column data
from the passed in datamodel and then launches it modally
:param event: the mouse event object, ''QMouseEvent''
"""
severities = {}
for severity, label in Message.SEVERITY_LABELS.items():
if severity in self._model.get_unique_severities():
severities[severity] = label
nodes = sorted(self._model.get_unique_nodes())
topics = sorted(self._model.get_unique_topics())
# menutext entries turned into
menutext = []
menutext.append([self.tr('Exclude'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]]])
menutext.append([self.tr('Highlight'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]]])
menutext.append([self.tr('Copy Selected')])
menutext.append([self.tr('Browse Selected')])
menu = QMenu()
submenus = []
subsubmenus = []
for item in menutext:
if len(item) > 1:
submenus.append(QMenu(item[0], menu))
for subitem in item[1]:
if len(subitem) > 1:
subsubmenus.append(QMenu(subitem[0], submenus[-1]))
if isinstance(subitem[1], dict):
for key in sorted(subitem[1].keys()):
action = subsubmenus[-1].addAction(subitem[1][key])
action.setData(key)
else:
for subsubitem in subitem[1]:
subsubmenus[-1].addAction(subsubitem)
submenus[-1].addMenu(subsubmenus[-1])
else:
submenus[-1].addAction(subitem[0])
menu.addMenu(submenus[-1])
else:
menu.addAction(item[0])
action = menu.exec_(event.globalPos())
if action is None or action == 0:
return
elif action.text() == self.tr('Browse Selected'):
self._show_browsers()
elif action.text() == self.tr('Copy Selected'):
rowlist = []
for current in self.table_view.selectionModel().selectedIndexes():
rowlist.append(self._proxy_model.mapToSource(current).row())
copytext = self._model.get_selected_text(rowlist)
if copytext is not None:
clipboard = QApplication.clipboard()
clipboard.setText(copytext)
elif action.text() == self.tr('Selected Message(s)'):
if action.parentWidget().title() == self.tr('Highlight'):
self._process_highlight_exclude_filter(action.text(), 'Message', False)
elif action.parentWidget().title() == self.tr('Exclude'):
self._process_highlight_exclude_filter(action.text(), 'Message', True)
else:
raise RuntimeError("Menu format corruption in ConsoleWidget._rightclick_menu()")
else:
# This processes the dynamic list entries (severity, node and topic)
try:
roottitle = action.parentWidget().parentWidget().title()
except:
raise RuntimeError("Menu format corruption in ConsoleWidget._rightclick_menu()")
if roottitle == self.tr('Highlight'):
self._process_highlight_exclude_filter(action.text(), action.parentWidget().title(), False)
elif roottitle == self.tr('Exclude'):
self._process_highlight_exclude_filter(action.text(), action.parentWidget().title(), True)
else:
raise RuntimeError("Unknown Root Action %s selected in ConsoleWidget._rightclick_menu()" % roottitle)