gnope php gtk gui gnope.org  

GtkDialog not displaying label

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



Joined: 29 Sep 2006
Posts: 10

PostPosted: Tue Oct 17, 2006 11:43 am    Post subject: GtkDialog not displaying label Reply with quote

Hi, i have an app which searches a DB. When the search starts i create a GTkDialog, with a label, and when it ends i destroy it. Problem is the app needs to run in the background when the dialog is displayed. If i use $dialog->run() it displays fine, but it stops the main loop, which i cant have. If i do show_all instead, it shows the dialog window, but no label is visible. Here's my code...

Code:


$text = "sometext";

$dialogOptions = 0;
$dialog = new GtkDialog('Message',null,$dialogOptions,$dialogButtons);
$message = new GtkLabel($text);

$dialog ->vbox->pack_start($text);
$dialog ->show_all();



if i do $dialog->vbox->show_all() it doesnt display anything.

Any ideas please?
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Tue Oct 17, 2006 12:03 pm    Post subject: Re: GtkDialog not displaying label Reply with quote

edlynn wrote:
Here's my code...
Code:

$message = new GtkLabel($text);

$dialog ->vbox->pack_start($text);


I hope it's not the code you're actually using...

You pack $text when you should be packing $message
Back to top
edlynn



Joined: 29 Sep 2006
Posts: 10

PostPosted: Tue Oct 17, 2006 12:30 pm    Post subject: Reply with quote

Sorry, yes, im doing

Code:


$dialog->vbox->pack_start($message);

Back to top
edlynn



Joined: 29 Sep 2006
Posts: 10

PostPosted: Tue Oct 17, 2006 12:36 pm    Post subject: Reply with quote

I think its could be something to do with me trying to create and display the dialog inside a function, and then im trying to passed the dialog back so i can select when to destroy it. So im doing ...

Code:


$msg = $this->popUpDialog("Searching","No buttons");   

//do some work here

$msg->destory();

function popUpDialog ($text,$extra)
{
        echo "Showing Dialog";
       
     $dialogOptions = 0;
      
     //Set up buttons
     $dialogButtons = array();
      
     //Dont show a horizontal seperator
    $dialogOptions = $dialogOptions | Gtk::DIALOG_NO_SEPARATOR;
      
            
   //Create the dialog
  $dialog = new GtkDialog('Message',null,$dialogOptions,$dialogButtons);
      
  //Add message
  $message = new GtkLabel($text);
      
   $dialog->vbox->pack_start($message);
               
    //display the dialog
    $dialog->vbox->show_all();
               
             
     $dialog->show_all();          
    return $dialog;
}
       


If i remove the $msg->destroy() it behaves quite oddly. When the window appears, there is no text in it. After the "//doing some work part" the label then appears! I'm obviously doing something wrong / odd here but i cant figure it out.
Back to top
kksou



Joined: 06 Sep 2006
Posts: 25

PostPosted: Tue Oct 17, 2006 3:57 pm    Post subject: Reply with quote

Hi Edlynn,

Guess you're trying to show a dialog saying "in progress..." before starting a long job. Ideally when the job is done, you will close the dialog.

Please take a look at the article:
http://www.nabble.com/-PHP-GTK--Help-with-Dialog-Popup-t196050.html

There are some solutions suggested there.

Regards,
/kksou


Last edited by kksou on Fri Oct 20, 2006 7:40 pm; edited 1 time in total
Back to top
edlynn



Joined: 29 Sep 2006
Posts: 10

PostPosted: Wed Oct 18, 2006 12:25 pm    Post subject: Reply with quote

Yes, thats exactly what i'm trying to do. Thanks for the reply, i'll have a look at that article.
Back to top
kksou



Joined: 06 Sep 2006
Posts: 25

PostPosted: Fri Oct 20, 2006 7:37 pm    Post subject: Reply with quote

Here's a sample code that displays a progress bar while processing a long task as shown below:



Code:
<?php
$window = new GtkWindow();
$window->set_size_request(400, 120);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Display progress bar while processing long task");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0); // add a small gap

$vbox->pack_start($hbox = new GtkHBox(), 0, 0);
$hbox->pack_start($button = new GtkButton('Start processing'), 1, 0);
$button->connect('clicked', 'start_processing');


$window->show_all();
Gtk::main();

function start_processing($button, $entry) {
    $show_progress_dialog = new ShowProgress(); // note 1
    $max = 30000; // note 2
    for ($i=0; $i<$max; ++$i) {
        echo "$i "; // note 2
        if ($i%1000==0) { // note 3
            $percent_complete = number_format($i/$max*100, 0);
            $show_progress_dialog->progress_bar->set_fraction($i/$max); // note 4
            $show_progress_dialog->progress_bar->set_text($percent_complete.'% Complete'); // note 5
            while (Gtk::events_pending()) {Gtk::main_iteration();} // note 6
        }
    }

    $show_progress_dialog->dialog->destroy(); // done. close the dialog box.
}

class ShowProgress { // note 1

    var $progress_bar;
    var $dialog;

    function ShowProgress() {
        $dialog = new GtkDialog('Work in progress...', null, Gtk::DIALOG_MODAL); // create a new dialog
        $top_area = $dialog->vbox;
        $top_area->pack_start(new GtkLabel('Please hold on while processing data...'));
        $this->progress_bar = new GtkProgressBar();
        $this->progress_bar->set_orientation(Gtk::PROGRESS_LEFT_TO_RIGHT);
        $top_area->pack_start($this->progress_bar, 0, 0);
        $dialog->set_has_separator(false);
        $dialog->show_all(); // show the dialog
        $this->dialog = $dialog; // keep a copy of the dialog ID
    }
}

?>


More explanation at:
http://www.kksou.com/php-gtk2/articles/display-progress-bar-while-processing-long-task.php

Regards,
/kksou
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.