Skip to content

Commit 2cf3f44

Browse files
committed
Add internal ebook reader, only support .cbz/.cbr for the moment
1 parent db54f71 commit 2cf3f44

24 files changed

+861
-192
lines changed

booksTools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def insertBook(tools: dict, database: bdd.BDD, file_name_template: str, file_nam
6666
tmp_guid = uid() # assign random guid for CBZ and CBR books
6767
list_args = list() # create list argument for external command execution
6868
list_args.append(tools['7zip'][os.name]['path']) # insert executable path
69-
temp_args = tools['7zip'][os.name]['params_deflate'].split(
70-
' ') # create table of raw command arguments
69+
temp_args = tools['7zip'][os.name]['params_deflate'].split(' ') # create table of raw command arguments
7170
for var in temp_args: # parse table of raw command arguments
7271
# insert parsed param
7372
list_args.append(var.replace('%input%', file).replace('%output%', tmpdir))
@@ -116,8 +115,7 @@ def insertBook(tools: dict, database: bdd.BDD, file_name_template: str, file_nam
116115
tmp_guid = uid() # assign random guid for CBZ and CBR books
117116
list_args = list() # create list argument for external command execution
118117
list_args.append(tools['7zip'][os.name]['path']) # insert executable path
119-
temp_args = tools['7zip'][os.name]['params_deflate'].split(
120-
' ') # create table of raw command arguments
118+
temp_args = tools['7zip'][os.name]['params_deflate'].split(' ') # create table of raw command arguments
121119
for var in temp_args: # parse table of raw command arguments
122120
# insert parsed param
123121
list_args.append(var.replace('%input%', file).replace('%output%', tmpdir))

common.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import uuid
22
import os
3+
import shutil
4+
import re
35
import time
46
import datetime
57
import enum
@@ -71,22 +73,6 @@ def uid():
7173
return uuid.uuid1().urn.replace('urn:uuid:', '')
7274

7375

74-
def listDir(dirName):
75-
"""
76-
Recursive function for listing files in a folder and his sub folders
77-
78-
:param dirName: path of the parsed dir
79-
:return: list(str)
80-
"""
81-
listOfFile = os.listdir(dirName)
82-
allFiles = list()
83-
for entry in listOfFile:
84-
fullPath = os.path.join(dirName, entry)
85-
if os.path.isdir(fullPath): allFiles = allFiles + listDir(fullPath)
86-
else: allFiles.append(fullPath)
87-
return allFiles
88-
89-
9076
def unixtimeToString(value: float, template: str = '%Y-%m-%d %H:%M:%S', months: list = list()):
9177
"""
9278
translate unix timestamp into human readable string
@@ -103,6 +89,26 @@ def unixtimeToString(value: float, template: str = '%Y-%m-%d %H:%M:%S', months:
10389
return datetime.datetime.utcfromtimestamp(value).strftime(template)
10490

10591

92+
def listDir(dirName: str, ext: str = None):
93+
"""
94+
Recursive function for listing files in a folder and his sub folders
95+
96+
:param dirName: path of the parsed dir
97+
:return: list(str)
98+
"""
99+
listOfFile = os.listdir(dirName)
100+
allFiles = list()
101+
for entry in listOfFile:
102+
fullPath = os.path.join(dirName, entry)
103+
if ext is not None and os.path.isfile(fullPath):
104+
if re.search("\\.({})$".format(ext), entry) is None: continue
105+
if os.path.isdir(fullPath):
106+
allFiles = allFiles + listDir(fullPath, ext)
107+
else:
108+
allFiles.append(fullPath)
109+
return allFiles
110+
111+
106112
def cleanDir(src_dir: str):
107113
for dirpath, _, _ in os.walk(src_dir, topdown=False): # Listing the files
108114
if dirpath == src_dir: break
@@ -111,6 +117,11 @@ def cleanDir(src_dir: str):
111117
except Exception:
112118
{}
113119

120+
121+
def rmDir(src_dir: str):
122+
shutil.rmtree(src_dir, ignore_errors=True)
123+
124+
114125
def cleanStringForUrl(string: str):
115126
return string\
116127
.replace(':', '_')\

dialog.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from PyQt5 import QtCore, QtGui, QtWidgets
2+
from lang import *
3+
4+
dialogStyle = """
5+
QMessageBox { background-color: rgb(62, 62, 62); color: rgb(255, 255, 255); }
6+
QWidget{ background-color: rgb(62, 62, 62); color: rgb(255, 255, 255); }
7+
QPushButton{ height:30px; }
8+
"""
9+
dialogStyleBtnGeneric = 'background-color: rgb(90, 90, 90); color: rgb(255, 255, 255);'
10+
dialogStyleBtnRed = 'background-color: rgb(234, 86, 86); color: rgb(255, 255, 255);'
11+
dialogStyleBtnGreen = 'background-color: rgb(0, 153, 15); color: rgb(255, 255, 255);'
12+
13+
14+
def InfoDialog(title: str, text: str, parent: any = None):
15+
lang = Lang()
16+
msgBox = QtWidgets.QMessageBox(parent)
17+
msgBox.setStyleSheet(dialogStyle)
18+
msgBox.setWindowTitle(title)
19+
msgBox.setText(text)
20+
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
21+
msgBox.button(QtWidgets.QMessageBox.Ok).setText(lang['Generic']['DialogBtnOk'])
22+
msgBox.button(QtWidgets.QMessageBox.Ok).setStyleSheet(dialogStyleBtnGeneric)
23+
msgBox.button(QtWidgets.QMessageBox.Ok).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
24+
msgBox.setDefaultButton(QtWidgets.QMessageBox.Ok)
25+
msgBox.setIcon(QtWidgets.QMessageBox.Information)
26+
ret = msgBox.exec()
27+
28+
29+
def InfoDialogConfirm(title: str, text: str, yes: str, no: str, parent: any = None):
30+
msgBox = QtWidgets.QMessageBox(parent)
31+
msgBox.setStyleSheet(dialogStyle)
32+
msgBox.setWindowTitle(title)
33+
msgBox.setText(text)
34+
msgBox.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
35+
msgBox.button(QtWidgets.QMessageBox.Yes).setText(yes)
36+
msgBox.button(QtWidgets.QMessageBox.Yes).setStyleSheet(dialogStyleBtnGreen)
37+
msgBox.button(QtWidgets.QMessageBox.Yes).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
38+
msgBox.button(QtWidgets.QMessageBox.No).setText(no)
39+
msgBox.button(QtWidgets.QMessageBox.No).setStyleSheet(dialogStyleBtnRed)
40+
msgBox.button(QtWidgets.QMessageBox.No).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
41+
msgBox.setDefaultButton(QtWidgets.QMessageBox.No)
42+
msgBox.setIcon(QtWidgets.QMessageBox.Information)
43+
ret = msgBox.exec()
44+
if ret == QtWidgets.QMessageBox.Yes: return True
45+
else: return False
46+
47+
48+
def WarnDialog(title: str, text: str, parent: any = None):
49+
lang = Lang()
50+
msgBox = QtWidgets.QMessageBox(parent)
51+
msgBox.setStyleSheet(dialogStyle)
52+
msgBox.setWindowTitle(title)
53+
msgBox.setText(text)
54+
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
55+
msgBox.button(QtWidgets.QMessageBox.Ok).setText(lang['Generic']['DialogBtnOk'])
56+
msgBox.button(QtWidgets.QMessageBox.Ok).setStyleSheet(dialogStyleBtnGeneric)
57+
msgBox.button(QtWidgets.QMessageBox.Ok).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
58+
msgBox.setDefaultButton(QtWidgets.QMessageBox.Ok)
59+
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
60+
ret = msgBox.exec()
61+
62+
63+
def WarnDialogConfirm(title: str, text: str, yes: str, no: str, parent: any = None):
64+
msgBox = QtWidgets.QMessageBox(parent)
65+
msgBox.setStyleSheet(dialogStyle)
66+
msgBox.setWindowTitle(title)
67+
msgBox.setText(text)
68+
msgBox.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
69+
msgBox.button(QtWidgets.QMessageBox.Yes).setText(yes)
70+
msgBox.button(QtWidgets.QMessageBox.Yes).setStyleSheet(dialogStyleBtnRed)
71+
msgBox.button(QtWidgets.QMessageBox.Yes).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
72+
msgBox.button(QtWidgets.QMessageBox.No).setText(no)
73+
msgBox.button(QtWidgets.QMessageBox.No).setStyleSheet(dialogStyleBtnGreen)
74+
msgBox.button(QtWidgets.QMessageBox.No).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
75+
msgBox.setDefaultButton(QtWidgets.QMessageBox.No)
76+
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
77+
ret = msgBox.exec()
78+
if ret == QtWidgets.QMessageBox.Yes: return True
79+
else: return False
80+

home/CentralBlockTable.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ def CentralBlockTableCellDoubleClicked(self, currentRow, currentColumn):
126126
# print("Book GUID : {}".format(guid_book))
127127
if self.currentBook != guid_book:
128128
self.currentBook = guid_book
129-
file = '"' + self.BDD.getBooks(guid_book)[0]['files'][0]['link'] + '"'
130-
print(file)
131-
try: retcode = subprocess.call(file, shell=True)
129+
args = list()
130+
if self.BDD.getBooks(guid_book)[0]['files'][0]['format'] in ['CBZ', 'CBR']:
131+
args.append('python')
132+
args.append(self.appDir + '/reader/main.py'.replace('/', os.sep))
133+
args.append(self.appDir + os.sep + self.BDD.getBooks(guid_book)[0]['files'][0]['link'].replace('/', os.sep))
134+
else:
135+
args.append(self.BDD.getBooks(guid_book)[0]['files'][0]['link'])
136+
print(args)
137+
try: retcode = subprocess.call(args, shell=True)
132138
except Exception:
133139
traceback.print_exc()
134140

home/home.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
1717
from common import *
18+
from dialog import *
1819
from lang import *
1920
from booksTools import *
2021
import bdd
@@ -100,34 +101,15 @@ def HeaderBlockBtnDelBookClicked(self):
100101
try:
101102
print("Bouton Delete book clické")
102103
if len(self.CentralBlockTable.selectedItems()) > 0:
103-
msgBox = QtWidgets.QMessageBox()
104-
msgBox.setStyleSheet("""
105-
QMessageBox {
106-
background-color: rgb(62, 62, 62); color: rgb(255, 255, 255);
107-
/*
108-
dialogbuttonbox-buttons-have-icons: true;
109-
dialog-ok-icon: url(ok.svg);
110-
dialog-cancel-icon: url(cancel.png),
111-
url(grayed_cancel.png) disabled;
112-
*/
113-
dialog-ok-background:rgb(234, 86, 86);
114-
}
115-
QWidget{ background-color: rgb(62, 62, 62); color: rgb(255, 255, 255); }
116-
QPushButton{ height:30px; }
117-
""")
118-
msgBox.setWindowTitle(self.lang['Home']['DialogConfirmDeleteBookWindowTitle'])
119-
msgBox.setText(self.lang['Home']['DialogConfirmDeleteBookWindowText'])
120-
msgBox.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
121-
msgBox.button(QtWidgets.QMessageBox.Yes).setText(self.lang['Home']['DialogConfirmDeleteBookBtnYes'])
122-
msgBox.button(QtWidgets.QMessageBox.Yes).setStyleSheet('background-color: rgb(234, 86, 86); color: rgb(255, 255, 255);')
123-
msgBox.button(QtWidgets.QMessageBox.Yes).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
124-
msgBox.button(QtWidgets.QMessageBox.No).setText(self.lang['Home']['DialogConfirmDeleteBookBtnNo'])
125-
msgBox.button(QtWidgets.QMessageBox.No).setStyleSheet('background-color: rgb(0, 153, 15); color: rgb(255, 255, 255);')
126-
msgBox.button(QtWidgets.QMessageBox.No).setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
127-
msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel)
128-
msgBox.setIcon(QMessageBox.Warning)
129-
ret = msgBox.exec()
130-
if ret == QtWidgets.QMessageBox.Yes:
104+
ret = WarnDialogConfirm(
105+
self.lang['Home']['DialogConfirmDeleteBookWindowTitle'],
106+
self.lang['Home']['DialogConfirmDeleteBookWindowText'],
107+
self.lang['Home']['DialogConfirmDeleteBookBtnYes'],
108+
self.lang['Home']['DialogConfirmDeleteBookBtnNo'],
109+
self
110+
)
111+
112+
if ret is True:
131113
items = self.CentralBlockTable.selectedItems()
132114
self.CentralBlockTable.clearSelection()
133115
for item in items:

icons/black/content_table.png

9.85 KB
Loading

icons/black/full_screen.png

10.7 KB
Loading

icons/black/info.png

19.5 KB
Loading

icons/black/light_warning.png

19.5 KB
Loading

icons/black/normal_screen.png

11.2 KB
Loading

0 commit comments

Comments
 (0)