mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Clean up create custom column dialog and use calibre message boxes
This commit is contained in:
parent
536eb02887
commit
daa81a787b
@ -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
|
||||
|
@ -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):
|
||||
|
@ -3,25 +3,45 @@ __copyright__ = '2010, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
'''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] = {
|
||||
|
@ -9,8 +9,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>391</width>
|
||||
<height>157</height>
|
||||
<width>528</width>
|
||||
<height>165</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -20,17 +20,10 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Create Tag-based Column</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>0</y>
|
||||
<width>371</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
<string>Create a custom column</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0,0">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
@ -43,14 +36,20 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Lookup name</string>
|
||||
<string>&Lookup name</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>column_name_box</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Column heading</string>
|
||||
<string>Column &heading</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>column_heading_box</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -70,14 +69,17 @@
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="column_heading_box">
|
||||
<property name="toolTip">
|
||||
<string>Column heading in the library view and category name in tags browser</string>
|
||||
<string>Column heading in the library view and category name in the tag browser</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Column type</string>
|
||||
<string>Column &type</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>column_type_box</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -129,7 +131,8 @@
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>column_name_box</tabstop>
|
||||
|
Loading…
x
Reference in New Issue
Block a user