mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Add an option to show a clock in full screen mode. Fixes #1022086 ([Enhancement] clock in full screen)
This commit is contained in:
parent
a9a0210815
commit
6b22664daf
@ -51,6 +51,8 @@ def config(defaults=None):
|
|||||||
help=_('The amount by which to change the font size when clicking'
|
help=_('The amount by which to change the font size when clicking'
|
||||||
' the font larger/smaller buttons. Should be a number between '
|
' the font larger/smaller buttons. Should be a number between '
|
||||||
'0 and 1.'))
|
'0 and 1.'))
|
||||||
|
c.add_opt('fullscreen_clock', default=False, action='store_true',
|
||||||
|
help=_('Show a clock in fullscreen mode.'))
|
||||||
|
|
||||||
fonts = c.add_group('FONTS', _('Font options'))
|
fonts = c.add_group('FONTS', _('Font options'))
|
||||||
fonts('serif_family', default='Times New Roman' if iswindows else 'Liberation Serif',
|
fonts('serif_family', default='Times New Roman' if iswindows else 'Liberation Serif',
|
||||||
@ -117,6 +119,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.hyphenate.setVisible(False)
|
self.hyphenate.setVisible(False)
|
||||||
self.hyphenate_default_lang.setVisible(False)
|
self.hyphenate_default_lang.setVisible(False)
|
||||||
self.hyphenate_label.setVisible(False)
|
self.hyphenate_label.setVisible(False)
|
||||||
|
self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock)
|
||||||
|
|
||||||
def accept(self, *args):
|
def accept(self, *args):
|
||||||
if self.shortcut_config.is_editing:
|
if self.shortcut_config.is_editing:
|
||||||
@ -148,6 +151,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
str(self.hyphenate_default_lang.itemData(idx).toString()))
|
str(self.hyphenate_default_lang.itemData(idx).toString()))
|
||||||
c.set('line_scrolling_stops_on_pagebreaks',
|
c.set('line_scrolling_stops_on_pagebreaks',
|
||||||
self.opt_line_scrolling_stops_on_pagebreaks.isChecked())
|
self.opt_line_scrolling_stops_on_pagebreaks.isChecked())
|
||||||
|
c.set('fullscreen_clock', self.opt_fullscreen_clock.isChecked())
|
||||||
return QDialog.accept(self, *args)
|
return QDialog.accept(self, *args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>479</width>
|
<width>839</width>
|
||||||
<height>630</height>
|
<height>630</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -167,20 +167,6 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="8" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_remember_window_size">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remember last used &window size and layout</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="9" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_remember_current_page">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remember the &current page when quitting</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
<item row="5" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="hyphenate">
|
<widget class="QCheckBox" name="hyphenate">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -205,13 +191,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_fit_images">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Resize images larger than the viewer window (needs restart)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="label_11">
|
<widget class="QLabel" name="label_11">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -247,13 +226,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="10" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_wheel_flips_pages">
|
|
||||||
<property name="text">
|
|
||||||
<string>Mouse &wheel flips pages</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QSpinBox" name="max_fs_width">
|
<widget class="QSpinBox" name="max_fs_width">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
@ -301,13 +273,48 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="11" column="0" colspan="2">
|
<item row="7" column="0">
|
||||||
|
<widget class="QCheckBox" name="opt_fit_images">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Resize images larger than the viewer window (needs restart)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="0">
|
||||||
|
<widget class="QCheckBox" name="opt_remember_window_size">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remember last used &window size and layout</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="1">
|
||||||
|
<widget class="QCheckBox" name="opt_wheel_flips_pages">
|
||||||
|
<property name="text">
|
||||||
|
<string>Mouse &wheel flips pages</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="1">
|
||||||
|
<widget class="QCheckBox" name="opt_remember_current_page">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remember the &current page when quitting</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="9" column="0">
|
||||||
<widget class="QCheckBox" name="opt_line_scrolling_stops_on_pagebreaks">
|
<widget class="QCheckBox" name="opt_line_scrolling_stops_on_pagebreaks">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Line &scrolling stops at page breaks</string>
|
<string>Line &scrolling stops at page breaks</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="9" column="1">
|
||||||
|
<widget class="QCheckBox" name="opt_fullscreen_clock">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show &clock in full screen mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -134,6 +134,7 @@ class Document(QWebPage): # {{{
|
|||||||
screen_width = QApplication.desktop().screenGeometry().width()
|
screen_width = QApplication.desktop().screenGeometry().width()
|
||||||
# Leave some space for the scrollbar and some border
|
# Leave some space for the scrollbar and some border
|
||||||
self.max_fs_width = min(opts.max_fs_width, screen_width-50)
|
self.max_fs_width = min(opts.max_fs_width, screen_width-50)
|
||||||
|
self.fullscreen_clock = opts.fullscreen_clock
|
||||||
|
|
||||||
def fit_images(self):
|
def fit_images(self):
|
||||||
if self.do_fit_images and not self.in_paged_mode:
|
if self.do_fit_images and not self.in_paged_mode:
|
||||||
@ -193,6 +194,14 @@ class Document(QWebPage): # {{{
|
|||||||
self.read_anchor_positions(use_cache=False)
|
self.read_anchor_positions(use_cache=False)
|
||||||
self.first_load = False
|
self.first_load = False
|
||||||
|
|
||||||
|
def colors(self):
|
||||||
|
self.javascript('''
|
||||||
|
bs = getComputedStyle(document.body);
|
||||||
|
py_bridge.value = [bs.backgroundColor, bs.color]
|
||||||
|
''')
|
||||||
|
ans = self.bridge_value
|
||||||
|
return (ans if isinstance(ans, list) else ['white', 'black'])
|
||||||
|
|
||||||
def read_anchor_positions(self, use_cache=True):
|
def read_anchor_positions(self, use_cache=True):
|
||||||
self.bridge_value = tuple(self.index_anchors)
|
self.bridge_value = tuple(self.index_anchors)
|
||||||
self.javascript(u'''
|
self.javascript(u'''
|
||||||
|
@ -6,9 +6,10 @@ from functools import partial
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from PyQt4.Qt import (QApplication, Qt, QIcon, QTimer, QByteArray, QSize,
|
from PyQt4.Qt import (QApplication, Qt, QIcon, QTimer, QByteArray, QSize,
|
||||||
QDoubleSpinBox, QLabel, QTextBrowser, QPropertyAnimation, QPainter,
|
QTime, QDoubleSpinBox, QLabel, QTextBrowser, QPropertyAnimation,
|
||||||
QBrush, QColor, pyqtSignal, QUrl, QRegExpValidator, QRegExp, QLineEdit,
|
QPainter, QBrush, QColor, pyqtSignal, QUrl, QRegExpValidator, QRegExp,
|
||||||
QToolButton, QMenu, QInputDialog, QAction, QKeySequence, QModelIndex)
|
QLineEdit, QToolButton, QMenu, QInputDialog, QAction, QKeySequence,
|
||||||
|
QModelIndex)
|
||||||
|
|
||||||
from calibre.gui2.viewer.main_ui import Ui_EbookViewer
|
from calibre.gui2.viewer.main_ui import Ui_EbookViewer
|
||||||
from calibre.gui2.viewer.printing import Printing
|
from calibre.gui2.viewer.printing import Printing
|
||||||
@ -288,6 +289,23 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.addAction(self.toggle_toolbar_action)
|
self.addAction(self.toggle_toolbar_action)
|
||||||
self.full_screen_label_anim = QPropertyAnimation(
|
self.full_screen_label_anim = QPropertyAnimation(
|
||||||
self.full_screen_label, 'size')
|
self.full_screen_label, 'size')
|
||||||
|
self.clock_label = QLabel('99:99', self)
|
||||||
|
self.clock_label.setVisible(False)
|
||||||
|
self.clock_label.setFocusPolicy(Qt.NoFocus)
|
||||||
|
self.clock_label_style = '''
|
||||||
|
QLabel {
|
||||||
|
text-align: right;
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-radius: 8px;
|
||||||
|
background-color: %s;
|
||||||
|
color: %s;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: larger;
|
||||||
|
padding: 5px;
|
||||||
|
}'''
|
||||||
|
self.clock_timer = QTimer(self)
|
||||||
|
self.clock_timer.timeout.connect(self.update_clock)
|
||||||
self.esc_full_screen_action = a = QAction(self)
|
self.esc_full_screen_action = a = QAction(self)
|
||||||
self.addAction(a)
|
self.addAction(a)
|
||||||
a.setShortcut(Qt.Key_Escape)
|
a.setShortcut(Qt.Key_Escape)
|
||||||
@ -454,9 +472,29 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
a.start()
|
a.start()
|
||||||
QTimer.singleShot(2750, self.full_screen_label.hide)
|
QTimer.singleShot(2750, self.full_screen_label.hide)
|
||||||
self.view.document.switch_to_fullscreen_mode()
|
self.view.document.switch_to_fullscreen_mode()
|
||||||
|
if self.view.document.fullscreen_clock:
|
||||||
|
self.show_clock()
|
||||||
|
|
||||||
|
def show_clock(self):
|
||||||
|
self.clock_label.setVisible(True)
|
||||||
|
self.clock_label.setText('99:99 AA')
|
||||||
|
self.clock_timer.start(1000)
|
||||||
|
self.clock_label.setStyleSheet(self.clock_label_style%
|
||||||
|
tuple(self.view.document.colors()))
|
||||||
|
self.clock_label.resize(self.clock_label.sizeHint())
|
||||||
|
sw = QApplication.desktop().screenGeometry(self.view)
|
||||||
|
self.clock_label.move(sw.width() - self.vertical_scrollbar.width() - 15
|
||||||
|
- self.clock_label.width(), sw.height() -
|
||||||
|
self.clock_label.height()-10)
|
||||||
|
self.update_clock()
|
||||||
|
|
||||||
|
def update_clock(self):
|
||||||
|
self.clock_label.setText(QTime.currentTime().toString('h:mm a'))
|
||||||
|
|
||||||
def showNormal(self):
|
def showNormal(self):
|
||||||
self.view.document.page_position.save()
|
self.view.document.page_position.save()
|
||||||
|
self.clock_label.setVisible(False)
|
||||||
|
self.clock_timer.stop()
|
||||||
self.window_mode_changed = 'normal'
|
self.window_mode_changed = 'normal'
|
||||||
self.esc_full_screen_action.setEnabled(False)
|
self.esc_full_screen_action.setEnabled(False)
|
||||||
self.tool_bar.setVisible(True)
|
self.tool_bar.setVisible(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user