PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Hanging Script (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Hanging Script


#3725
markusv (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Hanging Script 1 Month, 3 Weeks ago Karma: 0  
Hi everybody!

I'm making a php-gtk2 application using GtkBuilder (UI designed with glade). The whole thing is wrapped up in a class that extends GtkWindow, this way I only have to say
Code:
$win = new AppWin();
It all works very well, until I want to use a GtkStatusIcon. What happens is this: In AppWin::__construct(), I define a status icon using
Code:
$this->trayIcon = new GtkStatusIcon();
(and then the usual stuff, getting an icon image etc.), and all works well. But when I add a popup menu for the status icon and connect the popup-menu signal, the "magic" happens: On destroying the application window (which is, of course, connected to Gtk::main_quit()), the program won't stop (php is being executed indefinitely with status S+). phpinfo() says:
Code:
php-gtk

GTK+ support => enabled
GTK+ v => 2.20.0
If anybody could help me out with this, I would be very grateful. If you need any info (or source code), I'll be glad to share as little I know :-)
 
  The administrator has disabled public write access.

#3726
kksou (Admin)
Admin
Posts: 1240
graph
User Online Now Click here to see the profile of this user
Re:Hanging Script 1 Month, 3 Weeks ago Karma: 20  
Hi,

I've not familiar with GtkBuilder. I do mostly plain PHP-GTK2 programming. So I'm afraid I cannot help you here.

Hopefully somewhere else can help you. But I would suggest that you give some details. The information you've given here is too vague for anyone to give any constructive suggestion. You might want to give some information on what you've tried, tested or debugged. e.g. you mentioned that you've connected the popup-menu signal. Did it reach your callback function? Or did it not? Try zooming in to the line where the problem occur. Is it problem with the connect statement? Or problem in the callback function?

Regards,
/kksou
 
  The administrator has disabled public write access.

#3729
markusv (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:Hanging Script 1 Month, 3 Weeks ago Karma: 0  
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();
?>
 
 
Last Edit: 2010/07/15 16:56 By markusv.
  The administrator has disabled public write access.



Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved