I am working on a music database application for myself and I wanna write
the GUI using glade and obviously GTK, but I've not had much luck getting
things to work, I have two books on python and both say 'just do X' but if X
doesn't work I am kinda stuck, so if anyone could help me I would be
grateful.

The problem is that when I try to just show the GUI (never mind event
handlers and signals etc, just want the GUI to show atm) nothing happens,
python sorta sits there doing nothing. I have attached the glade file and
the python file in the hopes it'll only be one or two lines to change that I
am simply unaware of.

Thanks
Niadh
#!/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.gladefile = "musicdb-gui.glade"  
	        self.wTree = gtk.glade.XML(self.gladefile) 

		#Get the Main Window, and connect the "destroy" event
		self.window = self.wTree.get_widget( "window1" )

		if (self.window):
			self.window.connect( "destroy", gtk.main_quit )

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!"
			self.Print_Menu( )

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

	def Print_Menu( self ):
		try: 
			Option = "1"

			while Option != "0":
				print "1) Add album." 
				print "2) Edit album."
				print "3) Delete album."
				print "0) Exit."

				Option = raw_input( "Please enter a choice: " ) 
			
				if Option == "1":
					self.Add_Album( )

				elif Option == "2":
					self.Edit_Album( )

				elif Option == "3":
					self.Delete_Album( )

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

	def Add_Album( self ):
		try:
			Artist = raw_input( "Please enter the album artist: " )
			Album_Name = raw_input( "Please enter the album name: " )
			Release_Date = raw_input( "Please enter the release date: " )
			Format = raw_input( "Please enter the album format: " )

			print Artist + "\n" + Album_Name + "\n" + Release_Date + "\n" + Format

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

	def Edit_Album( self ):
		try:
			print "Edit album function." 

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

	def Delete_Album( self ):
		try:
			print "Delete album function."
	
		except Exception, ex:
			print "An error occured: %s." % ex


	## Sort the writing of stuff alpha-numerically. ##
	## Convert this all to SQL database. ##
	def CreateXMLFile( self ):
		try:
			XMLFile = file( "media-library.xml", "w" )
			Artists = os.listdir( "/home/niadh/Music/" )
			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( "/home/niadh/Music/" + 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( "/home/niadh/Music/" + 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( )

if __name__ == '__main__':
	UI = GUI( )
	gtk.main( )

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