Skip to content

Commit

Permalink
Allow metadata editor to embed directories
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Oct 14, 2017
1 parent 658d2f3 commit 08ed304
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
5 changes: 4 additions & 1 deletion gui/KCC.ui
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@
<property name="text">
<string>Editor</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p style='white-space:pre'&gt;Shift+Click to edit directory.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="icon">
<iconset resource="KCC.qrc">
<normaloff>:/Other/icons/editor.png</normaloff>:/Other/icons/editor.png</iconset>
Expand Down Expand Up @@ -454,7 +457,7 @@
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p style='white-space:pre'&gt;Shift+Click to select the output directory.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p style='white-space:pre'&gt;Shift+Click to select the output directory.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Convert</string>
Expand Down
53 changes: 33 additions & 20 deletions kindlecomicconverter/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,28 +500,38 @@ def selectFile(self):
GUI.jobList.scrollToBottom()

def selectFileMetaEditor(self):
if self.UnRAR:
if self.sevenza:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr *.cb7)')
else:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr)')
sname = ''
if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier:
dname = QtWidgets.QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath)
if dname != '':
sname = os.path.join(dname, 'ComicInfo.xml')
if sys.platform.startswith('win'):
sname = sname.replace('/', '\\')
self.lastPath = os.path.abspath(sname)
else:
if self.sevenza:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cb7)')
else:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz)')
if fname[0] != '':
if sys.platform.startswith('win'):
fname = fname[0].replace('/', '\\')
if self.UnRAR:
if self.sevenza:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr *.cb7)')
else:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cbr)')
else:
fname = fname[0]
self.lastPath = os.path.abspath(os.path.join(fname, os.pardir))
if self.sevenza:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz *.cb7)')
else:
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
'Comic (*.cbz)')
if fname[0] != '':
if sys.platform.startswith('win'):
sname = fname[0].replace('/', '\\')
else:
sname = fname[0]
self.lastPath = os.path.abspath(os.path.join(sname, os.pardir))
if sname != '':
try:
self.editor.loadData(fname)
self.editor.loadData(sname)
except Exception as err:
_, _, traceback = sys.exc_info()
GUI.sentry.captureException()
Expand Down Expand Up @@ -1109,7 +1119,10 @@ def loadData(self, file):
for field in (self.writerLine, self.pencillerLine, self.inkerLine, self.coloristLine):
field.setText(', '.join(self.parser.data[field.objectName().capitalize()[:-4] + 's']))
if self.seriesLine.text() == '':
self.seriesLine.setText(file.split('\\')[-1].split('/')[-1].split('.')[0])
if file.endswith('.xml'):
self.seriesLine.setText(file.split('\\')[-2])
else:
self.seriesLine.setText(file.split('\\')[-1].split('/')[-1].split('.')[0])

def saveData(self):
for field in (self.volumeLine, self.numberLine, self.muidLine):
Expand Down
1 change: 1 addition & 0 deletions kindlecomicconverter/KCC_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def retranslateUi(self, mainWindow):
self.colorBox.setText(_translate("mainWindow", "Color mode"))
self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto"))
self.editorButton.setText(_translate("mainWindow", "Editor"))
self.editorButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Shift+Click to edit directory.</p></body></html>"))
self.wikiButton.setText(_translate("mainWindow", "Wiki"))
self.directoryButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Add directory containing JPG, PNG or GIF files to queue.<br/><span style=\" font-weight:600;\">CBR, CBZ and CB7 files inside will not be processed!</span></p></body></html>"))
self.directoryButton.setText(_translate("mainWindow", "Add directory"))
Expand Down
4 changes: 2 additions & 2 deletions kindlecomicconverter/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(self, source):
'Bookmarks': []}
self.rawdata = None
self.compressor = None
if self.source.endswith('.xml'):
if self.source.endswith('.xml') and os.path.exists(self.source):
self.rawdata = parse(self.source)
self.parseXML()
else:
elif not self.source.endswith('.xml'):
if is_zipfile(self.source):
self.compressor = 'zip'
with ZipFile(self.source) as zip_file:
Expand Down

0 comments on commit 08ed304

Please sign in to comment.