mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix changing main toolbar in preferences causing donate button to disappear for the session
This commit is contained in:
parent
656859a58e
commit
f974854eb1
@ -14,6 +14,7 @@ from PyQt5.Qt import (
|
|||||||
|
|
||||||
from calibre.constants import isosx
|
from calibre.constants import isosx
|
||||||
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
||||||
|
from calibre.gui2.throbber import ThrobbingButton
|
||||||
|
|
||||||
|
|
||||||
class RevealBar(QWidget): # {{{
|
class RevealBar(QWidget): # {{{
|
||||||
@ -60,9 +61,20 @@ class RevealBar(QWidget): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
class ToolBar(QToolBar): # {{{
|
class ToolBar(QToolBar): # {{{
|
||||||
|
|
||||||
def __init__(self, donate, location_manager, parent):
|
def __init__(self, donate_action, location_manager, parent):
|
||||||
QToolBar.__init__(self, parent)
|
QToolBar.__init__(self, parent)
|
||||||
self.setMovable(False)
|
self.setMovable(False)
|
||||||
self.setFloatable(False)
|
self.setFloatable(False)
|
||||||
@ -71,12 +83,11 @@ class ToolBar(QToolBar): # {{{
|
|||||||
self.setStyleSheet('QToolButton:checked { font-weight: bold }')
|
self.setStyleSheet('QToolButton:checked { font-weight: bold }')
|
||||||
self.preferred_width = self.sizeHint().width()
|
self.preferred_width = self.sizeHint().width()
|
||||||
self.gui = parent
|
self.gui = parent
|
||||||
self.donate_button = donate
|
self.donate_action = donate_action
|
||||||
|
self.donate_button = None
|
||||||
self.added_actions = []
|
self.added_actions = []
|
||||||
|
|
||||||
self.location_manager = location_manager
|
self.location_manager = location_manager
|
||||||
donate.setAutoRaise(True)
|
|
||||||
donate.setCursor(Qt.PointingHandCursor)
|
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self.showing_donate = False
|
self.showing_donate = False
|
||||||
|
|
||||||
@ -84,7 +95,8 @@ class ToolBar(QToolBar): # {{{
|
|||||||
QToolBar.resizeEvent(self, ev)
|
QToolBar.resizeEvent(self, ev)
|
||||||
style = self.get_text_style()
|
style = self.get_text_style()
|
||||||
self.setToolButtonStyle(style)
|
self.setToolButtonStyle(style)
|
||||||
self.donate_button.setToolButtonStyle(style)
|
if self.showing_donate:
|
||||||
|
self.donate_button.setToolButtonStyle(style)
|
||||||
|
|
||||||
def get_text_style(self):
|
def get_text_style(self):
|
||||||
style = Qt.ToolButtonTextUnderIcon
|
style = Qt.ToolButtonTextUnderIcon
|
||||||
@ -121,6 +133,7 @@ class ToolBar(QToolBar): # {{{
|
|||||||
|
|
||||||
self.clear()
|
self.clear()
|
||||||
self.added_actions = []
|
self.added_actions = []
|
||||||
|
self.donate_button = None
|
||||||
|
|
||||||
bar = self
|
bar = self
|
||||||
|
|
||||||
@ -134,7 +147,10 @@ class ToolBar(QToolBar): # {{{
|
|||||||
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
||||||
ac.setVisible(False)
|
ac.setVisible(False)
|
||||||
elif what == 'Donate':
|
elif what == 'Donate':
|
||||||
|
self.donate_button = create_donate_button(self.donate_action)
|
||||||
bar.addWidget(self.donate_button)
|
bar.addWidget(self.donate_button)
|
||||||
|
self.donate_button.setIconSize(bar.iconSize())
|
||||||
|
self.donate_button.setToolButtonStyle(self.toolButtonStyle())
|
||||||
self.showing_donate = True
|
self.showing_donate = True
|
||||||
elif what in self.gui.iactions:
|
elif what in self.gui.iactions:
|
||||||
action = self.gui.iactions[what]
|
action = self.gui.iactions[what]
|
||||||
@ -486,12 +502,11 @@ else:
|
|||||||
|
|
||||||
class BarsManager(QObject):
|
class BarsManager(QObject):
|
||||||
|
|
||||||
def __init__(self, donate_button, location_manager, parent):
|
def __init__(self, donate_action, location_manager, parent):
|
||||||
QObject.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
self.donate_button, self.location_manager = (donate_button,
|
self.location_manager = location_manager
|
||||||
location_manager)
|
|
||||||
|
|
||||||
bars = [ToolBar(donate_button, location_manager, parent) for i in
|
bars = [ToolBar(donate_action, location_manager, parent) for i in
|
||||||
range(3)]
|
range(3)]
|
||||||
self.main_bars = tuple(bars[:2])
|
self.main_bars = tuple(bars[:2])
|
||||||
self.child_bars = tuple(bars[2:])
|
self.child_bars = tuple(bars[2:])
|
||||||
@ -520,6 +535,12 @@ class BarsManager(QObject):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def start_animation(self):
|
||||||
|
for b in self.bars:
|
||||||
|
if b.isVisible() and b.showing_donate:
|
||||||
|
b.donate_button.start_animation()
|
||||||
|
return True
|
||||||
|
|
||||||
def init_bars(self):
|
def init_bars(self):
|
||||||
self.bar_actions = tuple(
|
self.bar_actions = tuple(
|
||||||
[gprefs['action-layout-toolbar'+x] for x in ('', '-device')] +
|
[gprefs['action-layout-toolbar'+x] for x in ('', '-device')] +
|
||||||
@ -566,5 +587,6 @@ class BarsManager(QObject):
|
|||||||
for bar in self.bars:
|
for bar in self.bars:
|
||||||
bar.setIconSize(QSize(sz, sz))
|
bar.setIconSize(QSize(sz, sz))
|
||||||
bar.setToolButtonStyle(style)
|
bar.setToolButtonStyle(style)
|
||||||
self.donate_button.setIconSize(bar.iconSize())
|
if bar.showing_donate:
|
||||||
self.donate_button.setToolButtonStyle(style)
|
bar.donate_button.setIconSize(bar.iconSize())
|
||||||
|
bar.donate_button.setToolButtonStyle(style)
|
||||||
|
@ -14,7 +14,6 @@ from PyQt5.Qt import (QIcon, Qt, QWidget, QSize,
|
|||||||
|
|
||||||
from calibre.constants import __appname__
|
from calibre.constants import __appname__
|
||||||
from calibre.gui2.search_box import SearchBox2, SavedSearchBox
|
from calibre.gui2.search_box import SearchBox2, SavedSearchBox
|
||||||
from calibre.gui2.throbber import ThrobbingButton
|
|
||||||
from calibre.gui2.bars import BarsManager
|
from calibre.gui2.bars import BarsManager
|
||||||
from calibre.gui2.widgets2 import RightClickButton
|
from calibre.gui2.widgets2 import RightClickButton
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
@ -286,13 +285,12 @@ class MainWindowMixin(object): # {{{
|
|||||||
self._central_widget_layout = QVBoxLayout()
|
self._central_widget_layout = QVBoxLayout()
|
||||||
self.centralwidget.setLayout(self._central_widget_layout)
|
self.centralwidget.setLayout(self._central_widget_layout)
|
||||||
self.resize(1012, 740)
|
self.resize(1012, 740)
|
||||||
self.donate_button = ThrobbingButton()
|
|
||||||
self.location_manager = LocationManager(self)
|
self.location_manager = LocationManager(self)
|
||||||
|
|
||||||
self.iactions['Fetch News'].init_scheduler(db)
|
self.iactions['Fetch News'].init_scheduler(db)
|
||||||
|
|
||||||
self.search_bar = SearchBar(self)
|
self.search_bar = SearchBar(self)
|
||||||
self.bars_manager = BarsManager(self.donate_button,
|
self.bars_manager = BarsManager(self.donate_action,
|
||||||
self.location_manager, self)
|
self.location_manager, self)
|
||||||
for bar in self.bars_manager.main_bars:
|
for bar in self.bars_manager.main_bars:
|
||||||
self.addToolBar(Qt.TopToolBarArea, bar)
|
self.addToolBar(Qt.TopToolBarArea, bar)
|
||||||
|
@ -278,10 +278,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.toggle_to_tray_action = self.system_tray_menu.addAction(QIcon(I('page.png')), '')
|
self.toggle_to_tray_action = self.system_tray_menu.addAction(QIcon(I('page.png')), '')
|
||||||
self.toggle_to_tray_action.triggered.connect(self.system_tray_icon_activated)
|
self.toggle_to_tray_action.triggered.connect(self.system_tray_icon_activated)
|
||||||
self.system_tray_menu.addAction(self.donate_action)
|
self.system_tray_menu.addAction(self.donate_action)
|
||||||
self.donate_button.clicked.connect(self.donate_action.trigger)
|
|
||||||
self.donate_button.setToolTip(self.donate_action.text().replace('&', ''))
|
|
||||||
self.donate_button.setIcon(self.donate_action.icon())
|
|
||||||
self.donate_button.setStatusTip(self.donate_button.toolTip())
|
|
||||||
self.eject_action = self.system_tray_menu.addAction(
|
self.eject_action = self.system_tray_menu.addAction(
|
||||||
QIcon(I('eject.png')), _('&Eject connected device'))
|
QIcon(I('eject.png')), _('&Eject connected device'))
|
||||||
self.eject_action.setEnabled(False)
|
self.eject_action.setEnabled(False)
|
||||||
@ -401,8 +397,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.read_settings()
|
self.read_settings()
|
||||||
|
|
||||||
self.finalize_layout()
|
self.finalize_layout()
|
||||||
if self.bars_manager.showing_donate:
|
self.bars_manager.start_animation()
|
||||||
self.donate_button.start_animation()
|
|
||||||
self.set_window_title()
|
self.set_window_title()
|
||||||
|
|
||||||
for ac in self.iactions.values():
|
for ac in self.iactions.values():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user