| View previous topic :: View next topic |
| Author |
Message |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Thu Jun 29, 2006 11:44 pm Post subject: updating a widget |
|
|
hi guys,
i'm trying to create a gui using object-orientated programming. it consosts of a gtknotebook, some menus and a toolbar.
getting the gui running isnot the problem, but i have a toolbar with some tooglebuttons, which allow me to access some notebook-pages. the point is, i have also a gtkcombobox, which should allow me to acces some of the notebookpages.
so, when i click on a tooglebutton in the toolbar, it shows me me the right pages, no problem, but it should also update the the shown text in the combobox-widget which it does not, or to be more precise, in the background it does the changing, but the view of my gui is not updated, so the text will not be shown.
i know, its a bit complex, but it has to be done this way for some reasons.
i post the code of the class, which creates the combobox and should also update the entry here, if need be, i post the whole bunch of concerned classes, but i hope this will not be needed, because its quite a lot of code.
| Code: | class ArchivModul_ViewSelect extends GtkVBox {
public static $instance;
public static $comboentry;
public function __construct()
{
parent::__construct();
$label=new GtkLabel('Ansicht');
$this->comboentry = GtkComboBoxEntry::new_text();
$data = array('Standard', 'Datenblatt');
foreach ($data as $str) {$this->comboentry->append_text($str);}
$this->comboentry->set_size_request(90, 25);
$this->pack_start($label, false, false, 0);
$this->pack_start($this->comboentry, false, false, 0);
}
/**
* retrieves the current notebookpage and set the corresponding entry into the combobox .
*
* @access public
* @param
*/
public function getEntry() {
require_once 'MainNotebook.php';
$notebook = ArchivModul_MainNotebook::singleton();
$page = $notebook->get_nth_page($notebook->get_current_page());
$text= $notebook->get_tab_label_text($page);
$titlearray = explode(" ", $text);
if ($titlearray[1] == "DB"){$this->comboentry->get_child()->set_text('Datenblatt');}
elseif ($titlearray[1] == "Tree"){$this->comboentry->get_child()->set_text('Standard');}
else {$this->comboentry->get_child()->set_text('');}
}
public static function singleton()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
} |
so the object will be constructed, and the getEntry-method will be called from the tooglebuttons...
hope, you could help me. |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Thu Jun 29, 2006 11:57 pm Post subject: |
|
|
Stefan,
Theoretically it should work, at least set_text() modifies the entry:
| Code: | <?php
$window = new GtkWindow();
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$combo = GtkComboBoxEntry::new_text();
$combo->append_text('New Jersey');
$combo->append_text('New Mexico');
$combo->append_text('New York');
$window->add($combo);
$window->show_all();
$combo->get_child()->set_text('test?');
Gtk::main();
?> |
Now the question is why it doesn't do this for you.
- Are you doing some longer processing afterwards, so that the text gets updated after this long processing only?
- Does some *other* method changes the text immediately after? |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Jun 30, 2006 12:45 am Post subject: |
|
|
For the moment i'm just setting up the gui, so there is definitly now other processing, which could freeze my gui.
if i do apply the text directly in the constructor, the text will be set, but not afterwards in my method.
if i try it like shown above and use the get_text-method of gtkcombobox afterwards in the same method, it gives the corrrect text back. so it will just not be shown in my gui...
wonder why |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri Jun 30, 2006 12:50 am Post subject: |
|
|
| Try to call queue_draw() |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Jun 30, 2006 12:57 am Post subject: |
|
|
where?
within the getEntry-Method?? |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Jun 30, 2006 12:59 am Post subject: |
|
|
the following doesn't work:
| Code: | | $this->comboentry->queue_draw(); |
|
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri Jun 30, 2006 1:05 am Post subject: |
|
|
| And in the child (the entry itself)? |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Jun 30, 2006 1:11 am Post subject: |
|
|
no way  |
|
| Back to top |
|
 |
scott
Joined: 16 Feb 2006 Posts: 35
|
Posted: Fri Jun 30, 2006 2:23 pm Post subject: |
|
|
Hi Stefan,
One question, why are you using a GtkComboBoxEntry? This creates an entry with a drop down. You probably don't want people to freely type in new page values. I think if you just use a GtkComboBox you will find the UI much easier to work with from an end user perspective.
As for your setting a value problem, have you tried set_active()? From what I understand of your problem, you should be doing something like this:
| Code: | public function getEntry() {
...
// Hopefully the page num matches the combo index.
$pageNum = $notebook->get_current_page();
$this->comboentry->set_active($pageNum);
... |
|
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Jun 30, 2006 3:08 pm Post subject: |
|
|
hi scott,
i do now use GtkComboBox instead of ComboBoxEntry, but my main-problem with setting the values isn't solved yet. set_active doesn't work as well. |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Fri Jun 30, 2006 3:22 pm Post subject: |
|
|
If you echo the text that shall be set (or the notebook number) in the callback, do you get the correct values?
If not, try to use the connect_after() to connect the switch-page signal.
If nothing helps, make a copy of your code and remove all the unnecessary things, keeping only the code that produces the bug. Post it here (shouldn't be more than 30 lines then) |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Sat Jul 01, 2006 10:04 pm Post subject: |
|
|
hey christian,
when i echo the values of the combobox, i get the right/expected values, so my method sets them properly, it's just that the shown values of the gui won't be updated... |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Sun Jul 02, 2006 12:42 am Post subject: |
|
|
allright,
here are my functions, which produce the bug:
| Code: | class ArchivModul_Toolbar extends GtkToolbar {
...
public function toggleAkzession(GtkToolButton $button)
{
...
$selector = ArchivModul_ViewSelect::singleton();
$selector->getPage();
}
}
class ArchivModul_ViewSelect extends GtkVBox {
public static $instance;
public static $comboBox;
public function __construct()
{
...
}
function getPage()
{
$this->comboBox->set_active(0);
}
public static function singleton()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
|
the point is, if i press a tooglebutton in my toolbar (archivmodul_toolbar) it should load the getPage-Method of archivmodul_viewselect und set the first item of the coresponding liststore active. As far as i can see, the method really does this, but the combobox doesn't display the active item in his entry field. |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Sun Jul 02, 2006 12:48 am Post subject: |
|
|
allright guys, found the bug on my own (i have to admitt, a really stupid one): i forgot to instantiate the singleton-mode of the ViewSelect-Class on my main class, now it works like a charm!
Thanks a lot to all of you, who tried to help me.  |
|
| Back to top |
|
 |
|