Added some automatic settings for window size, last folder, tag style

git-svn-id: http://comictagger.googlecode.com/svn/trunk@67 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
beville@gmail.com 2012-11-20 06:34:09 +00:00
parent cf616d9336
commit da74046eb6
4 changed files with 74 additions and 40 deletions

View File

@ -35,6 +35,14 @@ class ComicTaggerSettings:
unrar_exe_path = ""
cv_api_key = ""
# automatic settings
last_selected_data_style = 0
last_opened_folder = None
last_main_window_width = 0
last_main_window_height = 0
last_main_window_x = 0
last_main_window_y = 0
@staticmethod
def getSettingsFolder():
if platform.system() == "Windows":
@ -93,23 +101,42 @@ class ComicTaggerSettings:
def load(self):
#print "reading", self.path
self.config.read( self.settings_file )
self.rar_exe_path = self.config.get( 'settings', 'rar_exe_path' )
self.unrar_exe_path = self.config.get( 'settings', 'unrar_exe_path' )
self.cv_api_key = self.config.get( 'settings', 'cv_api_key' )
#self.cv_api_key = self.config.get( 'settings', 'cv_api_key' )
self.last_selected_data_style = self.config.getint( 'auto', 'last_selected_data_style' )
self.last_opened_folder = self.config.get( 'auto', 'last_opened_folder' )
if self.config.has_option('auto', 'last_main_window_width'):
self.last_main_window_width = self.config.getint( 'auto', 'last_main_window_width' )
if self.config.has_option('auto', 'last_main_window_height'):
self.last_main_window_height = self.config.getint( 'auto', 'last_main_window_height' )
if self.config.has_option('auto', 'last_main_window_x'):
self.last_main_window_x = self.config.getint( 'auto', 'last_main_window_x' )
if self.config.has_option('auto', 'last_main_window_y'):
self.last_main_window_y = self.config.getint( 'auto', 'last_main_window_y' )
def save( self ):
if not self.config.has_section( 'settings' ):
self.config.add_section( 'settings' )
self.config.set( 'settings', 'cv_api_key', self.cv_api_key )
#self.config.set( 'settings', 'cv_api_key', self.cv_api_key )
self.config.set( 'settings', 'rar_exe_path', self.rar_exe_path )
self.config.set( 'settings', 'unrar_exe_path', self.unrar_exe_path )
if not self.config.has_section( 'auto' ):
self.config.add_section( 'auto' )
self.config.set( 'auto', 'last_selected_data_style', self.last_selected_data_style )
self.config.set( 'auto', 'last_opened_folder', self.last_opened_folder )
self.config.set( 'auto', 'last_main_window_width', self.last_main_window_width )
self.config.set( 'auto', 'last_main_window_height', self.last_main_window_height )
self.config.set( 'auto', 'last_main_window_x', self.last_main_window_x )
self.config.set( 'auto', 'last_main_window_y', self.last_main_window_y )
with open( self.settings_file, 'wb') as configfile:
self.config.write(configfile)

View File

@ -39,7 +39,7 @@ from genericmetadata import GenericMetadata
from comicvinetalker import ComicVineTalker
import utils
import codecs
#-----------------------------
def cli_mode( opts, settings ):
@ -98,9 +98,9 @@ def process_file_cli( filename, opts, settings ):
if cix:
print "------ComicRack tags--------"
if opts.raw:
print u"{0}".format(ca.readRawCIX()).encode("utf-8")
print u"{0}".format(ca.readRawCIX())
else:
print u"{0}".format(ca.readCIX()).encode("utf-8")
print u"{0}".format(ca.readCIX())
if opts.data_style is None or opts.data_style == MetaDataStyle.CBI:
if cbi:
@ -108,7 +108,7 @@ def process_file_cli( filename, opts, settings ):
if opts.raw:
pprint(json.loads(ca.readRawCBI()))
else:
print u"{0}".format(ca.readCBI()).encode("utf-8")
print u"{0}".format(ca.readCBI())
elif opts.delete_tags:
@ -229,6 +229,10 @@ def process_file_cli( filename, opts, settings ):
#-----------------------------
def main():
# try to make stdout encodings happy for unicode
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
opts = Options()
opts.parseCmdLineArgs()

