From daa81a787b746803bf613d76f47f1439ee03428b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 May 2010 19:00:04 -0600 Subject: [PATCH] Clean up create custom column dialog and use calibre message boxes --- src/calibre/gui2/__init__.py | 5 +- src/calibre/gui2/dialogs/config/__init__.py | 29 +-- .../dialogs/config/create_custom_column.py | 58 +++-- .../dialogs/config/create_custom_column.ui | 225 +++++++++--------- 4 files changed, 167 insertions(+), 150 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 2258457d45..78b68a8bfb 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -193,11 +193,14 @@ def warning_dialog(parent, title, msg, det_msg='', show=False): return d.exec_() return d -def error_dialog(parent, title, msg, det_msg='', show=False): +def error_dialog(parent, title, msg, det_msg='', show=False, + show_copy_button=True): d = MessageBox(QMessageBox.Critical, 'ERROR: '+title, msg, QMessageBox.Ok, parent, det_msg) d.setIconPixmap(QPixmap(I('dialog_error.svg'))) d.setEscapeButton(QMessageBox.Ok) + if not show_copy_button: + d.cb.setVisible(False) if show: return d.exec_() return d diff --git a/src/calibre/gui2/dialogs/config/__init__.py b/src/calibre/gui2/dialogs/config/__init__.py index dc7d6f8def..b5d145dfc5 100644 --- a/src/calibre/gui2/dialogs/config/__init__.py +++ b/src/calibre/gui2/dialogs/config/__init__.py @@ -8,14 +8,14 @@ from PyQt4.Qt import QDialog, QListWidgetItem, QIcon, \ SIGNAL, QThread, Qt, QSize, QVariant, QUrl, \ QModelIndex, QAbstractTableModel, \ QDialogButtonBox, QTabWidget, QBrush, QLineEdit, \ - QProgressDialog, QMessageBox + QProgressDialog from calibre.constants import iswindows, isosx, preferred_encoding from calibre.gui2.dialogs.config.config_ui import Ui_Dialog from calibre.gui2.dialogs.config.create_custom_column import CreateCustomColumn from calibre.gui2 import choose_dir, error_dialog, config, \ ALL_COLUMNS, NONE, info_dialog, choose_files, \ - warning_dialog, ResizableDialog + warning_dialog, ResizableDialog, question_dialog from calibre.utils.config import prefs from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks.oeb.iterator import is_supported @@ -648,16 +648,15 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): def del_custcol(self): idx = self.columns.currentRow() if idx < 0: - self.messagebox(_('You must select a column to delete it')) - return + return error_dialog(self, '', _('You must select a column to delete it'), + show=True) col = unicode(self.columns.item(idx).data(Qt.UserRole).toString()) if col not in self.custcols: - self.messagebox(_('The selected column is not a custom column')) - return - ret = self.messagebox(_('Do you really want to delete column %s and all its data')%self.custcols[col]['name'], - buttons=QMessageBox.Ok|QMessageBox.Cancel, - defaultButton=QMessageBox.Cancel) - if ret != QMessageBox.Ok: + return error_dialog(self, '', + _('The selected column is not a custom column'), show=True) + if not question_dialog(self, _('Are you sure?'), + _('Do you really want to delete column %s and all its data?') % + self.custcols[col]['name']): return self.columns.item(idx).setCheckState(False) self.columns.takeItem(idx) @@ -829,15 +828,13 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): else: self.database_location = os.path.abspath(path) if must_restart: - self.messagebox(_('The changes you made require that Calibre be restarted. Please restart as soon as practical.')) + warning_dialog(self, _('Must restart'), + _('The changes you made require that Calibre be ' + 'restarted. Please restart as soon as practical.'), + show=True) self.parent.must_restart_before_config = True QDialog.accept(self) - # might want to substitute the standard calibre box. However, the copy_to_clipboard - # functionality has no purpose, so ??? - def messagebox(self, m, buttons=QMessageBox.Ok, defaultButton=QMessageBox.Ok): - return QMessageBox.critical(None,'Calibre configuration', m, buttons, defaultButton) - class VacThread(QThread): def __init__(self, parent, db): diff --git a/src/calibre/gui2/dialogs/config/create_custom_column.py b/src/calibre/gui2/dialogs/config/create_custom_column.py index 89b31c41fa..03f8104223 100644 --- a/src/calibre/gui2/dialogs/config/create_custom_column.py +++ b/src/calibre/gui2/dialogs/config/create_custom_column.py @@ -3,25 +3,45 @@ __copyright__ = '2010, Kovid Goyal ' '''Dialog to create a new custom column''' +from functools import partial + from PyQt4.QtCore import SIGNAL from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant + from calibre.gui2.dialogs.config.create_custom_column_ui import Ui_QCreateCustomColumn +from calibre.gui2 import error_dialog class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): + column_types = { - 0:{'datatype':'text', 'text':_('Text, column shown in tags browser'), 'is_multiple':False}, - 1:{'datatype':'*text', 'text':_('Comma separated text, shown in tags browser'), 'is_multiple':True}, - 2:{'datatype':'comments', 'text':_('Text, column not shown in tags browser'), 'is_multiple':False}, - 3:{'datatype':'datetime', 'text':_('Date'), 'is_multiple':False}, - 4:{'datatype':'float', 'text':_('Float'), 'is_multiple':False}, - 5:{'datatype':'int', 'text':_('Integer'), 'is_multiple':False}, - 6:{'datatype':'rating', 'text':_('Rating (stars)'), 'is_multiple':False}, - 7:{'datatype':'bool', 'text':_('Yes/No'), 'is_multiple':False}, + 0:{'datatype':'text', + 'text':_('Text, column shown in the tag browser'), + 'is_multiple':False}, + 1:{'datatype':'*text', + 'text':_('Comma separated text, like tags, shown in the tag browser'), + 'is_multiple':True}, + 2:{'datatype':'comments', + 'text':_('Long text, like comments, not shown in the tag browser'), + 'is_multiple':False}, + 3:{'datatype':'datetime', + 'text':_('Date'), 'is_multiple':False}, + 4:{'datatype':'float', + 'text':_('Floating point numbers'), 'is_multiple':False}, + 5:{'datatype':'int', + 'text':_('Integers'), 'is_multiple':False}, + 6:{'datatype':'rating', + 'text':_('Ratings, shown with stars'), + 'is_multiple':False}, + 7:{'datatype':'bool', + 'text':_('Yes/No'), 'is_multiple':False}, } + def __init__(self, parent, editing, standard_colheads, standard_colnames): QDialog.__init__(self, parent) Ui_QCreateCustomColumn.__init__(self) self.setupUi(self) + self.simple_error = partial(error_dialog, self, show=True, + show_copy_button=False) self.connect(self.button_box, SIGNAL("accepted()"), self.accept) self.connect(self.button_box, SIGNAL("rejected()"), self.reject) self.parent = parent @@ -35,12 +55,11 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): return idx = parent.columns.currentRow() if idx < 0: - self.parent.messagebox(_('No column has been selected')) - return + return self.simple_error(_('No column selected'), + _('No column has been selected')) col = unicode(parent.columns.item(idx).data(Qt.UserRole).toString()) if col not in parent.custcols: - self.parent.messagebox(_('Selected column is not a user-defined column')) - return + return self.simple_error('', _('Selected column is not a user-defined column')) c = parent.custcols[col] self.column_name_box.setText(c['label']) @@ -62,11 +81,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): else: is_multiple = False if not col: - self.parent.messagebox(_('No lookup name was provided')) - return + return self.simple_error('', _('No lookup name was provided')) if not col_heading: - self.parent.messagebox(_('No column heading was provided')) - return + return self.simple_error('', _('No column heading was provided')) bad_col = False if col in self.parent.custcols: if not self.editing_col or self.parent.custcols[col]['num'] != self.orig_column_number: @@ -74,8 +91,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): if col in self.standard_colnames: bad_col = True if bad_col: - self.parent.messagebox(_('The lookup name %s is already used')%col) - return + return self.simple_error('', _('The lookup name %s is already used')%col) bad_head = False for t in self.parent.custcols: if self.parent.custcols[t]['name'] == col_heading: @@ -85,11 +101,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): if self.standard_colheads[t] == col_heading: bad_head = True if bad_head: - self.parent.messagebox(_('The heading %s is already used')%col_heading) - return + return self.simple_error('', _('The heading %s is already used')%col_heading) if ':' in col or ' ' in col or col.lower() != col: - self.parent.messagebox(_('The lookup name must be lower case and cannot contain ":"s or spaces')) - return + return self.simple_error('', _('The lookup name must be lower case and cannot contain ":"s or spaces')) if not self.editing_col: self.parent.custcols[col] = { diff --git a/src/calibre/gui2/dialogs/config/create_custom_column.ui b/src/calibre/gui2/dialogs/config/create_custom_column.ui index 9ba9c1d547..3e0556b815 100644 --- a/src/calibre/gui2/dialogs/config/create_custom_column.ui +++ b/src/calibre/gui2/dialogs/config/create_custom_column.ui @@ -9,8 +9,8 @@ 0 0 - 391 - 157 + 528 + 165 @@ -20,116 +20,119 @@ - Create Tag-based Column + Create a custom column - - - - 10 - 0 - 371 - 141 - - - - - QLayout::SetDefaultConstraint - - - 5 - - - - - - - Lookup name - - - - - - - Column heading - - - - - - - - 20 - 0 - - - - Used for searching the column. Must be lower case and not contain spaces or colons. - - - - - - - Column heading in the library view and category name in tags browser - - - - - - - Column type - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - What kind of information will be kept in the column. - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - true - - - - - - - - 75 - true - - - - Create and edit custom columns - - - - - + + + + + QLayout::SetDefaultConstraint + + + 5 + + + + + + + &Lookup name + + + column_name_box + + + + + + + Column &heading + + + column_heading_box + + + + + + + + 20 + 0 + + + + Used for searching the column. Must be lower case and not contain spaces or colons. + + + + + + + Column heading in the library view and category name in the tag browser + + + + + + + Column &type + + + column_type_box + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + What kind of information will be kept in the column. + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + 75 + true + + + + Create and edit custom columns + + + + + + column_name_box