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 #28 from rupor-github/gui-feature
Browse files Browse the repository at this point in the history
Some GUI fix
  • Loading branch information
dnkorpushov committed Jul 27, 2017
2 parents 630e8d9 + 42bb0e1 commit 8c99ba7
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 244 deletions.
22 changes: 12 additions & 10 deletions fb2mobi-gui.config
Expand Up @@ -5,26 +5,28 @@
<embedFontFamily/>
<hyphens>No</hyphens>
<outputFolder/>
<lastUsedPath/>
<lastUsedTargetPath>C:\Users\dnkorpushov\Desktop\dest</lastUsedTargetPath>
<lastUsedPath>C:\Users\dnkorpushov\Google Диск\Библиотека\Довлатов, Сергей</lastUsedPath>
<writeLog>True</writeLog>
<clearLogAfterExit>True</clearLogAfterExit>
<logLevel>INFO</logLevel>
<logLevel>DEBUG</logLevel>
<kindlePath/>
<kindleSyncCovers>True</kindleSyncCovers>
<kindleDocsSubfolder/>
<GoogleMail/>
<GooglePassword/>
<KindleMail/>
<bookInfoVisible>True</bookInfoVisible>
<bookInfoSplitterState>708, 259</bookInfoSplitterState>
<bookInfoSplitterState>712, 261</bookInfoSplitterState>
<columns>
<c0>328</c0>
<c1>177</c1>
<c2>201</c2>
<c0>356</c0>
<c1>281</c1>
<c2>73</c2>
</columns>
<geometry>
<x>365</x>
<y>370</y>
<width>990</width>
<height>562</height>
<x>243</x>
<y>238</y>
<width>996</width>
<height>558</height>
</geometry>
</settings>
62 changes: 34 additions & 28 deletions fb2mobi-gui.py
Expand Up @@ -40,6 +40,7 @@
TREE_LIST_CSS_UNACTIVE = "selection-color: black; selection-background-color: #D4D4D4; alternate-background-color: #F3F6FA;"

SUPPORT_URL = u'http://www.the-ebook.org/forum/viewtopic.php?t=30380'
HELP_URL = u'https://github.com/rupor-github/fb2mobi/wiki'

PROCESS_MODE_CONVERT = 0
PROCESS_MODE_KINDLE = 1
Expand All @@ -62,7 +63,8 @@ def __init__(self, parent, config):
self.comboFormat.addItem(f, f)

self.comboProfile.setCurrentIndex(self.comboProfile.findData(self.config.currentProfile))
self.comboFormat.setCurrentIndex(self.comboFormat.findData(self.config.currentFormat))
self.comboFormat.setCurrentIndex(self.comboFormat.findData(self.config.currentFormat))
self.lineDestFolder.setText(self.config.outputFolder)
self.checkWriteLog.setChecked(self.config.writeLog)
self.checkClearLogAfterExit.setChecked(self.config.clearLogAfterExit)
self.lineKindleDocsSubfolder.setText(self.config.kindleDocsSubfolder)
Expand Down Expand Up @@ -117,6 +119,9 @@ def OpenFontsFolder(self):
except:
pass

def selectDestPath(self):
self.lineDestFolder.setText(self.selectPath(self.lineDestFolder.text()))

def selectKindlePath(self):
self.lineKindlePath.setText(self.selectPath(self.lineKindlePath.text()))

Expand Down Expand Up @@ -146,6 +151,7 @@ def closeAccept(self):

self.config.kindlePath = os.path.normpath(self.lineKindlePath.text()) if self.lineKindlePath.text() else ''
self.config.kindleDocsSubfolder = self.lineKindleDocsSubfolder.text()
self.config.outputFolder = self.lineDestFolder.text()
self.config.GoogleMail = self.lineGoogleMail.text()
self.config.GooglePassword = self.lineGooglePassword.text()
self.config.KindleMail = self.lineKindleMail.text()
Expand Down Expand Up @@ -259,8 +265,8 @@ def __init__(self):
if os.path.exists(self.font_path):
self.gui_config.fontDb = FontDb(self.font_path)

if not self.gui_config.outputFolder:
self.gui_config.outputFolder = os.path.abspath(os.path.expanduser("~/Desktop"))
if not self.gui_config.lastUsedTargetPath:
self.gui_config.lastUsedTargetPath = os.path.abspath(os.path.expanduser("~/Desktop"))

