示例#1
0
 def contextMenuEvent(self, ev):
     cm = QMenu(self)
     paste = cm.addAction(QIcon.ic('edit-paste.png'), _('Paste cover'))
     copy = cm.addAction(QIcon.ic('edit-copy.png'), _('Copy cover'))
     save = cm.addAction(QIcon.ic('save.png'), _('Save cover to disk'))
     remove = cm.addAction(QIcon.ic('trash.png'), _('Remove cover'))
     gc = cm.addAction(QIcon.ic('default_cover.png'), _('Generate cover from metadata'))
     cm.addSeparator()
     if self.pixmap is not self.default_pixmap and self.data.get('id'):
         book_id = self.data['id']
         cm.tc = QMenu(_('Trim cover'))
         cm.tc.addAction(QIcon.ic('trim.png'), _('Automatically trim borders'), self.trim_cover)
         cm.tc.addAction(_('Trim borders manually'), self.manual_trim_cover)
         cm.tc.addSeparator()
         cm.tc.addAction(QIcon.ic('edit-undo.png'), _('Undo last trim'), self.undo_last_trim).setEnabled(self.last_trim_id == book_id)
         cm.addMenu(cm.tc)
         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)
     save.triggered.connect(self.save_cover)
     create_open_cover_with_menu(self, cm)
     cm.si = m = create_search_internet_menu(self.search_internet.emit)
     cm.addMenu(m)
     cm.exec(ev.globalPos())
示例#2
0
文件: toc.py 项目: kovidgoyal/calibre
 def show_context_menu(self, pos):
     index = self.indexAt(pos)
     m = QMenu(self)
     if index.isValid():
         m.addAction(QIcon.ic('plus.png'),
                     _('Expand all items under %s') % index.data(),
                     partial(self.expand_tree, index))
     m.addSeparator()
     m.addAction(QIcon.ic('plus.png'), _('Expand all items'),
                 self.expandAll)
     m.addAction(QIcon.ic('minus.png'), _('Collapse all items'),
                 self.collapseAll)
     m.addSeparator()
     if index.isValid():
         m.addAction(
             QIcon.ic('plus.png'),
             _('Expand all items at the level of {}').format(index.data()),
             partial(self.expand_at_level, index))
         m.addAction(
             QIcon.ic('minus.png'),
             _('Collapse all items at the level of {}').format(
                 index.data()), partial(self.collapse_at_level, index))
     m.addSeparator()
     m.addAction(QIcon.ic('edit-copy.png'),
                 _('Copy Table of Contents to clipboard'),
                 self.copy_to_clipboard)
     self.context_menu = m
     m.exec(self.mapToGlobal(pos))
示例#3
0
 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(self.mapToGlobal(pos))
示例#4
0
文件: toc.py 项目: qykth-git/calibre
 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))
示例#5
0
 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))
示例#6
0
    def show_context_menu(self, point):
        item = self.currentItem()

        def key(k):
            sc = str(QKeySequence(k | Qt.KeyboardModifier.ControlModifier).toString(QKeySequence.SequenceFormat.NativeText))
            return ' [%s]'%sc

        if item is not None:
            m = QMenu(self)
            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 = str(item.data(0, Qt.ItemDataRole.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.Key_Up), self.move_up)
            if idx + 1 < p.childCount():
                m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down')%ci)+key(Qt.Key.Key_Down), self.move_down)
            if item.parent() is not None:
                m.addAction(QIcon(I('back.png')), (_('Unindent "%s"')%ci)+key(Qt.Key.Key_Left), self.move_left)
            if idx > 0:
                m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key.Key_Right), self.move_right)

            m.addSeparator()
            case_menu = QMenu(_('Change case'), m)
            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())
示例#7
0
 def contextMenuEvent(self, ev):
     m = QMenu(self)
     m.addAction(QIcon.ic('sort.png'), _('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(QIcon.ic('drm-locked.png'),
                     _('Lock Virtual library tabs'), self.lock_tab)
     else:
         m.addAction(QIcon.ic('drm-unlocked.png'),
                     _('Unlock Virtual library tabs'), self.unlock_tab)
     i = self.tabAt(ev.pos())
     if i > -1:
         vl = str(self.tabData(i) or '')
         if vl:
             vln = vl.replace('&', '&&')
             m.addSeparator()
             m.addAction(QIcon.ic('edit_input.png'),
                         _('Edit "%s"') % vln,
                         partial(self.gui.do_create_edit, name=vl))
             m.addAction(QIcon.ic('trash.png'),
                         _('Delete "%s"') % vln,
                         partial(self.gui.remove_vl_triggered, name=vl))
     m.exec(ev.globalPos())
示例#8
0
 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())
