mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Refactor dialog base class into its own module for easier re-use
This commit is contained in:
parent
2d8dfc3a28
commit
2c8ac926b1
@ -21,7 +21,7 @@ from calibre.constants import ispy3, plugins, cache_dir
|
|||||||
from calibre.gui2 import NONE
|
from calibre.gui2 import NONE
|
||||||
from calibre.gui2.widgets2 import HistoryLineEdit2
|
from calibre.gui2.widgets2 import HistoryLineEdit2
|
||||||
from calibre.gui2.tweak_book import tprefs
|
from calibre.gui2.tweak_book import tprefs
|
||||||
from calibre.gui2.tweak_book.editor.insert_resource import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
|
|
||||||
if not ispy3:
|
if not ispy3:
|
||||||
if sys.maxunicode >= 0x10FFFF:
|
if sys.maxunicode >= 0x10FFFF:
|
||||||
|
@ -10,11 +10,11 @@ import sys, os
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import (
|
from PyQt4.Qt import (
|
||||||
QDialog, QGridLayout, QDialogButtonBox, QSize, QListView, QStyledItemDelegate,
|
QGridLayout, QSize, QListView, QStyledItemDelegate, QLabel, QPixmap,
|
||||||
QLabel, QPixmap, QApplication, QSizePolicy, QAbstractListModel, QVariant,
|
QApplication, QSizePolicy, QAbstractListModel, QVariant, Qt, QRect,
|
||||||
Qt, QRect, QPainter, QModelIndex, QSortFilterProxyModel, QLineEdit,
|
QPainter, QModelIndex, QSortFilterProxyModel, QLineEdit, QToolButton,
|
||||||
QToolButton, QIcon, QFormLayout, pyqtSignal, QTreeWidget, QTreeWidgetItem,
|
QIcon, QFormLayout, pyqtSignal, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
|
||||||
QVBoxLayout, QMenu, QInputDialog)
|
QMenu, QInputDialog)
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
@ -23,43 +23,11 @@ from calibre.ebooks.metadata.book.base import Metadata
|
|||||||
from calibre.gui2 import NONE, choose_files, error_dialog
|
from calibre.gui2 import NONE, choose_files, error_dialog
|
||||||
from calibre.gui2.languages import LanguagesEdit
|
from calibre.gui2.languages import LanguagesEdit
|
||||||
from calibre.gui2.tweak_book import current_container, tprefs
|
from calibre.gui2.tweak_book import current_container, tprefs
|
||||||
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from calibre.gui2.tweak_book.file_list import name_is_ok
|
from calibre.gui2.tweak_book.file_list import name_is_ok
|
||||||
from calibre.utils.localization import get_lang, canonicalize_lang
|
from calibre.utils.localization import get_lang, canonicalize_lang
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
class Dialog(QDialog):
|
|
||||||
|
|
||||||
def __init__(self, title, name, parent=None):
|
|
||||||
QDialog.__init__(self, parent)
|
|
||||||
self.setWindowTitle(title)
|
|
||||||
self.name = name
|
|
||||||
self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
||||||
self.bb.accepted.connect(self.accept)
|
|
||||||
self.bb.rejected.connect(self.reject)
|
|
||||||
|
|
||||||
self.setup_ui()
|
|
||||||
|
|
||||||
self.resize(self.sizeHint())
|
|
||||||
geom = tprefs.get(name + '-geometry', None)
|
|
||||||
if geom is not None:
|
|
||||||
self.restoreGeometry(geom)
|
|
||||||
if hasattr(self, 'splitter'):
|
|
||||||
state = tprefs.get(name + '-splitter-state', None)
|
|
||||||
if state is not None:
|
|
||||||
self.splitter.restoreState(state)
|
|
||||||
|
|
||||||
def accept(self):
|
|
||||||
tprefs.set(self.name + '-geometry', bytearray(self.saveGeometry()))
|
|
||||||
if hasattr(self, 'splitter'):
|
|
||||||
tprefs.set(self.name + '-splitter-state', bytearray(self.splitter.saveState()))
|
|
||||||
QDialog.accept(self)
|
|
||||||
|
|
||||||
def reject(self):
|
|
||||||
tprefs.set(self.name + '-geometry', bytearray(self.saveGeometry()))
|
|
||||||
if hasattr(self, 'splitter'):
|
|
||||||
tprefs.set(self.name + '-splitter-state', bytearray(self.splitter.saveState()))
|
|
||||||
QDialog.reject(self)
|
|
||||||
|
|
||||||
class ChooseName(Dialog): # {{{
|
class ChooseName(Dialog): # {{{
|
||||||
|
|
||||||
''' Chooses the filename for a newly imported file, with error checking '''
|
''' Chooses the filename for a newly imported file, with error checking '''
|
||||||
|
48
src/calibre/gui2/tweak_book/widgets.py
Normal file
48
src/calibre/gui2/tweak_book/widgets.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
|
print_function)
|
||||||
|
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
|
from PyQt4.Qt import (QDialog, QDialogButtonBox)
|
||||||
|
|
||||||
|
from calibre.gui2.tweak_book import tprefs
|
||||||
|
|
||||||
|
class Dialog(QDialog):
|
||||||
|
|
||||||
|
def __init__(self, title, name, parent=None):
|
||||||
|
QDialog.__init__(self, parent)
|
||||||
|
self.setWindowTitle(title)
|
||||||
|
self.name = name
|
||||||
|
self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||||
|
self.bb.accepted.connect(self.accept)
|
||||||
|
self.bb.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
self.setup_ui()
|
||||||
|
|
||||||
|
self.resize(self.sizeHint())
|
||||||
|
geom = tprefs.get(name + '-geometry', None)
|
||||||
|
if geom is not None:
|
||||||
|
self.restoreGeometry(geom)
|
||||||
|
if hasattr(self, 'splitter'):
|
||||||
|
state = tprefs.get(name + '-splitter-state', None)
|
||||||
|
if state is not None:
|
||||||
|
self.splitter.restoreState(state)
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
tprefs.set(self.name + '-geometry', bytearray(self.saveGeometry()))
|
||||||
|
if hasattr(self, 'splitter'):
|
||||||
|
tprefs.set(self.name + '-splitter-state', bytearray(self.splitter.saveState()))
|
||||||
|
QDialog.accept(self)
|
||||||
|
|
||||||
|
def reject(self):
|
||||||
|
tprefs.set(self.name + '-geometry', bytearray(self.saveGeometry()))
|
||||||
|
if hasattr(self, 'splitter'):
|
||||||
|
tprefs.set(self.name + '-splitter-state', bytearray(self.splitter.saveState()))
|
||||||
|
QDialog.reject(self)
|
||||||
|
|
||||||
|
def setup_ui(self):
|
||||||
|
raise NotImplementedError('You must implement this method in Dialog subclasses')
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user