SHARE
TWEET

Python - Glade + GTK.Builder

rucinskic Feb 8th, 2013 26 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CFlatGUI(object) :
  2.  
  3.     def __init__(self):
  4.  
  5.         self.builder = gtk.Builder()
  6.         self.builder.add_from_file("CFlatGUI.glade")
  7.         self.window = self.builder.get_object("application")
  8.  
  9.         # Connect the exit button to GTK's application quit handler
  10.         if self.window:
  11.  
  12.             self.window.connect("destroy", gtk.main_quit)
  13.  
  14.         #################################
  15.         # Create menu object References #
  16.         #################################
  17.        
  18.         # Create menu File object references
  19.         self.mnuFileNew = self.builder.get_object("mnuFileNew")
  20.         self.mnuFileOpen = self.builder.get_object("mnuFileOpen")
  21.         self.mnuFileSaveAs = self.builder.get_object("mnuFileSaveAs")
  22.         self.mnuFileSave = self.builder.get_object("mnuFileSave")
  23.         self.mnuFileQuit = self.builder.get_object("mnuFileQuit")
  24.  
  25.         # Create menu Edit object references
  26.         self.mnuEditProperties = self.builder.get_object("mnuEditProperties")
  27.         self.mnuEditPreferences = self.builder.get_object("mnuEditPreferences")
  28.  
  29.         # Create menu Record object references
  30.         self.mnuRecordStart = self.builder.get_object("mnuRecordStart")
  31.         self.mnuRecordCalibrate = self.builder.get_object("mnuRecordCalibrate")
  32.  
  33.         # Create menu Help object references
  34.         self.mnuHelpAbout = self.builder.get_object("mnuHelpAbout")
  35.  
  36.         ###################################
  37.         # Create dialog object References #
  38.         ###################################
  39.  
  40.         # Create dialog Calibrate object references
  41.         self.dlgCalibrate = self.builder.get_object("dlgCalibrate")
  42.         self.btnCancel_Calibrate = self.builder.get_object("btnCancel_Calibrate")
  43.         self.btnOK_Calibrate = self.builder.get_object("btnOK_Calibrate")
  44.  
  45.         # Create dialog Music Properties object references
  46.         self.dlgMusicProperties = self.builder.get_object("dlgMusicProperties")
  47.         self.btnCancel_Properties = self.builder.get_object("btnCancel_Properties")
  48.         self.btnOK_Properties = self.builder.get_object("btnOK_Properties")
  49.  
  50.         # Create dialog New object references
  51.         self.dlgNew = self.builder.get_object("dlgNew")
  52.         self.btnCancel_New = self.builder.get_object("btnCancel_New")
  53.         self.btnCreate_New = self.builder.get_object("btnCreate_New")
  54.  
  55.         # Create dialog Open object references
  56.         self.dlgOpen = self.builder.get_object("dlgCOpen")
  57.         self.btnCancel_Open = self.builder.get_object("btnCancel_Open")
  58.         self.btnOpen_Open = self.builder.get_object("btnOpen_Open")
  59.  
  60.         # Create dialog Save / Save As object references
  61.         self.dlgSave = self.builder.get_object("dlgSave")
  62.         self.btnCancel_Save = self.builder.get_object("btnCancel_Save")
  63.         self.btnSave_Save = self.builder.get_object("btnSave_Save")
  64.  
  65.         # Create dialog About object references
  66.         self.dlgAbout = self.builder.get_object("dlgAbout")
  67.  
  68.  
  69.  
  70.         # Create a dictionary for event listeners
  71.         event_dictionary = {
  72.  
  73.             "on_dlgCalibrate_close" : self.on_dlgCalibrate_close,
  74.             "on_dlgCalibrate_response" : self.on_dlgCalibrate_response,
  75.            
  76.             "on_dlgMusicProperties_close" : self.on_dlgMusicProperties_close,
  77.             "on_dlgMusicProperties_response" : self.on_dlgMusicProperties_response,
  78.            
  79.             "on_dlgNew_close" : self.on_dlgNew_close,
  80.             "on_dlgNew_response" : self.on_dlgNew_response,
  81.            
  82.             "on_dlgOpen_close" : self.on_dlgOpen_close,
  83.             "on_dlgOpen_response" : self.on_dlgOpen_response,
  84.            
  85.             "on_dlgSave_close" : self.on_dlgSave_close,
  86.             "on_dlgSave_response" : self.on_dlgSave_response,
  87.  
  88.             "on_dlgAbout_close" : self.on_dlgAbout_close,
  89.  
  90.             "on_mnuFileNew_Click" : self.on_mnuFile_activate,
  91.             "on_mnuFileOpen_Click" : self.on_mnuFile_activate,
  92.             "on_mnuFileSaveAs_Click" : self.on_mnuFile_activate,
  93.             "on_mnuFileSave_Click" : self.on_mnuFile_activate,
  94.             "on_mnuFileQuit_Click" : self.on_mnuFile_activate,
  95.  
  96.             "on_mnuEditProperties_Click" : self.on_mnuEdit_activate,
  97.             "on_mnuEditPreferences_Click" : self.on_mnuEdit_activate,
  98.  
  99.             "on_mnuRecordStart_Click" : self.on_mnuRecord_activate,
  100.             "on_mnuRecordEnd_Click" : self.on_mnuRecord_activate,
  101.             "on_mnuRecordCalibrate_Click" : self.on_mnuRecord_activate,
  102.  
  103.             "on_mnuHelpAbout" : self.on_mnuHelp_activate
  104.            
  105.         }
  106.  
  107.         # Connect all event signals from the dictionary to the application
  108.         self.builder.connect_signals( event_dictionary )
  109.  
  110.  
  111.     ##############################
  112.     # Start of callback handlers #
  113.     ##############################
  114.  
  115.     def on_dlgCalibrate_close(self, widget):
  116.         print "on_btnCancel_Calibrate"
  117.     def on_dlgCalibrate_response(self, widget):
  118.         print "on_btnOK_Calibrate"
  119.    
  120.     def on_dlgMusicProperties_close(self, widget):
  121.         print "on_btnCancel_Properties"
  122.     def on_dlgMusicProperties_response(self, widget):
  123.         print "on_btnOK_Properties"
  124.    
  125.     def on_dlgNew_close(self, widget):
  126.         print "on_btnCancel_New"
  127.     def on_dlgNew_response(self, widget):
  128.         print "on_btnCreate_New"
  129.    
  130.     def on_dlgOpen_close(self, widget):
  131.         print "on_btnCancel_Open"
  132.     def on_dlgOpen_response(self, widget):
  133.         print "on_btnOpen_Open"
  134.    
  135.     def on_dlgSave_close(self, widget):
  136.         print "on_btnCancel_Save"
  137.     def on_dlgSave_response(self, widget):
  138.         print "on_btnSave_Save"
  139.  
  140.     def on_dlgAbout_close(self, widget):
  141.         print "on_dlgAbout_close"
  142.         self.dlgAbout.show() # BUT THIS DOES NOT SHOW ABOUT BOX!!!!! << --------------------------------
  143.  
  144.  
  145.     def on_mnuFile_activate(self, widget):
  146.         print widget.name
  147.     def on_mnuEdit_activate(self, widget):
  148.         print widget.name
  149.     def on_mnuRecord_activate(self, widget):
  150.         print widget.name
  151.     def on_mnuHelp_activate(self, widget):
  152.         print widget.name
  153.    
  154. app = CFlatGUI()
  155. app.window.show() # Show the window
  156. # app.dlgAbout.show() ## THIS UNCOMMENTED WILL SHOW ABOUT BOX!!!!    << --------------------------------
  157. gtk.main()  # Loop that handles all GTK items such as signals
  158.  
  159.  
  160. '''
  161. ERROR MESSAGES
  162.  
  163.  
  164. Warning (from warnings module):
  165.  File "C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py", line 287
  166.    self.builder.connect_signals( event_dictionary )
  167. RuntimeWarning: missing handler 'on_mnuHelp_activate'
  168.  
  169. Warning (from warnings module):
  170.  File "C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py", line 287
  171.    self.builder.connect_signals( event_dictionary )
  172. RuntimeWarning: missing handler 'on_mnuRecord_activate'
  173.  
  174. Warning (from warnings module):
  175.  File "C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py", line 287
  176.    self.builder.connect_signals( event_dictionary )
  177. RuntimeWarning: missing handler 'on_mnuEdit_activate'
  178.  
  179. Warning (from warnings module):
  180.  File "C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py", line 287
  181.    self.builder.connect_signals( event_dictionary )
  182. RuntimeWarning: missing handler 'on_mnuFile_activate'
  183. '''
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top