PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Integrating sample code How to set up menu ? (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Integrating sample code How to set up menu ?
#469
Riseryn (User)
Fresh Boarder
Posts: 9
graphgraph
User Offline Click here to see the profile of this user
solved-Integrating sample code How to set up menu 2 Months, 2 Weeks ago Karma: 0  
Hi
Im trying to use "How to set up menu and radio menu - Part 1" in my program but if my window open correctly I have no menu.

Obviously Im making an error somewhere but where?
The error is probably in setup_menu function and caused by my usage of glade file I guess.

I got this error message :
(gescom.phpw:3256): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -4 and height 14

Im unable to find what widget produce this :(

Hope you can help me on this one :)

Here is my code

Code:
<?php
//Main window
//Create a new glade instance, load the 
// widgets from the file passed as parameter
$Main=new Module('Main');
$wndMain = $Main->select_Widget('wndMain');
$menubar = $Main->select_Widget('menuBar');//menuBar is the name of the GtkMenuBar
$wndMain->connect_simple('destroy', array('Gtk', 'main_quit'));

$menu_definition =  array
(
    '_File' => array('_New', '_Open', '_Close', '_Quit'),
    '_Test' => array('Test1', 'Test2', 'Test3', '<hr>',
                array('Selection 1', 'Selection 2', 'Selection 3'),
                '<hr>', 'Test4')
);

// setup menu
function setup_menu($menubar, $menus) 
{ 

	 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');
                }
            }
        }
    }
}
// process radio menu selection
function on_toggle($radio) 
{ // note 3
    $label = $radio->child->get_label();
    $active = $radio->get_active();
    echo("radio menu selected: $label\n");
}

// process menu item selection
function on_menu_select($menu_item) 
{
    $item = $menu_item->child->get_label();
    echo "menu selected: $item\n";
    if ($item=='_Quit') Gtk::main_quit();
}


setup_menu($menubar, $menu_definition);


//get screen size
$screen = $wndMain->get_screen(); 
$screen_width = $screen->get_width();
$screen_height = $screen->get_height();

//resize window Main(wndMain)
$wndMain->set_size_request($screen_width*2/3, $screen_height*2/3);

// set background image 
$wndMain->connect('expose_event', 'load_Logo');

// set Status Bar
$stbStatus_bar= $Main->select_Widget('status_bar');
// display a message in the status bar
$defLang="frFR";
	if($defLang=="frFR")
	{$date=strftime("%A %d %B %Y    %H:%M");}
		else{$date=strftime("%B %A %d %Y    %H:%M");}
$connected=" | ".$User." | ";
$txtStatus=$date.$connected;
$context_id = $stbStatus_bar->get_context_id('msg1');
$stbStatus_bar->push($context_id,' '.$txtStatus);

//Start the main loop

Gtk::main();
?>
 
 
Last Edit: 2008/07/24 16:23 By Riseryn.
  The administrator has disabled public write access.
#471
Riseryn (User)
Fresh Boarder
Posts: 9
graphgraph
User Offline Click here to see the profile of this user
Re:Integrating sample code How to set up menu ? 2 Months, 2 Weeks ago Karma: 0  
Ok finally after hours meticulously reading my code i find the culprit.

I just forgot the line
$wndMain->show_all();
before
Gtk::main();

How simple but irritating mistake :)
 
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Copyright © 2006-2008. kksou.com. All Rights Reserved