Sridhar R | 17 Jan 2004 13:31
Picon
Favicon

about widget creation in libglade

Hi,

I have one doubt regarding libglade.  How is it
creating the widgets from glade file.  It seems like
the widgets are created during creation of GladeXML
object.
  gxml = glade.XML('pathtogladefile')

I am searching for a way to _apply_ glade file to
existing widget (which is already created).  

I will make the above point clearer.  Look at the
following pygtk example, which doesn't use libglade.

class MyWindow(gtk.Window):
    def __init__(self):
        super(MyWindow, self).__init__()
        # any other stuffs like adding widgets
win = MyWindow()
win.show()

The main advantage of this style is `win` is actually
_is_ a widget (a gtk.Window).  So I call win.show()
instead of doing tricks like win.widget.show().  But
is it possible to achieve this advantage, when using
glade file for generating the UI.  NO!  I tried the
following.

class MyWindow2(gtk.Window):
    def __init__(self):
(Continue reading)

Christian Robottom Reis | 19 Jan 2004 19:53
Picon
Gravatar

Re: about widget creation in libglade

On Sat, Jan 17, 2004 at 04:31:33AM -0800, Sridhar R wrote:
> I think the solution to this problem is libglade
> should have a function that takes already created
> widget (window?) as id and sets the properties on that
> widget, then adding the children that widget.  That
> widget is commonly a gtk.Window.  If libglade has such
> a function them the above example could be written as
> ..
> 
> class MyWindowGreat(gtk.Window):
>     def __init__(self):
>         super(MyWindow, self).__init__()
>         self.gladexml = glade.XML('my.glade',
> existing=self)
>         wind = self.gladexml.get_widget('main_window')
>         print wind is self # This is prints `True`

How would you specify multiple pre-existing widgets? 

Normally I find myself wanting to customize the behaviour of a certain
Glade-created widget, and up to now I have relied on __class__
attribution and signals. It works, but it would be nice to allow
specifying your own handler for specific widgets in glade. Perhaps
something like 

    http://bugzilla.gnome.org/show_bug.cgi?id=69639

reports?

Take care,
(Continue reading)

Sridhar R | 20 Jan 2004 08:49
Picon
Favicon

Re: about widget creation in libglade


--- Christian Robottom Reis <kiko <at> async.com.br> wrote:
> On Sat, Jan 17, 2004 at 04:31:33AM -0800, Sridhar R
> wrote:
> > I think the solution to this problem is libglade
> > should have a function that takes already created
> > widget (window?) as id and sets the properties on
> that
> > widget, then adding the children that widget. 
> That
> > widget is commonly a gtk.Window.  If libglade has
> such
> > a function them the above example could be written
> as
> > ..
> > 
> > class MyWindowGreat(gtk.Window):
> >     def __init__(self):
> >         super(MyWindow, self).__init__()
> >         self.gladexml = glade.XML('my.glade',
> > existing=self)
> >         wind =
> self.gladexml.get_widget('main_window')
> >         print wind is self # This is prints `True`
> 
> How would you specify multiple pre-existing widgets?

  No. not multiple, only single.  glade.XML() creates
