Implemented file-renaming in GUI
git-svn-id: http://comictagger.googlecode.com/svn/trunk@273 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
parent
94c5882175
commit
ee9175087e
@ -409,7 +409,10 @@ def process_file_cli( filename, opts, settings, match_results ):
|
||||
new_ext = None # default
|
||||
|
||||
renamer = FileRenamer( md )
|
||||
renamer.setTemplate( "%series% v%volume% %issue% (of %issuecount%) (%year%)" )
|
||||
renamer.setTemplate( settings.rename_template )
|
||||
renamer.setIssueZeroPadding( settings.rename_issue_number_padding )
|
||||
renamer.setSmartCleanup( settings.rename_use_smart_string_cleanup )
|
||||
|
||||
new_name = renamer.determineName( filename, ext=new_ext )
|
||||
|
||||
if new_name == os.path.basename(filename):
|
||||
|
@ -42,7 +42,6 @@ class FileRenamer:
|
||||
self.template = template
|
||||
|
||||
def replaceToken( self, text, value, token ):
|
||||
|
||||
#helper func
|
||||
def isToken( word ):
|
||||
return (word[0] == "%" and word[-1:] == "%")
|
||||
|
@ -152,8 +152,11 @@ class PageListEditor(QWidget):
|
||||
#idx = int(str (self.listWidget.item( row ).text()))
|
||||
idx = int(self.listWidget.item( row ).data(Qt.UserRole).toPyObject()[0]['Image'])
|
||||
|
||||
image_data = self.comic_archive.getPage( idx )
|
||||
|
||||
if self.comic_archive is not None:
|
||||
image_data = self.comic_archive.getPage( idx )
|
||||
else:
|
||||
image_data = None
|
||||
|
||||
if image_data is not None:
|
||||
img = QImage()
|
||||
img.loadFromData( image_data )
|
||||
|
79
renamewindow.py
Normal file
79
renamewindow.py
Normal file
@ -0,0 +1,79 @@
|
||||
"""
|
||||
A PyQT4 dialog to confirm rename
|
||||
"""
|
||||
|
||||
"""
|
||||
Copyright 2012 Anthony Beville
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
|
||||
from PyQt4 import QtCore, QtGui, uic
|
||||
from settings import ComicTaggerSettings
|
||||
from settingswindow import SettingsWindow
|
||||
from filerenamer import FileRenamer
|
||||
import os
|
||||
import utils
|
||||
|
||||
class RenameWindow(QtGui.QDialog):
|
||||
|
||||
def __init__( self, parent, comic_archive, metadata, settings ):
|
||||
super(RenameWindow, self).__init__(parent)
|
||||
|
||||
uic.loadUi(os.path.join(ComicTaggerSettings.baseDir(), 'renamewindow.ui' ), self)
|
||||
|
||||
self.settings = settings
|
||||
self.metadata = metadata
|
||||
self.comic_archive = comic_archive
|
||||
self.new_name = None
|
||||
|
||||
self.btnSettings.clicked.connect( self.modifySettings )
|
||||
self.configRenamer()
|
||||
self.doPreview()
|
||||
|
||||
def configRenamer( self ):
|
||||
self.renamer = FileRenamer( self.metadata )
|
||||
self.renamer.setTemplate( self.settings.rename_template )
|
||||
self.renamer.setIssueZeroPadding( self.settings.rename_issue_number_padding )
|
||||
self.renamer.setSmartCleanup( self.settings.rename_use_smart_string_cleanup )
|
||||
|
||||
def doPreview( self ):
|
||||
self.new_name = self.renamer.determineName( self.comic_archive.path )
|
||||
preview = "\"{0}\" ==> \"{1}\"".format( self.comic_archive.path, self.new_name )
|
||||
self.textEdit.setPlainText( preview )
|
||||
|
||||
def modifySettings( self ):
|
||||
settingswin = SettingsWindow( self, self.settings )
|
||||
settingswin.setModal(True)
|
||||
settingswin.showRenameTab()
|
||||
settingswin.exec_()
|
||||
if settingswin.result():
|
||||
self.configRenamer()
|
||||
self.doPreview()
|
||||
|
||||
def accept( self ):
|
||||
QtGui.QDialog.accept(self)
|
||||
|
||||
if self.new_name == os.path.basename( self.comic_archive.path ):
|
||||
#print msg_hdr + "Filename is already good!"
|
||||
return
|
||||
|
||||
folder = os.path.dirname( os.path.abspath( self.comic_archive.path ) )
|
||||
new_abs_path = utils.unique_file( os.path.join( folder, self.new_name ) )
|
||||
|
||||
os.rename( self.comic_archive.path, new_abs_path )
|
||||
|
||||
self.new_name = new_abs_path
|
||||
|
||||
|
106
renamewindow.ui
Normal file
106
renamewindow.ui
Normal file
@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>dialogRename</class>
|
||||
<widget class="QDialog" name="dialogRename">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::NonModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>556</width>
|
||||
<height>210</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Archive Rename</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string> Preview:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="btnSettings">
|
||||
<property name="text">
|
||||
<string>Rename Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>10</y>
|
||||
<width>133</width>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>dialogRename</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>346</x>
|
||||
<y>187</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>277</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>dialogRename</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>346</x>
|
||||
<y>187</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>277</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -168,7 +168,7 @@ class SettingsWindow(QtGui.QDialog):
|
||||
self.settings.apply_cbl_transform_on_cv_import = self.cbxApplyCBLTransformOnCVIMport.isChecked()
|
||||
self.settings.apply_cbl_transform_on_bulk_operation = self.cbxApplyCBLTransformOnBatchOperation.isChecked()
|
||||
|
||||
self.settings.rename_template = self.leRenameTemplate.text()
|
||||
self.settings.rename_template = str(self.leRenameTemplate.text())
|
||||
self.settings.rename_issue_number_padding = int(self.leIssueNumPadding.text())
|
||||
self.settings.rename_use_smart_string_cleanup = self.cbxSmartCleanup.isChecked()
|
||||
|
||||
@ -215,5 +215,6 @@ class SettingsWindow(QtGui.QDialog):
|
||||
fileList = dialog.selectedFiles()
|
||||
control.setText( str(fileList[0]) )
|
||||
|
||||
|
||||
def showRenameTab( self ):
|
||||
self.tabWidget.setCurrentIndex(4)
|
||||
|
||||
|
@ -45,6 +45,7 @@ from logwindow import LogWindow
|
||||
from optionalmsgdialog import OptionalMessageDialog
|
||||
from pagelisteditor import PageListEditor
|
||||
from cbltransformer import CBLTransformer
|
||||
from renamewindow import RenameWindow
|
||||
import utils
|
||||
import ctversion
|
||||
|
||||
@ -1352,7 +1353,6 @@ class TaggerWindow( QtGui.QMainWindow):
|
||||
if self.comic_archive is not None and self.comic_archive.hasCBI():
|
||||
dlg = LogWindow( self )
|
||||
text = pprint.pformat( json.loads(self.comic_archive.readRawCBI()), indent=4 )
|
||||
print text
|
||||
dlg.setText(text )
|
||||
dlg.setWindowTitle( "Raw ComicBookLover Tag View" )
|
||||
dlg.exec_()
|
||||
@ -1379,5 +1379,15 @@ class TaggerWindow( QtGui.QMainWindow):
|
||||
self.metadataToForm()
|
||||
|
||||
def renameArchive(self):
|
||||
pass
|
||||
if self.comic_archive is not None:
|
||||
self.formToMetadata()
|
||||
dlg = RenameWindow( self, self.comic_archive, self.metadata, self.settings )
|
||||
dlg.setModal( True )
|
||||
if dlg.exec_():
|
||||
#reopen the archive, since the filename changed
|
||||
print dlg.new_name
|
||||
self.comic_archive = None
|
||||
self.openArchive( dlg.new_name )
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user