Hi everybody!
Thanks for your feedback, kksou!
Today I had
the idea. It works now, and for those who may, in the future, experience the same problem (which took me two weeks to figure out), I'm writing this post.
I was using a smaller version of my script (for better diagnosis), which you can see at the end of the post.
It works like described in the first post, i. e. it works all fine, until the window is destroyed, at which point the scrips refuses any further action (and the status icon is still visible, btw). If you leave out one of the connect_simple lines (the one that is marked), no problems arise, but it would be impossible to see the menu. Notice, too, that there is no GtkBuilder involved, so this can't be the source of the bug.
Today, I noticed that the callbacks usually are not non-static functions. So I just declared $this->tray and popup_tray_menu static, and changed the callback from array($this, ...) to array(self, ...).
Now it works like a charm :)
Best regards,
Markus.
| Code: |
<?php
class AppWindow extends GtkWindow
{
protected $tray;
protected $trayMenu;
public function __construct()
{
parent::__construct();
$this->set_title("Just a test!");
$this->add($vbox = new GtkVBox());
$vbox->pack_start(new GtkLabel("Just a test!"), null, false);
$vbox->pack_start(new GtkLabel("Just another test!"), null, false);
$this->tray = GtkStatusIcon::new_from_stock(Gtk::STOCK_EXECUTE);
$this->trayMenu = new GtkMenu();
$this->trayMenu->add($lol = new GtkMenuItem("LOL"));
// connect events
$lol->connect_simple("activate", function() {echo "clicked \"LOL\"!\n";});
// if you leave the following line out, no problems arise. But the
// menu will be un-poppable
$this->tray->connect_simple("popup-menu", array($this, "popup_tray_menu"));
$this->connect_simple("destroy", array("Gtk", "main_quit"));
GtkStatusIcon::position_menu($this->trayMenu, $this->tray);
$this->show_all();
Gtk::main();
}
public function popup_tray_menu()/*{{{*/
{
$this->trayMenu->show_all();
$this->trayMenu->popup();
}/*}}}*/
}
new AppWindow();
?>
|