the widgets immediately.  My problem is to instruct
not to create (a particular widget say gtk.Window i.e.
(Continue reading)

Christian Robottom Reis | 21 Jan 2004 12:17
Picon
Gravatar

Re: about widget creation in libglade

On Mon, Jan 19, 2004 at 11:49:07PM -0800, Sridhar R wrote:
>   No. not multiple, only single.  glade.XML() creates
> the widgets immediately.  My problem is to instruct
> not to create (a particular widget say gtk.Window i.e.
> toplevel in glade file) the widget immediately.  So
> that later I can pass my own widget (here gtk.Window
> instance, a base class instance) to some func in
> libglade so that it assigns properties acc. to glade
> file and return completely designed (with children
> added) window.
>  
> 
>  Again I tried this,
> 
>   class MyWind(gtk.Window):
> 
>    def __new__(cls, *args, **k):
>       xml = glade.XML('file.glade')
>       w = xml.get_widget('toplevel_wind')
>       return w
> 
>     def __init__(self):
>        pass
> 
> 
> But the problem here is self (in __init__) is a base
> class instance.

Well, one way to work around this is to define the gtk.Window in your
code, and have a dummy window defined in Glade that you destroy at
(Continue reading)

Sridhar R | 22 Jan 2004 08:30
Picon
Favicon

Re: about widget creation in libglade


--- Christian Robottom Reis <kiko <at> async.com.br> wrote:
> On Mon, Jan 19, 2004 at 11:49:07PM -0800, Sridhar R
> wrote:
> >   No. not multiple, only single.  glade.XML()
> creates
> > the widgets immediately.  My problem is to
> instruct
> > not to create (a particular widget say gtk.Window
> i.e.
> > toplevel in glade file) the widget immediately. 
> So
> > that later I can pass my own widget (here
> gtk.Window
> > instance, a base class instance) to some func in
> > libglade so that it assigns properties acc. to
> glade
> > file and return completely designed (with children
> > added) window.
> >  
> > 
> >  Again I tried this,
> > 
> >   class MyWind(gtk.Window):
> > 
> >    def __new__(cls, *args, **k):
> >       xml = glade.XML('file.glade')
> >       w = xml.get_widget('toplevel_wind')
> >       return w
> > 
(Continue reading)

Christian Robottom Reis | 22 Jan 2004 18:57
Picon
Gravatar

Re: about widget creation in libglade

On Wed, Jan 21, 2004 at 11:30:02PM -0800, Sridhar R wrote:
> > Well, one way to work around this is to define the
> > gtk.Window in your
> > code, and have a dummy window defined in Glade that
> > you destroy at
> > startup:
> > 
> >     class MyWindow(gtk.Window): pass
> >     
> >     gladewin = xml.get_widget('fake_toplevel')
> >     win = MyWindow()
> >     child = gladewin.get_children()[0]
> >     child.reparent(win)
> 
>    What about the properties of fake_toplevel windows
> defined in glade.  Aren't they got lost by default
> properties of `win` instance?

Yes, they are. You can copy them manually if you like -- just go through
all them and clone them into your MyWindow instance.

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

(Continue reading)

Sridhar R | 19 Jan 2004 07:51
Picon
Favicon

Re: about widget creation in libglade


Jan Weil wrote:
> Of course you can design top-level windows in glade.
> The only difference is that doing so you don't 
> subclass gtk.Window.
> Every time you need one of your toplevel windows you

> call 
> g = glade.XML('file', 'toplevelname')
> w = g.get_widget('toplevelname')
> And you get a regular widget for which you can set 
> properties afterwards.
> 
> I think it only feels less OOP-like which is why I 
> usually don't do it that way.
> Actually that means I have to set w's properties 
> (like border_width) 'by hand'.But that usually only 
> results in adding few more lines of code.

   I think python metaclasses CAN SOLVE the problem. 
I am justing getting my hands into metaclasses now. 
Seems like one can assign a custom __new__ function in
the metaclass so that the widget can be created from
gladeXML inside our new __new__ function.

   Have anybody got the solution (program) yet?

   I am researching on this now.  I'll post it if I
can find the solution.

(Continue reading)

Sridhar R | 18 Jan 2004 06:46
Picon
Favicon

Re: about widget creation in libglade


> I usually design my window using glade. 
> I call the child of the uppermost toplevel window 
> 'child'.
> Then I subclass gtk.Window and add glade.
> get_widget("child") to it in __init__.
> If I understood you correctly this also solves your
> problem, doesn't  it?

  Agreed.  But what if you have to set properties for
the top-level window.  Your solution means one cannot
design top-level windows in glade and that has to be
done manually in the program, after which the `child`
widget as to be gtk_widget_add ed to the created
top-level window.

=====
Sridhar R 
Email: r_sridhar <at> users.sf.net
WWW:   http://sridhar.has.it

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

(Continue reading)

Jan Weil | 18 Jan 2004 09:04
Picon

Re: about widget creation in libglade

On Sun, 2004-01-18 at 06:46, Sridhar R wrote:
>   Agreed.  But what if you have to set properties for
> the top-level window.  Your solution means one cannot
> design top-level windows in glade and that has to be
> done manually in the program, after which the `child`
> widget as to be gtk_widget_add ed to the created
> top-level window.

Of course you can design top-level windows in glade.
The only difference is that doing so you don't subclass gtk.Window.
Every time you need one of your toplevel windows you call 
g = glade.XML('file', 'toplevelname')
w = g.get_widget('toplevelname')
And you get a regular widget for which you can set properties
afterwards.

I think it only feels less OOP-like which is why I usually don't do it
that way.
Actually that means I have to set w's properties (like border_width) 'by
hand'.
But that usually only results in adding few more lines of code.

Jan

_______________________________________________
pygtk mailing list   pygtk <at> daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

(Continue reading)

Jan Weil | 17 Jan 2004 13:57
Picon

Re: about widget creation in libglade

Am Sam, den 17.01.2004 schrieb Sridhar R um 13:31:
> I have one doubt regarding libglade.  How is it
> creating the widgets from glade file.  It seems like
> the widgets are created during creation of GladeXML
> object.

That's true.

> I am searching for a way to _apply_ glade file to
> existing widget (which is already created).

That is (currently) not possible and does IMO not make sense (see
below).

[snip something about 'applying']

> Here there is a confusion.  Actually there are _two_
> windows in existense.  One is `self` and other is
> `wind`.  To avoid this I should _not_ inherit from
> gtk.Window.  But this means the advantages of previous
> example are lost.

Note that you can pass a second argument to glade.XML() which determines
the entry point in glade's widget tree.

I usually design my window using glade. 
I call the child of the uppermost toplevel window 'child'.
Then I subclass gtk.Window and add glade.get_widget("child") to it in
__init__.
If I understood you correctly this also solves your problem, doesn't it?
(Continue reading)


Gmane