Cleanup
This commit is contained in:
33
__main__.py
33
__main__.py
@@ -39,6 +39,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
Settings(self).read_settings() # This should populate all variables that need
|
Settings(self).read_settings() # This should populate all variables that need
|
||||||
# to be remembered across sessions
|
# to be remembered across sessions
|
||||||
Toolbars(self)
|
Toolbars(self)
|
||||||
|
# I don't know why this is needed
|
||||||
|
# I can't access the Qcombobox any other way
|
||||||
|
self.librarySortingBox = self.LibraryToolBar.children()[-1:][0]
|
||||||
|
|
||||||
database.DatabaseInit(self.database_path)
|
database.DatabaseInit(self.database_path)
|
||||||
|
|
||||||
# New tabs and their contents
|
# New tabs and their contents
|
||||||
@@ -84,9 +88,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
||||||
self.reload_listview()
|
self.reload_listview()
|
||||||
|
|
||||||
def reload_listview(self, sortingbox_index=0):
|
def reload_listview(self):
|
||||||
lib_ref = Library(self)
|
lib_ref = Library(self)
|
||||||
lib_ref.load_listView(sortingbox_index)
|
lib_ref.load_listView()
|
||||||
|
|
||||||
def close_tab_class(self, tab_index):
|
def close_tab_class(self, tab_index):
|
||||||
this_tab = Tabs(self, None)
|
this_tab = Tabs(self, None)
|
||||||
@@ -120,7 +124,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
self.current_textEdit.show()
|
self.current_textEdit.show()
|
||||||
|
|
||||||
def listclick(self, myindex):
|
def listclick(self, myindex):
|
||||||
# print('selected item index found at %s with data: %s' % (myindex.row(), myindex.data()))
|
|
||||||
index = self.listView.model().index(myindex.row(), 0)
|
index = self.listView.model().index(myindex.row(), 0)
|
||||||
print(self.listView.model().data(index, QtCore.Qt.UserRole))
|
print(self.listView.model().data(index, QtCore.Qt.UserRole))
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ class Library:
|
|||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
self.parent_window = parent
|
self.parent_window = parent
|
||||||
|
|
||||||
def load_listView(self, sortingbox_index=0):
|
def load_listView(self):
|
||||||
# TODO
|
# TODO
|
||||||
# The rest of it is just refreshing the listview
|
# The rest of it is just refreshing the listview
|
||||||
|
|
||||||
@@ -151,24 +154,15 @@ class Library:
|
|||||||
print('Database returned nothing')
|
print('Database returned nothing')
|
||||||
return
|
return
|
||||||
|
|
||||||
# The database query returns a tuple with the following indices
|
# The sorting indices are related to the indices of what the library returns
|
||||||
# Index 0 is the key ID is ignored
|
# by -1. Consider making this something more foolproof. Maybe.
|
||||||
|
sortingbox_index = self.parent_window.librarySortingBox.currentIndex()
|
||||||
# Sorting currently is on the basis of the book title
|
|
||||||
# Make this take hints from the SortBy dropdown, the FilterBy lineEdit
|
|
||||||
# and the fetch_data method in the database module
|
|
||||||
|
|
||||||
# if sortingbox_index == 0: # Title
|
|
||||||
# sorting_field = 1
|
|
||||||
# elif sortingbox_index == 1: # Author
|
|
||||||
# sorting_field = 2
|
|
||||||
# elif sortingbox_index == 2: # Year
|
|
||||||
# sorting_field = 3
|
|
||||||
|
|
||||||
books = sorted(books, key=lambda x: x[sortingbox_index + 1])
|
books = sorted(books, key=lambda x: x[sortingbox_index + 1])
|
||||||
|
|
||||||
for i in books:
|
for i in books:
|
||||||
|
|
||||||
|
# The database query returns a tuple with the following indices
|
||||||
|
# Index 0 is the key ID is ignored
|
||||||
book_title = i[1]
|
book_title = i[1]
|
||||||
book_author = i[2]
|
book_author = i[2]
|
||||||
book_year = i[3]
|
book_year = i[3]
|
||||||
@@ -273,8 +267,7 @@ class Toolbars:
|
|||||||
sortingBox.addItems(sorting_choices)
|
sortingBox.addItems(sorting_choices)
|
||||||
sortingBox.setObjectName('sortingBox')
|
sortingBox.setObjectName('sortingBox')
|
||||||
sortingBox.setToolTip('Sort by')
|
sortingBox.setToolTip('Sort by')
|
||||||
sortingBox.activated.connect(
|
sortingBox.activated.connect(self.parent_window.reload_listview)
|
||||||
self.parent_window.reload_listview, sortingBox.currentIndex())
|
|
||||||
|
|
||||||
# Spacer
|
# Spacer
|
||||||
spacer = QtWidgets.QWidget()
|
spacer = QtWidgets.QWidget()
|
||||||
|
Reference in New Issue
Block a user