本文整理汇总了Python中PySide.QtGui.QMenu.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.clear方法的具体用法?Python QMenu.clear怎么用?Python QMenu.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMenu
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
def testMenu(self):
self._actionDestroyed = False
w = QWidget()
menu = QMenu(w)
act = menu.addAction("MENU")
_ref = weakref.ref(act, self.actionDestroyed)
act = None
self.assertFalse(self._actionDestroyed)
menu.clear()
self.assertTrue(self._actionDestroyed)
示例2: Indicator
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class Indicator(QSystemTrayIcon):
def __init__(self, *args, **kwargs):
QSystemTrayIcon.__init__(self, *args, **kwargs)
self.app = QApplication.instance()
self.menu = QMenu()
self.setContextMenu(self.menu)
self.menu.aboutToShow.connect(self.update)
self.opened_notes = {}
self.activated.connect(self._activated)
def _activated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.menu.popup(QCursor().pos())
def _add_note(self, struct):
note = Note.from_tuple(struct)
title = note.title[:40].replace("&", "&&")
self.menu.addAction(title, Slot()(partial(self.open, note=note)))
@Slot()
def update(self):
self.menu.clear()
try:
version = self.app.provider.get_api_version()
except (dbus.exceptions.UnknownMethodException, dbus.exceptions.DBusException): # dbus raise some magic
version = -1
if version != API_VERSION:
action = self.menu.addAction(self.tr("API version missmatch, please restart"))
action.setEnabled(False)
if version < API_VERSION:
handler = self.app.provider.kill
else:
handler = partial(os.execlp, "everpad", "--replace")
self.menu.addAction(self.tr("Restart everpad"), handler)
return
if get_auth_token():
pin_notes = self.app.provider.find_notes(
"", dbus.Array([], signature="i"), dbus.Array([], signature="i"), 0, 20, Note.ORDER_UPDATED_DESC, 1
)
notes = self.app.provider.find_notes(
"",
dbus.Array([], signature="i"),
dbus.Array([], signature="i"),
0,
20 - len(pin_notes),
Note.ORDER_UPDATED_DESC,
0,
)
if len(notes) + len(pin_notes) or self.app.provider.is_first_synced():
self.menu.addAction(self.tr("All Notes"), self.show_all_notes)
self.menu.addSeparator()
if len(pin_notes):
for struct in pin_notes:
self._add_note(struct)
self.menu.addSeparator()
for struct in notes:
self._add_note(struct)
self.menu.addSeparator()
self.menu.addAction(self.tr("Create Note"), self.create)
first_sync = False
else:
first_sync = True
if self.app.provider.get_status() == STATUS_SYNC:
action = self.menu.addAction(
self.tr("Wait, first sync in progress") if first_sync else self.tr("Sync in progress")
)
action.setEnabled(False)
else:
if first_sync:
label = self.tr("Please perform first sync")
else:
last_sync = self.app.provider.get_last_sync()
delta_sync = (datetime.now() - datetime.strptime(last_sync, "%H:%M")).seconds // 60
if delta_sync == 0:
label = self.tr("Last Sync: Just now")
elif delta_sync == 1:
label = self.tr("Last Sync: %s min ago") % delta_sync
else:
label = self.tr("Last Sync: %s mins ago") % delta_sync
self.menu.addAction(label, Slot()(self.app.provider.sync))
self.menu.addAction(self.tr("Settings and Management"), self.show_management)
self.menu.addSeparator()
self.menu.addAction(self.tr("Exit"), self.exit)
def open(self, note, search_term=""):
old_note_window = self.opened_notes.get(note.id, None)
if old_note_window and not getattr(old_note_window, "closed", True):
editor = self.opened_notes[note.id]
editor.activateWindow()
else:
editor = Editor(note)
editor.show()
self.opened_notes[note.id] = editor
if search_term:
editor.findbar.set_search_term(search_term)
editor.findbar.show()
return editor
@Slot()
def create(self, attach=None, notebook_id=NONE_ID):
#.........这里部分代码省略.........
示例3: Indicator
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class Indicator(QSystemTrayIcon):
def __init__(self, app, *args, **kwargs):
QSystemTrayIcon.__init__(self, *args, **kwargs)
self.app = app
self.menu = QMenu()
self.setContextMenu(self.menu)
self.menu.aboutToShow.connect(self.update)
self.opened_notes = {}
self.management = None
@Slot()
def update(self):
self.menu.clear()
if get_auth_token():
for note_struct in self.app.provider.find_notes(
"", dbus.Array([], signature="i"), dbus.Array([], signature="i"), 0, 20, Note.ORDER_UPDATED_DESC
):
note = Note.from_tuple(note_struct)
self.menu.addAction(note.title[:40], Slot()(partial(self.open, note=note)))
self.menu.addSeparator()
self.menu.addAction(self.tr("Create Note"), self.create)
if self.app.provider.get_status() == STATUS_SYNC:
action = self.menu.addAction(self.tr("Sync in progress"))
action.setEnabled(False)
else:
self.menu.addAction(
self.tr("Last sync: %s") % self.app.provider.get_last_sync(), Slot()(self.app.provider.sync)
)
self.menu.addAction(self.tr("Settings and Management"), self.show_management)
self.menu.addSeparator()
self.menu.addAction(self.tr("Exit"), self.exit)
def open(self, note):
old_note_window = self.opened_notes.get(note.id, None)
if old_note_window and not getattr(old_note_window, "closed", True):
editor = self.opened_notes[note.id]
editor.activateWindow()
else:
editor = Editor(self.app, note)
editor.show()
self.opened_notes[note.id] = editor
return editor
@Slot()
def create(self, attach=None):
note_struct = Note( # maybe replace NONE's to somthing better
id=NONE_ID,
title=self.tr("New note"),
content=self.tr("New note content"),
tags=dbus.Array([], signature="i"),
notebook=NONE_ID,
created=NONE_VAL,
updated=NONE_VAL,
place="",
).struct
note = Note.from_tuple(self.app.provider.create_note(note_struct))
editor = self.open(note)
if attach:
editor.resource_edit.add_attach(attach)
@Slot()
def show_management(self):
if not self.management or getattr(self.management, "closed", True):
self.management = Management(self.app)
self.management.show()
else:
self.management.activateWindow()
@Slot()
def exit(self):
sys.exit(0)
示例4: Indicator
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class Indicator(QSystemTrayIcon):
"""Indicator applet class"""
notes_get = Signal(list)
def __init__(self, app, *args, **kwargs):
"""Init indicator
Keyword Arguments:
app -- QApplication
Returns: None
"""
QSystemTrayIcon.__init__(self, *args, **kwargs)
self._action_threads = []
self._cached_notes = {}
self.menu = QMenu()
self.setContextMenu(self.menu)
self.app = app
app.indicator = self
self.menu.aboutToShow.connect(self.update)
self.auth_dialog = AuthDialog(self.app)
self._notes = []
self.notes_get.connect(self.notes_getted)
self.get_notes()
@Slot(list)
def notes_getted(self, notes):
self._notes = notes
def get_notes(self):
self.app.sync_thread.action_receive.emit((
self.app.provider.get_notes,
('', 10), {}, self.notes_get,
))
@Slot()
def update(self):
"""Set notes to menu"""
self.menu.clear()
self._open_slots = []
if self.app.authenticated:
for note in self._notes:
slot = Slot()(partial(self.show_note, note[1]))
self._open_slots.append(slot)
self.menu.addAction(
note[2][:40],
slot,
)
self.menu.addSeparator()
self.menu.addAction(
self.tr('New note'),
self.new_note,
)
self.menu.addAction(
self.tr('Auth settings'),
self.auth_settings,
)
else:
self.menu.addAction(
self.tr('Please authorise'),
self.auth_settings,
)
self.menu.addAction(self.tr('Exit'), self.app.end)
self.get_notes()
@Slot()
def new_note(self):
"""Create new note"""
self.show_note(None, True)
@Slot()
def auth_settings(self):
"""Show auth settings dialog"""
self.auth_dialog.show()
def show_note(self, id, create=False):
"""Show note"""
if create:
note = None
else:
note = self.app.provider.get_note(id)
prev = self.app.opened.get(id, None)
if not prev or getattr(prev, 'closed', False):
self.app.opened[id] = NoteWindow(self.app, note, create)
self.app.opened[id].show()
示例5: Indicator
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class Indicator(QSystemTrayIcon):
def __init__(self, *args, **kwargs):
QSystemTrayIcon.__init__(self, *args, **kwargs)
self.app = QApplication.instance()
self.menu = QMenu()
self.setContextMenu(self.menu)
self.menu.aboutToShow.connect(self.update)
self.opened_notes = {}
self.activated.connect(self._activated)
self.settings = QSettings('everpad', 'everpad-pad')
def _activated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.menu.popup(QCursor().pos())
def _add_note(self, menu, struct):
note = Note.from_tuple(struct)
title = note.title[:40].replace('&', '&&')
menu.addAction(title, Slot()(
partial(self.open, note=note)
))
@Slot()
def update(self):
self.menu.clear()
try:
version = self.app.provider.get_api_version()
except ( # dbus raise some magic
dbus.exceptions.UnknownMethodException,
dbus.exceptions.DBusException,
):
version = -1
if version != API_VERSION:
action = self.menu.addAction(
self.tr('API version missmatch, please restart'),
)
action.setEnabled(False)
if version < API_VERSION:
handler = self.app.provider.kill
else:
handler = partial(os.execlp, 'everpad', '--replace')
self.menu.addAction(
self.tr('Restart everpad'), handler,
)
return
if self.app.provider.is_authenticated():
pin_notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20, Note.ORDER_UPDATED_DESC, 1,
)
sort_by_notebook = bool(int(
self.app.provider.get_settings_value('sort-by-notebook') or 0))
has_notes = False
if not sort_by_notebook:
notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
has_notes = bool(notes)
else:
notebooks = self.app.provider.list_notebooks()
notes = {}
for notebook_struct in notebooks:
notebook = Notebook.from_tuple(notebook_struct)
_notes = self.app.provider.find_notes('', [notebook.id],
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
notes[notebook] = _notes
if _notes:
has_notes = True
first_sync = not (
has_notes or len(pin_notes) or self.app.provider.is_first_synced()
)
status_syncing = self.app.provider.get_status() == STATUS_SYNC
if status_syncing and first_sync:
sync_label = self.tr('Wait, first sync in progress')
elif status_syncing and not first_sync:
sync_label = self.tr('Sync in progress')
elif not status_syncing and first_sync:
sync_label = self.tr('Please perform first sync')
else:
last_sync = self.app.provider.get_last_sync()
delta_sync = (
datetime.now() - datetime.strptime(last_sync, '%H:%M')
).seconds // 60
if delta_sync == 0:
sync_label = self.tr('Last Sync: Just now')
elif delta_sync == 1:
sync_label = self.tr('Last Sync: %s min ago') % delta_sync
else:
sync_label = self.tr('Last Sync: %s mins ago') % delta_sync
menu_items = {
'create_note': [self.tr('Create Note'), self.create],
'all_notes': [self.tr('All Notes'), self.show_all_notes],
'sync': [sync_label, Slot()(self.app.provider.sync)],
'pin_notes': pin_notes,
'notes': notes,
#.........这里部分代码省略.........
示例6: MTTSettingsMenu
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class MTTSettingsMenu(QMenu):
def __init__(self, parent=None):
super(MTTSettingsMenu, self).__init__(parent)
self.view = parent
self.is_master_cmd = False
# power user state
self.power_user = MTTSettings.value('powerUser')
self.__create_actions()
self.__populate_menu()
def keyPressEvent(self, event):
if event.modifiers() == Qt.ControlModifier:
self.is_master_cmd = True
super(MTTSettingsMenu, self).keyPressEvent(event)
def keyReleaseEvent(self, event):
self.is_master_cmd = False
super(MTTSettingsMenu, self).keyReleaseEvent(event)
def __create_actions(self):
def add_action(lbl, tip, cmd, checkable=False, checked=False):
a = QAction(lbl, self)
a.setStatusTip(tip)
a.triggered.connect(cmd)
if checkable:
a.setCheckable(True)
a.setChecked(checked)
return a
self.help_a = add_action(
'Help',
'Opens the online Help page',
self.on_settings_help)
self.switch_edit_a = add_action(
'Switch Edit/Source',
'Replace "Edit" button by "Source" button',
self.on_switch_source_edit_menu,
True,
MTTSettings.value('switchEdit'))
self.heads_up_a = add_action(
'HeadsUp Message',
'Show HeadsUp Message in viewport',
self.on_toggle_headsup,
True,
MTTSettings.value('showHeadsUp'))
self.focus_filter_a = add_action(
'Focus Filter Field at Startup',
'Focus filter field at startup',
self.on_toggle_focus,
True,
MTTSettings.value('filterFocus'))
self.force_relative_path_a = add_action(
'Force Relative Path',
'Set a relative path when selecting a new file',
self.on_force_relative_path,
True,
MTTSettings.value('forceRelativePath'))
self.show_real_attr_value_a = add_action(
'Show Real Attribute Value',
'Show fullpath instead of filtering path as Attribute Editor',
self.on_show_real_attribute_value,
True,
MTTSettings.value('showRealAttributeValue'))
self.manage_quick_filter_a = add_action(
'Manage Quick Filters',
'Manage filters that popup with right clic in filter field',
self.on_filter_manage_quick_filter)
self.clear_completion_cache_a = add_action(
'Clear Completion Cache',
'Erase auto completion cache of filter field',
self.on_filter_clear_completion_cache)
self.override_panels_a = add_action(
'Add CreateNode Button to Editors',
('Add "Create Node" to HyperShade and '
'Node Editor for the current session'),
self.on_override_panels)
self.export_to_csv = add_action(
'Export Texture List as CSV',
'Export current textures into a csv file',
self.view.model.export_as_csv)
self.about = add_action(
'About',
'About',
self.on_settings_about)
#.........这里部分代码省略.........
示例7: fill_submenu
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
def fill_submenu(window: QtGui.QMainWindow, menu: QtGui.QMenu, method):
menu.clear()
for menu_action in method():
menu_action.create(window, menu)
示例8: Indicator
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class Indicator(QSystemTrayIcon):
def __init__(self, app, *args, **kwargs):
QSystemTrayIcon.__init__(self, *args, **kwargs)
self.app = app
self.menu = QMenu()
self.setContextMenu(self.menu)
self.menu.aboutToShow.connect(self.update)
self.opened_notes = {}
self.activated.connect(self._activated)
def _activated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.menu.popup(QCursor().pos())
def _add_note(self, struct):
note = Note.from_tuple(struct)
title = note.title[:40].replace('&', '&&')
self.menu.addAction(title, Slot()(
partial(self.open, note=note)
))
@Slot()
def kill_all(self):
try:
self.app.provider.kill()
except dbus.exceptions.DBusException:
pass
os.system('everpad --replace')
@Slot()
def update(self):
self.menu.clear()
try:
version = self.app.provider.get_api_version()
except ( # dbus raise some magic
dbus.exceptions.UnknownMethodException,
dbus.exceptions.DBusException,
):
version = -1
if version != API_VERSION:
action = self.menu.addAction(
self.tr('API version missmatch, please restart'),
)
action.setEnabled(False)
self.menu.addAction(
self.tr('Restart everpad'), self.kill_all,
)
return
if get_auth_token():
pin_notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20, Note.ORDER_UPDATED_DESC, 1,
)
notes = self.app.provider.find_notes(
'', dbus.Array([], signature='i'),
dbus.Array([], signature='i'), 0,
20 - len(pin_notes), Note.ORDER_UPDATED_DESC, 0,
)
if len(notes) + len(pin_notes) or self.app.provider.is_first_synced():
self.menu.addAction(self.tr('All Notes'), self.show_all_notes)
self.menu.addSeparator()
if len(pin_notes):
for struct in pin_notes:
self._add_note(struct)
self.menu.addSeparator()
for struct in notes:
self._add_note(struct)
self.menu.addSeparator()
self.menu.addAction(self.tr('Create Note'), self.create)
first_sync = False
else:
first_sync = True
if self.app.provider.get_status() == STATUS_SYNC:
action = self.menu.addAction(
self.tr('Wait, first sync in progress') if first_sync
else self.tr('Sync in progress')
)
action.setEnabled(False)
else:
if first_sync:
label = self.tr('Please perform first sync')
else:
label = self.tr('Last sync: %s') % self.app.provider.get_last_sync()
self.menu.addAction(label, Slot()(self.app.provider.sync))
self.menu.addAction(self.tr('Settings and Management'), self.show_management)
self.menu.addSeparator()
self.menu.addAction(self.tr('Exit'), self.exit)
def open(self, note, search_term=''):
old_note_window = self.opened_notes.get(note.id, None)
if old_note_window and not getattr(old_note_window, 'closed', True):
editor = self.opened_notes[note.id]
editor.activateWindow()
else:
editor = Editor(self.app, note)
editor.show()
self.opened_notes[note.id] = editor
if search_term:
editor.findbar.set_search_term(search_term)
#.........这里部分代码省略.........
示例9: LogFilter
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import clear [as 别名]
class LogFilter(QFrame):
def __init__(self, parent=None):
super(LogFilter, self).__init__(parent=parent)
setup_ui(self)
self.filter_model = FilterModel(parent=self)
self._viewer = None
self.revs_menu = QMenu(parent=self)
self.revs_separator = None
self.rev_actions = QActionGroup(self)
self.rev_actions.addAction(self.action_all_refs)
self.select_revs_button.setMenu(self.revs_menu)
self.action_all_refs.revs = None
self.action_all_refs.triggered.connect(self.show_all_refs)
self.action_select_branches.triggered.connect(self.pick_branches)
self.filter_text.textEdited.connect(self.filter_text_edited)
@property
def source_model(self):
return self.filter_model.sourceModel()
@source_model.setter
def source_model(self, model):
self.filter_model.setSourceModel(model)
self.revs_menu.clear()
for action in self.rev_actions.actions():
if action is not self.action_all_refs:
self.rev_actions.removeAction(action)
self.revs_menu.addAction(self.action_all_refs)
if not model.repo.head_ref:
self.revs_menu.addAction(self.create_rev_action(model.repo, 'HEAD'))
for branch in model.repo.branches:
self.revs_menu.addAction(self.create_rev_action(model.repo, branch))
if model.all:
self._select_action(self.action_all_refs)
else:
selected_revs = model.revs
if not selected_revs:
if model.repo.head_ref:
selected_revs = (model.repo.head_ref,)
else:
selected_revs = ('HEAD',)
action = self._find_rev_action(selected_revs)
if not action:
action = self.create_rev_action(model.repo, model.revs)
self.revs_menu.addAction(action)
self._select_action(action)
self.revs_separator = self.revs_menu.addSeparator()
self.revs_menu.addAction(self.action_select_branches)
@property
def viewer(self):
return self._viewer
@viewer.setter
def viewer(self, new_viewer):
self._viewer = new_viewer
self._viewer.setModel(self.filter_model)
def create_rev_action(self, repo, *revs):
action = QAction(self.revs_menu)
action.revs = revs
action.setText(', '.join(str(rev) for rev in revs))
action.setCheckable(True)
action.setActionGroup(self.rev_actions)
action.triggered.connect(self._revs_action_triggered)
return action
def show_all_refs(self):
self._select_action(self.action_all_refs)
with busy_cursor():
self.source_model.revs = ()
self.source_model.all = True
self.source_model.refresh()
def pick_branches(self):
dialog = PickBranchesDialog(repo=self.source_model.repo, parent=self)
if dialog.exec_() == dialog.Accepted:
self.show_revs(*dialog.selected_branches)
def _select_action(self, action):
action.setChecked(True)
self.select_revs_button.setText(action.text())
def _revs_action_triggered(self):
self._select_action(self.sender())
with busy_cursor():
self.source_model.revs = self.sender().revs
self.source_model.all = False
self.source_model.refresh()
def _find_rev_action(self, revs):
return next((action for action in self.rev_actions.actions()
if action.revs == revs), None)
def show_revs(self, *revs):
action = self._find_rev_action(revs)
if not action:
action = self.create_rev_action(self.source_model.repo, *revs)
self.revs_menu.insertAction(self.revs_separator, action)
self._select_action(action)
#.........这里部分代码省略.........