How do I make this code work?

From: Date: Fri, 04 Mar 2005 23:41:17 +0000
Subject: How do I make this code work?
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-5587@lists.php.net to get a copy of this message
HI, As you all probably know by now I am learning PHP-GTK. I have created a very basic app with a filedialog and a file entry area. I have been able to get the button to call the file dialogue and open it What I want to do is, that when you select the file you want and click ok or double click on it the file and its path will appear in the file entry field. Can I ask that someone look at this and let me know if the code is right and also how I should write this to achieve my goal? Thanks guys Lance <?php /**
*    DPfile
*    0.01a
*
*    by
*    Lance Haig
*    LHaig@Haigmail.com
*    http://www.haigmail.com
*
*    File selector to learn
*
*    Changelog:
*    0.01a
*    - first version, so no changes  ;) */
//Load GTK if not happened yet if( !class_exists("gtk")) { dl( "php_gtk." . ( strstr( PHP_OS, "WIN") ? "dll" : "so")); } require_once( "GTK_MessageBox.inc"); $GLOBALS["appDeskFile"] = new dlgMainWindow(); $GLOBALS["appDeskFile"]->run(); /**
*    @author    Lance Haig LHaig@Haigmail.com
*    @version 0.01a
* */ class dlgMainWindow { /**
   *    The main dialog object
   *    @var GtkWindow/GtkDialog
*/ var $MainWindow; /**
   *    Array with all loaded GTK widgets for easy access
   *    @var array
*/ var $arWidgets;
   var $strPathSeparator    = "/";
/**
   *    Title of the dialog window
   *    Use this variable as MessageBox title
*/
   var $strTitle            = "Desktop File";
/**
   *    Constructor
   *    This function is called when you create an object of dlgMainWindow
*/ function dlgMainWindow() {
       $this->InitDialog();
}//function MainWindow() /**
   *    let the program enter the gtk input loop - start the user interface
*/ function run() {
       GTK::main();
}//function run() /**
   *    Main function
   *    Loads the user interface, shows the dialog and
   *    runs the main loop
*/ function InitDialog() {
       strstr( PHP_OS, "WIN") ? $this->strPathSeparator = "\\" : $this->strPathSeparator = "/";
       $this->BuildDialog();
       //Add here your extra initialization
       //like loading data/settings
             $this->MainWindow->show();
}//function InitDialog() /**
   *    dialog creation
   *    This one loads the widgets and connnects functions
*/ function BuildDialog() {
       //use libglade for user interface loading
       //Main window
       $this->glMainWindow        = &new GladeXML( dirname( __FILE__) . $this->strPathSeparator . "DeskFile.glade");
       $this->MainWindow        = $this->glMainWindow->get_widget( "MainWindow");
       $this->MainWindow        ->set_title( $this->strTitle);
       //$this->MainWindow        ->set_usize( 600, 450);
       $this->MainWindow        ->connect(    "destroy"        , array( &$this, "OnDestroy"));
       $this->MainWindow        ->connect(    "delete-event"    , array( &$this, "OnDelete"));
       $this->arWidgets["FileEntry"]    = $this->glMainWindow->get_widget( "FileEntry");
       $this->arWidgets["FileBrowse"]    = $this->glMainWindow->get_widget( "FileBrowse");
       $this->arWidgets["FileBrowse"]    ->connect(    "clicked"    , array( &$this, "FileDialog"));
}//function BuildDialog() /**
   *    If the dialog is being destroyed, the loop should end
   *    Place the SaveSettings calls and so here
*/ function OnDestroy() {
       Gtk::main_quit();
}//function OnDestroy() /**
   *    Call this function if you want to quit by hand
*/ function OnQuit() {
       if( $this->AskForQuit()) {
           $this->MainWindow->destroy();
       }
}//function OnQuit() /**
   *    This function is called if you click the "x" in the upper right of the window
   *    The question is: Do you want to keep the window?
   *    if you return false, the app is closed
   *    if you return true, the app keeps on working
*/ function OnDelete() {
       if( $this->AskForQuit()) {
           return false;
       } else {
           return true;
       }
}//function OnDelete() /**
   *    Asks the user if he really wants to quit
*/ function AskForQuit() {
       $bQuit    = (MessageBox( "Really quit?", $this->strTitle, MB_ICONQUESTION + MB_YESNO + MB_DEFBUTTON2) == IDYES);
       return $bQuit;
}//function AskForQuit() /** * */ function FileDialog( $objPara1) { $fs = &new GtkFileSelection('File Selection Example'); $ok_button = $fs->ok_button; $ok_button-> connect('clicked', 'enddialog', $fs); $ok_button->connect_object('clicked', array($fs, 'destroy')); $cancel_button = $fs->cancel_button; $cancel_button->connect('clicked', 'canceldialog'); $cancel_button->connect_object('clicked', array($fs, 'destroy')); $fs->show(); }//function FileDialog( $objPara1) }//class dlgMainWindow ?> -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.6.2 - Release Date: 04/03/2005

« previous php.gtk.general (#5587) next »