-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
113 lines (96 loc) · 4.72 KB
/
launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os.path
import Lib
from global_imports import *
class HomeWindow(QtWidgets.QMainWindow):
def __init__(self):
super(HomeWindow, self).__init__()
self.search_thread = QtCore.QThread()
self.search_obj = None
self.actionCenterWindow = None
self.ui = Lib.home.Ui_MainWindow()
self.ui.setupUi(self)
self.thread_pool = []
self.selection = Lib.Classes.Selection()
self.ui.tableView_books.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
self.ui.tableView_books.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.ui.tableView_books.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.ui.tableView_books.installEventFilter(self)
# header = ['Book Name', 'File Path', 'Size (KB)']
self.ui.pushButton_search.clicked.connect(self.openFile)
self.ui.actionOpen_Action_Center.triggered.connect(self.openActionCenter)
def get_selected_rows(self):
selection_model = self.ui.tableView_books.selectionModel()
selected = []
if selection_model:
row_count = self.ui.tableView_books.model().rowCount()
column_count = self.ui.tableView_books.model().columnCount()
for row in range(row_count):
column_data = []
for column_index in range(column_count):
column_ = selection_model.selectedRows(column_index)
try:
column_data.append(column_[0].data(0))
except IndexError: # IndexError may occur when there is no selection
return
break # break to only get the book name (first column)
selected.append(column_data[0])
self.selection.add_to_selection(Lib.Classes.Selection(selected))
def openActionCenter(self):
self.get_selected_rows()
if not self.selection:
return
self.actionCenterWindow = Lib.ActionCenter.ActionCenter(self.selection, self.ui.lineEdit_searchhPath.text())
self.actionCenterWindow.close_signal.connect(self.close_action_window)
self.actionCenterWindow.show()
self.hide()
def close_action_window(self):
self.show()
self.actionCenterWindow.close()
def openFile(self):
searchPath = self.ui.lineEdit_searchhPath.text()
book_dir = os.path.expanduser("~/Downloads/") if not searchPath else searchPath
folderName = Lib.FileOpener.OpenDir(self, "Select Book Directory", book_dir)
if folderName:
Lib.showStatus(self, f"Opening {folderName}")
self.ui.lineEdit_searchhPath.setText(folderName)
self.searchBooks(folderName)
def searchBooks(self, path: str):
if not hasattr(self, 'search_thread'):
self.search_thread = QtCore.QThread()
self.thread_pool.append(self.search_thread)
self.search_obj = Lib.ThreadObjects.FindBooks(path)
self.search_obj.ignore = [".jpeg", '.png', '.jpg', '.html', '.txt', '.db', '.py', '.js', '.css', '.pyc']
self.search_obj.status.connect(partial(Lib.showStatus, self))
self.search_obj.close.connect(self.Disconnect_searchThread)
self.search_obj.books_found.connect(self.set_data_to_table)
self.search_obj.moveToThread(self.search_thread)
self.search_thread.started.connect(self.search_obj.search)
self.search_thread.start()
def Disconnect_searchThread(self):
while True:
try:
self.search_thread.quit()
except Exception:
pass
try:
self.search_thread.disconnect()
except TypeError:
break
def set_data_to_table(self, books: typing.List[typing.List] = ...):
model = Lib.FileShowModel(books)
self.ui.tableView_books.setModel(model)
self.ui.tableView_books.adjustSize()
self.update()
def eventFilter(self, source: 'QtCore.QObject', event: 'QtCore.QEvent'):
if source == self.ui.tableView_books and event.type() == QtCore.QEvent.Resize:
table_width = self.ui.frame.width()
self.ui.tableView_books.setColumnWidth(0, (table_width * 25 // 100))
self.ui.tableView_books.setColumnWidth(1, (table_width * 50 // 100))
self.ui.tableView_books.setColumnWidth(2, (table_width * 27 // 100))
return super(HomeWindow, self).eventFilter(source, event)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
app.setStyle('Fusion')
w = HomeWindow()
w.show()
sys.exit(app.exec())