FileEntry clean up.
svn: r12423
This commit is contained in:
parent
39132b011a
commit
125266878d
@ -2,6 +2,7 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2001-2006 Donald N. Allingham
|
# Copyright (C) 2001-2006 Donald N. Allingham
|
||||||
|
# Copyright (C) 2009 Brian G. Matherly
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -21,74 +22,80 @@
|
|||||||
# $Id:_FileEntry.py 9912 2008-01-22 09:17:46Z acraphae $
|
# $Id:_FileEntry.py 9912 2008-01-22 09:17:46Z acraphae $
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import gtk
|
import gtk
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
class FileEntry(gtk.HBox):
|
class FileEntry(gtk.HBox):
|
||||||
def __init__(self,defname,title):
|
""" A widget that allows the user to select a file from the file system """
|
||||||
|
def __init__(self, defname, title):
|
||||||
gtk.HBox.__init__(self)
|
gtk.HBox.__init__(self)
|
||||||
|
|
||||||
self.title = title
|
self.title = title
|
||||||
self.dir = False
|
self.dir = False
|
||||||
|
self.__base_path = ""
|
||||||
|
self.__file_name = ""
|
||||||
self.entry = gtk.Entry()
|
self.entry = gtk.Entry()
|
||||||
self.entry.set_text(defname)
|
self.entry.set_text(defname)
|
||||||
self.set_filename(defname)
|
self.set_filename(defname)
|
||||||
self.set_spacing(6)
|
self.set_spacing(6)
|
||||||
self.set_homogeneous(False)
|
self.set_homogeneous(False)
|
||||||
self.button = gtk.Button()
|
self.button = gtk.Button()
|
||||||
im = gtk.Image()
|
image = gtk.Image()
|
||||||
im.set_from_stock(gtk.STOCK_OPEN,gtk.ICON_SIZE_BUTTON)
|
image.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
|
||||||
self.button.add(im)
|
self.button.add(image)
|
||||||
self.button.connect('clicked',self.select_file)
|
self.button.connect('clicked', self.__select_file)
|
||||||
self.pack_start(self.entry,True,True)
|
self.pack_start(self.entry, True, True)
|
||||||
self.pack_end(self.button,False,False)
|
self.pack_end(self.button, False, False)
|
||||||
|
|
||||||
def select_file(self, obj):
|
def __select_file(self, obj):
|
||||||
|
""" Call back function to handle the open button press """
|
||||||
if self.dir:
|
if self.dir:
|
||||||
my_action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
|
my_action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
|
||||||
else:
|
else:
|
||||||
my_action = gtk.FILE_CHOOSER_ACTION_SAVE
|
my_action = gtk.FILE_CHOOSER_ACTION_SAVE
|
||||||
|
|
||||||
f = gtk.FileChooserDialog(self.title,
|
dialog = gtk.FileChooserDialog(self.title,
|
||||||
action=my_action,
|
action=my_action,
|
||||||
buttons=(gtk.STOCK_CANCEL,
|
buttons=(gtk.STOCK_CANCEL,
|
||||||
gtk.RESPONSE_CANCEL,
|
gtk.RESPONSE_CANCEL,
|
||||||
gtk.STOCK_OPEN,
|
gtk.STOCK_OPEN,
|
||||||
gtk.RESPONSE_OK))
|
gtk.RESPONSE_OK))
|
||||||
|
|
||||||
name = os.path.basename(self.entry.get_text())
|
name = os.path.basename(self.entry.get_text())
|
||||||
if self.dir:
|
if self.dir:
|
||||||
if os.path.isdir(name):
|
if os.path.isdir(name):
|
||||||
f.set_current_name(name)
|
dialog.set_current_name(name)
|
||||||
elif os.path.isdir(os.path.basename(name)):
|
elif os.path.isdir(os.path.basename(name)):
|
||||||
f.set_current_name(os.path.basename(name))
|
dialog.set_current_name(os.path.basename(name))
|
||||||
else:
|
else:
|
||||||
f.set_current_name(name)
|
dialog.set_current_name(name)
|
||||||
f.set_current_folder(self.spath)
|
dialog.set_current_folder(self.__base_path)
|
||||||
f.present()
|
dialog.present()
|
||||||
status = f.run()
|
status = dialog.run()
|
||||||
if status == gtk.RESPONSE_OK:
|
if status == gtk.RESPONSE_OK:
|
||||||
self.set_filename(Utils.get_unicode_path(f.get_filename()))
|
self.set_filename(Utils.get_unicode_path(dialog.get_filename()))
|
||||||
f.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def set_filename(self,path):
|
def set_filename(self, path):
|
||||||
|
""" Set the currently selected dialog. """
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
if os.path.dirname(path):
|
if os.path.dirname(path):
|
||||||
self.spath = os.path.dirname(path)
|
self.__base_path = os.path.dirname(path)
|
||||||
self.defname = os.path.basename(path)
|
self.__file_name = os.path.basename(path)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.spath = os.getcwd()
|
self.__base_path = os.getcwd()
|
||||||
self.defname = path
|
self.__file_name = path
|
||||||
self.entry.set_text(os.path.join(self.spath,self.defname))
|
self.entry.set_text(os.path.join(self.__base_path, self.__file_name))
|
||||||
|
|
||||||
def gtk_entry(self):
|
def get_full_path(self, val):
|
||||||
return self.entry
|
""" Get the full path of the currently selected file. """
|
||||||
|
|
||||||
def get_full_path(self,val):
|
|
||||||
return self.entry.get_text()
|
return self.entry.get_text()
|
||||||
|
|
||||||
def set_directory_entry(self, opt):
|
def set_directory_entry(self, opt):
|
||||||
|
"""
|
||||||
|
Configure the FileEntry to either select a directory or a file.
|
||||||
|
Set it to True to select a directory.
|
||||||
|
Set it to False to select a file.
|
||||||
|
"""
|
||||||
self.dir = opt
|
self.dir = opt
|
||||||
|
@ -447,7 +447,6 @@ class ReportDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.target_fileentry = FileEntry(hid, _("Save As"))
|
self.target_fileentry = FileEntry(hid, _("Save As"))
|
||||||
spath = self.get_default_directory()
|
spath = self.get_default_directory()
|
||||||
self.target_fileentry.set_filename(spath)
|
self.target_fileentry.set_filename(spath)
|
||||||
self.target_fileentry.gtk_entry().set_position(len(spath))
|
|
||||||
# need any labels at top:
|
# need any labels at top:
|
||||||
label = gtk.Label("<b>%s</b>" % _('Document Options'))
|
label = gtk.Label("<b>%s</b>" % _('Document Options'))
|
||||||
label.set_use_markup(1)
|
label.set_use_markup(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user