Re: best practice
| From: | Rolland Dudemaine | Date: | Mon, 22 Apr 2002 11:11:10 +0000 |
| Subject: | Re: best practice | ||
| References: | 1 2 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-1823@lists.php.net to get a copy of this message | ||
Ok, I'll go for a mid-solution :
a loader that keeps references to give them later :
function get_widget($widget_name, $glade = null) {
static widget_array = array();
static $sglade;
$i = widget_array[$widget_name];
if (empty($i)) {
if (empty($sglade))
$sglade = $glade;
$i = $sglade->get_widget($widget_name);
widget_array[$widget_name] = $i;
}
retrun $i;
}
with $glade as a facultative argument.
Thanks for the advice,
Regards,
Rolland Dudemaine
----- Original Message -----
From: "Alan Knowles" <alan@akbkhome.com>
To: <rolland.dudemaine@msg-software.com>
Cc: <php-gtk-general@lists.php.net>
Sent: Monday, April 22, 2002 11:24 AM
Subject: Re: [PHP-GTK] best practice
> Its one of those perplexing questions :) -
>
> I would probably go for the preloader
>
> class myinterface {
> var $_interface_items = array(
> "window",
> "entrybox",
> "ok_button"
> );
> /* put this in a base classe ? */
> function load_glade($file) {
> $this->glade = &new GladeXML($file);
> foreach($this->_interface_items as $item)
> $this->$item = $this->glade->get_widget($item);
> }
>
> function main () {
> $this->load_glade("mygladefile");
> $this->entrybox->set_text("hello world");
> $this->window->show();
> }
> }
>
>
>
> if you can get the overload extension
> (http://www.php.net/manual/en/ref.overload.php) working you could try
>
> class myglade extends gladeXML {
>
> function &__get($name) {
> return $this->get_widget($name);
> }
>
> }
>
> hence you may be able to use
> overload('myglade');
> $glade = &new myglade('glade.xml');
> overload($glade)=
> $glade->window->show();
> $glade->gtktext_item->set_text("somevar");
>
> so you get all the glade objects automagically.. - I've not tested this
> - so it may/or may not work !- let me know if you have any success...
>
> regards
> alan
>
>
>
>
> Rolland Dudemaine wrote:
>
> >Heloo,
> >I'm using php-gtk along with libglade to create some complex yet
> >maintainable gui work.
> >Between those two, which is the best practice ?:
> >- have a GladeXML reference that lives along and ask it for components
each
> >time needed
> >- have an array loaded at startup that contains references to each of
these
> >components
> >
> >A motivated answer would be good, as I cannot really choose between one
or
> >another.
> >
> >Best regards,
> >
> >Rolland Dudemaine
> >
> >
>
>
>
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>