Sridhar R | 17 Jan 13:31 2004
Picon

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)

Jan Weil | 17 Jan 13:57 2004
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)

Christian Robottom Reis | 19 Jan 19:53 2004
Picon

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 08:49 2004
Picon

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 12:17 2004
Picon

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 08:30 2004
Picon

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 18:57 2004
Picon

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)


Gmane