Re: Problem with ToolBar in PHP-GTK2

From: Date: Wed, 08 Jun 2005 19:54:23 +0000
Subject: Re: Problem with ToolBar in PHP-GTK2
References: 1 2 3 4  Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-1375@lists.php.net to get a copy of this message
Thanks, Ivan. But thus he does not give to connect signals to buttons. See as I solved: <?php class ToolBar extends GtkToolBar {
    protected $buttons_id = array('gtk-new', 'gtk-media-pause', 'gtk-refresh', 'gtk-quit');
    protected $buttons = array();
    function __construct()
    {
        parent::__construct();
    }
    function load_buttons()
    {
        foreach($this->buttons_id as $id) {
            $this->buttons = array_merge($this->buttons, array($id => GtkToolButton::new_from_stock($id)));
        }
        $this->buttons['gtk-media-pause']->set_sensitive(false);
        $this->buttons['gtk-refresh']->set_sensitive(false);
    }
    function add_buttons()
    {
        foreach ($this->buttons as $button) {
            parent::add($button);
        }
    }
    function connect_signals($app)
    {
        $this->buttons['gtk-quit']->connect_object('clicked', array('Gtk', 'main_quit'));
        $this->buttons['gtk-new']->connect_object('clicked', array($app, 'load_game'));
    }
    static function get_toolbar($app)
    {
        $tool = &new ToolBar();
        $tool->load_buttons();
        $tool->connect_signals($app);
        $tool->add_buttons();
        return $tool;
    }
} ?> []'s Daniel Braga Ivan Rodriguez wrote:
Hi I have the same problem but i solved with <?php class ToolBar extends GtkToolBar {
    protected $buttons_id = array('gtk-new',
'gtk-media-pause','gtk-refresh', 'gtk-quit');
    protected $buttons = array();
    function __construct()
    {
        parent::__construct();
    }
    function load_buttons()
    {
        for($i = 0; $i < sizeof($this->buttons_id); $i++) {
               parent::add(GtkToolButton::new_from_stock($this->buttons_id[$i]));
        }
    }
    static function get_toolbar()
    {
        $tool = new ToolBar();
        $tool->load_buttons();
        return $tool;
    }
} $window = new GtkWindow(); $window->connect_object('destroy', array('gtk','main_quit')); $toolbar = ToolBar::get_toolbar(); $window->add($toolbar); $window->show_all(); Gtk::main(); ?> On 6/8/05, Daniel Braga <daniel@comentar.com.br> wrote:
/* translated from portuguese by Google */ I am trying to create a ToolBar in the Php-gtk2. Until I obtain, but instead of 4 buttons alone he appears 3. I place stock_ids of the buttons that I need in an Array and later I cover the Array generating the buttons and placing them in another Array. The problem is that the first button never is placed in the Array. I do not know if I am making some wrong thing. Somebody can give one help? [ ]'s Daniel Braga <?php class ToolBar extends GtkToolBar {
    var $buttons_id = array('gtk-new', 'gtk-media-pause',
'gtk-refresh', 'gtk-quit');
    var $buttons = array();
    function __construct()
    {
        parent::__construct();
    }
    function load_buttons()
    {
        foreach ($this->buttons_id as $stock_id) {
            $this->buttons[$stock_id] =
GtkToolButton::new_from_stock($stock_id);
        }
    }
    function add_buttons()
    {
        foreach ($this->buttons as $button) {
            parent::add($button);
        }
    }
    static function get_toolbar()
    {
        $tool = &new ToolBar();
        $tool->load_buttons();
        $tool->add_buttons();
        return $tool;
    }
} $window = new GtkWindow(); $window->connect_object('destroy', array('gtk','main_quit')); $toolbar = ToolBar::get_toolbar(); $window->add($toolbar); $window->show_all(); Gtk::main(); ?> -- PHP-GTK Development Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
____________________________________________________ Yahoo! Mail, cada vez melhor: agora com 1GB de espaço grátis! http://mail.yahoo.com.br

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