From 6b22664daf191c7ccef8078ccb5b1201c07c6555 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 11 Jul 2012 14:22:41 +0530 Subject: [PATCH] E-book viewer: Add an option to show a clock in full screen mode. Fixes #1022086 ([Enhancement] clock in full screen) --- src/calibre/gui2/viewer/config.py | 4 ++ src/calibre/gui2/viewer/config.ui | 67 ++++++++++++++----------- src/calibre/gui2/viewer/documentview.py | 9 ++++ src/calibre/gui2/viewer/main.py | 44 ++++++++++++++-- 4 files changed, 91 insertions(+), 33 deletions(-) diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py index 75284930b7..dccd541380 100644 --- a/src/calibre/gui2/viewer/config.py +++ b/src/calibre/gui2/viewer/config.py @@ -51,6 +51,8 @@ def config(defaults=None): help=_('The amount by which to change the font size when clicking' ' the font larger/smaller buttons. Should be a number between ' '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('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_default_lang.setVisible(False) self.hyphenate_label.setVisible(False) + self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock) def accept(self, *args): if self.shortcut_config.is_editing: @@ -148,6 +151,7 @@ class ConfigDialog(QDialog, Ui_Dialog): str(self.hyphenate_default_lang.itemData(idx).toString())) c.set('line_scrolling_stops_on_pagebreaks', self.opt_line_scrolling_stops_on_pagebreaks.isChecked()) + c.set('fullscreen_clock', self.opt_fullscreen_clock.isChecked()) return QDialog.accept(self, *args) diff --git a/src/calibre/gui2/viewer/config.ui b/src/calibre/gui2/viewer/config.ui index 48b77e0b34..4993f48c99 100644 --- a/src/calibre/gui2/viewer/config.ui +++ b/src/calibre/gui2/viewer/config.ui @@ -6,7 +6,7 @@ 0 0 - 479 + 839 630 @@ -167,20 +167,6 @@ - - - - Remember last used &window size and layout - - - - - - - Remember the &current page when quitting - - - @@ -205,13 +191,6 @@ - - - - &Resize images larger than the viewer window (needs restart) - - - @@ -247,13 +226,6 @@ - - - - Mouse &wheel flips pages - - - @@ -301,13 +273,48 @@ - + + + + &Resize images larger than the viewer window (needs restart) + + + + + + + Remember last used &window size and layout + + + + + + + Mouse &wheel flips pages + + + + + + + Remember the &current page when quitting + + + + Line &scrolling stops at page breaks + + + + Show &clock in full screen mode + + + diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 8beea63df4..784887a18f 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -134,6 +134,7 @@ class Document(QWebPage): # {{{ screen_width = QApplication.desktop().screenGeometry().width() # Leave some space for the scrollbar and some border self.max_fs_width = min(opts.max_fs_width, screen_width-50) + self.fullscreen_clock = opts.fullscreen_clock def fit_images(self): 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.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): self.bridge_value = tuple(self.index_anchors) self.javascript(u''' diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index b08262d707..3d76b08212 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -6,9 +6,10 @@ from functools import partial from threading import Thread from PyQt4.Qt import (QApplication, Qt, QIcon, QTimer, QByteArray, QSize, - QDoubleSpinBox, QLabel, QTextBrowser, QPropertyAnimation, QPainter, - QBrush, QColor, pyqtSignal, QUrl, QRegExpValidator, QRegExp, QLineEdit, - QToolButton, QMenu, QInputDialog, QAction, QKeySequence, QModelIndex) + QTime, QDoubleSpinBox, QLabel, QTextBrowser, QPropertyAnimation, + QPainter, QBrush, QColor, pyqtSignal, QUrl, QRegExpValidator, QRegExp, + QLineEdit, QToolButton, QMenu, QInputDialog, QAction, QKeySequence, + QModelIndex) from calibre.gui2.viewer.main_ui import Ui_EbookViewer from calibre.gui2.viewer.printing import Printing @@ -288,6 +289,23 @@ class EbookViewer(MainWindow, Ui_EbookViewer): self.addAction(self.toggle_toolbar_action) self.full_screen_label_anim = QPropertyAnimation( 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.addAction(a) a.setShortcut(Qt.Key_Escape) @@ -454,9 +472,29 @@ class EbookViewer(MainWindow, Ui_EbookViewer): a.start() QTimer.singleShot(2750, self.full_screen_label.hide) 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): self.view.document.page_position.save() + self.clock_label.setVisible(False) + self.clock_timer.stop() self.window_mode_changed = 'normal' self.esc_full_screen_action.setEnabled(False) self.tool_bar.setVisible(True)