diff --git a/src/libprs500/gui2/__init__.py b/src/libprs500/gui2/__init__.py index 12cf3301b4..c317c6cc2f 100644 --- a/src/libprs500/gui2/__init__.py +++ b/src/libprs500/gui2/__init__.py @@ -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 = { diff --git a/src/libprs500/gui2/dialogs/__init__.py b/src/libprs500/gui2/dialogs/__init__.py index 789efa5570..537ea16197 100644 --- a/src/libprs500/gui2/dialogs/__init__.py +++ b/src/libprs500/gui2/dialogs/__init__.py @@ -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() diff --git a/src/libprs500/gui2/dialogs/jobs.py b/src/libprs500/gui2/dialogs/jobs.py index 86778fc517..c0e2f5eec0 100644 --- a/src/libprs500/gui2/dialogs/jobs.py +++ b/src/libprs500/gui2/dialogs/jobs.py @@ -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() diff --git a/src/libprs500/gui2/dialogs/jobs.ui b/src/libprs500/gui2/dialogs/jobs.ui index 59e34bba4f..14a754072a 100644 --- a/src/libprs500/gui2/dialogs/jobs.ui +++ b/src/libprs500/gui2/dialogs/jobs.ui @@ -17,7 +17,7 @@ - + Qt::NoContextMenu @@ -43,6 +43,13 @@ + + + JobsView + QTableView +
widgets.h
+
+
diff --git a/src/libprs500/gui2/dialogs/widgets.py b/src/libprs500/gui2/dialogs/widgets.py new file mode 100644 index 0000000000..5b98bc9940 --- /dev/null +++ b/src/libprs500/gui2/dialogs/widgets.py @@ -0,0 +1,4 @@ +from libprs500.gui2 import TableView + +class JobsView(TableView): + pass \ No newline at end of file diff --git a/src/libprs500/gui2/jobs.py b/src/libprs500/gui2/jobs.py index 43073016be..eaae0d79de 100644 --- a/src/libprs500/gui2/jobs.py +++ b/src/libprs500/gui2/jobs.py @@ -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() + + \ No newline at end of file diff --git a/src/libprs500/gui2/library.py b/src/libprs500/gui2/library.py index 64be1c1801..76af53aa0e 100644 --- a/src/libprs500/gui2/library.py +++ b/src/libprs500/gui2/library.py @@ -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: diff --git a/src/libprs500/gui2/main.py b/src/libprs500/gui2/main.py index c9474ff46a..76705a42ee 100644 --- a/src/libprs500/gui2/main.py +++ b/src/libprs500/gui2/main.py @@ -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.upload_booklists() + self.device_manager.remove_books_from_metadata(paths, self.booklists()) + self.upload_booklists() + model.paths_deleted(paths) ############################################################################ diff --git a/src/libprs500/gui2/status.py b/src/libprs500/gui2/status.py index 5cebeada56..a227ee714c 100644 --- a/src/libprs500/gui2/status.py +++ b/src/libprs500/gui2/status.py @@ -95,14 +95,18 @@ class MovieButton(QFrame): self.setCursor(Qt.PointingHandCursor) self.setToolTip('Click to see list of active jobs.') movie.start() - movie.setPaused(True) + 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): diff --git a/src/libprs500/web/fetch/simple.py b/src/libprs500/web/fetch/simple.py index b9f6bbe388..2cf2548747 100644 --- a/src/libprs500/web/fetch/simple.py +++ b/src/libprs500/web/fetch/simple.py @@ -98,9 +98,9 @@ class RecursiveFetcher(object): def start_fetch(self, url): soup = BeautifulSoup('') - 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):