NYCPHP Meetup

NYPHP.org

[nycphp-talk] [ PHP-GTK ] - Button Callbacks Not Working

Joseph Crawford codebowl at gmail.com
Sat Oct 16 21:05:58 EDT 2004


I hope this is considered on topic because it is php related and i
didnt mark it as [OT]


Guys i am starting to learn php-gtk and i am having a bit of a
problem, when i click my button the Actions::destroy() method is not
called for the callback.

here are the errors i get when i run the app and click the button

[idle at vt-fairhaven1a-82 irc-php]$ php irc.php

Gtk-CRITICAL **: file gtkmain.c: line 582 (gtk_main_quit): assertion
`main_loops != NULL' failed.

Warning: Unable to call signal callback '' specified in
/home/idle/irc-php/class/button.class.php on line 9 in
/home/idle/irc-php/irc.php on line 15

[idle at vt-fairhaven1a-82 irc-php]$



here is my code

irc.php
===============================
<?php
//Load GTK if not happened yet
if( !class_exists("gtk")) {
    dl( "php_gtk." . PHP_SHLIB_SUFFIX);
}
include_once 'class/actions.class.php';
include_once 'class/ircapp.class.php';
include_once 'class/button.class.php';
include_once 'class/window.class.php';

$app = new IrcApp();
$app->main();

/* Run the program from top to bottom. */
Gtk::main();
?>


class/actions.class.php
===============================
<?php
class Actions {
    function Actions() {

    }

    function destroy() {
        gtk::main_quit();
    }
}
?>

class/ircapp.class.php
===============================
<?php

class IrcApp {

    function main() {
        /*Now, create the window widget as a variable.*/
        $window = &new Window("PHP Window Number 1", GTK_WIN_POS_CENTER);

        $button = &new Button("clickme");
        $button->connect('clicked', 'destroy');
        $window->add($button->get_handle());
        

        /*This statement is also necessary in all PHP-GTK applications
that have graphics on the screen.
        This shows all the parent widgets and their children.*/

        $window->show();

    }
}

?>

class/button.class.php
===============================
<?php
class Button {
    var $button;
    function Button($name) {
        $this->button = &new GtkButton($name);
    }

    function connect($action, $function) {
        $this->button->connect($action, Actions::$function());
    }

    function get_handle() {
        return $this->button;
    }
}

?>

class/window.class.php
===============================
<?php
class Window {
    var $window;

    function Window($title, $pos) {
        $this->window = &new GtkWindow();
        $this->window->set_title($title);
        $this->window->set_position($pos);
    }

    function show() {
        $this->window->show_all();
    }

    function add($item) {
        $this->window->add($item);
    }
}
?>

-- 
Joseph Crawford Jr.
Codebowl Solutions
codebowl at gmail.com

For a GMail account
contact me OFF-LIST



More information about the talk mailing list