Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from rupor-github/guihotfix
Browse files Browse the repository at this point in the history
GUI hotfix and some improving
  • Loading branch information
dnkorpushov authored Mar 13, 2017
2 parents c0b44f9 + d1e6508 commit 0a65258
Show file tree
Hide file tree
Showing 13 changed files with 654 additions and 446 deletions.
2 changes: 1 addition & 1 deletion build_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ -d ./dist ]; then
fi

echo "Building..."
python3 setup-all.mac.cx_freeze.py
python setup-all.mac.cx_freeze.py

rm -rf ./build/exe.macos*
mkdir dist
Expand Down
22 changes: 12 additions & 10 deletions fb2mobi-gui.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
<currentFormat>mobi</currentFormat>
<embedFontFamily/>
<hyphens>Profile</hyphens>
<outputFolder>C:\Users\dnkorpushov\Desktop\books</outputFolder>
<outputFolder>/Users/dnk/Desktop</outputFolder>
<lastUsedPath>C:\Users\dnkorpushov\Google Диск\Книги\Роберт ван Гулик</lastUsedPath>
<convertToSourceDirectory>False</convertToSourceDirectory>
<writeLog>True</writeLog>
<kindlePath>C:\work\kindleemu\documents</kindlePath>
<kindleCopyToDevice>True</kindleCopyToDevice>
<clearLogAfterExit>True</clearLogAfterExit>
<logLevel>INFO</logLevel>
<kindlePath>/Volumes/Kindle/documents</kindlePath>
<kindleCopyToDevice>False</kindleCopyToDevice>
<kindleSyncCovers>False</kindleSyncCovers>
<columns>
<c0>305</c0>
<c1>166</c1>
<c2>319</c2>
<c0>349</c0>
<c1>177</c1>
<c2>199</c2>
</columns>
<geometry>
<x>-1300</x>
<y>9</y>
<width>810</width>
<height>368</height>
<x>298</x>
<y>201</y>
<width>751</width>
<height>358</height>
</geometry>
</settings>
74 changes: 53 additions & 21 deletions fb2mobi-gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def run(self):
if os.path.exists(dest_file):
os.remove(dest_file)

self.config.log.info(' ')
fb2mobi.process_file(self.config, file, None)

if not os.path.exists(dest_file):
Expand Down Expand Up @@ -179,6 +180,7 @@ def __init__(self, parent, config):
self.lineDestPath.setText(self.config.outputFolder)
self.checkConvertToSrc.setChecked(self.config.convertToSourceDirectory)
self.checkWriteLog.setChecked(self.config.writeLog)
self.checkClearLogAfterExit.setChecked(self.config.clearLogAfterExit)

if self.config.hyphens.lower() == 'yes':
self.radioHypYes.setChecked(True)
Expand All @@ -198,7 +200,7 @@ def __init__(self, parent, config):
# Строим выбор шрифта
# для начала обновим список доступных шрифтов
self.config.fontDb.update_db()
self.comboFont.addItem('None', _translate('fb2mobi-gui', 'None'))
self.comboFont.addItem(_translate('fb2mobi-gui', 'None'), 'None')
for font in self.config.fontDb.families:
self.comboFont.addItem(font, font)

Expand All @@ -207,6 +209,8 @@ def __init__(self, parent, config):
else:
self.comboFont.setCurrentIndex(self.comboFont.findData(self.config.embedFontFamily))

self.comboLogLevel.setCurrentIndex(self.comboLogLevel.findText(self.config.logLevel))

self.lineKindlePath.setText(self.config.kindlePath)
self.checkCopyAfterConvert.setChecked(self.config.kindleCopyToDevice)
self.checkSyncCovers.setChecked(self.config.kindleSyncCovers)
Expand Down Expand Up @@ -274,6 +278,9 @@ def closeAccept(self):
self.config.kindleCopyToDevice = self.checkCopyAfterConvert.isChecked()
self.config.kindleSyncCovers = self.checkSyncCovers.isChecked()
self.config.writeLog = self.checkWriteLog.isChecked()
self.config.clearLogAfterExit = self.checkClearLogAfterExit.isChecked()
self.config.logLevel = self.comboLogLevel.currentText()

if self.comboFont.currentData() == 'None':
self.config.embedFontFamily = None
else:
Expand Down Expand Up @@ -315,10 +322,6 @@ def __init__(self):
self.copy_worker = None
self.is_convert_cancel = False

# Список стилей для встраивания шрифтов
self.style_rules = ['.titleblock', '.text-author', 'p', 'p.title', '.cite', '.poem',
'.table th', '.table td', '.annotation']

self.rootFileList = self.treeFileList.invisibleRootItem()
self.iconWhite = QIcon(':/Images/bullet_white.png')
self.iconRed = QIcon(':/Images/bullet_red.png')
Expand Down Expand Up @@ -353,21 +356,21 @@ def __init__(self):
self.gui_config = GuiConfig(self.gui_config_file)
self.gui_config.converterConfig = ConverterConfig(self.config_file)

