mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Avoid flashing during startup due to cover browser
During startup while the multiple resizes due to the various splitters adjusting their sizes happens, paint the cover browser in the window background color to avoid flashing.
This commit is contained in:
parent
2a324bc35d
commit
c6783b7037
@ -13,12 +13,13 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAction, QApplication, QDialog, QFont, QImage, QItemSelectionModel,
|
QAction, QApplication, QDialog, QFont, QImage, QItemSelectionModel, QKeySequence,
|
||||||
QKeySequence, QLabel, QSize, QSizePolicy, QStackedLayout, Qt, QTimer, pyqtSignal
|
QLabel, QPainter, QPalette, QSize, QSizePolicy, QStackedLayout, Qt, QTimer,
|
||||||
|
pyqtSignal,
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.constants import islinux
|
from calibre.constants import islinux
|
||||||
from calibre.ebooks.metadata import rating_to_stars, authors_to_string
|
from calibre.ebooks.metadata import authors_to_string, rating_to_stars
|
||||||
from calibre.gui2 import config, gprefs, rating_font
|
from calibre.gui2 import config, gprefs, rating_font
|
||||||
from calibre_extensions import pictureflow
|
from calibre_extensions import pictureflow
|
||||||
|
|
||||||
@ -186,10 +187,32 @@ class CoverFlow(pictureflow.PictureFlow):
|
|||||||
|
|
||||||
dc_signal = pyqtSignal()
|
dc_signal = pyqtSignal()
|
||||||
context_menu_requested = pyqtSignal()
|
context_menu_requested = pyqtSignal()
|
||||||
|
_ignore_paint_events = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ignore_paint_events(self):
|
||||||
|
return self._ignore_paint_events
|
||||||
|
|
||||||
|
@ignore_paint_events.setter
|
||||||
|
def ignore_paint_events(self, val):
|
||||||
|
if val != self._ignore_paint_events:
|
||||||
|
self._ignore_paint_events = val
|
||||||
|
if not val:
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def paintEvent(self, ev):
|
||||||
|
if self.ignore_paint_events and time.monotonic() - self.created_at < 1:
|
||||||
|
# Paint blank during startup to avoid flashing
|
||||||
|
p = QPainter(self)
|
||||||
|
p.fillRect(self.rect(), self.palette().color(QPalette.ColorRole.Window))
|
||||||
|
p.end()
|
||||||
|
else:
|
||||||
|
super().paintEvent(ev)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
pictureflow.PictureFlow.__init__(self, parent,
|
pictureflow.PictureFlow.__init__(self, parent,
|
||||||
config['cover_flow_queue_length']+1)
|
config['cover_flow_queue_length']+1)
|
||||||
|
self.created_at = time.monotonic()
|
||||||
self.setMinimumSize(QSize(300, 150))
|
self.setMinimumSize(QSize(300, 150))
|
||||||
self.setFocusPolicy(Qt.FocusPolicy.WheelFocus)
|
self.setFocusPolicy(Qt.FocusPolicy.WheelFocus)
|
||||||
self.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Expanding,
|
self.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Expanding,
|
||||||
|
@ -1246,6 +1246,11 @@ class Splitter(QSplitter):
|
|||||||
# when the event loop ticks
|
# when the event loop ticks
|
||||||
self.reapply_sizes.emit(sizes)
|
self.reapply_sizes.emit(sizes)
|
||||||
|
|
||||||
|
def ignore_child_paints(self, ignore=True):
|
||||||
|
for widget in self:
|
||||||
|
if hasattr(widget, 'ignore_paint_events'):
|
||||||
|
widget.ignore_paint_events = ignore
|
||||||
|
|
||||||
def do_resize(self, *args):
|
def do_resize(self, *args):
|
||||||
orig = self.desired_side_size
|
orig = self.desired_side_size
|
||||||
super().resizeEvent(self._resize_ev)
|
super().resizeEvent(self._resize_ev)
|
||||||
@ -1254,10 +1259,14 @@ class Splitter(QSplitter):
|
|||||||
while abs(self.side_index_size - orig) > 10 and c < 5:
|
while abs(self.side_index_size - orig) > 10 and c < 5:
|
||||||
self.apply_state(self.get_state(), save_desired=False)
|
self.apply_state(self.get_state(), save_desired=False)
|
||||||
c += 1
|
c += 1
|
||||||
|
self.ignore_child_paints(False)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for i in range(self.count()):
|
||||||
|
yield self.widget(i)
|
||||||
|
|
||||||
def resizeEvent(self, ev):
|
def resizeEvent(self, ev):
|
||||||
if self.resize_timer.isActive():
|
self.ignore_child_paints()
|
||||||
self.resize_timer.stop()
|
|
||||||
self._resize_ev = ev
|
self._resize_ev = ev
|
||||||
self.resize_timer.start()
|
self.resize_timer.start()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user