View File

@ -81,15 +81,21 @@ class TaggerWindow( QtGui.QMainWindow):
self.setWindowIcon(QtGui.QIcon(os.path.join(ComicTaggerSettings.baseDir(), 'graphics/app.png' )))
self.lblCover.setPixmap(QtGui.QPixmap(os.path.join(ComicTaggerSettings.baseDir(), 'graphics/nocover.png' )))
self.center()
self.show()
self.raise_()
#print platform.system(), platform.release()
self.dirtyFlag = False
self.settings = settings
self.data_style = MetaDataStyle.CIX
self.data_style = settings.last_selected_data_style
if self.settings.last_main_window_width != 0:
geo = QtCore.QRect( self.settings.last_main_window_x,
self.settings.last_main_window_y,
self.settings.last_main_window_width,
self.settings.last_main_window_height )
self.setGeometry( geo )
else:
self.center()
#set up a default metadata object
self.metadata = GenericMetadata()
self.comic_archive = None
@ -99,7 +105,7 @@ class TaggerWindow( QtGui.QMainWindow):
self.updateAppTitle()
self.setAcceptDrops(True)
self.updateSaveMenu()
self.droppedFile=None
self.droppedFile = None
self.page_browser = None
@ -116,9 +122,13 @@ class TaggerWindow( QtGui.QMainWindow):
self.updateStyleTweaks()
self.show()
self.raise_()
if filename is not None:
self.openArchive( filename )
def updateAppTitle( self ):
if self.comic_archive is None:
@ -222,9 +232,7 @@ class TaggerWindow( QtGui.QMainWindow):
self.toolBar.addAction( self.actionAutoSearch )
self.toolBar.addAction( self.actionClearEntryForm )
self.toolBar.addAction( self.actionPageBrowser )
#self.toolBar.addAction( self.actionRemoveCBLTags )
#self.toolBar.addAction( self.actionRemoveCRTags )
def repackageArchive( self ):
QtGui.QMessageBox.information(self, self.tr("Repackage Comic Archive"), self.tr("TBD"))
@ -274,6 +282,8 @@ class TaggerWindow( QtGui.QMainWindow):
if ca is not None and ca.seemsToBeAComicArchive():
self.settings.last_opened_folder = os.path.dirname( path )
# clear form and current metadata, we're all in!
if clear_form:
self.clearForm()
@ -665,6 +675,8 @@ class TaggerWindow( QtGui.QMainWindow):
dialog = QtGui.QFileDialog(self)
dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
if self.settings.last_opened_folder is not None:
dialog.setDirectory( self.settings.last_opened_folder )
#dialog.setFileMode(QtGui.QFileDialog.Directory )
if platform.system() != "Windows" and utils.which("unrar") is None:
@ -768,6 +780,8 @@ class TaggerWindow( QtGui.QMainWindow):
def setDataStyle(self, s):
self.data_style, b = self.cbDataStyle.itemData(s).toInt()
self.settings.last_selected_data_style = self.data_style
self.updateStyleTweaks()
self.updateSaveMenu()
@ -1103,6 +1117,12 @@ class TaggerWindow( QtGui.QMainWindow):
if self.dirtyFlagVerification( "Exit " + self.appName,
"If you quit now, data in the form will be lost. Are you sure?"):
geo = self.geometry()
self.settings.last_main_window_width = geo.width()
self.settings.last_main_window_height = geo.height()
self.settings.last_main_window_x = geo.x()
self.settings.last_main_window_y = geo.y()
self.settings.save()
event.accept()
else:
event.ignore()

View File

@ -31,8 +31,14 @@ def listToString( l ):
string += item
return string
def addtopath( dir ):
# TODO only add if not there already
if dir is not None and dir != "":
os.environ['PATH'] = dir + os.pathsep + os.environ['PATH']
# returns executable path, if it exists
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
@ -48,29 +54,6 @@ def which(program):
return None
def addtopath( dir ):
# TODO only add if not there already
if dir is not None and dir != "":
os.environ['PATH'] = dir + os.pathsep + os.environ['PATH']
# returns executable path, if it exists
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def removearticles( text ):
text = text.lower()
articles = ['and', 'the', 'a', '&', 'issue' ]