mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add donate button to tweak book
This commit is contained in:
parent
30d522527b
commit
3926d5a276
@ -8,10 +8,10 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from PyQt4.Qt import (Qt, QAction, QLabel, QMenu, QMenuBar, QObject,
|
||||
QToolBar, QToolButton, QSize, QVBoxLayout, QWidget)
|
||||
from PyQt4.Qt import (Qt, QAction, QMenu, QMenuBar, QObject,
|
||||
QToolBar, QToolButton, QSize)
|
||||
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2.throbber import create_donate_widget
|
||||
from calibre.gui2 import gprefs
|
||||
|
||||
class ToolBar(QToolBar): # {{{
|
||||
@ -54,7 +54,8 @@ class ToolBar(QToolBar): # {{{
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
ac = self.actionAt(ev.pos())
|
||||
if ac is None: return
|
||||
if ac is None:
|
||||
return
|
||||
ch = self.widgetForAction(ac)
|
||||
sm = getattr(ch, 'showMenu', None)
|
||||
if callable(sm):
|
||||
@ -88,15 +89,7 @@ class ToolBar(QToolBar): # {{{
|
||||
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
||||
ac.setVisible(False)
|
||||
elif what == 'Donate':
|
||||
self.d_widget = QWidget()
|
||||
self.d_widget.setLayout(QVBoxLayout())
|
||||
self.d_widget.layout().addWidget(self.donate_button)
|
||||
if isosx:
|
||||
self.d_widget.setStyleSheet('QWidget, QToolButton {background-color: none; border: none; }')
|
||||
self.d_widget.layout().setContentsMargins(0,0,0,0)
|
||||
self.d_widget.setContentsMargins(0,0,0,0)
|
||||
self.d_widget.filler = QLabel(u'\u00a0')
|
||||
self.d_widget.layout().addWidget(self.d_widget.filler)
|
||||
self.d_widget = create_donate_widget(self.donate_button)
|
||||
bar.addWidget(self.d_widget)
|
||||
self.showing_donate = True
|
||||
elif what in self.gui.iactions:
|
||||
@ -125,8 +118,8 @@ class ToolBar(QToolBar): # {{{
|
||||
aa = iac.qaction
|
||||
w = self.widgetForAction(aa)
|
||||
m = aa.menu()
|
||||
if (( (w is not None and w.geometry().contains(pos)) or
|
||||
(m is not None and m.isVisible() and m.geometry().contains(pos)) ) and
|
||||
if (((w is not None and w.geometry().contains(pos)) or
|
||||
(m is not None and m.isVisible() and m.geometry().contains(pos))) and
|
||||
getattr(iac, func)(event, md)):
|
||||
return True
|
||||
return False
|
||||
@ -151,8 +144,8 @@ class ToolBar(QToolBar): # {{{
|
||||
for ac in self.location_manager.available_actions:
|
||||
w = self.widgetForAction(ac)
|
||||
if w is not None:
|
||||
if ( md.hasFormat("application/calibre+from_library") or \
|
||||
md.hasFormat("application/calibre+from_device") ) and \
|
||||
if (md.hasFormat("application/calibre+from_library") or
|
||||
md.hasFormat("application/calibre+from_device")) and \
|
||||
w.geometry().contains(event.pos()) and \
|
||||
isinstance(w, QToolButton) and not w.isChecked():
|
||||
allowed = True
|
||||
|
@ -7,8 +7,9 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from PyQt4.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \
|
||||
QMetaObject
|
||||
QMetaObject, QLabel, QVBoxLayout, QWidget
|
||||
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2 import config
|
||||
|
||||
class ThrobbingButton(QToolButton):
|
||||
@ -44,7 +45,8 @@ class ThrobbingButton(QToolButton):
|
||||
self.update()
|
||||
|
||||
def start_animation(self):
|
||||
if config['disable_animations']: return
|
||||
if config['disable_animations']:
|
||||
return
|
||||
if self.animation.state() != self.animation.Stopped or not self.isVisible():
|
||||
return
|
||||
size = self.normal_icon_size.width()
|
||||
@ -57,9 +59,20 @@ class ThrobbingButton(QToolButton):
|
||||
self.animation.stop()
|
||||
self.animation_finished()
|
||||
|
||||
def create_donate_widget(button):
|
||||
w = QWidget()
|
||||
w.setLayout(QVBoxLayout())
|
||||
w.layout().addWidget(button)
|
||||
if isosx:
|
||||
w.setStyleSheet('QWidget, QToolButton {background-color: none; border: none; }')
|
||||
w.layout().setContentsMargins(0,0,0,0)
|
||||
w.setContentsMargins(0,0,0,0)
|
||||
w.filler = QLabel(u'\u00a0')
|
||||
w.layout().addWidget(w.filler)
|
||||
return w
|
||||
|
||||
if __name__ == '__main__':
|
||||
from PyQt4.Qt import QApplication, QWidget, QHBoxLayout, QIcon
|
||||
from PyQt4.Qt import QApplication, QHBoxLayout, QIcon
|
||||
app = QApplication([])
|
||||
w = QWidget()
|
||||
w.setLayout(QHBoxLayout())
|
||||
|
@ -11,12 +11,13 @@ from functools import partial
|
||||
from PyQt4.Qt import (
|
||||
QDockWidget, Qt, QLabel, QIcon, QAction, QApplication, QWidget, QEvent,
|
||||
QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal,
|
||||
QMenu, QHBoxLayout)
|
||||
QMenu, QHBoxLayout, QTimer, QUrl)
|
||||
|
||||
from calibre.constants import __appname__, get_version
|
||||
from calibre.gui2 import elided_text
|
||||
from calibre.gui2 import elided_text, open_url
|
||||
from calibre.gui2.keyboard import Manager as KeyboardManager
|
||||
from calibre.gui2.main_window import MainWindow
|
||||
from calibre.gui2.throbber import ThrobbingButton, create_donate_widget
|
||||
from calibre.gui2.tweak_book import current_container, tprefs, actions
|
||||
from calibre.gui2.tweak_book.file_list import FileListWidget
|
||||
from calibre.gui2.tweak_book.job import BlockingJob
|
||||
@ -438,6 +439,17 @@ class Main(MainWindow):
|
||||
a = create(_('Book tool bar'), 'global').addAction
|
||||
for x in ('new_file', 'open_book', 'global_undo', 'global_redo', 'save', 'create_checkpoint', 'toc', 'check_book'):
|
||||
a(getattr(self, 'action_' + x))
|
||||
self.donate_button = b = ThrobbingButton(self)
|
||||
b.clicked.connect(lambda : open_url(QUrl('http://calibre-ebook.com/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)
|
||||
|
||||
a = create(_('Polish book tool bar'), 'polish').addAction
|
||||
for x in ('embed_fonts', 'subset_fonts', 'smarten_punctuation'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user