diff --git a/src/calibre/gui2/convert/gui_conversion.py b/src/calibre/gui2/convert/gui_conversion.py index 148dc328ad..3072b8757a 100644 --- a/src/calibre/gui2/convert/gui_conversion.py +++ b/src/calibre/gui2/convert/gui_conversion.py @@ -27,13 +27,8 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, conne notification=DummyReporter(), log=None): if log is None: log = Log() - if dbspec is None: - from calibre.utils.config import prefs - from calibre.library.database2 import LibraryDatabase2 - dbpath = prefs['library_path'] - db = LibraryDatabase2(dbpath) - else: # To be implemented in the future - pass + from calibre.library import db + db = db() # Create a minimal OptionParser that we can append to parser = OptionParser() diff --git a/src/calibre/gui2/preferences/main.py b/src/calibre/gui2/preferences/main.py index 6524faec2d..d55f2d90d1 100644 --- a/src/calibre/gui2/preferences/main.py +++ b/src/calibre/gui2/preferences/main.py @@ -10,8 +10,8 @@ from functools import partial from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \ QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \ - QToolBar, QSize, pyqtSignal, QSizePolicy, QToolButton, QAction, \ - QPushButton, QHBoxLayout + QToolBar, QSize, pyqtSignal, QPixmap, QToolButton, QAction, \ + QDialogButtonBox, QHBoxLayout from calibre.constants import __appname__, __version__, islinux, isosx from calibre.gui2 import gprefs, min_available_height, available_width, \ @@ -20,6 +20,8 @@ from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin from calibre.customize.ui import preferences_plugins from calibre.utils.ordered_dict import OrderedDict +ICON_SIZE = 32 + class StatusBar(QStatusBar): # {{{ def __init__(self, parent=None): @@ -42,6 +44,32 @@ class StatusBar(QStatusBar): # {{{ # }}} +class BarTitle(QWidget): + + def __init__(self, parent=None): + QWidget.__init__(self, parent) + self._layout = QHBoxLayout() + self.setLayout(self._layout) + self._layout.addStretch(10) + self.icon = QLabel('') + self._layout.addWidget(self.icon) + self.title = QLabel('') + self.title.setStyleSheet('QLabel { font-weight: bold }') + self.title.setAlignment(Qt.AlignLeft | Qt.AlignCenter) + self._layout.addWidget(self.title) + self._layout.addStretch(10) + + def show_plugin(self, plugin): + self.pmap = QPixmap(plugin.icon).scaled(ICON_SIZE, ICON_SIZE, + Qt.KeepAspectRatio, Qt.SmoothTransformation) + self.icon.setPixmap(self.pmap) + self.title.setText(plugin.gui_name) + tt = plugin.description + self.setStatusTip(tt) + tt = textwrap.fill(tt) + self.setToolTip(tt) + self.setWhatsThis(tt) + class Category(QWidget): # {{{ plugin_activated = pyqtSignal(object) @@ -88,7 +116,6 @@ class Category(QWidget): # {{{ class Browser(QScrollArea): # {{{ show_plugin = pyqtSignal(object) - close_signal = pyqtSignal() def __init__(self, parent=None): QScrollArea.__init__(self, parent) @@ -119,14 +146,6 @@ class Browser(QScrollArea): # {{{ self.container = QWidget(self) self.container.setLayout(self._layout) self.setWidget(self.container) - if isosx: - self._osxl = QHBoxLayout() - self.close_button = QPushButton(_('Close')) - self.close_button.clicked.connect(self.close_requested) - self._osxl.addStretch(10) - self._osxl.addWidget(self.close_button) - #self._osxl.addStretch(10) - self._layout.addLayout(self._osxl) for name, plugins in self.category_map.items(): w = Category(name, plugins, self) @@ -134,8 +153,6 @@ class Browser(QScrollArea): # {{{ self._layout.addWidget(w) w.plugin_activated.connect(self.show_plugin.emit) - def close_requested(self, *args): - self.close_signal.emit() # }}} @@ -177,9 +194,15 @@ class Preferences(QMainWindow): self.setStatusBar(self.status_bar) self.stack = QStackedWidget(self) - self.setCentralWidget(self.stack) + self.cw = QWidget(self) + self.cw.setLayout(QVBoxLayout()) + self.cw.layout().addWidget(self.stack) + self.bb = QDialogButtonBox(QDialogButtonBox.Close) + self.cw.layout().addWidget(self.bb) + self.bb.rejected.connect(self.close, type=Qt.QueuedConnection) + self.setCentralWidget(self.cw) + self.bb.setVisible(isosx) self.browser = Browser(self) - self.browser.close_signal.connect(self.close, type=Qt.QueuedConnection) self.browser.show_plugin.connect(self.show_plugin) self.stack.addWidget(self.browser) self.scroll_area = QScrollArea(self) @@ -189,7 +212,7 @@ class Preferences(QMainWindow): self.bar = QToolBar(self) self.addToolBar(self.bar) self.bar.setVisible(False) - self.bar.setIconSize(QSize(32, 32)) + self.bar.setIconSize(QSize(ICON_SIZE, ICON_SIZE)) self.bar.setMovable(False) self.bar.setFloatable(False) self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) @@ -197,13 +220,8 @@ class Preferences(QMainWindow): self.commit) self.cancel_action = self.bar.addAction(QIcon(I('window-close.png')), _('&Cancel'), self.cancel) - self.bar_filler = QLabel('') - self.bar_filler.setSizePolicy(QSizePolicy.Expanding, - QSizePolicy.Preferred) - self.bar_filler.setStyleSheet( - 'QLabel { font-weight: bold }') - self.bar_filler.setAlignment(Qt.AlignHCenter | Qt.AlignCenter) - self.bar.addWidget(self.bar_filler) + self.bar_title = BarTitle(self.bar) + self.bar.addWidget(self.bar_title) self.restore_action = self.bar.addAction(QIcon(I('clear_left.png')), _('Restore &defaults'), self.restore_defaults) for ac, tt in [('apply', _('Save changes')), @@ -247,7 +265,7 @@ class Preferences(QMainWindow): self.restore_action.setToolTip(textwrap.fill(tt)) self.restore_action.setWhatsThis(textwrap.fill(tt)) self.restore_action.setStatusTip(tt) - self.bar_filler.setText(plugin.gui_name) + self.bar_title.show_plugin(plugin) self.setWindowIcon(QIcon(plugin.icon)) self.bar.setVisible(True)