Skip to content

Commit b32fee5

Browse files
committed
- Editor Nearly finished(image and link injector HS)
- Reader interface changed and optimized, information panel implemented
1 parent e2cd3bb commit b32fee5

21 files changed

+757
-525
lines changed

common/bdd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def get_books(self, guid: str = None, search: str = None):
173173
self.cursor.execute("SELECT * FROM books LEFT JOIN files ON(files.book_id = books.guid) "
174174
"WHERE " + tab[0] + " = '" + tab[1] + "'")
175175
ret = self.cursor.fetchall()
176+
elif re.search("^file:", search):
177+
file = search.replace('file:', '')
178+
self.cursor.execute("SELECT * FROM books JOIN files ON(files.book_id = books.guid) "
179+
"WHERE files.link = '" + file + "'")
180+
ret = self.cursor.fetchall()
176181
if ret is not None:
177182
prev_guid = ''
178183
for row in ret:

common/books.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def create_epub(title: str, authors: str = None, series: str = None, volume_numb
302302
return None
303303

304304

305-
def get_epub_info(path: str):
305+
def get_epub_info(path: str, clean: bool = False) -> dict or None:
306306
ret = {
307307
'guid': None,
308308
'title': None,
@@ -315,6 +315,28 @@ def get_epub_info(path: str):
315315
}
316316
try:
317317
if os.path.isfile(path) is True:
318+
if clean is False:
319+
_, ext = os.path.splitext(path)
320+
dir_path = os.path.dirname(os.path.realpath(path))
321+
file_short = path.replace(dir_path + os.sep, '')
322+
print('file_short=', file_short)
323+
BDD = bdd.BDD()
324+
template_file = BDD.get_param('import_file_template')
325+
separator_file = BDD.get_param('import_file_separator')
326+
tmp_tab_file = file_short.replace(separator_file, ' - ').replace(ext, '').split(' - ')
327+
tmp_tab_template = template_file.split(' - ')
328+
for index in range(0, len(tmp_tab_template)):
329+
if index >= len(tmp_tab_file):
330+
break
331+
if tmp_tab_template[index] == '%series%':
332+
ret['series'] = '??<' + tmp_tab_file[index] + '>??'
333+
if tmp_tab_template[index] == '%title%':
334+
ret['title'] = '??<' + tmp_tab_file[index] + '>??'
335+
if tmp_tab_template[index] == '%authors%':
336+
ret['authors'] = '??<' + tmp_tab_file[index] + '>??'
337+
if tmp_tab_template[index] == '%tags%':
338+
ret['tags'] = tmp_tab_file[index].split(',')
339+
318340
myzip = zipfile.ZipFile(path, 'r')
319341

320342
myfile = myzip.open('META-INF/container.xml')

common/files.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_file_size(file_name: str, human_readable: bool = True):
2727
return '{} bytes'.format(size)
2828

2929

30-
def get_file_type(file_path: str) -> str:
30+
def get_file_type(file_path: str, return_extension: bool = False) -> str or (str, str):
3131
file_path = file_path.replace('/', os.sep)
3232
file_tab = file_path.split(os.sep)
3333
ext = file_tab[len(file_tab) - 1]
@@ -44,8 +44,10 @@ def get_file_type(file_path: str) -> str:
4444
except Exception:
4545
end = True
4646
file_type = "application/octet-stream"
47-
48-
return file_type
47+
if return_extension is True:
48+
return file_type, ext
49+
else:
50+
return file_type
4951

5052

5153
def list_directory(directory_path: str, expected_extension: str = None):

editor/editing_pane.py

Lines changed: 108 additions & 92 deletions
Large diffs are not rendered by default.

editor/syntaxHighlight.py

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
import sys, os
12
from PyQt5.QtGui import *
23
from PyQt5.Qsci import *
34

45

56
class SimplePythonEditor(QsciScintilla):
67
ARROW_MARKER_NUM = 8
78

8-
def __init__(self, lexer_type, parent=None):
9+
def __init__(self, lexer_type, parent=None, style_data: dict = None):
910
super(SimplePythonEditor, self).__init__(parent)
1011

1112
# Set the default font
12-
font = QFont()
13-
font.setFamily('Courier')
13+
font = None
14+
font_family = 'Courier'
15+
font_id = None
16+
if style_data is not None:
17+
try:
18+
font_id = QFontDatabase.addApplicationFont(style_data['EditorQsciFont'].replace('/', os.sep))
19+
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
20+
except Exception:
21+
""
22+
font = QFont(font_family)
1423
font.setFixedPitch(True)
1524
font.setPointSize(10)
1625
self.setFont(font)
@@ -21,17 +30,11 @@ def __init__(self, lexer_type, parent=None):
2130
self.setMarginsFont(font)
2231
self.setMarginWidth(0, fontmetrics.width("00000") + 6)
2332
self.setMarginLineNumbers(0, True)
24-
self.setMarginsBackgroundColor(QColor("#cccccc"))
2533

2634
# Clickable margin 1 for showing markers
2735
self.setMarginSensitivity(1, True)
28-
# self.connect(self,
29-
# SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
30-
# self.on_margin_clicked)
3136
self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)
32-
self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
3337
self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
34-
self.setFoldMarginColors(QColor("#cccccc"), QColor("#333333"))
3538

