mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Start work on preferences widget
This commit is contained in:
parent
42f2e6cff5
commit
f8c496a924
@ -63,6 +63,9 @@ class Boss(QObject):
|
||||
self.gui.preview.split_start_requested.connect(self.split_start_requested)
|
||||
self.gui.preview.split_requested.connect(self.split_requested)
|
||||
|
||||
def preferences(self):
|
||||
pass
|
||||
|
||||
def mkdtemp(self, prefix=''):
|
||||
self.container_count += 1
|
||||
return tempfile.mkdtemp(prefix='%s%05d-' % (prefix, self.container_count), dir=self.tdir)
|
||||
@ -707,7 +710,6 @@ class Boss(QObject):
|
||||
actions['editor-copy'].setEnabled(ed.cut_available)
|
||||
actions['go-to-line-number'].setEnabled(ed.has_line_numbers)
|
||||
actions['fix-html-current'].setEnabled(ed.syntax == 'html')
|
||||
self.gui.keyboard.set_mode(ed.syntax)
|
||||
name = None
|
||||
for n, x in editors.iteritems():
|
||||
if ed is x:
|
||||
@ -716,7 +718,6 @@ class Boss(QObject):
|
||||
if name is not None and getattr(ed, 'syntax', None) == 'html':
|
||||
self.gui.preview.show(name)
|
||||
else:
|
||||
self.gui.keyboard.set_mode('other')
|
||||
actions['go-to-line-number'].setEnabled(False)
|
||||
|
||||
def editor_close_requested(self, editor):
|
||||
|
@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from calibre.gui2.keyboard import Manager
|
||||
|
||||
class KeyboardManager(object):
|
||||
|
||||
def __init__(self):
|
||||
self.modes = {mode: Manager(config_name='shortcuts/tweak-book-%s' % mode) for mode in
|
||||
('html', 'css', 'xml', 'other')}
|
||||
self.actions = {}
|
||||
self.current_mode = None
|
||||
|
||||
def register_shortcut(self, unique_name, name, default_keys=(),
|
||||
description=None, action=None, group=None, modes=None):
|
||||
if modes is None:
|
||||
modes = tuple(self.modes)
|
||||
for mode in modes:
|
||||
self.modes[mode].register_shortcut(
|
||||
unique_name, name, default_keys=default_keys, description=description,
|
||||
action=None, group=group)
|
||||
self.actions[unique_name] = action
|
||||
|
||||
def finalize(self):
|
||||
for km in self.modes.itervalues():
|
||||
km.finalize()
|
||||
|
||||
def set_mode(self, name):
|
||||
try:
|
||||
km = self.modes[name]
|
||||
except KeyError:
|
||||
name = 'other'
|
||||
km = self.modes[name]
|
||||
if name != self.current_mode:
|
||||
for un, action in self.actions.iteritems():
|
||||
keys = km.keys_map[un]
|
||||
action.setShortcuts(list(keys))
|
||||
self.current_mode = name
|
||||
|
||||
|
68
src/calibre/gui2/tweak_book/preferences.py
Normal file
68
src/calibre/gui2/tweak_book/preferences.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from PyQt4.Qt import (
|
||||
QDialog, QGridLayout, QStackedWidget, QDialogButtonBox, QListWidget,
|
||||
QListWidgetItem, QIcon)
|
||||
|
||||
from calibre.gui2.keyboard import ShortcutConfig
|
||||
from calibre.gui2.tweak_book import tprefs
|
||||
|
||||
class Preferences(QDialog):
|
||||
|
||||
def __init__(self, gui, initial_panel=None):
|
||||
QDialog.__init__(self, gui)
|
||||
self.l = l = QGridLayout(self)
|
||||
self.setLayout(l)
|
||||
|
||||
self.stacks = QStackedWidget(self)
|
||||
l.addWidget(self.stacks, 0, 1, 1, 1)
|
||||
|
||||
self.categories_list = cl = QListWidget(self)
|
||||
cl.currentRowChanged.connect(self.stacks.setCurrentIndex)
|
||||
l.addWidget(cl, 0, 0, 1, 1)
|
||||
|
||||
self.bb = bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
bb.accepted.connect(self.accept)
|
||||
bb.rejected.connect(self.reject)
|
||||
l.addWidget(bb, 1, 0, 1, 2)
|
||||
|
||||
self.resize(800, 600)
|
||||
geom = tprefs.get('preferences_geom', None)
|
||||
if geom is not None:
|
||||
self.restoreGeometry(geom)
|
||||
|
||||
self.keyboard_panel = ShortcutConfig(self)
|
||||
self.keyboard_panel.initialize(gui.keyboard)
|
||||
|
||||
for name, icon, panel in [(_('Keyboard'), 'keyboard.png', 'keyboard')]:
|
||||
i = QListWidgetItem(QIcon(I(icon)), name, cl)
|
||||
cl.addItem(i)
|
||||
self.stacks.addWidget(getattr(self, panel + '_panel'))
|
||||
|
||||
cl.setCurrentRow(0)
|
||||
cl.item(0).setSelected(True)
|
||||
|
||||
def accept(self):
|
||||
tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
|
||||
QDialog.accept(self)
|
||||
|
||||
def reject(self):
|
||||
tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
|
||||
QDialog.reject(self)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.gui2 import Application
|
||||
from calibre.gui2.tweak_book.main import option_parser
|
||||
from calibre.gui2.tweak_book.ui import Main
|
||||
app = Application([])
|
||||
opts = option_parser().parse_args(['dev'])
|
||||
main = Main(opts)
|
||||
d = Preferences(main)
|
||||
d.exec_()
|
||||
|
@ -13,12 +13,12 @@ from PyQt4.Qt import (
|
||||
QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal)
|
||||
|
||||
from calibre.constants import __appname__, get_version
|
||||
from calibre.gui2.keyboard import Manager as KeyboardManager
|
||||
from calibre.gui2.main_window import MainWindow
|
||||
from calibre.gui2.tweak_book import current_container, tprefs, actions, elided_text
|
||||
from calibre.gui2.tweak_book.file_list import FileListWidget
|
||||
from calibre.gui2.tweak_book.job import BlockingJob
|
||||
from calibre.gui2.tweak_book.boss import Boss
|
||||
from calibre.gui2.tweak_book.keyboard import KeyboardManager
|
||||
from calibre.gui2.tweak_book.preview import Preview
|
||||
from calibre.gui2.tweak_book.search import SearchPanel
|
||||
|
||||
@ -154,7 +154,6 @@ class Main(MainWindow):
|
||||
self.restore_state()
|
||||
|
||||
self.keyboard.finalize()
|
||||
self.keyboard.set_mode('other')
|
||||
|
||||
def elided_text(self, text, width=200, mode=Qt.ElideMiddle):
|
||||
return elided_text(self.font(), text, width=width, mode=mode)
|
||||
@ -187,6 +186,7 @@ class Main(MainWindow):
|
||||
self.action_save = reg('save.png', _('&Save'), self.boss.save_book, 'save-book', 'Ctrl+Shift+S', _('Save book'))
|
||||
self.action_save.setEnabled(False)
|
||||
self.action_quit = reg('quit.png', _('&Quit'), self.boss.quit, 'quit', 'Ctrl+Q', _('Quit'))
|
||||
self.action_preferences = reg('config.png', _('&Preferences'), self.boss.preferences, 'preferences', 'Ctrl+P', _('Preferences'))
|
||||
|
||||
# Editor actions
|
||||
group = _('Editor actions')
|
||||
@ -271,6 +271,9 @@ class Main(MainWindow):
|
||||
'Create a checkpoint with the current state of the book'))
|
||||
|
||||
def create_menubar(self):
|
||||
p, q = self.create_application_menubar()
|
||||
q.triggered.connect(self.action_quit.trigger)
|
||||
p.triggered.connect(self.action_preferences.trigger)
|
||||
b = self.menuBar()
|
||||
|
||||
f = b.addMenu(_('&File'))
|
||||
@ -290,6 +293,8 @@ class Main(MainWindow):
|
||||
e.addAction(self.action_editor_cut)
|
||||
e.addAction(self.action_editor_copy)
|
||||
e.addAction(self.action_editor_paste)
|
||||
e.addSeparator()
|
||||
e.addAction(self.action_preferences)
|
||||
|
||||
e = b.addMenu(_('&Tools'))
|
||||
e.addAction(self.action_toc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user