2006-05-31 06:18:07 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001-2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
# $Id:_FileEntry.py 9912 2008-01-22 09:17:46Z acraphae $
|
2006-05-31 06:18:07 +05:30
|
|
|
|
2006-05-31 08:11:46 +05:30
|
|
|
import os
|
2007-01-22 09:26:23 +05:30
|
|
|
import sys
|
2006-05-31 08:11:46 +05:30
|
|
|
import gtk
|
2009-02-24 10:11:23 +05:30
|
|
|
import Utils
|
2006-05-31 08:11:46 +05:30
|
|
|
|
2006-05-31 06:18:07 +05:30
|
|
|
class FileEntry(gtk.HBox):
|
|
|
|
def __init__(self,defname,title):
|
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
|
|
|
|
self.title = title
|
|
|
|
self.dir = False
|
|
|
|
self.entry = gtk.Entry()
|
|
|
|
self.entry.set_text(defname)
|
|
|
|
self.set_filename(defname)
|
|
|
|
self.set_spacing(6)
|
|
|
|
self.set_homogeneous(False)
|
|
|
|
self.button = gtk.Button()
|
|
|
|
im = gtk.Image()
|
|
|
|
im.set_from_stock(gtk.STOCK_OPEN,gtk.ICON_SIZE_BUTTON)
|
|
|
|
self.button.add(im)
|
|
|
|
self.button.connect('clicked',self.select_file)
|
|
|
|
self.pack_start(self.entry,True,True)
|
|
|
|
self.pack_end(self.button,False,False)
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def select_file(self, obj):
|
2006-05-31 06:18:07 +05:30
|
|
|
if self.dir:
|
|
|
|
my_action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
|
|
|
|
else:
|
|
|
|
my_action = gtk.FILE_CHOOSER_ACTION_SAVE
|
|
|
|
|
|
|
|
f = gtk.FileChooserDialog(self.title,
|
|
|
|
action=my_action,
|
|
|
|
buttons=(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
|
|
|
|
|
|
|
name = os.path.basename(self.entry.get_text())
|
|
|
|
if self.dir:
|
|
|
|
if os.path.isdir(name):
|
|
|
|
f.set_current_name(name)
|
|
|
|
elif os.path.isdir(os.path.basename(name)):
|
|
|
|
f.set_current_name(os.path.basename(name))
|
|
|
|
else:
|
|
|
|
f.set_current_name(name)
|
|
|
|
f.set_current_folder(self.spath)
|
2006-08-13 09:36:12 +05:30
|
|
|
f.present()
|
2006-05-31 06:18:07 +05:30
|
|
|
status = f.run()
|
|
|
|
if status == gtk.RESPONSE_OK:
|
2009-02-24 10:11:23 +05:30
|
|
|
self.set_filename(Utils.get_unicode_path(f.get_filename()))
|
2006-05-31 06:18:07 +05:30
|
|
|
f.destroy()
|
|
|
|
|
|
|
|
def set_filename(self,path):
|
|
|
|
if not path:
|
|
|
|
return
|
|
|
|
if os.path.dirname(path):
|
|
|
|
self.spath = os.path.dirname(path)
|
|
|
|
self.defname = os.path.basename(path)
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.spath = os.getcwd()
|
|
|
|
self.defname = path
|
|
|
|
self.entry.set_text(os.path.join(self.spath,self.defname))
|
|
|
|
|
|
|
|
def gtk_entry(self):
|
|
|
|
return self.entry
|
|
|
|
|
|
|
|
def get_full_path(self,val):
|
|
|
|
return self.entry.get_text()
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def set_directory_entry(self, opt):
|
2006-05-31 06:18:07 +05:30
|
|
|
self.dir = opt
|