Skip to content

Commit

Permalink
- Editor Nearly finished(image and link injector HS)
Browse files Browse the repository at this point in the history
- Reader interface changed and optimized, information panel implemented
  • Loading branch information
LordKBX committed Mar 10, 2021
1 parent e2cd3bb commit b32fee5
Show file tree
Hide file tree
Showing 21 changed files with 757 additions and 525 deletions.
5 changes: 5 additions & 0 deletions common/bdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ def get_books(self, guid: str = None, search: str = None):
self.cursor.execute("SELECT * FROM books LEFT JOIN files ON(files.book_id = books.guid) "
"WHERE " + tab[0] + " = '" + tab[1] + "'")
ret = self.cursor.fetchall()
elif re.search("^file:", search):
file = search.replace('file:', '')
self.cursor.execute("SELECT * FROM books JOIN files ON(files.book_id = books.guid) "
"WHERE files.link = '" + file + "'")
ret = self.cursor.fetchall()
if ret is not None:
prev_guid = ''
for row in ret:
Expand Down
24 changes: 23 additions & 1 deletion common/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def create_epub(title: str, authors: str = None, series: str = None, volume_numb
return None


def get_epub_info(path: str):
def get_epub_info(path: str, clean: bool = False) -> dict or None:
ret = {
'guid': None,
'title': None,
Expand All @@ -315,6 +315,28 @@ def get_epub_info(path: str):
}
try:
if os.path.isfile(path) is True:
if clean is False:
_, ext = os.path.splitext(path)
dir_path = os.path.dirname(os.path.realpath(path))
file_short = path.replace(dir_path + os.sep, '')
print('file_short=', file_short)
BDD = bdd.BDD()
template_file = BDD.get_param('import_file_template')
separator_file = BDD.get_param('import_file_separator')
tmp_tab_file = file_short.replace(separator_file, ' - ').replace(ext, '').split(' - ')
tmp_tab_template = template_file.split(' - ')
for index in range(0, len(tmp_tab_template)):
if index >= len(tmp_tab_file):
break
if tmp_tab_template[index] == '%series%':
ret['series'] = '??<' + tmp_tab_file[index] + '>??'
if tmp_tab_template[index] == '%title%':
ret['title'] = '??<' + tmp_tab_file[index] + '>??'
if tmp_tab_template[index] == '%authors%':
ret['authors'] = '??<' + tmp_tab_file[index] + '>??'
if tmp_tab_template[index] == '%tags%':
ret['tags'] = tmp_tab_file[index].split(',')

myzip = zipfile.ZipFile(path, 'r')

myfile = myzip.open('META-INF/container.xml')
Expand Down
8 changes: 5 additions & 3 deletions common/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_file_size(file_name: str, human_readable: bool = True):
return '{} bytes'.format(size)


def get_file_type(file_path: str) -> str:
def get_file_type(file_path: str, return_extension: bool = False) -> str or (str, str):
file_path = file_path.replace('/', os.sep)
file_tab = file_path.split(os.sep)
ext = file_tab[len(file_tab) - 1]
Expand All @@ -44,8 +44,10 @@ def get_file_type(file_path: str) -> str:
except Exception:
end = True
file_type = "application/octet-stream"

return file_type
if return_extension is True:
return file_type, ext
else:
return file_type


def list_directory(directory_path: str, expected_extension: str = None):
Expand Down
200 changes: 108 additions & 92 deletions editor/editing_pane.py

Large diffs are not rendered by default.

78 changes: 62 additions & 16 deletions editor/syntaxHighlight.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import sys, os
from PyQt5.QtGui import *
from PyQt5.Qsci import *


class SimplePythonEditor(QsciScintilla):
ARROW_MARKER_NUM = 8

def __init__(self, lexer_type, parent=None):
def __init__(self, lexer_type, parent=None, style_data: dict = None):
super(SimplePythonEditor, self).__init__(parent)

# Set the default font
font = QFont()
font.setFamily('Courier')
font = None
font_family = 'Courier'
font_id = None
if style_data is not None:
try:
font_id = QFontDatabase.addApplicationFont(style_data['EditorQsciFont'].replace('/', os.sep))
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
except Exception:
""
font = QFont(font_family)
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
Expand All @@ -21,17 +30,11 @@ def __init__(self, lexer_type, parent=None):
self.setMarginsFont(font)
self.setMarginWidth(0, fontmetrics.width("00000") + 6)
self.setMarginLineNumbers(0, True)
self.setMarginsBackgroundColor(QColor("#cccccc"))

# Clickable margin 1 for showing markers
self.setMarginSensitivity(1, True)
# self.connect(self,
# SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'),
# self.on_margin_clicked)
self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM)
self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
self.setFoldMarginColors(QColor("#cccccc"), QColor("#333333"))

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

# Current line visible with special background color
self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

# Set Python lexer
# Set style for Python comments (style number 1) to a fixed-width
# courier.
#

if lexer_type is not None:
self.elexer = lexer_type
self.elexer.setFont(font)
self.elexer.setDefaultFont(font)
self.setLexer(self.elexer)
else:
self.elexer = None

text = bytearray(str.encode("Arial"))
style_ok = False
if style_data is not None:
try:
self.setMarginsBackgroundColor(QColor(style_data['EditorQsciMarginsBackgroundColor']))
self.setMarginsForegroundColor(QColor(style_data['EditorQsciMarginsForegroundColor']))
self.setMarkerBackgroundColor(QColor(style_data['EditorQsciMarkerBackgroundColor']), self.ARROW_MARKER_NUM)
self.setFoldMarginColors(
QColor(style_data['EditorQsciFoldMarginColor1']),
QColor(style_data['EditorQsciFoldMarginColor2'])
)
self.setCaretLineBackgroundColor(style_data['EditorQsciCaretLineBackgroundColor'])

self.setColor(QColor(style_data['EditorQsciDefaultTextColor']))
self.setPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))

if self.elexer is not None:
self.elexer.setDefaultColor(QColor(style_data['EditorQsciDefaultTextColor']))
self.elexer.setDefaultPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))
self.elexer.setPaper(QColor(style_data['EditorQsciDefaultBackgroundColor']))

if isinstance(lexer_type, QsciLexerXML) is True:
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTextColor']), QsciLexerXML.Default)
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTagColor']), QsciLexerXML.Tag)
self.elexer.setColor(QColor(style_data['EditorQsciXMLDefaultTagColor']), QsciLexerXML.UnknownTag)

style_ok = True
except Exception:
""
if style_ok is False:
self.setMarginsBackgroundColor(QColor("#333333"))
self.setMarginsForegroundColor(QColor("#ffffff"))
self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM)
self.setFoldMarginColors(QColor("#cccccc"), QColor("#333333"))
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

self.setColor(QColor("#ffffff"))
self.setPaper(QColor("#A6A6A6"))

if self.elexer is not None:
self.elexer.setDefaultPaper(QColor("#A6A6A6"))
self.elexer.setDefaultColor(QColor("#ffffff"))
self.elexer.setPaper(QColor("#A6A6A6"))

if isinstance(lexer_type, QsciLexerXML) is True:
self.elexer.setColor(QColor.fromRgb(255, 255, 255), QsciLexerXML.Default)
self.elexer.setColor(QColor('#000080'), QsciLexerXML.Tag)
self.elexer.setColor(QColor('#000080'), QsciLexerXML.UnknownTag)

text = bytearray(str.encode(font_family))
# 32, "Courier New"
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text)

Expand Down

0 comments on commit b32fee5

Please sign in to comment.