mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix deletion bug in device books model and store column widths in jobs view
This commit is contained in:
parent
976cf43e42
commit
709dd81a08
@ -16,7 +16,8 @@
|
||||
import sys, os, re, StringIO, traceback
|
||||
from PyQt4.QtCore import QVariant, QSettings, QFileInfo, QObject, SIGNAL, QBuffer, \
|
||||
QByteArray
|
||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, QIcon
|
||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||
QIcon, QTableView
|
||||
from libprs500 import __appname__ as APP_TITLE
|
||||
from libprs500 import __author__
|
||||
NONE = QVariant() #: Null value to return from the data function of item models
|
||||
@ -58,6 +59,32 @@ def human_readable(size):
|
||||
return size + " " + suffix
|
||||
|
||||
|
||||
class TableView(QTableView):
|
||||
def __init__(self, parent):
|
||||
QTableView.__init__(self, parent)
|
||||
self.read_settings()
|
||||
|
||||
|
||||
def read_settings(self):
|
||||
self.cw = str(QSettings().value(self.__class__.__name__ + ' column widths', QVariant('')).toString())
|
||||
try:
|
||||
self.cw = tuple(int(i) for i in self.cw.split(','))
|
||||
except ValueError:
|
||||
self.cw = None
|
||||
|
||||
def write_settings(self):
|
||||
settings = QSettings()
|
||||
settings.setValue(self.__class__.__name__ + ' column widths',
|
||||
QVariant(','.join(str(self.columnWidth(i))
|
||||
for i in range(self.model().columnCount(None)))))
|
||||
|
||||
def restore_column_widths(self):
|
||||
if self.cw and len(self.cw):
|
||||
for i in range(len(self.cw)):
|
||||
self.setColumnWidth(i, self.cw[i])
|
||||
return True
|
||||
|
||||
|
||||
class FileIconProvider(QFileIconProvider):
|
||||
|
||||
ICONS = {
|
||||
|
@ -23,5 +23,9 @@ class Dialog(QObject):
|
||||
self.dialog = QDialog(window)
|
||||
self.accept = self.dialog.accept
|
||||
self.reject = self.dialog.reject
|
||||
self.dialog.closeEvent = self.close_event
|
||||
self.window = window
|
||||
self.isVisible = self.dialog.isVisible
|
||||
|
||||
def close_event(self, e):
|
||||
e.accept()
|
||||
|
@ -38,3 +38,7 @@ class JobsDialog(Ui_JobsDialog, Dialog):
|
||||
|
||||
def hide(self):
|
||||
self.dialog.hide()
|
||||
|
||||
def close_event(self, e):
|
||||
self.jobs_view.write_settings()
|
||||
e.accept()
|
||||
|
@ -17,7 +17,7 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QTableView" name="jobs_view" >
|
||||
<widget class="JobsView" name="jobs_view" >
|
||||
<property name="contextMenuPolicy" >
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
@ -43,6 +43,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>JobsView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>widgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../images.qrc" />
|
||||
</resources>
|
||||
|
4
src/libprs500/gui2/dialogs/widgets.py
Normal file
4
src/libprs500/gui2/dialogs/widgets.py
Normal file
@ -0,0 +1,4 @@
|
||||
from libprs500.gui2 import TableView
|
||||
|
||||
class JobsView(TableView):
|
||||
pass
|
@ -105,7 +105,6 @@ class JobManager(QAbstractTableModel):
|
||||
self.cleanup = {}
|
||||
self.device_job_icon = QVariant(QIcon(':/images/reader.svg'))
|
||||
self.job_icon = QVariant(QIcon(':/images/jobs.svg'))
|
||||
self.wrapper = textwrap.TextWrapper(width=40)
|
||||
|
||||
def terminate_device_jobs(self):
|
||||
changed = False
|
||||
@ -235,7 +234,7 @@ class JobManager(QAbstractTableModel):
|
||||
job = self.jobs[keys[row]]
|
||||
if role == Qt.DisplayRole:
|
||||
if col == 0:
|
||||
return QVariant('\n'.join(self.wrapper.wrap(job.description)))
|
||||
return QVariant(job.description)
|
||||
if col == 1:
|
||||
status = 'Waiting'
|
||||
if job.isRunning():
|
||||
@ -260,4 +259,9 @@ class JobManager(QAbstractTableModel):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def closeEvent(self, e):
|
||||
self.jobs_view.write_settings()
|
||||
e.accept()
|
||||
|
||||
|
||||
|
@ -22,12 +22,11 @@ from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor,
|
||||
QPen, QStyle, QPainter, QLineEdit, QApplication, \
|
||||
QPalette
|
||||
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
||||
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex, \
|
||||
QSettings
|
||||
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex
|
||||
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
from libprs500.library.database import LibraryDatabase
|
||||
from libprs500.gui2 import NONE
|
||||
from libprs500.gui2 import NONE, TableView
|
||||
|
||||
class LibraryDelegate(QItemDelegate):
|
||||
COLOR = QColor("blue")
|
||||
@ -326,7 +325,7 @@ class BooksModel(QAbstractTableModel):
|
||||
return done
|
||||
|
||||
|
||||
class BooksView(QTableView):
|
||||
class BooksView(TableView):
|
||||
TIME_FMT = '%d %b %Y'
|
||||
wrapper = textwrap.TextWrapper(width=20)
|
||||
|
||||
@ -341,7 +340,7 @@ class BooksView(QTableView):
|
||||
return ('%.'+str(precision)+'f') % ((size/(1024.*1024.)),)
|
||||
|
||||
def __init__(self, parent, modelcls=BooksModel):
|
||||
QTableView.__init__(self, parent)
|
||||
TableView.__init__(self, parent)
|
||||
self.display_parent = parent
|
||||
self._model = modelcls(self)
|
||||
self.setModel(self._model)
|
||||
@ -356,24 +355,7 @@ class BooksView(QTableView):
|
||||
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.cw = str(QSettings().value(self.__class__.__name__ + ' column widths', QVariant('')).toString())
|
||||
try:
|
||||
self.cw = tuple(int(i) for i in self.cw.split(','))
|
||||
except ValueError:
|
||||
self.cw = None
|
||||
|
||||
def write_settings(self):
|
||||
settings = QSettings()
|
||||
settings.setValue(self.__class__.__name__ + ' column widths',
|
||||
QVariant(','.join(str(self.columnWidth(i))
|
||||
for i in range(self.model().columnCount(None)))))
|
||||
|
||||
def restore_column_widths(self):
|
||||
if self.cw and len(self.cw):
|
||||
for i in range(len(self.cw)):
|
||||
self.setColumnWidth(i, self.cw[i])
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_database(self, db):
|
||||
self._model.set_database(db)
|
||||
@ -448,16 +430,10 @@ class DeviceBooksModel(BooksModel):
|
||||
indices = self.row_indices(self.index(row, 0))
|
||||
self.emit(SIGNAL('dataChanged(QModelIndex, QModelIndex)'), indices[0], indices[-1])
|
||||
|
||||
def path_about_to_be_deleted(self, path):
|
||||
for row in range(len(self.map)):
|
||||
if self.db[self.map[row]].path == path:
|
||||
#print row, path
|
||||
#print self.rowCount(None)
|
||||
self.beginRemoveRows(QModelIndex(), row, row)
|
||||
self.map.pop(row)
|
||||
self.endRemoveRows()
|
||||
#print self.rowCount(None)
|
||||
return
|
||||
def paths_deleted(self, paths):
|
||||
self.map = list(range(0, len(self.db)))
|
||||
self.resort(False)
|
||||
self.research(True)
|
||||
|
||||
def indices_to_be_deleted(self):
|
||||
ans = []
|
||||
@ -492,6 +468,7 @@ class DeviceBooksModel(BooksModel):
|
||||
self.map = result
|
||||
if reset:
|
||||
self.reset()
|
||||
self.last_search = text
|
||||
|
||||
def sort(self, col, order, reset=True):
|
||||
if not self.db:
|
||||
|
@ -353,10 +353,9 @@ class Main(QObject, Ui_MainWindow):
|
||||
|
||||
if self.delete_memory.has_key(id):
|
||||
paths, model = self.delete_memory.pop(id)
|
||||
for path in paths:
|
||||
model.path_about_to_be_deleted(path)
|
||||
self.device_manager.remove_books_from_metadata((path,), self.booklists())
|
||||
self.device_manager.remove_books_from_metadata(paths, self.booklists())
|
||||
self.upload_booklists()
|
||||
model.paths_deleted(paths)
|
||||
|
||||
############################################################################
|
||||
|
||||
|
@ -96,13 +96,17 @@ class MovieButton(QFrame):
|
||||
self.setToolTip('Click to see list of active jobs.')
|
||||
movie.start()
|
||||
movie.setPaused(True)
|
||||
self.jobs_dialog.jobs_view.restore_column_widths()
|
||||
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
if self.jobs_dialog.isVisible():
|
||||
self.jobs_dialog.jobs_view.write_settings()
|
||||
self.jobs_dialog.hide()
|
||||
else:
|
||||
self.jobs_dialog.jobs_view.read_settings()
|
||||
self.jobs_dialog.show()
|
||||
self.jobs_dialog.jobs_view.restore_column_widths()
|
||||
|
||||
|
||||
class StatusBar(QStatusBar):
|
||||
|
@ -98,9 +98,9 @@ class RecursiveFetcher(object):
|
||||
|
||||
def start_fetch(self, url):
|
||||
soup = BeautifulSoup('<a href="'+url+'" />')
|
||||
print 'Downloading',
|
||||
self.logger.info('Downloading')
|
||||
res = self.process_links(soup, url, 0, into_dir='')
|
||||
print '%s saved to %s'%(url, res)
|
||||
self.logger.info('%s saved to %s', url, res)
|
||||
return res
|
||||
|
||||
def is_link_ok(self, url):
|
||||
|
Loading…
x
Reference in New Issue
Block a user