mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make visible columns in the library view configurable via the config dialog.
This commit is contained in:
parent
4d14a272c4
commit
63f971dd92
@ -102,6 +102,28 @@ class TableView(QTableView):
|
||||
for i in range(len(self.cw)):
|
||||
self.setColumnWidth(i, self.cw[i])
|
||||
return True
|
||||
|
||||
def set_visible_columns(self, cols=None):
|
||||
'''
|
||||
@param cols: A list of booleans or None. If an entry is False the corresponding column
|
||||
is hidden, if True it is shown.
|
||||
'''
|
||||
if cols:
|
||||
QSettings().setValue(self.__class__.__name__ + ' visible columns',
|
||||
QVariant(repr(cols)))
|
||||
else:
|
||||
cols = qstring_to_unicode(QSettings().value(self.__class__.__name__ + ' visible columns',
|
||||
QVariant('')).toString())
|
||||
if cols:
|
||||
cols = eval(cols)
|
||||
else:
|
||||
cols = [True for i in range(self.model().columnCount(self))]
|
||||
|
||||
for i in range(len(cols)):
|
||||
hidden = self.isColumnHidden(i)
|
||||
self.setColumnHidden(i, not cols[i])
|
||||
if hidden and cols[i]:
|
||||
self.resizeColumnToContents(i)
|
||||
|
||||
|
||||
class FileIconProvider(QFileIconProvider):
|
||||
|
@ -14,8 +14,8 @@
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
import os
|
||||
|
||||
from PyQt4.QtGui import QDialog, QMessageBox
|
||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList, QTimer
|
||||
from PyQt4.QtGui import QDialog, QMessageBox, QListWidgetItem
|
||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList, QTimer, Qt
|
||||
|
||||
from libprs500 import islinux
|
||||
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
||||
@ -23,12 +23,13 @@ from libprs500.gui2 import qstring_to_unicode, choose_dir, error_dialog
|
||||
|
||||
class ConfigDialog(QDialog, Ui_Dialog):
|
||||
|
||||
def __init__(self, window, db):
|
||||
def __init__(self, window, db, columns):
|
||||
QDialog.__init__(self, window)
|
||||
Ui_Dialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
|
||||
self.db = db
|
||||
self.current_cols = columns
|
||||
settings = QSettings()
|
||||
path = qstring_to_unicode(\
|
||||
settings.value("database path",
|
||||
@ -52,6 +53,15 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.priority.addItem('Idle')
|
||||
if not islinux:
|
||||
self.dirs_box.setVisible(False)
|
||||
|
||||
for hidden, hdr in self.current_cols:
|
||||
item = QListWidgetItem(hdr, self.columns)
|
||||
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable)
|
||||
if hidden:
|
||||
item.setCheckState(Qt.Unchecked)
|
||||
else:
|
||||
item.setCheckState(Qt.Checked)
|
||||
|
||||
|
||||
def compact(self, toggled):
|
||||
d = Vacuum(self, self.db)
|
||||
@ -76,7 +86,9 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
settings = QSettings()
|
||||
settings.setValue('use roman numerals for series number', QVariant(self.roman_numerals.isChecked()))
|
||||
settings.setValue('network timeout', QVariant(self.timeout.value()))
|
||||
path = qstring_to_unicode(self.location.text())
|
||||
path = qstring_to_unicode(self.location.text())
|
||||
self.final_columns = [self.columns.item(i).checkState() == Qt.Checked for i in range(self.columns.count())]
|
||||
|
||||
if not path or not os.path.exists(path) or not os.path.isdir(path):
|
||||
d = error_dialog(self, _('Invalid database location'), _('Invalid database location ')+path+_('<br>Must be a directory.'))
|
||||
d.exec_()
|
||||
|
@ -5,8 +5,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>408</width>
|
||||
<height>378</height>
|
||||
<width>451</width>
|
||||
<height>507</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
@ -154,7 +154,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0" >
|
||||
<item row="6" column="0" >
|
||||
<widget class="QGroupBox" name="dirs_box" >
|
||||
<property name="title" >
|
||||
<string>Frequently used directories</string>
|
||||
@ -249,7 +249,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" >
|
||||
<item row="7" column="0" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -262,6 +262,22 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0" >
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Select visible &columns in library view</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QListWidget" name="columns" >
|
||||
<property name="selectionMode" >
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2" />
|
||||
|
@ -12,6 +12,7 @@
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
from libprs500.gui2 import qstring_to_unicode
|
||||
import os, textwrap, traceback, time, re, sre_constants
|
||||
from datetime import timedelta, datetime
|
||||
from operator import attrgetter
|
||||
@ -411,6 +412,7 @@ class BooksView(TableView):
|
||||
QObject.connect(self.model(), SIGNAL('rowsInserted(QModelIndex, int, int)'), self.resizeRowsToContents)
|
||||
# Resetting the model should resize rows (model is reset after search and sort operations)
|
||||
QObject.connect(self.model(), SIGNAL('modelReset()'), self.resizeRowsToContents)
|
||||
self.set_visible_columns()
|
||||
|
||||
|
||||
def set_database(self, db):
|
||||
|
@ -676,9 +676,14 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
d = error_dialog(self, _('Cannot configure'), _('Cannot configure while there are running jobs.'))
|
||||
d.exec_()
|
||||
return
|
||||
d = ConfigDialog(self, self.library_view.model().db)
|
||||
columns = [(self.library_view.isColumnHidden(i), \
|
||||
self.library_view.model().headerData(i, Qt.Horizontal, Qt.DisplayRole).toString())\
|
||||
for i in range(self.library_view.model().columnCount(None))]
|
||||
d = ConfigDialog(self, self.library_view.model().db, columns)
|
||||
d.exec_()
|
||||
if d.result() == d.Accepted:
|
||||
self.library_view.set_visible_columns(d.final_columns)
|
||||
|
||||
if os.path.dirname(self.database_path) != d.database_location:
|
||||
try:
|
||||
newloc = os.path.join(d.database_location, os.path.basename(self.database_path))
|
||||
|
Loading…
x
Reference in New Issue
Block a user