Progress image generation for table

This commit is contained in:
BasioMeusPuga
2017-11-29 02:55:43 +05:30
parent 8cd8ec4ccd
commit c72eff22c7
4 changed files with 41 additions and 11 deletions

View File

@@ -56,12 +56,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.statusBar.addWidget(self.sorterProgress)
self.sorterProgress.setVisible(False)
# Init the Library
self.lib_ref = Library(self)
# Application wide temporary directory
self.temp_dir = QtCore.QTemporaryDir()
# Init the Library
self.lib_ref = Library(self)
# Library toolbar
self.libraryToolBar = LibraryToolBar(self)
self.libraryToolBar.addButton.triggered.connect(self.add_books)

View File

@@ -129,11 +129,12 @@ class Library:
# all_metadata is just being sent. It is not being displayed
# It will be correlated to the current row as its first userrole
self.table_rows.append(
(title, author, year, tags, all_metadata))
(title, author, None, year, tags, all_metadata))
def create_table_model(self):
table_header = ['Title', 'Author', 'Year', 'Tags']
self.table_model = LibraryTableModel(table_header, self.table_rows)
table_header = ['Title', 'Author', 'Status', 'Year', 'Tags']
self.table_model = LibraryTableModel(
table_header, self.table_rows, self.parent_window.temp_dir.path())
self.create_table_proxy_model()
def create_table_proxy_model(self):
@@ -148,7 +149,7 @@ class Library:
def update_table_proxy_model(self):
self.table_proxy_model.invalidateFilter()
self.table_proxy_model.setFilterParams(
self.parent_window.libraryToolBar.searchBar.text(), [0, 1, 3])
self.parent_window.libraryToolBar.searchBar.text(), [0, 1, 4])
# This isn't needed, but it forces a model update every time the
# text in the line edit changes. So I guess it is needed.
self.table_proxy_model.setFilterFixedString(

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env python3
import os
from PyQt5 import QtCore, QtGui
from resources import pie_chart
class LibraryItemModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel):
@@ -13,10 +16,12 @@ class LibraryTableModel(QtCore.QAbstractTableModel):
# Sorting is taken care of by the QSortFilterProxy model
# which has an inbuilt sort method
def __init__(self, header_data, display_data, parent=None):
def __init__(self, header_data, display_data, temp_dir=None, parent=None):
super(LibraryTableModel, self).__init__(parent)
self.header_data = header_data
self.display_data = display_data
self.temp_dir = temp_dir # Is only needed for the main table
# This model is otherwise reusable if this remains None
def rowCount(self, parent):
return len(self.display_data)
@@ -28,13 +33,38 @@ class LibraryTableModel(QtCore.QAbstractTableModel):
if not index.isValid():
return None
if role == QtCore.Qt.DecorationRole and index.column() == 2 and self.temp_dir:
return_pixmap = None
file_exists = self.display_data[index.row()][5]['file_exists']
position = self.display_data[index.row()][5]['position']
if not file_exists:
return_pixmap = QtGui.QIcon(':/images/error.svg').pixmap(
QtCore.Qt.SizeHintRole + 10)
if position:
current_chapter = position['current_chapter']
total_chapters = position['total_chapters']
progress_percent = int(current_chapter * 100 / total_chapters)
if current_chapter == total_chapters:
return_pixmap = QtGui.QIcon(':/images/checkmark.svg').pixmap(
QtCore.Qt.SizeHintRole + 10)
else:
pie_chart.GeneratePie(progress_percent, self.temp_dir).generate()
svg_path = os.path.join(self.temp_dir, 'lector_progress.svg')
return_pixmap = QtGui.QIcon(svg_path).pixmap(
QtCore.Qt.SizeHintRole + 10)
return return_pixmap
if role == QtCore.Qt.DisplayRole:
value = self.display_data[index.row()][index.column()]
file_exists = self.display_data[index.row()][4]['file_exists']
return value
elif role == QtCore.Qt.UserRole:
# The rest of the roles can be accomodated here.
value = self.display_data[index.row()][4]
value = self.display_data[index.row()][5]
return value
else:
return QtCore.QVariant()

View File

@@ -339,7 +339,6 @@ class FixedPushButton(QtWidgets.QPushButton):
class Tab(QtWidgets.QWidget):
def __init__(self, metadata, parent=None):
# TODO
# A horizontal slider to control flow
# Take hint from a position function argument to open the book
# at a specific page