示例#9
0
 def show_context_menu(self, pos):
     menu = QMenu(self)
     menu.addAction(QIcon.ic('plus.png'), _('Expand all'),
                    self.plugin_view.expandAll)
     menu.addAction(QIcon.ic('minus.png'), _('Collapse all'),
                    self.plugin_view.collapseAll)
     menu.exec(self.plugin_view.mapToGlobal(pos))
示例#10
0
 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))
示例#11
0
 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())
示例#12
0
    def contextMenuEvent(self, event):
        index = self.indexAt(event.pos())

        if not index.isValid():
            return

        plugin = self.model().get_plugin(index)

        menu = QMenu(self)
        ca = menu.addAction(_('Configure...'), partial(self.configure_plugin, plugin))
        if not plugin.is_customizable():
            ca.setEnabled(False)
        menu.exec(event.globalPos())
示例#13
0
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()
    from calibre.gui2.ui import get_gui
    if add_popup_action:
        ema = get_gui().iactions['Show Book Details'].menuless_qaction
        menu.addAction(_('Open the Book details window') + '\t' + ema.shortcut().toString(QKeySequence.SequenceFormat.NativeText), book_info.show_book_info)
    else:
        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())
示例#14
0
    def contextMenuEvent(self, event):
        index = self.indexAt(event.pos())

        if not index.isValid():
            return

        result = self.model().get_result(index)

        menu = QMenu(self)
        da = menu.addAction(_('Download...'), partial(self.download_requested.emit, result))
        if not result.downloads:
            da.setEnabled(False)
        menu.addSeparator()
        menu.addAction(_('Show in store'), partial(self.open_requested.emit, result))
        menu.exec(event.globalPos())
示例#15
0
文件: ui.py 项目: qykth-git/calibre
    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)
示例#16
0
 def contextMenuEvent(self, ev):
     cm = QMenu(self)
     paste = cm.addAction(_('Paste cover'))
     copy = cm.addAction(_('Copy cover'))
     save = cm.addAction(_('Save cover to disk'))
     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)
     save.triggered.connect(self.save_cover)
     create_open_cover_with_menu(self, cm)
     cm.si = m = create_search_internet_menu(self.search_internet.emit)
     cm.addMenu(m)
     cm.exec(ev.globalPos())
示例#17
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     data = self._page.contextMenuData()
     url = data.linkUrl()
     url = str(url.toString(NO_URL_FORMATTING)).strip()
     text = data.selectedText()
     if text:
         ca = self.pageAction(QWebEnginePage.WebAction.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(safe_open_url, data.linkUrl()))
     if QWebEngineContextMenuData.MediaType.MediaTypeImage <= data.mediaType(
     ) <= QWebEngineContextMenuData.MediaType.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(
                     ) == QWebEngineContextMenuData.MediaType.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())
示例#18
0
 def context_menu(self, pos):
     index = self.indexAt(pos)
     if index.isValid():
         try:
             char_code = int(self.model().data(index,
                                               Qt.ItemDataRole.UserRole))
         except (TypeError, ValueError):
             pass
         else:
             m = QMenu(self)
             m.addAction(
                 QIcon(I('edit-copy.png')),
                 _('Copy %s to clipboard') % codepoint_to_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')) %
                 codepoint_to_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))
示例#19
0
    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(
                CLASS_ATTRIBUTE_PROPERTY):
            cls = self.editor.class_for_position(pos)
            if cls:
                class_name = cls['class']
                m.addAction(
                    _('Rename the class {}').format(class_name),
                    partial(self.rename_class.emit, class_name))

        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))
示例#20
0
 def show_context_menu(self, pos):
     menu = QMenu(self)
     menu.addAction(_('Expand all'), self.view.expandAll)
     menu.addAction(_('Collapse all'), self.view.collapseAll)
     menu.exec(self.view.mapToGlobal(pos))