-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoPanel.py
282 lines (248 loc) · 12.4 KB
/
InfoPanel.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import os, sys, re
import base64
import traceback
import urllib.parse
import PyQt5.QtCore
import PyQt5.QtGui
import PyQt5.QtWidgets
from common.common import *
from common.vars import *
from common.dialog import *
class HomeWindowInfoPanel:
current_book = None
info_panel_current_link = None
info_panel_link_last_sender = None
info_panel_current_nb_files = None
info_panel_link_context_menu_open = False
info_panel_initialized = False
def init_info_panel(self):
self.info_block_file_formats_value.setOpenExternalLinks(True)
self.info_block_file_formats_value.setContextMenuPolicy(PyQt5.QtCore.Qt.CustomContextMenu)
self.info_block_file_formats_value.linkHovered.connect(self.info_panel_link_hover)
self.info_block_file_formats_value.customContextMenuRequested.connect(self.info_panel_link_context_menu)
self.info_panel_initialized = True
def set_info_panel(self, book: dict = None):
"""
Insert into the info pannel the details values of the book
:param book: dict of the spécified book
:return: void
"""
if self.info_panel_initialized is False:
self.init_info_panel()
# print(book)
passed = True
if book is None:
passed = False
else:
if not is_in(book, ['title', 'series', 'authors', 'files']):
passed = False
if passed is True:
try:
boldind_list = [
self.info_block_title_label,
self.info_block_serie_label,
self.info_block_authors_label,
self.info_block_file_formats_label,
self.info_block_size_label
]
for elm in boldind_list:
elm.setProperty('bold', True)
elm.style().unpolish(elm)
elm.style().polish(elm)
self.current_book = book['guid']
self.info_block_title_value.setText(book['title'])
self.info_block_serie_value.setText(book['series'])
self.info_block_authors_value.setText(book['authors'])
# info_block_synopsis
self.metadata_window_clear_layout(self.info_block_synopsis.layout())
if book['synopsis'] is not None and book['synopsis'].strip() != "":
la0 = QtWidgets.QLabel('Synopsis')
la0.setProperty('bold', True)
self.info_block_synopsis.layout().addWidget(la0)
spacer1 = QtWidgets.QSpacerItem(10, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.info_block_synopsis.layout().addItem(spacer1)
la1 = QtWidgets.QLabel(book['synopsis'])
la1.setWordWrap(True)
la1.setMargin(5)
scl = QtWidgets.QScrollArea()
scl.setLayout(QtWidgets.QVBoxLayout())
scl.setVerticalScrollBar(QtWidgets.QScrollBar(PyQt5.QtCore.Qt.Vertical))
# scl.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)
scl.setVerticalScrollBarPolicy(PyQt5.QtCore.Qt.ScrollBarAsNeeded)
scl.setHorizontalScrollBarPolicy(PyQt5.QtCore.Qt.ScrollBarAlwaysOff)
scl.setWidgetResizable(True)
scl.setWidget(la1)
self.info_block_synopsis.layout().addWidget(scl)
else:
spacer1 = QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.info_block_synopsis.layout().addItem(spacer1)
formats = ''
sizes = ''
self.info_panel_current_nb_files = len(book['files'])
for file in book['files']:
if formats != '':
formats += ' / '
sizes += ' / '
link = file['link']
if re.search("^data/", link):
link = 'file:///' + self.app_directory.replace(os.sep, '/') + '/' + link
# link = self.app_directory.replace(os.sep, '/') + '/' + link
# elif re.search("^(http|https)://", link): {}
else:
link = 'file:///' + link.replace(os.sep, '/')
link = link.replace(' ', '%20')
# HomeLinkColor
self.style = self.BDD.get_param('style')
formats += '<a href="' + link + '" style="color: '
formats += get_style_var(self.style, 'HomeLinkColor')+';">' + file['format'] + '</a>'
sizes += file['size']
self.info_block_file_formats_value.setProperty('book_id', self.current_book)
self.info_block_file_formats_value.setText(formats)
self.info_block_size_value.setText(sizes)
except Exception:
traceback.print_exc()
try:
icon = PyQt5.QtGui.QIcon()
tbimg = book['cover'].split(',', 1)
by = PyQt5.QtCore.QByteArray()
by.fromBase64(tbimg[1].encode('utf-8'))
image = PyQt5.QtGui.QPixmap()
image.loadFromData(base64.b64decode(tbimg[1]))
"""
if tbimg[0] == 'data:image/jpeg;base64':
image.loadFromData(by, "JPG")
if tbimg[0] == 'data:image/png;base64':
image.loadFromData(by, "PNG")
"""
icon.addPixmap(image, PyQt5.QtGui.QIcon.Normal, PyQt5.QtGui.QIcon.Off)
self.info_block_cover.setIcon(icon)
self.info_block_cover.setIconSize(PyQt5.QtCore.QSize(160, 160))
self.info_block_cover.setToolTip("<img src='{}'/>".format(book['cover']))
except Exception as err:
# traceback.print_exc()
icon = PyQt5.QtGui.QIcon()
icon.addPixmap(PyQt5.QtGui.QPixmap(self.app_directory + '/ressources/icons/white/book.png'), PyQt5.QtGui.QIcon.Normal, PyQt5.QtGui.QIcon.Off)
self.info_block_cover.setIcon(icon)
self.info_block_cover.setIconSize(PyQt5.QtCore.QSize(130, 130))
else:
self.info_block_title_value.setText("")
self.info_block_serie_value.setText("")
self.info_block_authors_value.setText("")
self.info_block_file_formats_value.setText("")
self.info_block_size_value.setText("")
icon = PyQt5.QtGui.QIcon()
icon.addPixmap(PyQt5.QtGui.QPixmap(self.app_directory+'/icons/white/book.png'), PyQt5.QtGui.QIcon.Normal, PyQt5.QtGui.QIcon.Off)
self.info_block_cover.setIcon(icon)
self.info_block_cover.setIconSize(PyQt5.QtCore.QSize(130, 130))
def info_panel_link_hover(self, link: str):
if link is None or link.strip() == '':
return
self.info_panel_current_link = urllib.parse.unquote(link).replace('/', os.sep)
def info_panel_link_context_menu(self):
if self.info_panel_link_context_menu_open is True:
return
self.info_panel_link_context_menu_open = True
try:
if self.info_panel_current_link is None or self.info_panel_current_link.strip() == '':
return
menu = PyQt5.QtWidgets.QMenu(self.info_block_file_formats_value)
action0 = PyQt5.QtWidgets.QAction(self.lang['Library/InfoBlockLinkContestMenu/open'], None)
action0.triggered.connect(self.info_panel_link_open)
menu.addAction(action0)
if self.info_panel_current_link.lower().endswith(('.epub', '.epub2', '.epub3')):
action1 = PyQt5.QtWidgets.QAction(self.lang['Library/InfoBlockLinkContestMenu/edit'], None)
action1.triggered.connect(self.info_panel_link_edit)
menu.addAction(action1)
if self.info_panel_current_nb_files > 1:
action2 = PyQt5.QtWidgets.QAction(self.lang['Library/InfoBlockLinkContestMenu/delete'], None)
action2.triggered.connect(self.info_panel_link_delete_file)
menu.addAction(action2)
else:
action2 = PyQt5.QtWidgets.QAction(self.lang['Library/InfoBlockLinkContestMenu/deleteBook'], None)
action2.triggered.connect(self.info_panel_link_delete_book)
menu.addAction(action2)
ext = self.info_panel_current_link[self.info_panel_current_link.rindex('.')+1:].upper()
print('ext=', ext)
plugs = common.vars.get_plugins('library', 'contextMenu', None, ext)
for plug in plugs:
lg = self.lang.test_lang()
tx = None
for label in plug['interface']['label']:
if label['lang'] == self.lang.default_language and tx is None:
tx = label['content']
if label['lang'] == lg:
tx = label['content']
action3 = PyQt5.QtWidgets.QAction(tx, None)
action3.setProperty('plugin', plug['name'])
action3.setProperty('book_id', self.current_book)
tt = [plug['archetype']]
try:
tt = plug['archetype'].split(':')
except Exception:
pass
action3.setProperty('archetype', tt[0])
if tt[0] == 'conversion':
tt2 = ['.', 'conv']
try:
tt2 = tt[1].split('-')
action3.setProperty('end_format', tt2[1])
except Exception:
action3.setProperty('end_format', 'CONV')
pf = self.info_panel_current_link.replace('/', os.sep)
rp = pf.rindex('.')
action3.setProperty('args', {
'input': pf,
'output': os.path.dirname(os.path.realpath(pf)),
'output2': pf[:rp]
})
else:
action3.setProperty('args', {})
# plugin_exec(executor_dir, {'input': executor_file, 'output': executor_file2})
action3.triggered.connect(self.context_menu_plugin_exec)
menu.addAction(action3)
menu.exec_(PyQt5.QtGui.QCursor.pos())
except Exception:
traceback.print_exc()
self.info_panel_link_context_menu_open = False
def info_panel_link_open(self):
cmd = '"'+self.info_panel_current_link+'"'
print(cmd)
os.system(cmd)
def info_panel_link_edit(self):
args = list()
exe = app_directory + '/editor.exe'.replace('/', os.sep)
if os.path.isfile(exe):
args.append(app_directory + '/editor.exe'.replace('/', os.sep))
args.append(self.info_panel_current_link)
args.append('debug')
else:
args.append('python')
args.append(app_directory + '/editor/editor.py'.replace('/', os.sep))
args.append(self.info_panel_current_link)
args.append('debug')
try:
return_code = subprocess.call(args, shell=True)
except Exception:
traceback.print_exc()
def info_panel_link_delete_file(self):
ret = WarnDialogConfirm(
self.lang['Library']['DialogConfirmDeleteBookWindowTitle2'],
self.lang['Library']['DialogConfirmDeleteBookWindowText2'],
self.lang['Library']['DialogConfirmDeleteBookBtnYes'],
self.lang['Library']['DialogConfirmDeleteBookBtnNo'],
self
)
if ret is True:
self.BDD.delete_book(None, self.info_panel_current_link)
self.set_info_panel(self.BDD.get_books(self.current_book)[0])
def info_panel_link_delete_book(self):
ret = WarnDialogConfirm(
self.lang['Library']['DialogConfirmDeleteBookWindowTitle'],
self.lang['Library']['DialogConfirmDeleteBookWindowText'],
self.lang['Library']['DialogConfirmDeleteBookBtnYes'],
self.lang['Library']['DialogConfirmDeleteBookBtnNo'],
self
)
if ret is True:
self.BDD.delete_book(self.current_book)
self.load_books(self.BDD.get_books())