3639
# Brace matching: enable for a brace immediately before or after
3740
# the current position
@@ -40,21 +43,64 @@ def __init__(self, lexer_type, parent=None):
4043

4144
# Current line visible with special background color
4245
self.setCaretLineVisible(True)
43-
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
44-
45-
# Set Python lexer
46-
# Set style for Python comments (style number 1) to a fixed-width
47-
# courier.
48-
#
4946

5047
if lexer_type is not None:
5148
self.elexer = lexer_type
49+
self.elexer.setFont(font)
5250
self.elexer.setDefaultFont(font)
5351
self.setLexer(self.elexer)
5452
else:
5553
self.elexer = None
5654

57-
text = bytearray(str.encode("Arial"))
55+
style_ok = False
56+
if style_data is not None:
57+
try:
58+
self.setMarginsBackgroundColor(QColor(style_data['EditorQsciMarginsBackgroundColor']))
59+
self.setMarginsForegroundColor(QColor(style_data['EditorQsciMarginsForegroundColor']))
60+
self.setMarkerBackgroundColor(QColor(style_data['EditorQsciMarkerBackgroundColor']), self.ARROW_MARKER_NUM)
61+
self.setFoldMarginColors(
62+
QColor(style_data['EditorQsciFoldMarginColor1']),
63+
QColor(style_data['EditorQsciFoldMarginColor2'])
64+
)
65+
self.setCaretLineBackgroundColor(style_data['EditorQsciCaretLineBackgroundColor'])
66+
67+
self.setColor(QColor(style_data['EditorQsciDefaultTextColor']))
68+
self.setPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))
69+
70+
if self.elexer is not None:
71+
self.elexer.setDefaultColor(QColor(style_data['EditorQsciDefaultTextColor']))
72+
self.elexer.setDefaultPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))
73+
self.elexer.setPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))
74+
75+
if isinstance(lexer_type, QsciLexerXML) is True:
76+
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTextColor']), QsciLexerXML.Default)
77+
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTagColor']), QsciLexerXML.Tag)
78+
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTagColor']), QsciLexerXML.UnknownTag)
79+
80+
style_ok = True
81+
except Exception:
82+
""
83+
if style_ok is False:
84+
self.setMarginsBackgroundColor(QColor("#333333"))
85+
self.setMarginsForegroundColor(QColor("#ffffff"))
86+
self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
87+
self.setFoldMarginColors(QColor("#cccccc"), QColor("#333333"))
88+
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
89+
90+
self.setColor(QColor("#ffffff"))
91+
self.setPaper(QColor("#A6A6A6"))
92+
93+
if self.elexer is not None:
94+
self.elexer.setDefaultPaper(QColor("#A6A6A6"))
95+
self.elexer.setDefaultColor(QColor("#ffffff"))
96+
self.elexer.setPaper(QColor("#A6A6A6"))
97+
98+
if isinstance(lexer_type, QsciLexerXML) is True:
99+
self.elexer.setColor(QColor.fromRgb(255, 255, 255), QsciLexerXML.Default)
100+
self.elexer.setColor(QColor('#000080'), QsciLexerXML.Tag)
101+
self.elexer.setColor(QColor('#000080'), QsciLexerXML.UnknownTag)
102+
103+
text = bytearray(str.encode(font_family))
58104
# 32, "Courier New"
59105
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text)
60106

0 commit comments

Comments
 (0)