mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Nicer rendering for the splash screen message
This commit is contained in:
parent
f629347c7a
commit
e1a628d533
@ -6,7 +6,7 @@ from functools import partial
|
||||
|
||||
import apsw
|
||||
from PyQt5.Qt import (
|
||||
QCoreApplication, QIcon, QObject, QTimer, Qt, QSplashScreen, QBrush, QColor)
|
||||
QCoreApplication, QIcon, QObject, QTimer)
|
||||
|
||||
from calibre import prints, plugins, force_unicode
|
||||
from calibre.constants import (iswindows, __appname__, isosx, DEBUG, islinux,
|
||||
@ -16,6 +16,7 @@ from calibre.gui2 import (
|
||||
ORG_NAME, APP_UID, initialize_file_icon_provider, Application, choose_dir,
|
||||
error_dialog, question_dialog, gprefs, setup_gui_option_parser)
|
||||
from calibre.gui2.main_window import option_parser as _option_parser
|
||||
from calibre.gui2.splash_screen import SplashScreen
|
||||
from calibre.utils.config import prefs, dynamic
|
||||
|
||||
if iswindows:
|
||||
@ -160,36 +161,6 @@ class EventAccumulator(object):
|
||||
def __call__(self, ev):
|
||||
self.events.append(ev)
|
||||
|
||||
class SplashScreen(QSplashScreen):
|
||||
|
||||
def __init__(self):
|
||||
self.drawn_once = False
|
||||
pmap = QIcon(I('library.png', allow_user_override=False)).pixmap(512, 512)
|
||||
QSplashScreen.__init__(self, pmap)
|
||||
self.setWindowTitle(__appname__)
|
||||
|
||||
def drawContents(self, painter):
|
||||
self.drawn_once = True
|
||||
painter.setBackgroundMode(Qt.OpaqueMode)
|
||||
painter.setBackground(QBrush(QColor(0xee, 0xee, 0xee)))
|
||||
painter.setPen(Qt.black)
|
||||
painter.setRenderHint(painter.TextAntialiasing, True)
|
||||
r = self.rect().adjusted(5, 5, -5, -5)
|
||||
br = painter.drawText(r, Qt.AlignLeft, self.message())
|
||||
painter.fillRect(br.adjusted(-2, -3, 80, 3), painter.background())
|
||||
br = painter.drawText(r, Qt.AlignLeft, self.message())
|
||||
|
||||
def show_message(self, msg):
|
||||
self.showMessage(msg)
|
||||
self.wait_for_draw()
|
||||
|
||||
def wait_for_draw(self):
|
||||
# Without this the splash screen is not painted on linux and windows
|
||||
self.drawn_once = False
|
||||
st = time.time()
|
||||
while not self.drawn_once and (time.time() - st < 0.1):
|
||||
Application.instance().processEvents()
|
||||
|
||||
class GuiRunner(QObject):
|
||||
'''Make sure an event loop is running before starting the main work of
|
||||
initialization'''
|
||||
|
60
src/calibre/gui2/splash_screen.py
Normal file
60
src/calibre/gui2/splash_screen.py
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
from PyQt5.Qt import Qt, QSplashScreen, QIcon, QApplication, QTransform
|
||||
|
||||
from calibre.constants import __appname__
|
||||
from calibre.utils.monotonic import monotonic
|
||||
|
||||
class SplashScreen(QSplashScreen):
|
||||
|
||||
def __init__(self, develop=False):
|
||||
self.drawn_once = False
|
||||
self.develop = develop
|
||||
pmap = QIcon(I('library.png', allow_user_override=False)).pixmap(512, 512)
|
||||
QSplashScreen.__init__(self, pmap)
|
||||
self.setWindowTitle(__appname__)
|
||||
|
||||
def drawContents(self, painter):
|
||||
self.drawn_once = True
|
||||
painter.save()
|
||||
painter.setPen(Qt.black)
|
||||
painter.setRenderHint(painter.TextAntialiasing, True)
|
||||
f = painter.font()
|
||||
f.setPixelSize(18)
|
||||
painter.setFont(f)
|
||||
t = QTransform()
|
||||
t.translate(330, 450)
|
||||
painter.setTransform(t)
|
||||
painter.rotate(-98)
|
||||
painter.drawText(0, 0, self.message())
|
||||
painter.restore()
|
||||
|
||||
def show_message(self, msg):
|
||||
self.showMessage(msg)
|
||||
self.wait_for_draw()
|
||||
|
||||
def wait_for_draw(self):
|
||||
# Without this the splash screen is not painted on linux and windows
|
||||
self.drawn_once = False
|
||||
st = monotonic()
|
||||
while not self.drawn_once and (monotonic() - st < 0.1):
|
||||
QApplication.instance().processEvents()
|
||||
|
||||
def keyPressEvent(self, ev):
|
||||
if not self.develop:
|
||||
return QSplashScreen.keyPressEvent(self, ev)
|
||||
ev.accept()
|
||||
QApplication.instance().quit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.gui2 import Application
|
||||
app = Application([])
|
||||
spl = SplashScreen(develop=True)
|
||||
spl.show()
|
||||
spl.show_message('Testing the splash screen message...')
|
||||
app.exec_()
|
Loading…
x
Reference in New Issue
Block a user