Re: gladexml::signal_autoconnect parameter

From: Date: Sun, 29 Aug 2004 18:03:18 +0000
Subject: Re: gladexml::signal_autoconnect parameter
References: 1  Groups: php.gtk.dev php.gtk.doc 
Request: Send a blank email to php-gtk-dev+get-742@lists.php.net to get a copy of this message
Christian Weiske wrote:
While documenting the glade extension I stumbled over the signal_autoconnect function. It does not require but accept one parameter of type array. As I didn't find any other documentation and didn't get smart of the php-gtk sources: Could somebody (Andrei?) explain the meaning of this array?
Basically it works this warning: I haven't used this stuff for years!): As usual you build your GUI in glade and define some handlers for signals, etc. Then you load the glade file into PHP-GTK: $gx = &new GladeXML( GLADE_XML_GUI_FILE)) and you've also prepared all kinds of functions (== handlers) you already defined in the glade file. Now it's time to map the handlers from the glade file to your actualy PHP application functions/methods. This is were signal_autoconnect comes into play. Basically, the parameter is a hash in the form of name_of_handler_from_glade_file => which_php_function_to_call. In real source code, this could look like this: @$gx->signal_autoconnect( array( // main window
   'on_menu_file_quit_activate'            =>  array( array( &$this, 'shutdown')),
   'on_mainWindow_destroy'                 =>  array( array( &$this, 'shutdown')),
   'on_textSqlIn_key_press_event'          =>  array( array( &$this, 'doQuery')),
// database manager window
   'on_menu_manage_activate'               =>  array( array( &$this->managerGui, 'show')),
'on_windowManageDatabases_delete_event' => array( array( &$this->managerGui, 'hide')),
   'on_buttonAdd_clicked'                  =>  array( array( &$this->managerGui, 'newConnection')),
   'on_buttonApply_clicked'                =>  array( array( &$this->managerGui, 'applyChanges')),
   'on_listConnections_select_row'         =>  array( array( &$this->managerGui, 'configuredConnectionSelected')),
   'on_buttonDelete_clicked'               =>  array( array( &$this->managerGui, 'deleteConnection')),
   'on_buttonConnect_clicked'              =>  array( array( &$this->notebook, 'addConnection')),
   'on_statusList_button_press_event'      =>  array( array( &$this->notebook, 'selectRow')),
   'on_windowAbout_delete_event'           =>  array( array( &$this->aboutDialog, 'hide')),
   'on_menu_help_about_activate'           =>  array( array( &$this->aboutDialog, 'show')),
'on_windowManageDatabases_key_press_event'=>array( array( &$this->managerGui, 'processKeyboardEvents')),
   'on_connectionNotebook_switch_page'     =>  array( array( &$this->notebookGui, 'watchPageSwitch'))
)); "on_menu_file_quit_activate", "on_mainWindow_destroy", etc. are all define in the glade XML file. Here's a short snip from the glade generated XML file:
     <widget>
       <class>GtkMenuItem</class>
       <name>menu_file_quit</name>
       <accelerator>
         <modifiers>GDK_CONTROL_MASK</modifiers>
         <key>GDK_q</key>
         <signal>activate</signal>
       </accelerator>
       <signal>
         <name>activate</name>
         <handler>on_menu_file_quit_activate</handler>
         <last_modification_time>Sun, 08 Apr 2001 22:38:29 GMT</last_modification_time>
       </signal>
       <label>Quit</label>
       <right_justify>False</right_justify>
     </widget>
</widget> As you can see, the signal activate is defined to call the handler on_menu_file_quit_activate, which is mapped via signal_autoconnect() to the right PHP handler. I think, if your PHP functions are named exactly the way they are named in the glade XML file, you don't have to use the array. However, in bigger applications (which these snipplets are from, although it never grew over a certain size) you don't want to have zillions of global functions; thus you remap them to your dedicated objects/methods as you can see in the example above. I do not remember, why the right part of the hash is an array itself. The syntax is: signal_autoconnect( array( 'glade_handler' => array('php_function_to_call'), )); When you connect to objects, you need to use the array syntax: signal_autoconnect( array( 'glade_hjandler' => array( array(&$object, 'method') ) )); However, as stated, I don't remmeber why it's an array at all; maybe it's possible to have multitple handlers called. Attached is an small writing about php-gtk from that time, maybe it's of value to you (I've renamed the HTML file to txt in the hope it won't get stripped); it contains signal_autoconnect() examples too. HTH, sincerly, - Markus

« previous php.gtk.dev (#742) next »