Merge from trunk

This commit is contained in:
Charles Haley 2010-09-07 14:29:06 +01:00
commit 3db2373264
2 changed files with 44 additions and 31 deletions

View File

@ -27,13 +27,8 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, conne
notification=DummyReporter(), log=None): notification=DummyReporter(), log=None):
if log is None: if log is None:
log = Log() log = Log()
if dbspec is None: from calibre.library import db
from calibre.utils.config import prefs db = db()
from calibre.library.database2 import LibraryDatabase2
dbpath = prefs['library_path']
db = LibraryDatabase2(dbpath)
else: # To be implemented in the future
pass
# Create a minimal OptionParser that we can append to # Create a minimal OptionParser that we can append to
parser = OptionParser() parser = OptionParser()

View File

@ -10,8 +10,8 @@ from functools import partial
from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \ from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \
QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \ QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \
QToolBar, QSize, pyqtSignal, QSizePolicy, QToolButton, QAction, \ QToolBar, QSize, pyqtSignal, QPixmap, QToolButton, QAction, \
QPushButton, QHBoxLayout QDialogButtonBox, QHBoxLayout
from calibre.constants import __appname__, __version__, islinux, isosx from calibre.constants import __appname__, __version__, islinux, isosx
from calibre.gui2 import gprefs, min_available_height, available_width, \ 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.customize.ui import preferences_plugins
from calibre.utils.ordered_dict import OrderedDict from calibre.utils.ordered_dict import OrderedDict
ICON_SIZE = 32
class StatusBar(QStatusBar): # {{{ class StatusBar(QStatusBar): # {{{
def __init__(self, parent=None): 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): # {{{ class Category(QWidget): # {{{
plugin_activated = pyqtSignal(object) plugin_activated = pyqtSignal(object)
@ -88,7 +116,6 @@ class Category(QWidget): # {{{
class Browser(QScrollArea): # {{{ class Browser(QScrollArea): # {{{
show_plugin = pyqtSignal(object) show_plugin = pyqtSignal(object)
close_signal = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
QScrollArea.__init__(self, parent) QScrollArea.__init__(self, parent)
@ -119,14 +146,6 @@ class Browser(QScrollArea): # {{{
self.container = QWidget(self) self.container = QWidget(self)
self.container.setLayout(self._layout) self.container.setLayout(self._layout)
self.setWidget(self.container) 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(): for name, plugins in self.category_map.items():
w = Category(name, plugins, self) w = Category(name, plugins, self)
@ -134,8 +153,6 @@ class Browser(QScrollArea): # {{{
self._layout.addWidget(w) self._layout.addWidget(w)
w.plugin_activated.connect(self.show_plugin.emit) 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.setStatusBar(self.status_bar)
self.stack = QStackedWidget(self) 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 = Browser(self)
self.browser.close_signal.connect(self.close, type=Qt.QueuedConnection)
self.browser.show_plugin.connect(self.show_plugin) self.browser.show_plugin.connect(self.show_plugin)
self.stack.addWidget(self.browser) self.stack.addWidget(self.browser)
self.scroll_area = QScrollArea(self) self.scroll_area = QScrollArea(self)
@ -189,7 +212,7 @@ class Preferences(QMainWindow):
self.bar = QToolBar(self) self.bar = QToolBar(self)
self.addToolBar(self.bar) self.addToolBar(self.bar)
self.bar.setVisible(False) self.bar.setVisible(False)
self.bar.setIconSize(QSize(32, 32)) self.bar.setIconSize(QSize(ICON_SIZE, ICON_SIZE))
self.bar.setMovable(False) self.bar.setMovable(False)
self.bar.setFloatable(False) self.bar.setFloatable(False)
self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
@ -197,13 +220,8 @@ class Preferences(QMainWindow):
self.commit) self.commit)
self.cancel_action = self.bar.addAction(QIcon(I('window-close.png')), self.cancel_action = self.bar.addAction(QIcon(I('window-close.png')),
_('&Cancel'), self.cancel) _('&Cancel'), self.cancel)
self.bar_filler = QLabel('') self.bar_title = BarTitle(self.bar)
self.bar_filler.setSizePolicy(QSizePolicy.Expanding, self.bar.addWidget(self.bar_title)
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.restore_action = self.bar.addAction(QIcon(I('clear_left.png')), self.restore_action = self.bar.addAction(QIcon(I('clear_left.png')),
_('Restore &defaults'), self.restore_defaults) _('Restore &defaults'), self.restore_defaults)
for ac, tt in [('apply', _('Save changes')), for ac, tt in [('apply', _('Save changes')),
@ -247,7 +265,7 @@ class Preferences(QMainWindow):
self.restore_action.setToolTip(textwrap.fill(tt)) self.restore_action.setToolTip(textwrap.fill(tt))
self.restore_action.setWhatsThis(textwrap.fill(tt)) self.restore_action.setWhatsThis(textwrap.fill(tt))
self.restore_action.setStatusTip(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.setWindowIcon(QIcon(plugin.icon))
self.bar.setVisible(True) self.bar.setVisible(True)