Fileselection window of Gnome/GTK

Alistair Thomas astavale at yahoo.co.uk
Thu Jan 16 13:57:40 EST 2003


In article <b0597d$ltf34 at imsp212.netvigator.com>, "Wouter van Marle"
<wouterm at spammers-unite-here.com> wrote:

> What I have done so far: in glade I created a file selection widget, and
> connected the OK and Cancel butten to signal when <clicked>. Then in my
> python program I open the file selection widget, and connect the two
> signals.
> Now this simply does not work

Here's a quick copy and paste of some code which I use, hopefully give you
some clues. Although the code probably  isn't enough to work:

from GUI import window, dialogues

a = dialogues.file_selector ( 'Open', self.specfile.localsource )
if hasattr ( a, 'filename'):
	self.specfile.source[ b ].location = a.filename

----------
window module
----------
import gtk, gnome.ui, libglade

class open ( libglade.GladeXML ) :
	"""Creates an open window.
It assumes the project has one glade file which contains all
the window's layouts. Specify this file's location using the
'glade_file' attribute of the window module.
To create the open window object specify the window's name
as held in the glade file."""

	def __init__ (self , window ):
		libglade.GladeXML.__init__ ( self , glade_file , window )
		self.window = window

	def add_handlers ( self , handlers ):
		"Add dictionary of signal handlers to the open window"
		self.signal_autoconnect ( handlers )

	def remove_handlers ( self , handlers ):
		"Is this useful or even possible?"
		pass

	def close ( self ):
		self.get_widget ( self.window ). destroy ()

------------
dialogues module
------------
import gtk, gnome.ui, libglade, GDK
import window

def about ( widget = None ):
	window.open( "about" )

class file_selector ( window.open ):

	def __init__ ( self , type = "Browse", filename = "" ):
		window.open.__init__ ( self , "fileselector" )
		a = self.get_widget ( "fileselector" )
		a.set_title ( type )
		if type== "Open":
			a.hide_fileop_buttons ()
		if type== "Save As":
			a.show_fileop_buttons ()
		self.add_handlers ( {     "ok_button" : self.ok_button ,
					"cancel_button" : self.cancel_button,
					"closed" : self.closed } )
		a.set_filename ( filename )
		gtk.mainloop ()

	def ok_button ( self , widget ):
		a = widget.get_toplevel ( )
		self.filename = a.get_filename ()
		self.close ()

	def cancel_button ( self , widget ):
		self.close ()

	def closed ( self, widget = None ):
		gtk.mainquit ()




More information about the Python-list mailing list