1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-18 12:00:21 +01:00

* Code clean up.

* Removed unnecessary imports.
 * Adapted to PEP8.
This commit is contained in:
2008-04-16 14:05:20 +00:00
parent 6691415f12
commit f98c905591
10 changed files with 284 additions and 213 deletions

View File

@@ -31,15 +31,17 @@ class Qst(object):
if "OK" button pressed, return "True"
"Cancel" button return "False"
"""
def __init__(self, title="", message="", secondarymsg=""):
self.dialog = gtk.MessageDialog(
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_QUESTION,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_QUESTION,
buttons = gtk.BUTTONS_OK_CANCEL,
message_format = message,
)
self.dialog.set_title(title)
self.dialog.format_secondary_text(secondarymsg)
def run(self):
retval = self.dialog.run()
self.dialog.destroy()
@@ -49,57 +51,67 @@ class Qst(object):
class Inf(object):
"""Show simple dialog for notices"""
def __init__(self, title="", message="", secondarymsg=""):
self.dialog = gtk.MessageDialog(
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_OK,
message_format = message,
)
self.dialog.set_title(title)
self.dialog.format_secondary_text(secondarymsg)
self.dialog.connect('response', lambda dialog, response: self.ret(response))
self.dialog.connect('response',
lambda dialog, response: self.ret(response))
self.dialog.show()
def ret(self,result):
self.dialog.destroy()
return True
class Wrn(object):
"""Show simple dialog for warnings"""
def __init__(self, title="", message="", secondarymsg=""):
self.dialog = gtk.MessageDialog(
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_WARNING,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_WARNING,
buttons = gtk.BUTTONS_CLOSE,
message_format = message,
)
self.dialog.set_title(title)
self.dialog.format_secondary_text(secondarymsg)
self.dialog.connect('response', lambda dialog, response: self.ret(response))
self.dialog.connect('response',
lambda dialog, response: self.ret(response))
self.dialog.show()
def ret(self,result):
self.dialog.destroy()
return True
class Err(object):
"""Show simple dialog for errors"""
def __init__(self, title="", message="", secondarymsg=""):
self.dialog = gtk.MessageDialog(
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_ERROR,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_ERROR,
buttons = gtk.BUTTONS_CLOSE,
message_format = message,
)
message_format = message)
self.dialog.set_title(title)
self.dialog.format_secondary_text(secondarymsg)
self.dialog.connect('response', lambda dialog, response: self.ret(response))
self.dialog.connect('response',
lambda dialog, response: self.ret(response))
self.dialog.run()
def ret(self,result):
self.dialog.destroy()
return True
class Abt(object):
"""Show simple about dialog"""
def __init__(self, name=None, ver="", title="", authors=[],licence=""):
self.dialog = gtk.AboutDialog()
self.dialog.set_title(title)
@@ -107,17 +119,19 @@ class Abt(object):
self.dialog.set_license(licence)
self.dialog.set_name(name)
self.dialog.set_authors(authors)
self.dialog.connect('response', lambda dialog, response: self.dialog.destroy())
self.dialog.connect('response',
lambda dialog, response: self.dialog.destroy())
self.dialog.show()
class InputDiskLabel(object):
"""Sepcific dialog for quering user for a disc label"""
def __init__(self, label=""):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
self.label = ""
if label!= None:
self.label = label
def run(self):
gladexml = gtk.glade.XML(self.gladefile, "inputDialog")
dialog = gladexml.get_widget("inputDialog")
@@ -128,14 +142,15 @@ class InputDiskLabel(object):
if result == gtk.RESPONSE_OK:
return entry.get_text()
return None
class InputNewName(object):
"""Sepcific dialog for quering user for a disc label"""
def __init__(self, name=""):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
self.label = ""
self.name = name
def run(self):
gladexml = gtk.glade.XML(self.gladefile, "renameDialog")
dialog = gladexml.get_widget("renameDialog")
@@ -149,9 +164,9 @@ class InputNewName(object):
class PointDirectoryToAdd(object):
"""Sepcific dialog for quering user for selecting directory to add"""
URI="file://"+os.path.abspath(os.path.curdir)
def __init__(self,volname='',dirname=''):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
self.gladexml = gtk.glade.XML(self.gladefile, "addDirDialog")
@@ -159,8 +174,10 @@ class PointDirectoryToAdd(object):
self.volname.set_text(volname)
self.directory = self.gladexml.get_widget("directory")
self.directory.set_text(dirname)
self.gladexml.signal_autoconnect({"on_browse_activate":self.show_dirchooser,"on_browse_clicked":self.show_dirchooser})
sigs = {"on_browse_activate":self.show_dirchooser,
"on_browse_clicked":self.show_dirchooser}
self.gladexml.signal_autoconnect(sigs)
def show_dirchooser(self,widget):
"""dialog for point the mountpoint"""
dialog = gtk.FileChooserDialog(
@@ -170,13 +187,11 @@ class PointDirectoryToAdd(object):
gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK
)
)
gtk.RESPONSE_OK))
dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
dialog.set_default_response(gtk.RESPONSE_OK)
if self.URI:
dialog.set_current_folder_uri(self.URI)
response = dialog.run()
@@ -184,14 +199,17 @@ class PointDirectoryToAdd(object):
self.directory.set_text(dialog.get_filename())
self.__class__.URI = dialog.get_current_folder_uri()
dialog.destroy()
def run(self):
dialog = self.gladexml.get_widget("addDirDialog")
ch = True
result = dialog.run()
while ch:
if result == gtk.RESPONSE_OK and (self.volname.get_text()=='' or self.directory.get_text() == ''):
a = Err("Error - pyGTKtalog","There are fields needed to be filled.","Cannot add directory without path and disc label.")
if result == gtk.RESPONSE_OK and (self.volname.get_text()=='' or \
self.directory.get_text() == ''):
a = Err("Error - pyGTKtalog",
"There are fields needed to be filled.",
"Cannot add directory without path and disc label.")
ch = True
result = dialog.run()
else:
@@ -204,9 +222,9 @@ class PointDirectoryToAdd(object):
class ChooseDBFilename(object):
"""Sepcific dialog for quering user for selecting filename for database"""
URI="file://"+os.path.abspath(os.path.curdir)
def __init__(self):
self.dialog = gtk.FileChooserDialog(
title="Save catalog as...",
@@ -215,15 +233,13 @@ class ChooseDBFilename(object):
gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE,
gtk.RESPONSE_OK
)
)
gtk.RESPONSE_OK))
self.dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
self.dialog.set_default_response(gtk.RESPONSE_OK)
self.dialog.set_do_overwrite_confirmation(True)
self.dialog.set_title('Save catalog to file...')
f = gtk.FileFilter()
f.set_name("Catalog files")
f.add_pattern("*.pgt")
@@ -232,7 +248,7 @@ class ChooseDBFilename(object):
f.set_name("All files")
f.add_pattern("*.*")
self.dialog.add_filter(f)
def run(self):
if self.URI:
self.dialog.set_current_folder_uri(self.URI)
@@ -253,12 +269,13 @@ class ChooseDBFilename(object):
self.dialog.destroy()
return None
pass
class LoadDBFile(object):
"""Specific class for displaying openFile dialog. It has veryfication for file existence."""
"""Specific class for displaying openFile dialog. It has veryfication
for file existence."""
URI="file://"+os.path.abspath(os.path.curdir)
def __init__(self):
self.dialog = gtk.FileChooserDialog(
title="Open catalog",
@@ -267,12 +284,10 @@ class LoadDBFile(object):
gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK
)
)
gtk.RESPONSE_OK))
self.dialog.set_default_response(gtk.RESPONSE_OK)
f = gtk.FileFilter()
f.set_name("Catalog files")
f.add_pattern("*.pgt")
@@ -281,7 +296,7 @@ class LoadDBFile(object):
f.set_name("All files")
f.add_pattern("*.*")
self.dialog.add_filter(f)
def show_dialog(self):
response = self.dialog.run()
filename = None
@@ -294,7 +309,7 @@ class LoadDBFile(object):
return 'ok',filename
else:
return 'cancel',None
def run(self):
if self.URI:
self.dialog.set_current_folder_uri(self.URI)
@@ -310,7 +325,9 @@ class LoadDBFile(object):
self.dialog.destroy()
return filename
except:
a = Err("Error - pyGTKtalog","File doesn't exist.","The file that you choose does not exist. Choose another one, or cancel operation.")
a = Err("Error - pyGTKtalog","File doesn't exist.",
"The file that you choose does not exist." + \
" Choose another one, or cancel operation.")
ch = True
res, filename = self.show_dialog()
@@ -318,9 +335,9 @@ class LoadDBFile(object):
class LoadImageFile(object):
"""class for displaying openFile dialog. It have possibility of multiple
selection."""
URI="file://"+os.path.abspath(os.path.curdir)
def __init__(self, multiple=False):
self.dialog = gtk.FileChooserDialog(
title="Select image",
@@ -329,15 +346,15 @@ class LoadImageFile(object):
gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK
)
)
gtk.RESPONSE_OK))
self.dialog.set_select_multiple(multiple)
self.dialog.set_default_response(gtk.RESPONSE_OK)
f = gtk.FileFilter()
f.set_name("All Images")
for i in ['*.jpg', '*.jpeg', '*.gif', '*.png', '*.tif', '*.tiff', '*.tga', '*.pcx', '*.bmp', '*.xbm', '*.xpm', '*.jp2', '*.jpx', '*.pnm']:
for i in ['*.jpg', '*.jpeg', '*.gif', '*.png', '*.tif', '*.tiff',
'*.tga', '*.pcx', '*.bmp', '*.xbm', '*.xpm', '*.jp2',
'*.jpx', '*.pnm']:
f.add_pattern(i)
self.dialog.add_filter(f)
f = gtk.FileFilter()
@@ -345,33 +362,33 @@ class LoadImageFile(object):
f.add_pattern("*.*")
self.dialog.add_filter(f)
self.preview = gtk.Image()
self.dialog.set_preview_widget(self.preview)
self.dialog.connect("update-preview", self.update_preview_cb)
def run(self):
if self.URI:
self.dialog.set_current_folder_uri(self.URI)
response = self.dialog.run()
filenames = None
only_thumbs = False
if response == gtk.RESPONSE_OK:
try:
if self.dialog.get_select_multiple():
filenames = self.dialog.get_filenames()
else:
filenames = self.dialog.get_filename()
if self.dialog.get_extra_widget().get_active():
only_thumbs = True
except:
pass
self.__class__.URI = self.dialog.get_current_folder_uri()
self.dialog.destroy()
return filenames, only_thumbs
def update_preview_cb(self, widget):
filename = self.dialog.get_preview_filename()
try:
@@ -382,18 +399,19 @@ class LoadImageFile(object):
have_preview = False
self.dialog.set_preview_widget_active(have_preview)
return
class StatsDialog(object):
"""Sepcific dialog for display stats"""
def __init__(self, values={}):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
self.values = values
def run(self):
gladexml = gtk.glade.XML(self.gladefile, "statDialog")
dialog = gladexml.get_widget("statDialog")
if self.values.has_key('discs'):
if 'discs' in self.values:
entry = gladexml.get_widget("discs_entry")
entry.set_text(str(self.values['discs']))
else:
@@ -401,8 +419,8 @@ class StatsDialog(object):
entry = gladexml.get_widget("discs_entry")
label.hide()
entry.hide()
if self.values.has_key('dirs'):
if 'dirs' in self.values:
entry = gladexml.get_widget("dirs_entry")
entry.set_text(str(self.values['dirs']))
else:
@@ -410,46 +428,66 @@ class StatsDialog(object):
entry = gladexml.get_widget("dirs_entry")
label.hide()
entry.hide()
if self.values.has_key('files'):
if 'files' in self.values:
entry = gladexml.get_widget("files_entry")
entry.set_text(str(self.values['files']))
if self.values.has_key('size'):
if 'size' in self.values:
entry = gladexml.get_widget("size_entry")
entry.set_text(str(self.values['size']))
result = dialog.run()
dialog.destroy()
if result == gtk.RESPONSE_OK:
return entry.get_text()
return None
class TagsDialog(object):
"""Sepcific dialog for display stats"""
def __init__(self):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
def run(self):
gladexml = gtk.glade.XML(self.gladefile, "tagsDialog")
dialog = gladexml.get_widget("tagsDialog")
entry = gladexml.get_widget("tag_entry1")
result = dialog.run()
dialog.destroy()
if result == gtk.RESPONSE_OK:
return entry.get_text()
return None
class EditDialog(object):
"""Sepcific dialog for display stats"""
def __init__(self, values={}):
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
self.values = values
def run(self):
gladexml = gtk.glade.XML(self.gladefile, "file_editDialog")
dialog = gladexml.get_widget("file_editDialog")
filename = gladexml.get_widget("filename_entry")
filename.set_text(str(self.values['filename']))
description = gladexml.get_widget("description_text")
note = gladexml.get_widget("note_text")
if self.values.has_key('description'):
if 'description' in self.values:
buff = gtk.TextBuffer()
buff.set_text(str(self.values['description']))
description.set_buffer(buff)
if self.values.has_key('note'):
if 'note' in self.values:
buff = gtk.TextBuffer()
buff.set_text(str(self.values['note']))
note.set_buffer(buff)
result = dialog.run()
if result == gtk.RESPONSE_OK:
d = description.get_buffer()