def show_context_menu(self, pos): menu = QMenu(self) menu.addAction(actions['edit-toc']) menu.addAction(_('&Expand all'), self.view.expandAll) menu.addAction(_('&Collapse all'), self.view.collapseAll) menu.addAction(self.refresh_action) menu.exec_(self.view.mapToGlobal(pos))
def menu_contextual_tabla(position): habilitar_botones_tabla() id_columna = vt.tbl_tabla.currentColumn( ) #recoge nº de la columna seleccionada fila = vt.tbl_tabla.currentRow() #recoge nº de fila seleccionada id_fila = vt.tbl_tabla.item( fila, 0).text() #valor de la columna 'Id' de la fila seleccionada if id_columna < 7: #en todas las columnas salvo la 7 el menu tiene opciones 'Editar' y 'Copiar': menu = QMenu() opcion_copiar = menu.addAction("Copiar") opcion_editar = menu.addAction("Editar") opcion_ver = menu.addAction("Ver cómic") seleccion = menu.exec_(vt.tbl_tabla.mapToGlobal(position)) if seleccion == opcion_copiar: QApplication.clipboard().setText( vt.tbl_tabla.currentItem().text()) #copia dato al portapapeles elif seleccion == opcion_editar: edicion_dato() #llama funcion de editar elif seleccion == opcion_ver: ficha_comic() elif id_columna == 7 and not Path( "portadas/" + str(id_fila) + ".jpg").is_file( ): #en columna 7 (Portadas) solo se muestra opción 'Editar': menu = QMenu() opcion = menu.addAction("Editar") seleccion = menu.exec_(vt.tbl_tabla.mapToGlobal(position)) if seleccion == opcion: edicion_dato()
def show_context_menu(self, point): idx = self.currentIndex() if idx and idx.isValid() and not idx.data(Qt.UserRole): m = QMenu() m.addAction(QIcon(I('view.png')), _('View this cover at full size'), self.show_cover) m.addAction(QIcon(I('edit-copy.png')), _('Copy this cover to clipboard'), self.copy_cover) m.exec_(QCursor.pos())
def show_context_menu(self, pos): item = self.itemAt(pos) if item is not None: result = item.data(0, Qt.ItemDataRole.UserRole) else: result = None items = self.selectedItems() m = QMenu(self) if isinstance(result, dict): m.addAction(_('Open in viewer'), partial(self.item_activated, item)) m.addAction(_('Show in calibre'), partial(self.show_in_calibre, item)) if result.get('annotation', {}).get('type') == 'highlight': m.addAction(_('Edit notes'), partial(self.edit_notes, item)) if items: m.addSeparator() m.addAction( ngettext('Export selected item', 'Export {} selected items', len(items)).format(len(items)), self.export_requested.emit) m.addAction( ngettext('Delete selected item', 'Delete {} selected items', len(items)).format(len(items)), self.delete_requested.emit) m.addSeparator() m.addAction(_('Expand all'), self.expandAll) m.addAction(_('Collapse all'), self.collapseAll) m.exec_(self.mapToGlobal(pos))
def show_context_menu(self, pos): m = QMenu(self) a = m.addAction(_('Customize this toolbar')) a.triggered.connect(self.customize) a = m.addAction(_('Hide this toolbar')) a.triggered.connect(self.hide_toolbar) m.exec_(pos)
def contextMenuEvent(self, ev): menu = QMenu(self) data = self._page.contextMenuData() url = data.linkUrl() url = unicode_type(url.toString(NO_URL_FORMATTING)).strip() text = data.selectedText() if text: ca = self.pageAction(QWebEnginePage.Copy) if ca.isEnabled(): menu.addAction(ca) menu.addAction(actions['reload-preview']) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) if url.partition(':')[0].lower() in {'http', 'https'}: menu.addAction(_('Open link'), partial(open_url, data.linkUrl())) if data.MediaTypeImage <= data.mediaType() <= data.MediaTypeFile: url = data.mediaUrl() if url.scheme() == FAKE_PROTOCOL: href = url.path().lstrip('/') if href: c = current_container() resource_name = c.href_to_name(href) if resource_name and c.exists( resource_name ) and resource_name not in c.names_that_must_not_be_changed: self.add_open_with_actions(menu, resource_name) if data.mediaType() == data.MediaTypeImage: mime = c.mime_map[resource_name] if mime.startswith('image/'): menu.addAction( _('Edit %s') % resource_name, partial(self.edit_image, resource_name)) menu.exec_(ev.globalPos())
def contextMenuEvent(self, e): row = self.currentRow() if self.item(row): event = self.item(row).data(Qt.UserRole) menu = QMenu(self) edit_action = menu.addAction( self.style().standardIcon(QStyle.SP_FileDialogDetailedView), 'Edit' ) edit_action.triggered.connect( lambda: self.popup_event_editor(row)) menu.addAction(self.new) # insert_action = menu.addAction( # self.style().standardIcon(QStyle.SP_FileIcon), # 'Insert Event' # ) # insert_action.triggered.connect( # lambda: self.insert_event(self.currentRow(), self.NOP.copy()) # ) if event.pointers: follow_action = menu.addAction( self.style().standardIcon(QStyle.SP_ArrowForward), 'Follow' ) follow_action.triggered.connect(lambda: self.follow(row)) menu.exec_(e.globalPos())
def context_menu_requested(self, widget, ev): if isinstance(widget, Heading): start = widget else: found = False for w in reversed(self.widgets): if w is widget: found = True elif found and isinstance(w, Heading): start = w break else: return found = False lines = [] for w in self.widgets: if found and isinstance(w, Heading): break if w is start: found = True if found: lines += w.lines_for_copy if not lines: return block = '\n'.join(lines).replace('\xa0', ' ') heading = lines[0] m = QMenu(self) m.addAction(QIcon(I('edit-copy.png')), _('Copy') + ' ' + heading.replace('\xa0', ' '), lambda : QApplication.instance().clipboard().setText(block)) all_lines = [] for w in self.widgets: all_lines += w.lines_for_copy all_text = '\n'.join(all_lines).replace('\xa0', ' ') m.addAction(QIcon(I('edit-copy.png')), _('Copy everything'), lambda : QApplication.instance().clipboard().setText(all_text)) m.exec_(ev.globalPos())
def details_context_menu_event(view, ev, book_info, add_popup_action=False): url = view.anchorAt(ev.pos()) menu = QMenu(view) menu.addAction(QIcon(I('edit-copy.png')), _('Copy all book details'), partial(copy_all, view)) search_internet_added = False if url and url.startswith('action:'): data = json_loads(from_hex_bytes(url.split(':', 1)[1])) search_internet_added = add_item_specific_entries( menu, data, book_info) elif url and not url.startswith('#'): ac = book_info.copy_link_action ac.current_url = url ac.setText(_('Copy link location')) menu.addAction(ac) if not search_internet_added and hasattr(book_info, 'search_internet'): menu.addSeparator() menu.si = create_search_internet_menu(book_info.search_internet) menu.addMenu(menu.si) for ac in tuple(menu.actions()): if not ac.isEnabled(): menu.removeAction(ac) if add_popup_action: menu.addSeparator() ac = menu.addAction(_('Open the Book details window')) ac.triggered.connect(book_info.show_book_info) if len(menu.actions()) > 0: menu.exec_(ev.globalPos())
def contextMenuEvent(self, ev): from calibre.gui2.open_with import populate_menu, edit_programs cm = QMenu(self) paste = cm.addAction(_("Paste Cover")) copy = cm.addAction(_("Copy Cover")) remove = cm.addAction(_("Remove Cover")) gc = cm.addAction(_("Generate Cover from metadata")) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) remove.triggered.connect(self.remove_cover) gc.triggered.connect(self.generate_cover) m = QMenu(_("Open cover with...")) populate_menu(m, self.open_with, "cover_image") if len(m.actions()) == 0: cm.addAction(_("Open cover with..."), self.choose_open_with) else: m.addSeparator() m.addAction(_("Add another application to open cover..."), self.choose_open_with) m.addAction(_("Edit Open With applications..."), partial(edit_programs, "cover_image", self)) cm.addMenu(m) cm.exec_(ev.globalPos())
def contextMenuEvent(self, event): menu = QMenu() testAction = QAction('Go Inside', None) testAction.triggered.connect(self.showTempleView) menu.addAction(testAction) menu.exec_(event.screenPos()) event.accept()
def contextMenuEvent(self, ev): from calibre.gui2.open_with import populate_menu, edit_programs cm = QMenu(self) paste = cm.addAction(_('Paste cover')) copy = cm.addAction(_('Copy cover')) remove = cm.addAction(_('Remove cover')) gc = cm.addAction(_('Generate cover from metadata')) cm.addSeparator() if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) remove.triggered.connect(self.remove_cover) gc.triggered.connect(self.generate_cover) m = QMenu(_('Open cover with...')) populate_menu(m, self.open_with, 'cover_image') if len(m.actions()) == 0: cm.addAction(_('Open cover with...'), self.choose_open_with) else: m.addSeparator() m.addAction(_('Add another application to open cover...'), self.choose_open_with) m.addAction(_('Edit Open with applications...'), partial(edit_programs, 'cover_image', self)) cm.ocw = m cm.addMenu(m) cm.si = m = create_search_internet_menu(self.search_internet.emit) cm.addMenu(m) cm.exec_(ev.globalPos())
def eventFilter(self, obj, event): base = super(Central, self) if obj is not self.editor_tabs.tabBar() or event.type( ) != QEvent.MouseButtonPress or event.button() not in (Qt.RightButton, Qt.MidButton): return base.eventFilter(obj, event) index = self.editor_tabs.tabBar().tabAt(event.pos()) if index < 0: return base.eventFilter(obj, event) if event.button() == Qt.MidButton: self._close_requested(index) ed = self.editor_tabs.widget(index) if ed is not None: menu = QMenu(self) menu.addAction(actions['close-current-tab'].icon(), _('Close tab'), partial(self.close_requested.emit, ed)) menu.addSeparator() menu.addAction(actions['close-all-but-current-tab'].icon(), _('Close other tabs'), partial(self.close_all_but, ed)) menu.addAction(actions['close-tabs-to-right-of'].icon(), _('Close tabs to the right of this tab'), partial(self.close_to_right, ed)) menu.exec_(self.editor_tabs.tabBar().mapToGlobal(event.pos())) return True
def show_context_menu(self, point): idx = self.currentIndex() if idx and idx.isValid() and not idx.data(Qt.ItemDataRole.UserRole): m = QMenu(self) m.addAction(QIcon(I('view.png')), _('View this cover at full size'), self.show_cover) m.addAction(QIcon(I('edit-copy.png')), _('Copy this cover to clipboard'), self.copy_cover) m.exec_(QCursor.pos())
def show_context_menu(self, point): item = self.currentItem() def key(k): sc = unicode_type(QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText)) return ' [%s]'%sc if item is not None: m = QMenu() m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item) m.addAction(QIcon(I('modified.png')), _('Bulk rename all selected items'), self.bulk_rename) m.addAction(QIcon(I('trash.png')), _('Remove all selected items'), self.del_items) m.addSeparator() ci = unicode_type(item.data(0, Qt.DisplayRole) or '') p = item.parent() or self.invisibleRootItem() idx = p.indexOfChild(item) if idx > 0: m.addAction(QIcon(I('arrow-up.png')), (_('Move "%s" up')%ci)+key(Qt.Key_Up), self.move_up) if idx + 1 < p.childCount(): m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down')%ci)+key(Qt.Key_Down), self.move_down) if item.parent() is not None: m.addAction(QIcon(I('back.png')), (_('Unindent "%s"')%ci)+key(Qt.Key_Left), self.move_left) if idx > 0: m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key_Right), self.move_right) m.addSeparator() case_menu = QMenu(_('Change case')) case_menu.addAction(_('Upper case'), self.upper_case) case_menu.addAction(_('Lower case'), self.lower_case) case_menu.addAction(_('Swap case'), self.swap_case) case_menu.addAction(_('Title case'), self.title_case) case_menu.addAction(_('Capitalize'), self.capitalize) m.addMenu(case_menu) m.exec_(QCursor.pos())
def contextMenuEvent(self, ev): m = QMenu(self) m.addAction(_('Sort tabs alphabetically'), self.sort_alphabetically) hidden = self.current_db.new_api.pref('virt_libs_hidden') if hidden: s = m._s = m.addMenu(_('Restore hidden tabs')) for x in hidden: s.addAction(x, partial(self.restore, x)) m.addAction(_('Hide Virtual library tabs'), self.disable_bar) if gprefs['vl_tabs_closable']: m.addAction(_('Lock Virtual library tabs'), self.lock_tab) else: m.addAction(_('Unlock Virtual library tabs'), self.unlock_tab) i = self.tabAt(ev.pos()) if i > -1: vl = unicode_type(self.tabData(i) or '') if vl: m.addSeparator() m.addAction( _('Edit "%s"') % vl, partial(self.gui.do_create_edit, name=vl)) m.addAction( _('Delete "%s"') % vl, partial(self.gui.remove_vl_triggered, name=vl)) m.exec_(ev.globalPos())
def show_context_menu(self, point): item = self.currentItem() def key(k): sc = unicode(QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText)) return ' [%s]'%sc if item is not None: m = QMenu() ci = unicode(item.data(0, Qt.DisplayRole) or '') p = item.parent() or self.invisibleRootItem() idx = p.indexOfChild(item) if idx > 0: m.addAction(QIcon(I('arrow-up.png')), (_('Move "%s" up')%ci)+key(Qt.Key_Up), self.move_up) if idx + 1 < p.childCount(): m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down')%ci)+key(Qt.Key_Down), self.move_down) m.addAction(QIcon(I('trash.png')), _('Remove all selected items'), self.del_items) if item.parent() is not None: m.addAction(QIcon(I('back.png')), (_('Unindent "%s"')%ci)+key(Qt.Key_Left), self.move_left) if idx > 0: m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key_Right), self.move_right) m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item) m.addAction(_('Change all selected items to title case'), self.title_case) m.addAction(_('Change all selected items to upper case'), self.upper_case) m.addAction(QIcon(I('modified.png')), _('Bulk rename all selected items'), self.bulk_rename) m.exec_(QCursor.pos())
def details_context_menu_event(view, ev, book_info, add_popup_action=False, edit_metadata=None): url = view.anchorAt(ev.pos()) menu = QMenu(view) copy_menu = menu.addMenu(QIcon(I('edit-copy.png')), _('Copy')) copy_menu.addAction(QIcon(I('edit-copy.png')), _('All book details'), partial(copy_all, view)) if view.textCursor().hasSelection(): copy_menu.addAction(QIcon(I('edit-copy.png')), _('Selected text'), view.copy) copy_menu.addSeparator() copy_links_added = False search_internet_added = False search_menu = QMenu(_('Search'), menu) search_menu.setIcon(QIcon(I('search.png'))) if url and url.startswith('action:'): data = json_loads(from_hex_bytes(url.split(':', 1)[1])) search_internet_added = add_item_specific_entries( menu, data, book_info, copy_menu, search_menu) create_copy_links(copy_menu, data) copy_links_added = True elif url and not url.startswith('#'): ac = book_info.copy_link_action ac.current_url = url ac.setText(_('Copy link location')) menu.addAction(ac) if not copy_links_added: create_copy_links(copy_menu) if not search_internet_added and hasattr(book_info, 'search_internet'): sim = create_search_internet_menu(book_info.search_internet) if search_menu.isEmpty(): search_menu = sim else: search_menu.addSeparator() for ac in sim.actions(): search_menu.addAction(ac) ac.setText(_('Search {0} for this book').format(ac.text())) if not search_menu.isEmpty(): menu.addMenu(search_menu) for ac in tuple(menu.actions()): if not ac.isEnabled(): menu.removeAction(ac) menu.addSeparator() if add_popup_action: ac = menu.addAction(_('Open the Book details window')) ac.triggered.connect(book_info.show_book_info) else: from calibre.gui2.ui import get_gui ema = get_gui().iactions['Edit Metadata'].menuless_qaction menu.addAction( _('Open the Edit metadata window') + '\t' + ema.shortcut().toString(QKeySequence.SequenceFormat.NativeText), edit_metadata) if len(menu.actions()) > 0: menu.exec_(ev.globalPos())
def showTreeMenu(self, point): item = self.ui.treeWidget.itemAt(point) if item != None and item.parent() != None: self.curDb = item.parent().text(0) self.curCol = item.text(0) ctxMenu = QMenu() ctxMenu.addAction(self.ctxAction) ctxMenu.exec_(QtGui.QCursor.pos())
def showTreeMenu(self,point): item = self.ui.treeWidget.itemAt(point) if item != None and item.parent() != None: self.curDb = item.parent().text(0) self.curCol = item.text(0) ctxMenu = QMenu() ctxMenu.addAction(self.ctxAction) ctxMenu.exec_(QtGui.QCursor.pos())
def context_menu(self, pos): m = QMenu(self) if self.items.count() > 0: m.addAction(QIcon(I('edit-copy.png')), _('Copy list of errors to clipboard'), self.copy_to_clipboard) if list(m.actions()): m.exec_(self.mapToGlobal(pos))
def show_context_menu(self, pos): item = self.itemAt(pos) if not item: return m = QMenu(self) m.addAction(_('Close tabs to the bottom'), partial(self.close_tabs_to_bottom, item)) m.addAction(_('Close other tabs'), partial(self.close_other_tabs, item)) m.addAction(_('Close this tree'), partial(self.close_tree, item)) m.exec_(self.mapToGlobal(pos))
def show_context_menu(self, pos): pos = self.viewport().mapToGlobal(pos) locations = self.selected_locations m = QMenu(self) if locations: m.addAction(_('Delete selected files'), self.delete_selected) self.customize_context_menu(m, locations, self.current_location) if len(m.actions()) > 0: m.exec_(pos)
def itemTableViewContextMenu(self, pos): menu = QMenu() funcs = self.getFuncsAllSelectedItemsHave() if funcs == None: return for k, v in funcs.iteritems(): menu.addAction(tStr(k), lambda func=v: func(self.getCurrentSelected(), self.actor)) menu.exec_(self.tableView.mapToGlobal(pos))
def context_menu(self, pos): index = self.indexAt(pos) m = QMenu(self) if index.isValid(): m.addAction(_('Expand all items under %s') % index.data(), partial(self.expand_tree, index)) m.addSeparator() m.addAction(_('Expand all items'), self.expandAll) m.addAction(_('Collapse all items'), self.collapseAll) m.exec_(self.mapToGlobal(pos))
def openTableContextMenu(self, position): menu = QMenu() rows = [] for item in self.tableWidget.selectedItems(): rows.append(self.tableWidget.row(item)) menu.addAction("Remove selected rows", lambda: self.tableManager.removeRows(rows)) menu.exec_(self.tableWidget.viewport().mapToGlobal(position))
def contextMenuEvent(self, ev): m = QMenu(self) m.addAction(_('Sort alphabetically'), self.sort_alphabetically) hidden = self.current_db.prefs['virt_libs_hidden'] if hidden: s = m._s = m.addMenu(_('Restore hidden tabs')) for x in hidden: s.addAction(x, partial(self.restore, x)) m.addAction(_('Hide virtual library tabs'), self.disable_bar) m.exec_(ev.globalPos())
def contextMenuEvent(self, ev): cm = QMenu(self) paste = cm.addAction(_("Paste Cover")) copy = cm.addAction(_("Copy Cover")) remove = cm.addAction(_("Remove Cover")) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) remove.triggered.connect(self.remove_cover) cm.exec_(ev.globalPos())
def contextMenuEvent(self, ev): cm = QMenu(self) paste = cm.addAction(_('Paste Cover')) copy = cm.addAction(_('Copy Cover')) remove = cm.addAction(_('Remove Cover')) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) remove.triggered.connect(self.remove_cover) cm.exec_(ev.globalPos())
def showContextMenu(self, widget, pos): """ Show context menu. Arguments: widget (QWidget): Widget displaying popup menu. pos (QPoint): Mouse cursor position. """ menu = QMenu(self._astergui.mainWindow()) self._add_actions(menu, self._context) if len(menu.actions()) > 0: menu.exec_(widget.mapToGlobal(pos))
def contextMenuEvent(self, event): index = self.indexAt(event.pos()) if not index.isValid(): return plugin = self.model().get_plugin(index) menu = QMenu() ca = menu.addAction(_('Configure...'), partial(self.configure_plugin, plugin)) if not plugin.is_customizable(): ca.setEnabled(False) menu.exec_(event.globalPos())
def contextMenuEvent(self, ev): menu = QMenu(self) p = self.page() mf = p.mainFrame() r = mf.hitTestContent(ev.pos()) url = unicode_type(r.linkUrl().toString(NO_URL_FORMATTING)).strip() ca = self.pageAction(QWebPage.Copy) if ca.isEnabled(): menu.addAction(ca) menu.addAction(actions['reload-preview']) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) if url.partition(':')[0].lower() in {'http', 'https'}: menu.addAction(_('Open link'), partial(open_url, r.linkUrl())) menu.exec_(ev.globalPos())
def contextMenuEvent(self, ev): menu = QMenu(self) p = self.page() mf = p.mainFrame() r = mf.hitTestContent(ev.pos()) url = unicode(r.linkUrl().toString(QUrl.None)).strip() ca = self.pageAction(QWebPage.Copy) if ca.isEnabled(): menu.addAction(ca) menu.addAction(actions['reload-preview']) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) if url.partition(':')[0].lower() in {'http', 'https'}: menu.addAction(_('Open link'), partial(open_url, r.linkUrl())) menu.exec_(ev.globalPos())
def contextMenuEvent(self, ev): menu = QMenu(self) data = self._page.contextMenuData() url = data.linkUrl() url = unicode_type(url.toString(NO_URL_FORMATTING)).strip() text = data.selectedText() if text: ca = self.pageAction(QWebEnginePage.Copy) if ca.isEnabled(): menu.addAction(ca) menu.addAction(actions['reload-preview']) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) if url.partition(':')[0].lower() in {'http', 'https'}: menu.addAction(_('Open link'), partial(open_url, data.linkUrl())) menu.exec_(ev.globalPos())
def contextMenuEvent(self, event): index = self.indexAt(event.pos()) if not index.isValid(): return result = self.model().get_result(index) menu = QMenu() da = menu.addAction(_('Download...'), partial(self.download_requested.emit, result)) if not result.downloads: da.setEnabled(False) menu.addSeparator() menu.addAction(_('Goto in store...'), partial(self.open_requested.emit, result)) menu.exec_(event.globalPos())
def context_menu(self, pos): index = self.indexAt(pos) if index.isValid(): try: char_code = int(self.model().data(index, Qt.UserRole)) except (TypeError, ValueError): pass else: m = QMenu(self) m.addAction(QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % chr(char_code), partial(self.copy_to_clipboard, char_code)) m.addAction(QIcon(I('rating.png')), (_('Remove %s from favorites') if self.showing_favorites else _('Add %s to favorites')) % chr(char_code), partial(self.remove_from_favorites, char_code)) if self.showing_favorites: m.addAction(_('Restore favorites to defaults'), self.restore_defaults) m.exec_(self.mapToGlobal(pos))
def scrollbar_context_menu(self, x, y, frac): m = QMenu(self) amap = {} def a(text, name): m.addAction(text) amap[text] = name a(_('Scroll here'), 'here') m.addSeparator() a(_('Start of book'), 'start_of_book') a(_('End of book'), 'end_of_book') m.addSeparator() a(_('Previous section'), 'previous_section') a(_('Next section'), 'next_section') m.addSeparator() a(_('Start of current file'), 'start_of_file') a(_('End of current file'), 'end_of_file') m.addSeparator() a(_('Hide this scrollbar'), 'toggle_scrollbar') q = m.exec_(QCursor.pos()) if not q: return q = amap[q.text()] if q == 'here': self.web_view.goto_frac(frac) else: self.web_view.trigger_shortcut(q)
def contextMenuEvent(self, ev): m = QMenu(self) m.addAction(_('Sort alphabetically'), self.sort_alphabetically) hidden = self.current_db.prefs['virt_libs_hidden'] if hidden: s = m._s = m.addMenu(_('Restore hidden tabs')) for x in hidden: s.addAction(x, partial(self.restore, x)) m.addAction(_('Hide virtual library tabs'), self.disable_bar) i = self.tabAt(ev.pos()) if i > -1: vl = unicode(self.tabData(i) or '') if vl: m.addSeparator() m.addAction(_('Edit "%s"') % vl, partial(self.gui.do_create_edit, name=vl)) m.addAction(_('Delete "%s"') % vl, partial(self.gui.remove_vl_triggered, name=vl)) m.exec_(ev.globalPos())
def eventFilter(self, obj, event): base = super(Central, self) if obj is not self.editor_tabs.tabBar() or event.type() != QEvent.MouseButtonPress or event.button() not in (Qt.RightButton, Qt.MidButton): return base.eventFilter(obj, event) index = self.editor_tabs.tabBar().tabAt(event.pos()) if index < 0: return base.eventFilter(obj, event) if event.button() == Qt.MidButton: self._close_requested(index) ed = self.editor_tabs.widget(index) if ed is not None: menu = QMenu(self) menu.addAction(actions['close-current-tab'].icon(), _('Close tab'), partial(self.close_requested.emit, ed)) menu.addSeparator() menu.addAction(actions['close-all-but-current-tab'].icon(), _('Close other tabs'), partial(self.close_all_but, ed)) menu.exec_(self.editor_tabs.tabBar().mapToGlobal(event.pos())) return True
def show_context_menu(self, pos): m = QMenu(self) a = m.addAction i = unicode(self.textCursor().selectedText()).rstrip('\0') if i: a(QIcon(I('edit-copy.png')), _('Copy to clipboard'), self.copy).setShortcut(QKeySequence.Copy) if len(self.changes) > 0: a(QIcon(I('arrow-up.png')), _('Previous change'), partial(self.next_change.emit, -1)) a(QIcon(I('arrow-down.png')), _('Next change'), partial(self.next_change.emit, 1)) if self.show_open_in_editor: b = self.cursorForPosition(pos).block() if b.isValid(): a(QIcon(I('tweak.png')), _('Open file in the editor'), partial(self.generate_sync_request, b.blockNumber())) if len(m.actions()) > 0: m.exec_(self.mapToGlobal(pos))
def contextMenuEvent(self, event): if self.item != None: menu = QMenu(self.parent()) self.actionUpdate = QtWidgets.QAction(self.parent()) icon = QIcon() icon.addPixmap(QPixmap(":/icons/16x16/update"), QIcon.Normal, QIcon.Off) self.actionUpdate.setIcon(icon) self.actionUpdate.setObjectName(self.item.name) self.actionUpdate.setText("Update") self.actionUpdate.triggered.connect(self.onUpdate) menu.addAction(self.actionUpdate) self.actionDelete = QtWidgets.QAction(self.parent()) icon = QIcon() icon.addPixmap(QPixmap(":/icons/16x16/delete"), QIcon.Normal, QIcon.Off) self.actionDelete.setIcon(icon) self.actionDelete.setObjectName(self.item.name) self.actionDelete.setText("Supprimer") self.actionDelete.triggered.connect(self.onDelete) menu.addAction(self.actionDelete) menu.exec_(self.mapToGlobal(event.pos()))
def contextMenuEvent(self, event): if not self.isColumnHidden(0): menu = QMenu(self) checkAction = menu.addAction(_("Check Selected")) uncheckAction = menu.addAction(_("Uncheck Selected")) action = menu.exec_(self.mapToGlobal(event.pos())) for row in self.get_selected_rows(): cb = self.item(self.get_row_linenum(row),0) if action == checkAction: cb.setCheckState(Qt.Checked) if action == uncheckAction: cb.setCheckState(Qt.Unchecked)
def contextMenuEvent(self, ev): from calibre.gui2.open_with import populate_menu cm = QMenu(self) paste = cm.addAction(_('Paste Cover')) copy = cm.addAction(_('Copy Cover')) remove = cm.addAction(_('Remove Cover')) gc = cm.addAction(_('Generate Cover from metadata')) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) remove.triggered.connect(self.remove_cover) gc.triggered.connect(self.generate_cover) m = QMenu(_('Open with...')) populate_menu(m, self.open_with, 'jpeg') if len(m.actions()) == 0: cm.addAction(_('Open with...'), self.choose_open_with) else: m.addSeparator() m.addAction(_('Choose other program...'), self.choose_open_with) cm.addMenu(m) cm.exec_(ev.globalPos())
def show_context_menu(self, pos): m = QMenu(self) a = m.addAction c = self.editor.cursorForPosition(pos) origc = QTextCursor(c) current_cursor = self.editor.textCursor() r = origr = self.editor.syntax_range_for_cursor(c) if (r is None or not r.format.property(SPELL_PROPERTY)) and c.positionInBlock() > 0 and not current_cursor.hasSelection(): c.setPosition(c.position() - 1) r = self.editor.syntax_range_for_cursor(c) if r is not None and r.format.property(SPELL_PROPERTY): word = self.editor.text_for_range(c.block(), r) locale = self.editor.spellcheck_locale_for_cursor(c) orig_pos = c.position() c.setPosition(orig_pos - utf16_length(word)) found = False self.editor.setTextCursor(c) if self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False): found = True fc = self.editor.textCursor() if fc.position() < c.position(): self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False) spell_cursor = self.editor.textCursor() if current_cursor.hasSelection(): # Restore the current cursor so that any selection is preserved # for the change case actions self.editor.setTextCursor(current_cursor) if found: suggestions = dictionaries.suggestions(word, locale)[:7] if suggestions: for suggestion in suggestions: ac = m.addAction(suggestion, partial(self.editor.simple_replace, suggestion, cursor=spell_cursor)) f = ac.font() f.setBold(True), ac.setFont(f) m.addSeparator() m.addAction(actions['spell-next']) m.addAction(_('Ignore this word'), partial(self._nuke_word, None, word, locale)) dics = dictionaries.active_user_dictionaries if len(dics) > 0: if len(dics) == 1: m.addAction(_('Add this word to the dictionary: {0}').format(dics[0].name), partial( self._nuke_word, dics[0].name, word, locale)) else: ac = m.addAction(_('Add this word to the dictionary')) dmenu = QMenu(m) ac.setMenu(dmenu) for dic in dics: dmenu.addAction(dic.name, partial(self._nuke_word, dic.name, word, locale)) m.addSeparator() if origr is not None and origr.format.property(LINK_PROPERTY): href = self.editor.text_for_range(origc.block(), origr) m.addAction(_('Open %s') % href, partial(self.link_clicked.emit, href)) if origr is not None and (origr.format.property(TAG_NAME_PROPERTY) or origr.format.property(CSS_PROPERTY)): word = self.editor.text_for_range(origc.block(), origr) item_type = 'tag_name' if origr.format.property(TAG_NAME_PROPERTY) else 'css_property' url = help_url(word, item_type, self.editor.highlighter.doc_name, extra_data=current_container().opf_version) if url is not None: m.addAction(_('Show help for: %s') % word, partial(open_url, url)) for x in ('undo', 'redo'): ac = actions['editor-%s' % x] if ac.isEnabled(): a(ac) m.addSeparator() for x in ('cut', 'copy', 'paste'): ac = actions['editor-' + x] if ac.isEnabled(): a(ac) m.addSeparator() m.addAction(_('&Select all'), self.editor.select_all) if self.selected_text or self.has_marked_text: update_mark_text_action(self) m.addAction(actions['mark-selected-text']) if self.syntax != 'css' and actions['editor-cut'].isEnabled(): cm = QMenu(_('Change &case'), m) for ac in 'upper lower swap title capitalize'.split(): cm.addAction(actions['transform-case-' + ac]) m.addMenu(cm) if self.syntax == 'html': m.addAction(actions['multisplit']) m.exec_(self.editor.viewport().mapToGlobal(pos))
class BookLayout (QWidget, Ui_BookLayout): def __init__ (self, parent=None): super(BookLayout, self).__init__(parent) self.setupUi(self) self.next.clicked.connect(self.goNext) self.previous.clicked.connect(self.goPrevious) self.treeView = None self.pages_widget = [] self.model = None def load (self,model=None): if model!=None: self.model = model self.model.print_() if self.treeView != None: self.treeView.disconnect() self.treeView.setParent(None) self.tree_view_layout.removeWidget(self.treeView) self.tree_model.disconnect() self.tree_model.setParent(None) else: self.stackedWidget.removeWidget(self.page_3) self.stackedWidget.removeWidget(self.page_4) for page_widget in self.pages_widget : page_widget.setParent(None) self.stackedWidget.removeWidget(page_widget) self.pages_widget .clear() self.treeView = CustomTreeView(self.tree_view_page) # self.treeView.setDragEnabled(True) # self.treeView.setAcceptDrops(True) self.treeView.setDropIndicatorShown(True) self.treeView.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop) self.treeView.setObjectName("treeView") self.tree_view_layout.addWidget(self.treeView) self.treeView.setIndentation(10) self.treeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.onContextMenu) self.treeView.activated.connect(self.changeCurrentPage) self.tree_model = TreeModel(self.model) self.tree_model.dataChanged.connect(self.updateModel) self.treeView.setModel(self.tree_model) self.treeView.setWindowTitle("Simple Tree Model") self.treeView.header().hide() self.treeView.setAlternatingRowColors(True) self.contextMenu = QMenu(self.treeView) for child in self.model.root.children: self.processChapter(child) print ('nombre de page :',self.stackedWidget.count()) if self.stackedWidget.count() >= 1 : self.next.setEnabled(True) # self.stackedWidget.removeWidget(self.page) # self.stackedWidget.removeWidget(self.page_2) # self.stackedWidget.addWidget(self.book_homepage) self.stackedWidget.setCurrentIndex(0) def reload (self): print("-----------------") self.model.print_() if self.treeView != None: self.treeView.setParent(None) self.tree_view_layout.removeWidget(self.treeView) else: self.stackedWidget.removeWidget(self.page_3) self.stackedWidget.removeWidget(self.page_4) for page_widget in self.pages_widget : page_widget.setParent(None) self.stackedWidget.removeWidget(page_widget) self.pages_widget.clear() self.treeView = CustomTreeView(self.tree_view_page) self.treeView.setDropIndicatorShown(True) self.treeView.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop) self.treeView.setObjectName("treeView") self.tree_view_layout.addWidget(self.treeView) self.treeView.setIndentation(10) self.treeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.onContextMenu) self.treeView.activated.connect(self.changeCurrentPage) self.tree_model = TreeModel(self.model) self.tree_model.dataChanged.connect(self.updateModel) self.treeView.setModel(self.tree_model) self.treeView.setWindowTitle("Simple Tree Model") self.treeView.header().hide() self.treeView.setAlternatingRowColors(True) self.contextMenu = QMenu(self.treeView) # print ('len(self.model.children())', len(self.model.children())) for child in self.model.root.children: self.processChapter(child) # print ('nombre de page :',self.stackedWidget.count()) if self.stackedWidget.count() >= 1 : self.next.setEnabled(True) self.stackedWidget.setCurrentIndex(0) def updateModel(self): print ('change drag and drop') root = self.tree_model.rootItem self.model = Book() self.model.root = Chapitre(None,root.data(0),root.data(1)) for child in root.children: self.processUpdateModel(self.model.root,child) def processUpdateModel(self,parent,node): print ('processUpdateModel') chap = Chapitre(parent,node.data(0),node.data(1)) parent.addChild(chap) for c in node.children: self.processUpdateModel(chap,c) def processChapter (self, chapitre): if len(chapitre.children) != 0: for sub in chapitre.children : self.processChapter(sub) else: if chapitre.content != None : basepath = Config().instance.path_to_book() filename= os.path.join(basepath,chapitre.content) w_page = PageWidget (filename, self) self.stackedWidget.addWidget(w_page) self.pages_widget.append(w_page) chapitre.indice = self.stackedWidget.count() - 1 else: print ('pppppppppp') def onContextMenu(self, point): print ('onCOntextMenu') index = self.treeView.indexAt(point) chapter = self.tree_model.metadata_model(index, QtCore.Qt.EditRole) if index.isValid() : self.contextMenu.clear() action_add = QAction("ajout sous chapitre", self.treeView) action_add.triggered.connect(partial(self.onAddChapter, chapter)) self.contextMenu.addAction(action_add) action_add_page = QAction("ajout Page", self.treeView) action_add_page.triggered.connect(partial(self.onAddPage, chapter)) self.contextMenu.addAction(action_add_page) action_remove = QAction("remove", self.treeView) action_remove.triggered.connect(partial(self.onRemove, chapter)) self.contextMenu.addAction(action_remove) self.contextMenu.exec_(self.treeView.mapToGlobal(point)) def onAddChapter(self, chapter): print ('onAddChapter') if chapter.content != None: chapitre = chapter.getParent() else: chapitre = chapter test = Chapitre(chapitre, "undefined") chapitre.addChild(test) self.load() def onRemove (self, chapter): print ('onRemove') if chapter.parent() != None: chapter.parent.children.remove(chapter) self.load() def onAddPage(self, chapter): print ('onAddPage') filename = QFileDialog.getOpenFileName(self, caption='Choisir le contenu de la page', directory=Config().instance.settings.path_to_book()) if filename : if chapter.content != None: chapitre = chapter.getParent() else: chapitre = chapter print ('chapitre partnt',chapitre.title) test = Chapitre(chapitre, "undefined", os.path.basename(filename[0])) chapitre.addChild(test) self.model.print_() self.reload() def goPrevious (self): print ('goPrevious') new_index = max(0, self.stackedWidget.currentIndex() - 1) self.stackedWidget.setCurrentIndex(new_index) if new_index == 0: self.previous.setEnabled(False) self.next.setEnabled(True) def goNext (self): print ('goNext') new_index = min(self.stackedWidget.count() - 1, self.stackedWidget.currentIndex() + 1) self.stackedWidget.setCurrentIndex(new_index) if new_index == (self.stackedWidget.count() - 1): self.next.setEnabled(False) self.previous.setEnabled(True) def onEdit (self): print ('onEdit') current = None for child in self.model.root.children: if len(child.children) != 0: for sub in child.children : if sub.indice == self.stackedWidget.currentIndex(): current = sub break else: if child.indice == self.stackedWidget.currentIndex(): current = child break if current != None : textEdit = HtmlEditor(self)#BookEditWindow(self.stackedWidget.currentIndex(),current.content, self) textEdit.fileSaved.connect(self.onUpdatePage) textEdit.load(os.path.join(Config().instance.settings.path_to_book(),current.content)) #textEdit.setWindowModality(QtCore.Qt.ApplicationModal) #textEdit.resize(700, 800) textEdit.show() def onUpdatePage (self): print ('onUpdatePage') widget = self.stackedWidget.currentWidget() ind = self.stackedWidget.currentIndex() widget.load() self.stackedWidget.setCurrentIndex(ind) def changeCurrentPage(self, index): print ('changeCurrentPage') indice = self.tree_model.metadata_indice(index, QtCore.Qt.DecorationRole) self.stackedWidget.setCurrentIndex(indice)
def menuHeros(self,event): #====== Menu Move ========== print ('context menu event de heros') menu_move = QMenu("Move") moveNormal = QAction("Normal",None) moveNormal.setData(1.0) moveNormal.triggered.connect(self.onActionMoveNormal) menu_move.addAction(moveNormal) moveSlow= QAction("Slow",None) moveSlow.setData(0.5) moveSlow.triggered.connect(self.onActionMoveNormal) menu_move.addAction(moveSlow) # moveVerySlow= QAction("Very Slow",None) # moveVerySlow.setData(0.25) # moveVerySlow.triggered.connect(self.onActionMove) # menu_move.addAction(moveVerySlow) moveFast= QAction("Fast",None) moveFast.setData(2.0) moveFast.triggered.connect(self.onActionMoveNormal) menu_move.addAction(moveFast) # moveVeryFast= QAction("Very Fast",None) # moveVeryFast.setData(4.0) # moveVeryFast.triggered.connect(self.onActionMove) # menu_move.addAction(moveVeryFast) actionTeleport= QAction("Teleport",None) actionTeleport.setData(0.0) actionTeleport.triggered.connect(self.onActionMoveNormal) menu_move.addAction(actionTeleport) #========== Menu Actions ======== menu_actions = QMenu("Action") actionAttack= QAction("Attack",None) menu_actions.addAction(actionAttack) actionHeal= QAction("Soigne",None) menu_actions.addAction(actionHeal) #======== MENU GENERAL ================ menu = QMenu() # ok = True # for w in self.univers.selectedWarriors(): # for action in self.univers.list_actions.values(): # if action.LeftPartContainHeros(w.id): # ok = False # break # if ok == True : action_running = False for w in self.univers.selectedWarriors(): if w.attribs['status']!= "repos": print ("mmmmmmmmm",w.attribs['status']) action_running = True if action_running == True : actionCancel= QAction("Cancel",None) actionCancel.triggered.connect(self.onActionCancel) menu.addAction(actionCancel) else: menu.addMenu(menu_move) menu.addMenu(menu_actions) actionPlacement= QAction("Placement",None) actionPlacement.triggered.connect(self.onActionPlacement) actionPlacement.setData(0.0) # en placement on teleport forcement menu.addAction(actionPlacement) if len(self.univers.selectedWarriors())==1 : if self.univers.selectedWarriors()[0].attribs['HP']== 0: actionRebirth= QAction("Rebirth",None) menu.addAction(actionRebirth) else: actionKill= QAction("Kill",None) menu.addAction(actionKill) #menu.exec_(event.screenPos()) #event.accept() menu.exec_(event.globalPos())
def context_menu(self, pos): m = QMenu() if self.items.count() > 0: m.addAction(QIcon(I('edit-copy.png')), _('Copy list of errors to clipboard'), self.copy_to_clipboard) if list(m.actions()): m.exec_(self.mapToGlobal(pos))