1
1
import os , sys , traceback , json , subprocess
2
+ import concurrent .futures
3
+ import PyQt5 .QtCore
4
+ import PyQt5 .QtGui
5
+ import PyQt5 .QtWidgets
2
6
from common .files import *
3
7
from common .common import *
4
8
import SortingBlockTree
5
9
import settings
6
10
import InfoPanel
7
11
12
+ executor = concurrent .futures .ThreadPoolExecutor (max_workers = 50 )
13
+ executor_dir = ''
14
+ executor_file = ''
15
+
16
+
17
+ def wait_on_editor ():
18
+ global executor_dir , executor_file
19
+ args = list ()
20
+ exe = executor_dir + '/editor.exe' .replace ('/' , os .sep )
21
+ if os .path .isfile (exe ):
22
+ if os .name == 'nt' :
23
+ args .append ('start' )
24
+ args .append (executor_dir + '/editor.exe' .replace ('/' , os .sep ))
25
+ args .append (executor_file .replace ('/' , os .sep ))
26
+ # args.append('debug')
27
+ else :
28
+ if os .name == 'nt' :
29
+ args .append ('start' )
30
+ args .append ('python' )
31
+ args .append (executor_dir + '/editor/editor.py' .replace ('/' , os .sep ))
32
+ args .append (executor_file .replace ('/' , os .sep ))
33
+ args .append ('debug' )
34
+
35
+ try :
36
+ return_code = subprocess .call (args , shell = True )
37
+ except Exception :
38
+ traceback .print_exc ()
39
+
40
+
41
+ def wait_on_reader ():
42
+ global executor_dir , executor_file
43
+ args = list ()
44
+ exe = executor_dir + '/reader.exe' .replace ('/' , os .sep )
45
+ if os .path .isfile (exe ):
46
+ if os .name == 'nt' :
47
+ args .append ('start' )
48
+ args .append (executor_dir + '/reader.exe' .replace ('/' , os .sep ))
49
+ args .append (executor_file .replace ('/' , os .sep ))
50
+ # args.append('debug')
51
+ else :
52
+ # if os.name == 'nt':
53
+ # args.append('start')
54
+ args .append ('python' )
55
+ args .append (executor_dir + '/reader/reader.py' .replace ('/' , os .sep ))
56
+ args .append (executor_file .replace ('/' , os .sep ))
57
+ args .append ('debug' )
58
+
59
+ try :
60
+ return_code = subprocess .call (args , shell = True )
61
+ except Exception :
62
+ traceback .print_exc ()
63
+
64
+
65
+ def wait_on_open_ext ():
66
+ global executor_file
67
+ args = list ()
68
+ args .append ('start' )
69
+ args .append (executor_file .replace ('/' , os .sep ))
70
+
71
+ try :
72
+ return_code = subprocess .call (args , shell = True )
73
+ except Exception :
74
+ traceback .print_exc ()
75
+
8
76
9
77
class HomeWindowCentralBlock (InfoPanel .HomeWindowInfoPanel ):
10
78
central_block_table_cases_uid_list = []
@@ -24,6 +92,8 @@ def central_block_table_define_slots(self):
24
92
:return:
25
93
"""
26
94
self .central_block_table .currentCellChanged .connect (self .central_block_table_new_selection )
95
+ self .central_block_table .setContextMenuPolicy (PyQt5 .QtCore .Qt .CustomContextMenu )
96
+ self .central_block_table .customContextMenuRequested .connect (self .central_block_table_context_menu )
27
97
self .central_block_table .itemChanged .connect (self .central_block_table_item_changed )
28
98
self .central_block_table .cellDoubleClicked .connect (self .central_block_table_cell_double_clicked )
29
99
self .central_block_table .horizontalHeader ().sortIndicatorChanged .connect (self .central_block_table_sort_indicator_changed )
@@ -144,32 +214,22 @@ def central_block_table_cell_double_clicked(self, current_row, current_column):
144
214
:param current_column:
145
215
:return: void
146
216
"""
217
+ global executor_dir , executor_file
147
218
# print("--------------------------------")
148
219
# print("central_block_table_cell_double_clicked")
149
220
item = self .central_block_table .item (current_row , current_column )
150
221
guid_book = item .data (99 )
151
222
# print("Book GUID : {}".format(guid_book))
152
223
if self .currentBook != guid_book :
153
224
self .currentBook = guid_book
154
- args = list ()
155
- if self .BDD .get_books (guid_book )[0 ]['files' ][0 ]['format' ] in ['CBZ' , 'CBR' , 'EPUB' ]:
156
- exe = self .app_directory + '/reader.exe' .replace ('/' , os .sep )
157
- if os .path .isfile (exe ):
158
- args .append (self .app_directory + '/reader.exe' .replace ('/' , os .sep ))
159
- args .append (self .BDD .get_books (guid_book )[0 ]['files' ][0 ]['link' ].replace ('/' , os .sep ))
160
- args .append ('debug' )
161
- else :
162
- args .append ('python' )
163
- args .append (self .app_directory + '/reader/reader.py' .replace ('/' , os .sep ))
164
- args .append (self .BDD .get_books (guid_book )[0 ]['files' ][0 ]['link' ].replace ('/' , os .sep ))
165
- args .append ('debug' )
225
+ files = self .BDD .get_books (guid_book )[0 ]['files' ]
226
+ if files [0 ]['format' ] in ['CBZ' , 'CBR' , 'EPUB' ]:
227
+ executor_dir = self .app_directory
228
+ executor_file = files [0 ]['link' ]
229
+ executor .submit (wait_on_reader )
166
230
else :
167
- args .append (self .BDD .get_books (guid_book )[0 ]['files' ][0 ]['link' ])
168
- print (args )
169
- try :
170
- return_code = subprocess .call (args , shell = True )
171
- except Exception :
172
- traceback .print_exc ()
231
+ executor_file = files [0 ]['link' ]
232
+ executor .submit (wait_on_open_ext )
173
233
174
234
def central_block_table_item_changed (self , new_item ):
175
235
"""
@@ -218,6 +278,29 @@ def central_block_table_item_changed(self, new_item):
218
278
except Exception :
219
279
traceback .print_exc ()
220
280
281
+ def central_block_table_context_menu (self , point : PyQt5 .QtCore .QPoint ):
282
+ global executor_dir , executor_file
283
+ try :
284
+ current_row = self .central_block_table .currentRow ()
285
+ current_column = self .central_block_table .currentColumn ()
286
+ guid_book = self .central_block_table .item (current_row , current_column ).data (99 )
287
+ book_infos = self .BDD .get_books (guid_book )[0 ]
288
+ menu = PyQt5 .QtWidgets .QMenu ()
289
+ action0 = PyQt5 .QtWidgets .QAction (self .lang ['Library/CentralBlockTableContextMenu/EditMetadata' ], None )
290
+ action0 .triggered .connect (lambda : print ("Edit Metadata!" ))
291
+ menu .addAction (action0 )
292
+ for file in book_infos ['files' ]:
293
+ if file ['format' ] == 'EPUB' :
294
+ executor_dir = self .app_directory
295
+ executor_file = file ['link' ]
296
+ action1 = PyQt5 .QtWidgets .QAction (self .lang ['Library/CentralBlockTableContextMenu/EditBook' ], None )
297
+ action1 .triggered .connect (lambda : executor .submit (wait_on_editor ))
298
+ menu .addAction (action1 )
299
+ menu .exec (PyQt5 .QtGui .QCursor .pos ())
300
+
301
+ except Exception :
302
+ traceback .print_exc ()
303
+
221
304
@staticmethod
222
305
def new_book_table_item (guid : str , book_type : str , value : str , editable : bool = True , alt : any = None ,
223
306
alt_type : str = None , locked : bool = False ):
0 commit comments