Hey, again, have spent most of the day playing around and reading about
python and glade and thus far this is what I have, now I have a few issues I
have questions about, firstly how do I get the text associated with a
toolbar button and change it for example if you notice the 'play' button
when this is pressed I wish for the button to be renamed and re-iconed to
'pause' but have no idea how to do this or even if it's possible, I imagine
so, but I don't actually know.

Secondly, while I have discovered a way to close a window by essentially
crashing it in program what is the safest way to close a gtk window from
within python, in my program here I have an about dialog box that opens, but
when it closes it either takes the whole application with it (which I
quickly corrected) or crashes un-gracefully and while the window appears to
close, it's in fact crashed.

If anyone could provide help I'd again, be grateful, obviously I'm just
learning the language, and while my method to learn a language may seem odd,
I don't tent to learn from reading up on programming languages, I learn by
solving problems I come across, and since I'm a 'scratch my own itch' kinda
guy I start writing applications to solve problems I have and learn a new
language as I go, it's the most effective way for me to learn a new language
by drafting an application and building it.
#!/usr/bin/env python

import sys, os, os.path, gtk.glade, pygtk, gtk
pygtk.require( "2.0" )

class GUI:
	def __init__( self ):
		## Set the Glade file. ##
		self.wTree = gtk.glade.XML( "musicdb-gui.glade", "window1" )

		## Event handlers. ##
		dic= { "on_window1_destroy" : self.Main_Quit, 
			"on_mnu_quit_activate" : self.Main_Quit, 
			"on_BTN_Add_Album_clicked" : self.Add_Album,
			"on_mnu_Add_Album_activate" : self.Add_Album, 
			"on_BTN_Edit_Album_clicked" : self.Edit_Album, 
			"on_mnu_Edit_Album_activate" : self.Edit_Album,
			"on_BTN_Delete_Album_clicked" : self.Delete_Album, 
			"on_mnu_Delete_Album_activate" : self.Delete_Album,
			"on_BTN_Play_clicked" : self.Play, 
			"on_BTN_Stop_clicked" : self.Stop, 
			"on_mnu_Help_activate" : self.About }
		self.wTree.signal_autoconnect ( dic )
		
	## Functions for event handlers. ##
	def Main_Quit( self, obj ):
		gtk.main_quit( )
		sys.exit( 1 )
	
	def About_Quit( self, obj ):
		gtk.window_quit( )

	def Add_Album( self, obj ):
		print "Add album."

	def Edit_Album( self, obj ):
		print "Edit album."

	def Delete_Album( self, obj ):
		print "Delete album."

	def Play( self, obj ):
		try:
			print "Play track."
		except Exception, ex:
			print "An error occured: %s." % ex

	def Stop( self, obj ):
		print "Stop track."

	def About( self, obj ):
		self.wTree = gtk.glade.XML( "musicdb-gui.glade", "dialog1" )

		dic = { 
			"on_BTN_OK_clicked" : self.About_Quit,
			"on_BTN_Quit_clicked" : self.About_Quit,
			"on_dialog1_destroy" : self.About_Quit
			}

		self.wTree.signal_autoconnect ( dic )

class Application:	
	## Need a data structure that can hold a string and another data structure. ##
	## Try out dictionarys. ##
	def __init__( self ):	
		try:
			print "Welcome to RecordStore!"
			if __name__ == '__main__':
				try:
					GUI( )
					gtk.gdk.threads_init( )
				except:
					print "No threading was enabled when pyGTK was compiled!"
					sys.exit( 1 )

			gtk.gdk.threads_enter( )
			gtk.main( )
			gtk.gdk.threads_leave( )

		except Exception, ex:
			print "An error has occured: %s." % ex

	## Sort the writing of stuff alpha-numerically. ##
	## Convert this all to SQL database. ##
	def CreateXMLFile( self ):
		try:
			RootMusic = "/home/niadh/Music/"
			XMLFile = file( "media-library.xml", "w" )
			Artists = os.listdir( RootMusic )
			ArtistsIterate = 0 
			XMLFile.write( "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n" )
			XMLFile.write( "<music>\n" )

			## Artist listing. ##
			while ArtistsIterate < len( Artists ):
				AlbumIterate = 0
				location = os.path.join( RootMusic + Artists[ ArtistsIterate ] )
				Albums = os.listdir( location )
				XMLFile.write( "\t<artist>\n" + "\t\t<name>" + Artists[ ArtistsIterate ] + "</name>\n" )

				## Album listing. ##
				while AlbumIterate < len( Albums ):
					TrackIterate = 0
					location = os.path.join( RootMusic + Artists[ ArtistsIterate ] + "/" + Albums[ AlbumIterate ] )
					Tracks = os.listdir( location )
					XMLFile.write( "\t\t<album>\n" )
					XMLFile.write( "\t\t\t<albumname>" + Albums[ AlbumIterate ] + "</albumname>\n" )
					XMLFile.write( "\t\t\t<releasedate>" + "</releasedate>\n" )
					XMLFile.write( "\t\t\t<format>" + "</format>\n" )			
					AlbumIterate = AlbumIterate +1	

					## Track listing. ##	
					while TrackIterate < len( Tracks ):
						XMLFile.write( "\t\t\t<track>" + Tracks[ TrackIterate ] + "</track>\n" )
						TrackIterate = TrackIterate +1	

					XMLFile.write( "\t\t</album>\n" )	
			
				XMLFile.write ( "\t</artist>\n\n" )
				ArtistsIterate = ArtistsIterate +1
			XMLFile.write( "</music>\n" )

		except Exception, ex: 
			print "An error occured: %s." % ex
			
App = Application( )

Attachment: musicdb-gui.glade
Description: application/glade

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to