def about_to_show_configure_menu(self): ac = self.alter_tb.m.show_counts_action ac.setText(_('Hide counts') if gprefs['tag_browser_show_counts'] else _('Show counts')) ac.setIcon(QIcon.ic('minus.png') if gprefs['tag_browser_show_counts'] else QIcon.ic('plus.png')) ac = self.alter_tb.m.show_avg_rating_action ac.setText(_('Hide average rating') if config['show_avg_rating'] else _('Show average rating')) ac.setIcon(QIcon.ic('minus.png' if config['show_avg_rating'] else 'plus.png'))
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())
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))
def build_context_menu(self): cm = QMenu(self) paste = cm.addAction(QIcon.ic('edit-paste.png'), _('Paste cover')) copy = cm.addAction(QIcon.ic('edit-copy.png'), _('Copy 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) return cm
def show_context_menu(self, pos): menu = QMenu(self) menu.addAction(actions['edit-toc']) menu.addAction(QIcon.ic('plus.png'), _('&Expand all'), self.view.expandAll) menu.addAction(QIcon.ic('minus.png'), _('&Collapse all'), self.view.collapseAll) menu.addAction(self.refresh_action) menu.exec(self.view.mapToGlobal(pos))
def show_context_menu(self, point): index = self.indexAt(point) h = index.data(Qt.ItemDataRole.UserRole) self.context_menu = m = QMenu(self) if h is not None: m.addAction(QIcon(I('edit_input.png')), _('Modify this highlight'), self.edit_requested.emit) m.addAction(QIcon(I('modified.png')), _('Edit notes for this highlight'), self.edit_notes_requested.emit) m.addAction(QIcon(I('trash.png')), ngettext( 'Delete this highlight', 'Delete selected highlights', len(self.selectedItems()) ), self.delete_requested.emit) m.addSeparator() m.addAction(QIcon.ic('plus.png'), _('Expand all'), self.expandAll) m.addAction(QIcon.ic('minus.png'), _('Collapse all'), self.collapseAll) self.context_menu.popup(self.mapToGlobal(point)) return True
def __init__(self, text, key, ascending, parent): QAction.__init__(self, text, parent) self.key, self.ascending = key, ascending self.triggered.connect(self) ic = category_icon_map['custom:'] if self.key.startswith('#') else category_icon_map.get(key) if ic: self.setIcon(QIcon.ic(ic))
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())
def genesis(self): self.search_icon = QIcon.ic('search.png') self.qaction.triggered.connect(self.toggle_selected) self.menu = m = self.qaction.menu() m.aboutToShow.connect(self.about_to_show_menu) ma = partial(self.create_menu_action, m) self.show_marked_action = a = ma('mark_with_text', _('Mark books with text label'), icon='marked.png') a.triggered.connect(partial(self.mark_with_text, book_ids=None)) global mark_books_with_text mark_books_with_text = self.mark_with_text self.show_marked_action = a = ma('show-marked', _('Show marked books'), icon='search.png', shortcut='Shift+Ctrl+M') a.triggered.connect(self.show_marked) self.show_marked_with_text = QMenu( _('Show marked books with text label')) self.show_marked_with_text.setIcon(self.search_icon) m.addMenu(self.show_marked_with_text) self.clear_selected_marked_action = a = ma( 'clear-marks-on-selected', _('Clear marks for selected books'), icon='clear_left.png') a.triggered.connect(self.clear_marks_on_selected_books) self.clear_marked_action = a = ma('clear-all-marked', _('Clear all marked books'), icon='clear_left.png') a.triggered.connect(self.clear_all_marked) m.addSeparator() self.mark_author_action = a = ma( 'mark-author', _('Mark all books by selected author(s)'), icon='plus.png') connect_lambda(a.triggered, self, lambda self: self.mark_field('authors', True)) self.mark_series_action = a = ma( 'mark-series', _('Mark all books in the selected series'), icon='plus.png') connect_lambda(a.triggered, self, lambda self: self.mark_field('series', True)) m.addSeparator() self.unmark_author_action = a = ma( 'unmark-author', _('Clear all books by selected author(s)'), icon='minus.png') connect_lambda(a.triggered, self, lambda self: self.mark_field('authors', False)) self.unmark_series_action = a = ma( 'unmark-series', _('Clear all books in the selected series'), icon='minus.png') connect_lambda(a.triggered, self, lambda self: self.mark_field('series', False))
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 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())
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))
def __init__(self, parent, db): QObject.__init__(self, parent) self.internet_connection_failed = False self._parent = parent self.no_internet_msg = _( 'Cannot download news as no internet connection ' 'is active') self.no_internet_dialog = d = error_dialog(self._parent, self.no_internet_msg, _('No internet connection'), show_copy_button=False) d.setModal(False) self.recipe_model = RecipeModel() self.db = db self.lock = QMutex(QMutex.RecursionMode.Recursive) self.download_queue = set() self.news_menu = QMenu() self.news_icon = QIcon(I('news.png')) self.scheduler_action = QAction(QIcon(I('scheduler.png')), _('Schedule news download'), self) self.news_menu.addAction(self.scheduler_action) self.scheduler_action.triggered[bool].connect(self.show_dialog) self.cac = QAction(QIcon(I('user_profile.png')), _('Add or edit a custom news source'), self) self.cac.triggered[bool].connect(self.customize_feeds) self.news_menu.addAction(self.cac) self.news_menu.addSeparator() self.all_action = self.news_menu.addAction( QIcon.ic('download-metadata.png'), _('Download all scheduled news sources'), self.download_all_scheduled) self.timer = QTimer(self) self.timer.start(int(self.INTERVAL * 60 * 1000)) self.timer.timeout.connect(self.check) self.oldest = gconf['oldest_news'] QTimer.singleShot(5 * 1000, self.oldest_check)
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(QIcon.ic('viewer.png'), _('Open in viewer'), partial(self.item_activated, item)) m.addAction(QIcon.ic('lt.png'), _('Show in calibre'), partial(self.show_in_calibre, item)) if result.get('annotation', {}).get('type') == 'highlight': m.addAction(QIcon.ic('modified.png'), _('Edit notes'), partial(self.edit_notes, item)) if items: m.addSeparator() m.addAction(QIcon.ic('save.png'), ngettext('Export selected item', 'Export {} selected items', len(items)).format(len(items)), self.export_requested.emit) m.addAction(QIcon.ic('trash.png'), ngettext('Delete selected item', 'Delete {} selected items', len(items)).format(len(items)), self.delete_requested.emit) m.addSeparator() m.addAction(QIcon.ic('plus.png'), _('Expand all'), self.expandAll) m.addAction(QIcon.ic('minus.png'), _('Collapse all'), self.collapseAll) m.exec(self.mapToGlobal(pos))
def __init__(self, gui, row, toggle_shortcut): self.is_pane = gprefs.get('quickview_is_pane', False) if not self.is_pane: QDialog.__init__(self, gui, flags=Qt.WindowType.Widget) else: QDialog.__init__(self, gui) Ui_Quickview.__init__(self) self.setupUi(self) self.isClosed = False self.current_book = None self.closed_by_button = False if self.is_pane: self.main_grid_layout.setContentsMargins(0, 0, 0, 0) else: self.setWindowIcon(self.windowIcon()) self.books_table_column_widths = None try: self.books_table_column_widths = \ gprefs.get('quickview_dialog_books_table_widths', None) if not self.is_pane: geom = gprefs.get('quickview_dialog_geometry', None) if geom: QApplication.instance().safe_restore_geometry( self, QByteArray(geom)) except: pass self.view = gui.library_view self.db = self.view.model().db self.gui = gui self.is_closed = False self.current_book_id = None # the db id of the book used to fill the lh pane self.current_column = None # current logical column in books list self.current_key = None # current lookup key in books list self.last_search = None self.no_valid_items = False self.follow_library_view = True self.apply_vls.setCheckState( Qt.CheckState.Checked if gprefs['qv_respects_vls'] else Qt. CheckState.Unchecked) self.apply_vls.stateChanged.connect(self.vl_box_changed) self.fm = self.db.field_metadata self.items.setSelectionMode( QAbstractItemView.SelectionMode.SingleSelection) self.items.currentTextChanged.connect(self.item_selected) self.items.setProperty('highlight_current_item', 150) self.items.itemDoubleClicked.connect(self.item_doubleclicked) self.items.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.items.customContextMenuRequested.connect( self.show_item_context_menu) focus_filter = WidgetFocusFilter(self.items) focus_filter.focus_entered_signal.connect(self.focus_entered) self.items.installEventFilter(focus_filter) self.tab_pressed_signal.connect(self.tab_pressed) return_filter = BooksTableFilter(self.books_table) return_filter.return_pressed_signal.connect(self.return_pressed) self.books_table.installEventFilter(return_filter) focus_filter = WidgetFocusFilter(self.books_table) focus_filter.focus_entered_signal.connect(self.focus_entered) self.books_table.installEventFilter(focus_filter) self.close_button.clicked.connect(self.close_button_clicked) self.refresh_button.clicked.connect(self.refill) self.tab_order_widgets = [ self.items, self.books_table, self.lock_qv, self.dock_button, self.refresh_button, self.close_button ] for idx, widget in enumerate(self.tab_order_widgets): widget.installEventFilter( WidgetTabFilter(widget, idx, self.tab_pressed_signal)) self.books_table.setSelectionBehavior( QAbstractItemView.SelectionBehavior.SelectRows) self.books_table.setSelectionMode( QAbstractItemView.SelectionMode.SingleSelection) self.books_table.setProperty('highlight_current_item', 150) # Set up the books table columns self.add_columns_to_widget() self.books_table_header_height = self.books_table.height() self.books_table.cellDoubleClicked.connect(self.book_doubleclicked) self.books_table.currentCellChanged.connect( self.books_table_cell_changed) self.books_table.cellClicked.connect( self.books_table_set_search_string) self.books_table.cellActivated.connect( self.books_table_set_search_string) self.books_table.sortByColumn(0, Qt.SortOrder.AscendingOrder) # get the standard table row height. Do this here because calling # resizeRowsToContents can word wrap long cell contents, creating # double-high rows self.books_table.setRowCount(1) self.books_table.setItem(0, 0, TableItem()) self.books_table.resizeRowsToContents() self.books_table_row_height = self.books_table.rowHeight(0) self.books_table.setRowCount(0) # Add the data self.refresh(row) self.slave_timers = [QTimer(self), QTimer(self), QTimer(self)] self.view.clicked.connect( partial(self.delayed_slave, func=self.slave, dex=0)) self.view.selectionModel().currentColumnChanged.connect( partial(self.delayed_slave, func=self.column_slave, dex=1)) QCoreApplication.instance().aboutToQuit.connect(self.save_state) self.view.model().new_bookdisplay_data.connect( partial(self.delayed_slave, func=self.book_was_changed, dex=2)) self.close_button.setDefault(False) self.close_button_tooltip = _( 'The Quickview shortcut ({0}) shows/hides the Quickview panel') self.refresh_button.setIcon(QIcon.ic('view-refresh.png')) self.close_button.setIcon(self.style().standardIcon( QStyle.StandardPixmap.SP_DialogCloseButton)) if self.is_pane: self.dock_button.setText(_('Undock')) self.dock_button.setToolTip( _('Show the Quickview panel in its own floating window')) self.dock_button.setIcon(QIcon(I('arrow-up.png'))) # Remove the ampersands from the buttons because shortcuts exist. self.lock_qv.setText(_('Lock Quickview contents')) self.refresh_button.setText(_('Refresh')) self.gui.quickview_splitter.add_quickview_dialog(self) self.close_button.setVisible(False) else: self.dock_button.setToolTip( _('Embed the Quickview panel into the main calibre window')) self.dock_button.setIcon(QIcon(I('arrow-down.png'))) self.set_focus() self.books_table.horizontalHeader().sectionResized.connect( self.section_resized) self.dock_button.clicked.connect(self.show_as_pane_changed) self.view.model().search_done.connect(self.check_for_no_items) # Enable the refresh button only when QV is locked self.refresh_button.setEnabled(False) self.lock_qv.stateChanged.connect(self.lock_qv_changed) self.view_icon = QIcon(I('view.png')) self.view_plugin = self.gui.iactions['View'] self.edit_metadata_icon = QIcon(I('edit_input.png')) self.quickview_icon = QIcon(I('quickview.png')) self.select_book_icon = QIcon(I('library.png')) self.search_icon = QIcon(I('search.png')) self.books_table.setContextMenuPolicy( Qt.ContextMenuPolicy.CustomContextMenu) self.books_table.customContextMenuRequested.connect( self.show_context_menu) # Add the quickview toggle as a shortcut for the close button # Don't add it if it identical to the current &X shortcut because that # breaks &X if (not self.is_pane and toggle_shortcut and self.close_button.shortcut() != toggle_shortcut): toggle_sc = QShortcut(toggle_shortcut, self.close_button) toggle_sc.activated.connect(lambda: self.close_button_clicked()) toggle_sc.setEnabled(True) self.close_button.setToolTip( _('Alternate shortcut: ') + toggle_shortcut.toString())
def build_virtual_library_menu(self, m, add_tabs_action=True): m.clear() a = m.addAction(QIcon.ic('plus.png'), _('Create Virtual library')) a.triggered.connect(partial(self.do_create_edit, name=None)) db = self.current_db virt_libs = db.new_api.pref('virtual_libraries', {}) a = self.edit_menu self.build_virtual_library_list(a, self.do_create_edit) if virt_libs: m.addMenu(a).setIcon(QIcon.ic('edit_input.png')) a = self.rm_menu self.build_virtual_library_list(a, self.remove_vl_triggered) if virt_libs: m.addMenu(a).setIcon(QIcon.ic('minus.png')) if virt_libs: m.addAction(QIcon.ic('toc.png'), _('Quick select Virtual library'), self.choose_vl_triggerred) if add_tabs_action: if gprefs['show_vl_tabs']: m.addAction(_('Hide Virtual library tabs'), self.vl_tabs.disable_bar) else: m.addAction(_('Show Virtual libraries as tabs'), self.vl_tabs.enable_bar) m.addSeparator() a = self.ar_menu a.clear() a.setIcon(self.checked if db.data.get_search_restriction_name() else self.empty) self.build_search_restriction_list() m.addMenu(a) m.addSeparator() current_lib = db.data.get_base_restriction_name() if not current_lib: a = m.addAction(self.checked, self.no_restriction) else: a = m.addAction(self.empty, self.no_restriction) a.triggered.connect(partial(self.apply_virtual_library, library='')) a = m.addAction(self.current_search_action) if self.search_based_vl_name: a = m.addAction( self.checked if db.data.get_base_restriction_name().startswith('*') else self.empty, self.search_based_vl_name) a.triggered.connect(partial(self.apply_virtual_library, library=self.search_based_vl_name)) m.addSeparator() for vl in sorted(virt_libs.keys(), key=sort_key): is_current = vl == current_lib a = m.addAction(self.checked if is_current else self.empty, vl.replace('&', '&&')) if is_current: a.triggered.connect(self.apply_virtual_library) else: a.triggered.connect(partial(self.apply_virtual_library, library=vl))
def build_email_entries(self, sync_menu): from calibre.gui2.device import DeviceAction for ac in self.email_actions: self.removeAction(ac) self.email_actions = [] self.memory = [] opts = email_config().parse() if opts.accounts: self.email_to_menu = QMenu(_('Email to') + '...', self) ac = self.addMenu(self.email_to_menu) self.email_actions.append(ac) self.email_to_and_delete_menu = QMenu( _('Email to and delete from library') + '...', self) keys = sorted(opts.accounts.keys()) def sk(account): return primary_sort_key(opts.aliases.get(account) or account) for account in sorted(keys, key=sk): formats, auto, default = opts.accounts[account] subject = opts.subjects.get(account, '') alias = opts.aliases.get(account, '') dest = 'mail:' + account + ';' + formats + ';' + subject action1 = DeviceAction(dest, False, False, I('mail.png'), alias or account) action2 = DeviceAction(dest, True, False, I('mail.png'), (alias or account) + ' ' + _('(delete from library)')) self.email_to_menu.addAction(action1) self.email_to_and_delete_menu.addAction(action2) self.memory.append(action1) self.memory.append(action2) if default: ac = DeviceAction(dest, False, False, I('mail.png'), _('Email to') + ' ' + (alias or account)) self.addAction(ac) self.email_actions.append(ac) ac.a_s.connect(sync_menu.action_triggered) action1.a_s.connect(sync_menu.action_triggered) action2.a_s.connect(sync_menu.action_triggered) action1 = DeviceAction('choosemail:', False, False, I('mail.png'), _('Select recipients')) action2 = DeviceAction( 'choosemail:', True, False, I('mail.png'), _('Select recipients') + ' ' + _('(delete from library)')) self.email_to_menu.addAction(action1) self.email_to_and_delete_menu.addAction(action2) self.memory.append(action1) self.memory.append(action2) tac1 = DeviceAction('choosemail:', False, False, I('mail.png'), _('Email to selected recipients...')) self.addAction(tac1) tac1.a_s.connect(sync_menu.action_triggered) self.memory.append(tac1) self.email_actions.append(tac1) ac = self.addMenu(self.email_to_and_delete_menu) self.email_actions.append(ac) action1.a_s.connect(sync_menu.action_triggered) action2.a_s.connect(sync_menu.action_triggered) else: ac = self.addAction(QIcon.ic('mail.png'), _('Setup email based sharing of books')) self.email_actions.append(ac) ac.triggered.connect(self.setup_email)
def __init__(self, parent): QFrame.__init__(self, parent) self.setFrameStyle(QFrame.Shape.NoFrame if gprefs['tag_browser_old_look'] else QFrame.Shape.StyledPanel) self._parent = parent self._layout = QVBoxLayout(self) self._layout.setContentsMargins(0,0,0,0) # Set up the find box & button self.tb_bar = tbb = TagBrowserBar(self) tbb.clear_find.connect(self.reset_find) self.alter_tb, self.item_search, self.search_button = tbb.alter_tb, tbb.item_search, tbb.search_button self.toggle_search_button = tbb.toggle_search_button self._layout.addWidget(tbb) self.current_find_position = None self.search_button.clicked.connect(self.find) self.item_search.lineEdit().textEdited.connect(self.find_text_changed) self.item_search.activated[str].connect(self.do_find) # The tags view parent.tags_view = TagsView(parent) self.tags_view = parent.tags_view self._layout.insertWidget(0, parent.tags_view) # Now the floating 'not found' box l = QLabel(self.tags_view) self.not_found_label = l l.setFrameStyle(QFrame.Shape.StyledPanel) l.setAutoFillBackground(True) l.setText('<p><b>'+_('No more matches.</b><p> Click Find again to go to first match')) l.setAlignment(Qt.AlignmentFlag.AlignVCenter) l.setWordWrap(True) l.resize(l.sizeHint()) l.move(10,20) l.setVisible(False) self.not_found_label_timer = QTimer() self.not_found_label_timer.setSingleShot(True) self.not_found_label_timer.timeout.connect(self.not_found_label_timer_event, type=Qt.ConnectionType.QueuedConnection) self.collapse_all_action = ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser collapse all', _('Collapse all'), default_keys=(), action=ac, group=_('Tag browser')) connect_lambda(ac.triggered, self, lambda self: self.tags_view.collapseAll()) # The Configure Tag Browser button l = self.alter_tb ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser alter', _('Configure Tag browser'), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(l.showMenu) l.m.aboutToShow.connect(self.about_to_show_configure_menu) l.m.show_counts_action = ac = l.m.addAction('counts') ac.triggered.connect(self.toggle_counts) l.m.show_avg_rating_action = ac = l.m.addAction(QIcon.ic('rating.png'), 'avg rating') ac.triggered.connect(self.toggle_avg_rating) sb = l.m.addAction(QIcon.ic('sort.png'), _('Sort by')) sb.m = l.sort_menu = QMenu(l.m) sb.setMenu(sb.m) sb.bg = QActionGroup(sb) # Must be in the same order as db2.CATEGORY_SORTS for i, x in enumerate((_('Name'), _('Number of books'), _('Average rating'))): a = sb.m.addAction(x) sb.bg.addAction(a) a.setCheckable(True) if i == 0: a.setChecked(True) sb.setToolTip( _('Set the sort order for entries in the Tag browser')) sb.setStatusTip(sb.toolTip()) ma = l.m.addAction(QIcon.ic('search.png'), _('Search type when selecting multiple items')) ma.m = l.match_menu = QMenu(l.m) ma.setMenu(ma.m) ma.ag = QActionGroup(ma) # Must be in the same order as db2.MATCH_TYPE for i, x in enumerate((_('Match any of the items'), _('Match all of the items'))): a = ma.m.addAction(x) ma.ag.addAction(a) a.setCheckable(True) if i == 0: a.setChecked(True) ma.setToolTip( _('When selecting multiple entries in the Tag browser ' 'match any or all of them')) ma.setStatusTip(ma.toolTip()) mt = l.m.addAction(_('Manage authors, tags, etc.')) mt.setToolTip(_('All of these category_managers are available by right-clicking ' 'on items in the Tag browser above')) mt.m = l.manage_menu = QMenu(l.m) mt.setMenu(mt.m) ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser toggle item', _("'Click' found item"), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(self.toggle_item) ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser set focus', _("Give the Tag browser keyboard focus"), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(self.give_tb_focus)
def __init__(self, parent, current_img, current_url, geom_name='viewer_image_popup_geometry', prefs=gprefs): QDialog.__init__(self) self.prefs = prefs self.current_image_name = '' self.maximized_at_last_fullscreen = False self.setWindowFlag(Qt.WindowType.WindowMinimizeButtonHint) self.setWindowFlag(Qt.WindowType.WindowMaximizeButtonHint) self.avail_geom = self.screen().availableGeometry() self.current_img = current_img self.current_url = current_url self.factor = 1.0 self.geom_name = geom_name self.scrollarea = sa = ScrollArea() sa.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) sa.setBackgroundRole(QPalette.ColorRole.Dark) self.label = l = Label(sa) l.zoom_requested.connect(self.zoom_requested) sa.toggle_fit.connect(self.toggle_fit) sa.setWidget(l) self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.zi_button = zi = bb.addButton( _('Zoom &in'), QDialogButtonBox.ButtonRole.ActionRole) self.zo_button = zo = bb.addButton( _('Zoom &out'), QDialogButtonBox.ButtonRole.ActionRole) self.save_button = so = bb.addButton( _('&Save as'), QDialogButtonBox.ButtonRole.ActionRole) self.copy_button = co = bb.addButton( _('&Copy'), QDialogButtonBox.ButtonRole.ActionRole) self.rotate_button = ro = bb.addButton( _('&Rotate'), QDialogButtonBox.ButtonRole.ActionRole) self.fullscreen_button = fo = bb.addButton( _('&Full screen'), QDialogButtonBox.ButtonRole.ActionRole) zi.setIcon(QIcon(I('plus.png'))) zo.setIcon(QIcon(I('minus.png'))) so.setIcon(QIcon(I('save.png'))) co.setIcon(QIcon.ic('edit-copy.png')) ro.setIcon(QIcon(I('rotate-right.png'))) fo.setIcon(QIcon(I('page.png'))) zi.clicked.connect(self.zoom_in) zo.clicked.connect(self.zoom_out) so.clicked.connect(self.save_image) co.clicked.connect(self.copy_image) self.copy_action = QAction(self) self.addAction(self.copy_action) self.copy_action.triggered.connect(self.copy_button.click) self.copy_action.setShortcut(QKeySequence.StandardKey.Copy) ro.clicked.connect(self.rotate_image) fo.setCheckable(True) self.l = l = QVBoxLayout(self) l.addWidget(sa) self.h = h = QHBoxLayout() h.setContentsMargins(0, 0, 0, 0) l.addLayout(h) self.fit_image = i = QCheckBox(_('&Fit image')) i.setToolTip(_('Fit image inside the available space')) i.setChecked(bool(self.prefs.get('image_popup_fit_image'))) i.stateChanged.connect(self.fit_changed) h.addWidget(i), h.addStretch(), h.addWidget(bb) if self.fit_image.isChecked(): self.set_to_viewport_size() geom = self.prefs.get(self.geom_name) if geom is not None: self.restoreGeometry(geom) fo.setChecked(self.isFullScreen()) fo.toggled.connect(self.toggle_fullscreen)
def library_qicon(lib_name=''): q = library_icon_path(lib_name) if os.path.exists(q): return QIcon(q) return getattr(library_qicon, 'default_icon', None) or QIcon.ic('lt.png')