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.exec_()
|
||||||
return d
|
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,
|
d = MessageBox(QMessageBox.Critical, 'ERROR: '+title, msg, QMessageBox.Ok,
|
||||||
parent, det_msg)
|
parent, det_msg)
|
||||||
d.setIconPixmap(QPixmap(I('dialog_error.svg')))
|
d.setIconPixmap(QPixmap(I('dialog_error.svg')))
|
||||||
d.setEscapeButton(QMessageBox.Ok)
|
d.setEscapeButton(QMessageBox.Ok)
|
||||||
|
if not show_copy_button:
|
||||||
|
d.cb.setVisible(False)
|
||||||
if show:
|
if show:
|
||||||
return d.exec_()
|
return d.exec_()
|
||||||
return d
|
return d
|
||||||
|
@ -8,14 +8,14 @@ from PyQt4.Qt import QDialog, QListWidgetItem, QIcon, \
|
|||||||
SIGNAL, QThread, Qt, QSize, QVariant, QUrl, \
|
SIGNAL, QThread, Qt, QSize, QVariant, QUrl, \
|
||||||
QModelIndex, QAbstractTableModel, \
|
QModelIndex, QAbstractTableModel, \
|
||||||
QDialogButtonBox, QTabWidget, QBrush, QLineEdit, \
|
QDialogButtonBox, QTabWidget, QBrush, QLineEdit, \
|
||||||
QProgressDialog, QMessageBox
|
QProgressDialog
|
||||||
|
|
||||||
from calibre.constants import iswindows, isosx, preferred_encoding
|
from calibre.constants import iswindows, isosx, preferred_encoding
|
||||||
from calibre.gui2.dialogs.config.config_ui import Ui_Dialog
|
from calibre.gui2.dialogs.config.config_ui import Ui_Dialog
|
||||||
from calibre.gui2.dialogs.config.create_custom_column import CreateCustomColumn
|
from calibre.gui2.dialogs.config.create_custom_column import CreateCustomColumn
|
||||||
from calibre.gui2 import choose_dir, error_dialog, config, \
|
from calibre.gui2 import choose_dir, error_dialog, config, \
|
||||||
ALL_COLUMNS, NONE, info_dialog, choose_files, \
|
ALL_COLUMNS, NONE, info_dialog, choose_files, \
|
||||||
warning_dialog, ResizableDialog
|
warning_dialog, ResizableDialog, question_dialog
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.ebooks.oeb.iterator import is_supported
|
from calibre.ebooks.oeb.iterator import is_supported
|
||||||
@ -648,16 +648,15 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
|
|||||||
def del_custcol(self):
|
def del_custcol(self):
|
||||||
idx = self.columns.currentRow()
|
idx = self.columns.currentRow()
|
||||||
if idx < 0:
|
if idx < 0:
|
||||||
self.messagebox(_('You must select a column to delete it'))
|
return error_dialog(self, '', _('You must select a column to delete it'),
|
||||||
return
|
show=True)
|
||||||
col = unicode(self.columns.item(idx).data(Qt.UserRole).toString())
|
col = unicode(self.columns.item(idx).data(Qt.UserRole).toString())
|
||||||
if col not in self.custcols:
|
if col not in self.custcols:
|
||||||
self.messagebox(_('The selected column is not a custom column'))
|
return error_dialog(self, '',
|
||||||
return
|
_('The selected column is not a custom column'), show=True)
|
||||||
ret = self.messagebox(_('Do you really want to delete column %s and all its data')%self.custcols[col]['name'],
|
if not question_dialog(self, _('Are you sure?'),
|
||||||
buttons=QMessageBox.Ok|QMessageBox.Cancel,
|
_('Do you really want to delete column %s and all its data?') %
|
||||||
defaultButton=QMessageBox.Cancel)
|
self.custcols[col]['name']):
|
||||||
if ret != QMessageBox.Ok:
|
|
||||||
return
|
return
|
||||||
self.columns.item(idx).setCheckState(False)
|
self.columns.item(idx).setCheckState(False)
|
||||||
self.columns.takeItem(idx)
|
self.columns.takeItem(idx)
|
||||||
@ -829,15 +828,13 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
|
|||||||
else:
|
else:
|
||||||
self.database_location = os.path.abspath(path)
|
self.database_location = os.path.abspath(path)
|
||||||
if must_restart:
|
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
|
self.parent.must_restart_before_config = True
|
||||||
QDialog.accept(self)
|
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):
|
class VacThread(QThread):
|
||||||
|
|
||||||
def __init__(self, parent, db):
|
def __init__(self, parent, db):
|
||||||
|
@ -3,25 +3,45 @@ __copyright__ = '2010, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
'''Dialog to create a new custom column'''
|
'''Dialog to create a new custom column'''
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.QtCore import SIGNAL
|
from PyQt4.QtCore import SIGNAL
|
||||||
from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant
|
from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant
|
||||||
|
|
||||||
from calibre.gui2.dialogs.config.create_custom_column_ui import Ui_QCreateCustomColumn
|
from calibre.gui2.dialogs.config.create_custom_column_ui import Ui_QCreateCustomColumn
|
||||||
|
from calibre.gui2 import error_dialog
|
||||||
|
|
||||||
class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
||||||
|
|
||||||
column_types = {
|
column_types = {
|
||||||
0:{'datatype':'text', 'text':_('Text, column shown in tags browser'), 'is_multiple':False},
|
0:{'datatype':'text',
|
||||||
1:{'datatype':'*text', 'text':_('Comma separated text, shown in tags browser'), 'is_multiple':True},
|
'text':_('Text, column shown in the tag browser'),
|
||||||
2:{'datatype':'comments', 'text':_('Text, column not shown in tags browser'), 'is_multiple':False},
|
'is_multiple':False},
|
||||||
3:{'datatype':'datetime', 'text':_('Date'), 'is_multiple':False},
|
1:{'datatype':'*text',
|
||||||
4:{'datatype':'float', 'text':_('Float'), 'is_multiple':False},
|
'text':_('Comma separated text, like tags, shown in the tag browser'),
|
||||||
5:{'datatype':'int', 'text':_('Integer'), 'is_multiple':False},
|
'is_multiple':True},
|
||||||
6:{'datatype':'rating', 'text':_('Rating (stars)'), 'is_multiple':False},
|
2:{'datatype':'comments',
|
||||||
7:{'datatype':'bool', 'text':_('Yes/No'), 'is_multiple':False},
|
'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):
|
def __init__(self, parent, editing, standard_colheads, standard_colnames):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
Ui_QCreateCustomColumn.__init__(self)
|
Ui_QCreateCustomColumn.__init__(self)
|
||||||
self.setupUi(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("accepted()"), self.accept)
|
||||||
self.connect(self.button_box, SIGNAL("rejected()"), self.reject)
|
self.connect(self.button_box, SIGNAL("rejected()"), self.reject)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@ -35,12 +55,11 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
|||||||
return
|
return
|
||||||
idx = parent.columns.currentRow()
|
idx = parent.columns.currentRow()
|
||||||
if idx < 0:
|
if idx < 0:
|
||||||
self.parent.messagebox(_('No column has been selected'))
|
return self.simple_error(_('No column selected'),
|
||||||
return
|
_('No column has been selected'))
|
||||||
col = unicode(parent.columns.item(idx).data(Qt.UserRole).toString())
|
col = unicode(parent.columns.item(idx).data(Qt.UserRole).toString())
|
||||||
if col not in parent.custcols:
|
if col not in parent.custcols:
|
||||||
self.parent.messagebox(_('Selected column is not a user-defined column'))
|
return self.simple_error('', _('Selected column is not a user-defined column'))
|
||||||
return
|
|
||||||
|
|
||||||
c = parent.custcols[col]
|
c = parent.custcols[col]
|
||||||
self.column_name_box.setText(c['label'])
|
self.column_name_box.setText(c['label'])
|
||||||
@ -62,11 +81,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
|||||||
else:
|
else:
|
||||||
is_multiple = False
|
is_multiple = False
|
||||||
if not col:
|
if not col:
|
||||||
self.parent.messagebox(_('No lookup name was provided'))
|
return self.simple_error('', _('No lookup name was provided'))
|
||||||
return
|
|
||||||
if not col_heading:
|
if not col_heading:
|
||||||
self.parent.messagebox(_('No column heading was provided'))
|
return self.simple_error('', _('No column heading was provided'))
|
||||||
return
|
|
||||||
bad_col = False
|
bad_col = False
|
||||||
if col in self.parent.custcols:
|
if col in self.parent.custcols:
|
||||||
if not self.editing_col or self.parent.custcols[col]['num'] != self.orig_column_number:
|
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:
|
if col in self.standard_colnames:
|
||||||
bad_col = True
|
bad_col = True
|
||||||
if bad_col:
|
if bad_col:
|
||||||
self.parent.messagebox(_('The lookup name %s is already used')%col)
|
return self.simple_error('', _('The lookup name %s is already used')%col)
|
||||||
return
|
|
||||||
bad_head = False
|
bad_head = False
|
||||||
for t in self.parent.custcols:
|
for t in self.parent.custcols:
|
||||||
if self.parent.custcols[t]['name'] == col_heading:
|
if self.parent.custcols[t]['name'] == col_heading:
|
||||||
@ -85,11 +101,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
|||||||
if self.standard_colheads[t] == col_heading:
|
if self.standard_colheads[t] == col_heading:
|
||||||
bad_head = True
|
bad_head = True
|
||||||
if bad_head:
|
if bad_head:
|
||||||
self.parent.messagebox(_('The heading %s is already used')%col_heading)
|
return self.simple_error('', _('The heading %s is already used')%col_heading)
|
||||||
return
|
|
||||||
if ':' in col or ' ' in col or col.lower() != col:
|
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 self.simple_error('', _('The lookup name must be lower case and cannot contain ":"s or spaces'))
|
||||||
return
|
|
||||||
|
|
||||||
if not self.editing_col:
|
if not self.editing_col:
|
||||||
self.parent.custcols[col] = {
|
self.parent.custcols[col] = {
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>391</width>
|
<width>528</width>
|
||||||
<height>157</height>
|
<height>165</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -20,116 +20,119 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Create Tag-based Column</string>
|
<string>Create a custom column</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="verticalLayoutWidget">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="geometry">
|
<item>
|
||||||
<rect>
|
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0,0">
|
||||||
<x>10</x>
|
<property name="sizeConstraint">
|
||||||
<y>0</y>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
<width>371</width>
|
</property>
|
||||||
<height>141</height>
|
<property name="margin">
|
||||||
</rect>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0,0">
|
<item row="2" column="0">
|
||||||
<property name="sizeConstraint">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<item row="0" column="0">
|
||||||
</property>
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="margin">
|
<property name="text">
|
||||||
<number>5</number>
|
<string>&Lookup name</string>
|
||||||
</property>
|
</property>
|
||||||
<item row="2" column="0">
|
<property name="buddy">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<cstring>column_name_box</cstring>
|
||||||
<item row="0" column="0">
|
</property>
|
||||||
<widget class="QLabel" name="label_2">
|
</widget>
|
||||||
<property name="text">
|
</item>
|
||||||
<string>Lookup name</string>
|
<item row="1" column="0">
|
||||||
</property>
|
<widget class="QLabel" name="label">
|
||||||
</widget>
|
<property name="text">
|
||||||
</item>
|
<string>Column &heading</string>
|
||||||
<item row="1" column="0">
|
</property>
|
||||||
<widget class="QLabel" name="label">
|
<property name="buddy">
|
||||||
<property name="text">
|
<cstring>column_heading_box</cstring>
|
||||||
<string>Column heading</string>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="0" column="1">
|
||||||
<item row="0" column="1">
|
<widget class="QLineEdit" name="column_name_box">
|
||||||
<widget class="QLineEdit" name="column_name_box">
|
<property name="minimumSize">
|
||||||
<property name="minimumSize">
|
<size>
|
||||||
<size>
|
<width>20</width>
|
||||||
<width>20</width>
|
<height>0</height>
|
||||||
<height>0</height>
|
</size>
|
||||||
</size>
|
</property>
|
||||||
</property>
|
<property name="toolTip">
|
||||||
<property name="toolTip">
|
<string>Used for searching the column. Must be lower case and not contain spaces or colons.</string>
|
||||||
<string>Used for searching the column. Must be lower case and not contain spaces or colons.</string>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="1" column="1">
|
||||||
<item row="1" column="1">
|
<widget class="QLineEdit" name="column_heading_box">
|
||||||
<widget class="QLineEdit" name="column_heading_box">
|
<property name="toolTip">
|
||||||
<property name="toolTip">
|
<string>Column heading in the library view and category name in the tag browser</string>
|
||||||
<string>Column heading in the library view and category name in tags browser</string>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
</item>
|
<item row="2" column="0">
|
||||||
<item row="2" column="0">
|
<widget class="QLabel" name="label_3">
|
||||||
<widget class="QLabel" name="label_3">
|
<property name="text">
|
||||||
<property name="text">
|
<string>Column &type</string>
|
||||||
<string>Column type</string>
|
</property>
|
||||||
</property>
|
<property name="buddy">
|
||||||
</widget>
|
<cstring>column_type_box</cstring>
|
||||||
</item>
|
</property>
|
||||||
<item row="2" column="1">
|
</widget>
|
||||||
<widget class="QComboBox" name="column_type_box">
|
</item>
|
||||||
<property name="sizePolicy">
|
<item row="2" column="1">
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
<widget class="QComboBox" name="column_type_box">
|
||||||
<horstretch>0</horstretch>
|
<property name="sizePolicy">
|
||||||
<verstretch>0</verstretch>
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
</sizepolicy>
|
<horstretch>0</horstretch>
|
||||||
</property>
|
<verstretch>0</verstretch>
|
||||||
<property name="minimumSize">
|
</sizepolicy>
|
||||||
<size>
|
</property>
|
||||||
<width>70</width>
|
<property name="minimumSize">
|
||||||
<height>0</height>
|
<size>
|
||||||
</size>
|
<width>70</width>
|
||||||
</property>
|
<height>0</height>
|
||||||
<property name="toolTip">
|
</size>
|
||||||
<string>What kind of information will be kept in the column.</string>
|
</property>
|
||||||
</property>
|
<property name="toolTip">
|
||||||
</widget>
|
<string>What kind of information will be kept in the column.</string>
|
||||||
</item>
|
</property>
|
||||||
</layout>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
</layout>
|
||||||
<widget class="QDialogButtonBox" name="button_box">
|
</item>
|
||||||
<property name="orientation">
|
<item row="3" column="0">
|
||||||
<enum>Qt::Horizontal</enum>
|
<widget class="QDialogButtonBox" name="button_box">
|
||||||
</property>
|
<property name="orientation">
|
||||||
<property name="standardButtons">
|
<enum>Qt::Horizontal</enum>
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
</property>
|
||||||
</property>
|
<property name="standardButtons">
|
||||||
<property name="centerButtons">
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
<bool>true</bool>
|
</property>
|
||||||
</property>
|
<property name="centerButtons">
|
||||||
</widget>
|
<bool>true</bool>
|
||||||
</item>
|
</property>
|
||||||
<item row="1" column="0">
|
</widget>
|
||||||
<widget class="QLabel" name="label_6">
|
</item>
|
||||||
<property name="font">
|
<item row="1" column="0">
|
||||||
<font>
|
<widget class="QLabel" name="label_6">
|
||||||
<weight>75</weight>
|
<property name="font">
|
||||||
<bold>true</bold>
|
<font>
|
||||||
</font>
|
<weight>75</weight>
|
||||||
</property>
|
<bold>true</bold>
|
||||||
<property name="text">
|
</font>
|
||||||
<string>Create and edit custom columns</string>
|
</property>
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Create and edit custom columns</string>
|
||||||
</item>
|
</property>
|
||||||
</layout>
|
</widget>
|
||||||
</widget>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>column_name_box</tabstop>
|
<tabstop>column_name_box</tabstop>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user