gnope php gtk gui gnope.org  

Crazy PHP-GTK2 Problem - Am I Losing My Mind?

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
kylemhall



Joined: 21 Nov 2007
Posts: 1

PostPosted: Wed Nov 21, 2007 10:11 pm    Post subject: Crazy PHP-GTK2 Problem - Am I Losing My Mind? Reply with quote

Here's the deal, I'm beginning to write an internet cafe type program in PHP-GTK2.

I've created a LoginWindow class that extends GtkWindow. It's has username and password entry fields, and a login button. All of them are public.

I then wrote a main app to use this LoginWindow like so:
Code:

<?php
  require_once('LoginWindow.php');
  $loginWindow = new LoginWindow();

  $loginWindow->loginButton->connect( 'clicked', 'performLogin', $loginWindow );

  $loginWindow->show_all();

  Gtk::main();


  function performLogin( $loginWindow ){
    $loginWindow->hide_all();
  }

  function quitNow() {
    exit();
  }
?>

When I click the loginButton, which executes the performLogin callback, the *loginButton* dissapears, instead of the entire window. I checked, and indeed, inside performLogin(), $loginWindow refers to loginButton, *not* loginWindow. What's going on?

The only way I can make it work is to make $loginWindow a global, and take it out of the callback parameters. A horrible solution. Can anyone help me out?

Here's the code for the LoginWindow class:
Code:

<?php
class LoginWindow extends GtkWindow {
    public $usernameEntry;
    public $passwordEntry;
    public $loginButton;
    public $quitButton;

  public function __construct() {
    parent::__construct();

    $screen = GdkScreen::get_default();
    $screenWidth = $screen->get_width();
    $screenHeight = $screen->get_height();
 
    $this->set_decorated( 0 );
    $this->set_default_size( $screenWidth, $screenHeight );
    $this->fullscreen();
    $this->set_keep_above( 1 );
 
    $loginBox = new GtkVBox();
    $usernameBox = new GtkHBox();
    $passwordBox = new GtkHBox();
 
    $usernameLabel = new GtkLabel("Username:");
    $this->usernameEntry = new GtkEntry();
    $passwordLabel = new GtkLabel("Password:");
    $this->passwordEntry = new GtkEntry();
    $this->loginButton = new GtkButton("Log In");
 
    $usernameBox->pack_start( $usernameLabel );
    $usernameBox->pack_start( $this->usernameEntry );
    $passwordBox->pack_start( $passwordLabel );
    $passwordBox->pack_start( $this->passwordEntry );
    $loginBox->pack_start( $usernameBox );
    $loginBox->pack_start( $passwordBox );
    $loginBox->pack_start( $this->loginButton );

    if ( DEBUG ) {
      $this->quitButton = new GtkButton("Quit");
#      $quitButton->connect( 'clicked', 'LoginWindow::quitButtonPressed' );
      $loginBox->pack_start( $this->quitButton );
    }
 
    $this->connect_simple( 'destroy', array('Gtk', 'main_quit') );
 
    $centerHBox = new GtkHBox();
    $centerVBox = new GtkVBox();
    $leftBox = new GtkHBox();
    $rightBox = new GtkHBox();
    $topBox = new GtkHBox();
    $bottomBox = new GtkHBox();
 
    $centerHBox->pack_start( $leftBox, true );
    $centerHBox->pack_start( $loginBox, false );
    $centerHBox->pack_start( $rightBox, true );
    $centerVBox->pack_start( $topBox, true );
    $centerVBox->pack_start( $centerHBox, false );
    $centerVBox->pack_start( $bottomBox, true );
 
    $this->add( $centerVBox );
   
  }
 
  public function hideLogin() {
    $this->hide_all();
  } 
 
}
?>

And the *full* code of kioskClient, just in case:
Code:

<?php
  global $_CONSTANTS;
  $_CONSTANTS['DEBUG'] = true;

  require_once('LoginWindow.php');

  $loginWindow = new LoginWindow();

  $loginWindow->loginButton->connect( 'clicked', 'performLogin', $loginWindow );
  $loginWindow->quitButton->connect( 'clicked', 'quitNow' );
 
  $loginWindow->show_all();

#  $gdkWindow = $loginWindow->get_parent_window();
#  $gdkWindow->set_override_redirect( 1 ); ## Doesn't work.

  Gtk::main();

 
  function performLogin( $loginWindow ){
    $loginWindow->hide_all();
  }
 
  function quitNow() {
    exit();
  }
?>
Back to top
kksou



Joined: 06 Sep 2006
Posts: 25

PostPosted: Thu Nov 22, 2007 7:44 am    Post subject: Reply with quote

Your code is running perfectly ok, except one part.

Just change your login button's signal handler to:

Code:
function performLogin( $button, $loginWindow ){
    $loginWindow->hide_all();
}


It should now work just as you've intended...

Regards,
/kksou

p.s. For the signal button 'clicked', PHP-GTK2 always passes along with it the pointer to the button as the first argument. That's why your button keeps disappearing instead of the window.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.