def create_toolbars(self): def create(text, name): name += '-bar' b = self.addToolBar(text) b.setObjectName(name) # Needed for saveState setattr(self, name.replace('-', '_'), b) actions[name] = b.toggleViewAction() return b a = create(_('Book tool bar'), 'global').addAction for x in ('new_file', 'open_book', None, 'global_undo', 'global_redo', 'create_checkpoint', 'save', None, 'toc', 'check_book', 'spell_check_book'): if x is None: self.global_bar.addSeparator() continue a(getattr(self, 'action_' + x)) self.donate_button = b = ThrobbingButton(self) b.clicked.connect(open_donate) b.setAutoRaise(True) self.donate_widget = w = create_donate_widget(b) if hasattr(w, 'filler'): w.filler.setVisible(False) b.set_normal_icon_size(self.global_bar.iconSize().width(), self.global_bar.iconSize().height()) b.setIcon(QIcon(I('donate.png'))) b.setToolTip(_('Donate to support calibre development')) QTimer.singleShot(10, b.start_animation) self.global_bar.addWidget(w) self.global_bar.addAction(self.action_insert_char) a(self.action_help) a = create(_('Polish book tool bar'), 'polish').addAction for x in ('embed_fonts', 'subset_fonts', 'smarten_punctuation', 'remove_unused_css'): a(getattr(self, 'action_' + x))
def init_main_window_mixin(self, db): self.setObjectName('MainWindow') self.setWindowIcon(QIcon(I('lt.png'))) self.setWindowTitle(__appname__) self.setContextMenuPolicy(Qt.NoContextMenu) self.centralwidget = QWidget(self) self.setCentralWidget(self.centralwidget) self._central_widget_layout = QVBoxLayout() self.centralwidget.setLayout(self._central_widget_layout) self.resize(1012, 740) self.donate_button = ThrobbingButton() self.location_manager = LocationManager(self) self.iactions['Fetch News'].init_scheduler(db) self.search_bar = SearchBar(self) self.bars_manager = BarsManager(self.donate_button, self.location_manager, self) for bar in self.bars_manager.main_bars: self.addToolBar(Qt.TopToolBarArea, bar) for bar in self.bars_manager.child_bars: self.addToolBar(Qt.BottomToolBarArea, bar) self.bars_manager.update_bars() # This is disabled because it introduces various toolbar related bugs # The width of the toolbar becomes the sum of both toolbars if tweaks['unified_title_toolbar_on_osx']: self.setUnifiedTitleAndToolBarOnMac(True) l = self.centralwidget.layout() l.addWidget(self.search_bar)
def add(bar, ac): if ac is None: bar.addSeparator() elif ac == 'donate': self.donate_button = b = ThrobbingButton(self) b.clicked.connect(open_donate) b.setAutoRaise(True) b.setToolTip(_('Donate to support calibre development')) if animate: QTimer.singleShot(10, b.start_animation) bar.addWidget(b) else: try: bar.addAction(actions[ac]) except KeyError: if DEBUG: prints('Unknown action for toolbar %r: %r' % (unicode_type(bar.objectName()), ac))
def init_main_window_mixin(self, db): self.setObjectName('MainWindow') self.setWindowIcon(QIcon(I('lt.png'))) self.setWindowTitle(__appname__) self.setContextMenuPolicy(Qt.NoContextMenu) self.centralwidget = QWidget(self) self.setCentralWidget(self.centralwidget) self._central_widget_layout = QVBoxLayout() self.centralwidget.setLayout(self._central_widget_layout) self.resize(1012, 740) self.donate_button = ThrobbingButton() self.location_manager = LocationManager(self) self.iactions['Fetch News'].init_scheduler(db) self.search_bar = SearchBar(self) self.bars_manager = BarsManager(self.donate_button, self.location_manager, self) for bar in self.bars_manager.main_bars: self.addToolBar(Qt.TopToolBarArea, bar) for bar in self.bars_manager.child_bars: self.addToolBar(Qt.BottomToolBarArea, bar) self.bars_manager.update_bars() # This is disabled because it introduces various toolbar related bugs # The width of the toolbar becomes the sum of both toolbars if tweaks['unified_title_toolbar_on_osx']: try: self.setUnifiedTitleAndToolBarOnMac(True) except AttributeError: pass # PyQt5 seems to be missing this property l = self.centralwidget.layout() # And now, start adding the real widgets l.addWidget(self.search_bar) # Add in the widget for the shutdown messages. It is invisible until a # message is shown smw = self.shutdown_message_widget = QLabel(self) smw.setAlignment(Qt.AlignCenter) smw.setVisible(False) smw.setAutoFillBackground(True) smw.setStyleSheet( 'QLabel { background-color: rgba(200, 200, 200, 200); color: black }' )
def add(bar, ac): if ac is None: bar.addSeparator() elif ac == 'donate': self.donate_button = b = ThrobbingButton(self) b.clicked.connect(open_donate) b.setAutoRaise(True) self.donate_widget = w = create_donate_widget(b) if hasattr(w, 'filler'): w.filler.setVisible(False) b.set_normal_icon_size(self.global_bar.iconSize().width(), self.global_bar.iconSize().height()) b.setIcon(QIcon(I('donate.png'))) b.setToolTip(_('Donate to support calibre development')) if animate: QTimer.singleShot(10, b.start_animation) bar.addWidget(w) else: try: bar.addAction(actions[ac]) except KeyError: if DEBUG: prints('Unknown action for toolbar %r: %r' % (unicode(bar.objectName()), ac))
def create_donate_button(action): ans = ThrobbingButton() ans.setAutoRaise(True) ans.setCursor(Qt.PointingHandCursor) ans.clicked.connect(action.trigger) ans.setToolTip(action.text().replace('&', '')) ans.setIcon(action.icon()) ans.setStatusTip(ans.toolTip()) return ans