Re: Menu Help

From: Date: Thu, 14 Jul 2005 07:05:30 +0000
Subject: Re: Menu Help
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6009@lists.php.net to get a copy of this message
Bulio wrote:
Hi everyone. I am currently making a text-editor program with a menubar on the top. What I would like to know, is how do I define things in the menu? Example: File->Open Would open the Open box in php gtk. I Have file-> open currently, but It does nothing. I want to know how to write in what it does. Thanks
Since I just re-started working on php-gtk apps I also might share some refreshed expirience withit ;) I first started by creating manually all the gtkmenus and items but it's painful. And since I'm not yet at the point to use Glade (available from http://wingtk.sf.net/ ) to create the UI with a designer, I used the GtkItemFactory [1]. With the factory you can create a complete menu with a single array defining the structure and behaviour. The factory may look something like this: $accelgroup = &new GtkAccelGroup(); $window->add_accel_group(&$accelgroup); $fac = &new GtkItemFactory(GtkMenuBar::get_type(), '<mainmenu>', &$accelgroup); $items = array( array( '/_Administration/_Liste aktualisieren', 'F5', array(&$this, 'updateList'), 0, NULL), array('/_Administration/sep1', NULL, NULL, 0, '<Separator>'), array('/_Administration/_Beenden', '<ALT>-F4', array(&$this, 'quit'), 0, ''), array('/_Diverses/_Filter', '', NULL, 0, '<CheckItem>'), ); $fac->create_items($items); $menubar = &$fac->get_widget("<mainmenu>"); $menubar->show(); At this point the $menubar is ready to be packed somewhere in your layout. The $accellGroup is necessary to have the keyboard shortcuts also working. The '/' character separates the menus, the '_' character says that the next character is accessible with the keyboard shortcuts. It's likely that for some menu entries you need specific options. You can retrieve any of the menu widget with get_widget() like we did already for the menubar. For instance I needed the toggled signal but the factory by default only assigns connects to the activate signal: $menu = &$fac->get_widget('/Diverses/Filter'); $menu->connect('toggled', array(&$this, 'menuFilterToggled')); HTH :) - Markus [1] http://gtk.php.net/manual/en/gtk.gtkitemfactory.constructor.php

« previous php.gtk.general (#6009) next »