if not self.gui_config.currentFormat:
self.gui_config.currentFormat = 'mobi'
Expand Down Expand Up @@ -413,7 +419,7 @@ def process(self, mode):
config.current_profile['css'] = css_file

if mode == PROCESS_MODE_CONVERT:
config.output_dir = self.gui_config.outputFolder
config.output_dir = self.gui_config.outputFolder if self.gui_config.outputFolder else self.gui_config.lastUsedTargetPath
else:
config.output_dir = tempfile.mkdtemp()

Expand Down Expand Up @@ -551,18 +557,18 @@ def process(self, mode):
progressDlg.deleteLater()

def convertToDisk(self):
if not self.gui_config.outputFolder:
self.gui_config.outputFolder = os.path.expanduser('~')

files = self.getFileList()
if len(files) > 0:
dlgPath = QFileDialog(self, _translate('fb2mobi-gui', 'Select folder to convert'), self.gui_config.outputFolder)
dlgPath.setFileMode(QFileDialog.Directory)
dlgPath.setOption(QFileDialog.ShowDirsOnly, True)

if dlgPath.exec_():
for d in dlgPath.selectedFiles():
self.gui_config.outputFolder = os.path.normpath(d)
if not self.gui_config.outputFolder:
dlgPath = QFileDialog(self, _translate('fb2mobi-gui', 'Select folder to convert'), self.gui_config.lastUsedTargetPath)
dlgPath.setFileMode(QFileDialog.Directory)
dlgPath.setOption(QFileDialog.ShowDirsOnly, True)

if dlgPath.exec_():
for d in dlgPath.selectedFiles():
self.gui_config.lastUsedTargetPath = os.path.normpath(d)
self.process(PROCESS_MODE_CONVERT)
else:
self.process(PROCESS_MODE_CONVERT)

def sendToKindle(self):
Expand All @@ -581,6 +587,7 @@ def enableSendViaMail(self):

def findKindle(self):
mounted_fs = []
add_files = []

if sys.platform == 'darwin':
list_dir = os.listdir('/Volumes')
Expand All @@ -595,11 +602,15 @@ def findKindle(self):

for fs in mounted_fs:
dir_documents = os.path.join(fs, 'documents')
dir_system = os.path.join(fs, 'system', 'thumbnails')
file_version = os.path.join(fs, 'system', 'version.txt')
dir_system = os.path.join(fs, 'system')

if os.path.exists(dir_documents) and os.path.exists(dir_system) and os.path.exists(file_version):
return fs
if os.path.exists(dir_documents) and os.path.exists(dir_system):
# Kindle Paperwhite, Voyage, Oasis
if os.path.exists(os.path.join(fs, 'system', 'thumbnails')) and os.path.exists(os.path.join(fs, 'system', 'version.txt')):
return fs
# Kindle 4, 5
elif os.path.exists(os.path.join(fs, 'system', 'com.amazon.ebook.booklet.reader', 'reader.pref')):
return fs

return ''

Expand All @@ -613,7 +624,7 @@ def checkKindleStatus(self):
if self.kindle_path and os.path.isdir(self.kindle_path):
self.toolSendToKindle.setEnabled(True)
self.actionSendToKindle.setEnabled(True)
self.labelStatus.setText(_translate('fb2mobi-gui', 'Kindle connected to {0}'.format(self.kindle_path)))
self.labelStatus.setText(_translate('fb2mobi-gui', 'Kindle connected to {0}').format(self.kindle_path))
else:
self.toolSendToKindle.setEnabled(False)
self.actionSendToKindle.setEnabled(False)
Expand Down Expand Up @@ -726,15 +737,6 @@ def openLog(self):
self.openFile(self.log_file)


def checkDestDir(self):
filename = os.path.normpath(self.gui_config.outputFolder)
if not os.path.exists(filename):
QMessageBox.critical(self, _translate('fb2mobi-gui', 'Error'), _translate('fb2mobi-gui', 'Folder does not exist.'))
return False
else:
return True


def generateFontCSS(self):
# Список стилей для встраивания шрифтов
style_rules = ['.titleblock', '.text-author', 'p', 'p.title', '.cite', '.poem',
Expand Down Expand Up @@ -995,6 +997,10 @@ def closeApp(self):

self.close()

def openHelpURL(self):
webbrowser.open(url=HELP_URL)


def openSupportURL(self):
webbrowser.open(url=SUPPORT_URL)

Expand Down

0 comments on commit 8c99ba7

Please sign in to comment.