From 7e4673f2937a5cd245b13a56e5e910f27a740010 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 4 Jul 2010 13:06:07 -0600 Subject: [PATCH] Remove vanity and move its functionality to the status bar --- src/calibre/gui2/device.py | 9 ++------ src/calibre/gui2/init.py | 43 +++++++++++++++++++++++++++++++++----- src/calibre/gui2/main.ui | 28 +------------------------ src/calibre/gui2/ui.py | 15 ++----------- src/calibre/gui2/update.py | 8 ++----- 5 files changed, 45 insertions(+), 58 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 4acde6089b..39a53002e2 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -758,10 +758,8 @@ class DeviceMixin(object): # {{{ self.refresh_ondevice_info (device_connected = True, reset_only = True) else: self.device_connected = None + self.status_bar.device_disconnected() self.location_view.model().update_devices() - self.vanity.setText(self.vanity_template%\ - dict(version=self.latest_version, device=' ')) - self.device_info = ' ' if self.current_view() != self.library_view: self.book_details.reset_info() self.location_view.setCurrentIndex(self.location_view.model().index(0)) @@ -775,10 +773,7 @@ class DeviceMixin(object): # {{{ return self.device_job_exception(job) info, cp, fs = job.result self.location_view.model().update_devices(cp, fs) - self.device_info = _('Connected ')+info[0] - self.vanity.setText(self.vanity_template%\ - dict(version=self.latest_version, device=self.device_info)) - + self.status_bar.device_connected(info[0]) self.device_manager.books(Dispatcher(self.metadata_downloaded)) def metadata_downloaded(self, job): diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 056d0c0d1d..d9a3835623 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -5,14 +5,15 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import functools +import functools, sys, os from PyQt4.Qt import QMenu, Qt, pyqtSignal, QToolButton, QIcon, QStackedWidget, \ - QSize, QSizePolicy, QStatusBar, QUrl + QSize, QSizePolicy, QStatusBar, QUrl, QLabel from calibre.utils.config import prefs from calibre.ebooks import BOOK_EXTENSIONS -from calibre.constants import isosx, __appname__, preferred_encoding +from calibre.constants import isosx, __appname__, preferred_encoding, \ + __version__ from calibre.gui2 import config, is_widescreen, open_url from calibre.gui2.library.views import BooksView, DeviceBooksView from calibre.gui2.widgets import Splitter @@ -366,14 +367,43 @@ class Stack(QStackedWidget): # {{{ class StatusBar(QStatusBar): # {{{ + def __init__(self, parent=None): + QStatusBar.__init__(self, parent) + self.default_message = __appname__ + ' ' + _('version') + ' ' + \ + self.get_version() + ' ' + _('created by Kovid Goyal') + self.device_string = '' + self.update_label = QLabel('') + self.update_label.setOpenExternalLinks(True) + self.addPermanentWidget(self.update_label) + def initialize(self, systray=None): - self.default_message = 'Welcome to calibre' self.systray = systray self.notifier = get_notifier(systray) self.messageChanged.connect(self.message_changed, type=Qt.QueuedConnection) self.message_changed('') + def device_connected(self, devname): + self.device_string = _('Connected ') + devname + self.clearMessage() + + def device_disconnected(self): + self.device_string = '' + self.clearMessage() + + def new_version_available(self, ver, url): + msg = (u'%s: %s') % ( + _('Update found'), url, ver) + self.update_label.setText(msg) + self.update_label.setCursor(Qt.PointingHandCursor) + + def get_version(self): + dv = os.environ.get('CALIBRE_DEVELOP_FROM', None) + v = __version__ + if getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path: + v += '*' + return v + def show_message(self, msg, timeout=0): self.showMessage(msg, timeout) if self.notifier is not None and not config['disable_tray_notification']: @@ -389,7 +419,10 @@ class StatusBar(QStatusBar): # {{{ def message_changed(self, msg): if not msg or msg.isEmpty() or msg.isNull(): - self.showMessage(self.default_message) + extra = '' + if self.device_string: + extra = ' ..::.. ' + self.device_string + self.showMessage(self.default_message + extra) # }}} diff --git a/src/calibre/gui2/main.ui b/src/calibre/gui2/main.ui index 7720f308a3..da2722a0a5 100644 --- a/src/calibre/gui2/main.ui +++ b/src/calibre/gui2/main.ui @@ -119,33 +119,7 @@ - - - - - - 0 - 0 - - - - - 16777215 - 90 - - - - - - - Qt::RichText - - - true - - - - + diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 9a3ab86750..10cef9b2cb 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -19,7 +19,7 @@ from PyQt4.Qt import Qt, SIGNAL, QObject, QTimer, \ QMessageBox, QHelpEvent from calibre import prints, patheq -from calibre.constants import __version__, __appname__, isosx +from calibre.constants import __appname__, isosx from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.config import prefs, dynamic from calibre.utils.ipc.server import Server @@ -203,18 +203,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceMixin, ToolbarMixin, # {{{ self.device_manager.umount_device) self.eject_action.triggered.connect(self.device_manager.umount_device) - ####################### Vanity ######################## - self.vanity_template = _('

For help see the: User Manual' - '
')%'http://calibre-ebook.com/user_manual' - dv = os.environ.get('CALIBRE_DEVELOP_FROM', None) - v = __version__ - if getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path: - v += '*' - self.vanity_template += _('%s: %s by Kovid Goyal ' - '%%(version)s
%%(device)s

')%(__appname__, v) - self.latest_version = ' ' - self.vanity.setText(self.vanity_template%dict(version=' ', device=' ')) - self.device_info = ' ' + #################### Update notification ################### UpdateMixin.__init__(self, opts) ####################### Setup Toolbar ##################### diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index 84168d17b5..38612c46f2 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -49,12 +49,8 @@ class UpdateMixin(object): def update_found(self, version): os = 'windows' if iswindows else 'osx' if isosx else 'linux' url = 'http://calibre-ebook.com/download_%s'%os - self.latest_version = '
' + _('' - 'Latest version: %s')%(url, version) - self.vanity.setText(self.vanity_template%\ - (dict(version=self.latest_version, - device=self.device_info))) - self.vanity.update() + self.status_bar.new_version_available(version, url) + if config.get('new_version_notification') and \ dynamic.get('update to version %s'%version, True): if question_dialog(self, _('Update available'),