Beispiel #1
0
function setup_menu($vbox, $menu_definition)
{
    // note 1
    $menubar = new GtkMenuBar();
    // note 2
    $vbox->pack_start($menubar, 0, 0);
    foreach ($menu_definition as $toplevel => $sublevels) {
        $menubar->append($top_menu = new GtkMenuItem($toplevel));
        $menu = new GtkMenu();
        $top_menu->set_submenu($menu);
        foreach ($sublevels as $item) {
            if ($item == '<hr>') {
                $menu->append(new GtkSeparatorMenuItem());
            } else {
                $item2 = str_replace('_', '', $item);
                $item2 = str_replace(' ', '_', $item2);
                $stock_image_name = 'Gtk::STOCK_' . strtoupper($item2);
                $stock_image = '';
                if (defined($stock_image_name)) {
                    $stock_image = constant($stock_image_name);
                }
                // note 3
                $action = new GtkAction($item, $item, '', $stock_image);
                // note 4
                $menu_item = $action->create_menu_item();
                // note 5
                $action->connect('activate', 'on_menu_select', $item);
                // note 6
                $menu->append($menu_item);
                // note 7
            }
        }
    }
}
Beispiel #2
0
function setup_menu($vbox, $menus)
{
    // note 1
    $menubar = new GtkMenuBar();
    $vbox->pack_start($menubar, 0, 0);
    foreach ($menus as $toplevel => $sublevels) {
        $menubar->append($top_menu = new GtkMenuItem($toplevel));
        $menu = new GtkMenu();
        $top_menu->set_submenu($menu);
        foreach ($sublevels as $submenu) {
            if (is_array($submenu)) {
                // set up radio menus
                $i = 0;
                $radio[0] = null;
                foreach ($submenu as $radio_item) {
                    // note 3
                    $radio[$i] = new GtkRadioMenuItem($radio[0], $radio_item);
                    $radio[$i]->connect('toggled', "on_toggle");
                    $menu->append($radio[$i]);
                    ++$i;
                }
                $radio[0]->set_active(1);
                // select the first item
            } else {
                if ($submenu == '<hr>') {
                    $menu->append(new GtkSeparatorMenuItem());
                } else {
                    $menu->append($menu_item = new GtkMenuItem($submenu));
                    $menu_item->connect('activate', 'on_menu_select');
                }
            }
        }
    }
}
		private function GenerateMenus($menu, $menus){
			foreach($menus AS $key => $value){
				$newmenu = new GtkMenuItem($key);
				
				if (is_array($value)){
					$submenu = new GtkMenu();
					$submenu->set_size_request(135, -1);
					$this->GenerateMenus($submenu, $value);
					
					$newmenu->set_submenu($submenu);
				}else{
					$newmenu->connect("activate", array($this, "MenuClicked"), $value);
				}
				
				$menu->append($newmenu);
			}
		}
Beispiel #4
0
function setup_menu($vbox, $menus)
{
    global $G;
    $menubar = new GtkMenuBar();
    $vbox->pack_start($menubar, 0, 0);
    foreach ($menus as $toplevel => $sublevels) {
        $menubar->append($top_menu = new GtkMenuItem($toplevel));
        $menu = new GtkMenu();
        $top_menu->set_submenu($menu);
        foreach ($sublevels as $submenu) {
            if (is_array($submenu)) {
                // set up radio menus
                $i = 0;
                $radio[0] = null;
                foreach ($submenu as $radio_item) {
                    $radio[$i] = new GtkRadioMenuItem($radio[0], $radio_item);
                    $radio[$i]->connect('toggled', "on_toggle");
                    $menu->append($radio[$i]);
                    ++$i;
                }
                $radio[0]->set_active(1);
                // select the first item
            } else {
                if ($submenu == '<hr>') {
                    $menu->append(new GtkSeparatorMenuItem());
                } else {
                    $submenu2 = str_replace('_', '', $submenu);
                    // note 1
                    $submenu2 = str_replace(' ', '_', $submenu2);
                    // note 1
                    $stock_image_name = 'Gtk::STOCK_' . strtoupper($submenu2);
                    // note 1
                    if (defined($stock_image_name)) {
                        $menu_item = new GtkImageMenuItem(constant($stock_image_name));
                        // note 2
                    } else {
                        $menu_item = new GtkMenuItem($submenu);
                    }
                    $menu->append($menu_item);
                    $menu_item->connect('activate', 'on_menu_select');
                }
            }
        }
    }
}
 /**
  * @name __construct($label="")
  * @param string $label Texto do menuitem
  * @return GtkMenuItem
  */
 public function __construct($label = "")
 {
     parent::__construct($label);
 }
Beispiel #6
0
 function Menu($vbox, $menu_definition, $accel_group)
 {
     $this->menu_definition = $menu_definition;
     $menubar = new GtkMenuBar();
     $vbox->pack_start($menubar, 0, 0);
     foreach ($menu_definition as $toplevel => $sublevels) {
         $top_menu = new GtkMenuItem($toplevel);
         $menubar->append($top_menu);
         $menu = new GtkMenu();
         $top_menu->set_submenu($menu);
         // let's ask php-gtk to tell us when user press the 2nd Alt key
         $menu->connect('key-press-event', array(&$this, 'on_menu_keypress'), $toplevel);
         //*
         foreach ($sublevels as $submenu) {
             if (strpos("{$submenu}", '|') === false) {
                 $accel_key = '';
             } else {
                 list($submenu, $accel_key) = explode('|', $submenu);
             }
             if ($submenu == '<hr>') {
                 $menu->append(new GtkSeparatorMenuItem());
             } else {
                 $submenu2 = str_replace('_', '', $submenu);
                 $submenu2 = str_replace(' ', '_', $submenu2);
                 $stock_image_name = 'Gtk::STOCK_' . strtoupper($submenu2);
                 if (defined($stock_image_name)) {
                     $menu_item = new GtkImageMenuItem(constant($stock_image_name));
                 } else {
                     $menu_item = new GtkMenuItem($submenu);
                 }
                 if ($accel_key != '') {
                     $menu_item->add_accelerator("activate", $accel_group, ord($accel_key), Gdk::CONTROL_MASK, 1);
                 }
                 $menu->append($menu_item);
                 $menu_item->connect('activate', array(&$this, 'on_menu_select'));
                 $this->menuitem[$toplevel][$submenu] = $menu_item;
             }
             //                }
         }
         // */
     }
 }
Beispiel #7
0
 /**
  * Create the menu.
  *
  * The menu is very simple. It an exit menu item, which exits
  * the application, and an about menu item, which shows some
  * basic information about the application itself.
  *
  * @access private
  * @param  none
  * @return &object The GtkMenuBar
  */
 function &_createMenu()
 {
     // Create the menu bar.
     $menuBar = new GtkMenuBar();
     // Create the main (only) menu item.
     $phpHeader = new GtkMenuItem('PHPUnit');
     // Add the menu item to the menu bar.
     $menuBar->append($phpHeader);
     // Create the PHPUnit menu.
     $phpMenu = new GtkMenu();
     // Add the menu items
     $about = new GtkMenuItem('About...');
     $about->connect('activate', array(&$this, 'about'));
     $phpMenu->append($about);
     $exit = new GtkMenuItem('Exit');
     $exit->connect_object('activate', array('gtk', 'main_quit'));
     $phpMenu->append($exit);
     // Complete the menu.
     $phpHeader->set_submenu($phpMenu);
     return $menuBar;
 }