log = logging.getLogger('fb2mobi')
log.setLevel("DEBUG")
self.log = logging.getLogger('fb2mobi')
self.log.setLevel(self.gui_config.logLevel)

log_stream_handler = logging.StreamHandler()
log_stream_handler.setLevel(fb2mobi.get_log_level(self.gui_config.converterConfig.console_level))
log_stream_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
log.addHandler(log_stream_handler)
self.log_stream_handler = logging.StreamHandler()
self.log_stream_handler.setLevel(fb2mobi.get_log_level(self.gui_config.converterConfig.console_level))
self.log_stream_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
self.log.addHandler(self.log_stream_handler)

if self.gui_config.writeLog:
log_file_handler = logging.FileHandler(filename=self.log_file, mode='a', encoding='utf-8')
log_file_handler.setLevel(fb2mobi.get_log_level(self.gui_config.converterConfig.log_level))
log_file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
log.addHandler(log_file_handler)
self.log_file_handler = logging.FileHandler(filename=self.log_file, mode='a', encoding='utf-8')
self.log_file_handler.setLevel(fb2mobi.get_log_level(self.gui_config.converterConfig.log_level))
self.log_file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
if self.gui_config.writeLog:
self.log.addHandler(self.log_file_handler)

self.gui_config.converterConfig.log = log
self.gui_config.converterConfig.log = self.log
# Строим базу доступных шрифтов
self.font_path = os.path.normpath(os.path.join(config_path, 'profiles/fonts'))
if os.path.exists(self.font_path):
Expand Down Expand Up @@ -537,6 +540,10 @@ def startConvert(self):
self.convertedCount = 0
self.convertedFiles = []

self.gui_config.converterConfig = ConverterConfig(self.config_file)
self.gui_config.converterConfig.log = self.log


self.convert_worker = ConvertThread(files, self.gui_config)
self.convert_worker.convertBegin.connect(self.convertBegin)
self.convert_worker.convertDone.connect(self.convertDone)
Expand All @@ -554,6 +561,11 @@ def startConvert(self):


def generateFontCSS(self):
# Список стилей для встраивания шрифтов
style_rules = ['.titleblock', '.text-author', 'p', 'p.title', '.cite', '.poem',
'.table th', '.table td', '.annotation', 'body']


css_string = modules.default_css.default_css
css = cssutils.parseString(css_string)

Expand All @@ -562,9 +574,6 @@ def generateFontCSS(self):
font_bold = ''
font_bolditalic = ''

print(self.gui_config.embedFontFamily)
print(self.gui_config.fontDb.families[self.gui_config.embedFontFamily])

if 'Regular' in self.gui_config.fontDb.families[self.gui_config.embedFontFamily]:
font_regular = self.gui_config.fontDb.families[self.gui_config.embedFontFamily]['Regular']

Expand All @@ -588,10 +597,18 @@ def generateFontCSS(self):
css.add('@font-face {{ font-family: "para"; src: url("fonts/{0}"); font-weight: bold; }}'.format(font_bold))
css.add('@font-face {{ font-family: "para"; src: url("fonts/{0}"); font-style: italic; font-weight: bold; }}'.format(font_bolditalic))

found_body = False

for rule in css:
if rule.type == rule.STYLE_RULE:
if rule.selectorText in self.style_rules:
if rule.selectorText in style_rules:
rule.style['font-family'] = '"para"'
if rule.selectorText == 'body':
found_body = True

# Добавим стиль для
if not found_body:
css.add('body {font-family: "para"; line-height: 100%; }')

css_path = os.path.join(os.path.dirname(self.config_file), 'profiles')
if not os.path.exists(css_path):
Expand Down Expand Up @@ -759,6 +776,12 @@ def addFilesAction(self):


def closeApp(self):
# Очистим лог-файл на выходе, если указано в настройках
if self.gui_config.clearLogAfterExit:
if self.log_file:
with open(self.log_file, 'w'):
pass

win_x = self.pos().x()
win_y = self.pos().y()
win_width = self.size().width()
Expand Down Expand Up @@ -795,10 +818,19 @@ def openFile(self, filename):


def settings(self):
prev_writeLog = self.gui_config.writeLog

settingsDlg = SettingsDialog(self, self.gui_config)
if settingsDlg.exec_():
self.gui_config = settingsDlg.config
self.gui_config.write()
self.log.setLevel(self.gui_config.logLevel)

if prev_writeLog != self.gui_config.writeLog:
if self.gui_config.writeLog:
self.gui_config.converterConfig.log.addHandler(self.log_file_handler)
else:
self.gui_config.converterConfig.log.removeHandler(self.log_file_handler)


def about(self):
Expand Down
Loading

0 comments on commit 0a65258

Please sign in to comment.