New module for threaded functions
This commit is contained in:
@@ -71,8 +71,8 @@ import sorter
|
|||||||
import database
|
import database
|
||||||
|
|
||||||
from resources import mainwindow
|
from resources import mainwindow
|
||||||
from widgets import LibraryToolBar, BookToolBar, Tab
|
from widgets import LibraryToolBar, BookToolBar, Tab, LibraryDelegate
|
||||||
from widgets import LibraryDelegate, BackGroundTabUpdate, BackGroundBookAddition
|
from threaded import BackGroundTabUpdate, BackGroundBookAddition
|
||||||
from library import Library
|
from library import Library
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
|
||||||
|
39
threaded.py
Normal file
39
threaded.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sorter
|
||||||
|
import database
|
||||||
|
|
||||||
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
|
class BackGroundTabUpdate(QtCore.QThread):
|
||||||
|
def __init__(self, database_path, all_metadata, parent=None):
|
||||||
|
super(BackGroundTabUpdate, self).__init__(parent)
|
||||||
|
self.database_path = database_path
|
||||||
|
self.all_metadata = all_metadata
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
hash_position_pairs = []
|
||||||
|
for i in self.all_metadata:
|
||||||
|
file_hash = i['hash']
|
||||||
|
position = i['position']
|
||||||
|
hash_position_pairs.append([file_hash, position])
|
||||||
|
|
||||||
|
database.DatabaseFunctions(
|
||||||
|
self.database_path).modify_position(hash_position_pairs)
|
||||||
|
|
||||||
|
|
||||||
|
class BackGroundBookAddition(QtCore.QThread):
|
||||||
|
def __init__(self, parent_window, file_list, database_path, parent=None):
|
||||||
|
super(BackGroundBookAddition, self).__init__(parent)
|
||||||
|
self.parent_window = parent_window
|
||||||
|
self.file_list = file_list
|
||||||
|
self.database_path = database_path
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
books = sorter.BookSorter(
|
||||||
|
self.file_list,
|
||||||
|
'addition',
|
||||||
|
self.database_path)
|
||||||
|
parsed_books = books.initiate_threads()
|
||||||
|
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
||||||
|
self.parent_window.lib_ref.generate_model('addition', parsed_books)
|
34
widgets.py
34
widgets.py
@@ -707,37 +707,3 @@ class MyAbsModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
# We're using this to be able to access the match() method
|
# We're using this to be able to access the match() method
|
||||||
super(MyAbsModel, self).__init__(parent)
|
super(MyAbsModel, self).__init__(parent)
|
||||||
|
|
||||||
|
|
||||||
class BackGroundTabUpdate(QtCore.QThread):
|
|
||||||
def __init__(self, database_path, all_metadata, parent=None):
|
|
||||||
super(BackGroundTabUpdate, self).__init__(parent)
|
|
||||||
self.database_path = database_path
|
|
||||||
self.all_metadata = all_metadata
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
hash_position_pairs = []
|
|
||||||
for i in self.all_metadata:
|
|
||||||
file_hash = i['hash']
|
|
||||||
position = i['position']
|
|
||||||
hash_position_pairs.append([file_hash, position])
|
|
||||||
|
|
||||||
database.DatabaseFunctions(
|
|
||||||
self.database_path).modify_position(hash_position_pairs)
|
|
||||||
|
|
||||||
|
|
||||||
class BackGroundBookAddition(QtCore.QThread):
|
|
||||||
def __init__(self, parent_window, file_list, database_path, parent=None):
|
|
||||||
super(BackGroundBookAddition, self).__init__(parent)
|
|
||||||
self.parent_window = parent_window
|
|
||||||
self.file_list = file_list
|
|
||||||
self.database_path = database_path
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
books = sorter.BookSorter(
|
|
||||||
self.file_list,
|
|
||||||
'addition',
|
|
||||||
self.database_path)
|
|
||||||
parsed_books = books.initiate_threads()
|
|
||||||
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
|
||||||
self.parent_window.lib_ref.generate_model('addition', parsed_books)
|
|
||||||
|
Reference in New Issue
Block a user