[pygtk] How to run gtk.Builder.connect_signals multiple times?

2011-06-27 Thread Mac Ryan
I posted the same question on Stack Overflow, but so far it only got 3
views and no answers... :(

http://stackoverflow.com/questions/6492000

In the design of my program I would like to pass around the
gkt.Builder() instance to various modules (each of them has
some of the handlers for managing the GUI), but I found out 
that once the builder is instantiated one can only call the
connect_signals() method once: if called more than once, any 
call after the second will return None (which would mean: 
all signals have been connected, which is a blatant lie!).

I tried to see if I could understand how/where gtk.Builder 
stores the handler names that are assigned within the Glade 
GUI, in order to write my own method to overcome this limitation, 
but after more than an hour of console experiments I still
haven't understand where this information is stored.

Is there anybody on the list that is able to advice me? Basically I
would be happy in any of these scenarios:

* Find a way to re-use the same builder over and over.
* Find an alternative method to *AUTO-assign* methods of various modules
  as callbacks to GUI-emitted signals (with the GUI being defined in a
  monolithic Glade Builder XML file).
* Find a way to extract from the from the gtk.Builder (or in some other
  way) the pairs widget-instance-expected-handler-name as defined in
  the Glade editor.

As for my previous mail on this list: I solved the problem myself:
what I misunderstood was the correct use of the method dialogue.run().

Thanks in advance for your time,
/mac
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] How to run gtk.Builder.connect_signals multiple times?

2011-06-27 Thread Giuseppe Penone
I invite you to take a look to the source code of my simplest application
http://www.giuspen.com/nautilus-pyextensions/
where as you can see gtk.Builder() is called only once and there's no need
for further calls.

the code that you have to look for:

class GladeWidgetsWrapper:
   Handles the retrieval of glade widgets

   def __init__(self, glade_file_path, gui_instance):
  try:
 self.glade_widgets = gtk.Builder()
 self.glade_widgets.set_translation_domain(cons.APP_NAME)
 self.glade_widgets.add_from_file(glade_file_path)
 self.glade_widgets.connect_signals(gui_instance)
  except: print Failed to load the glade file

   def __getitem__(self, key):
  Gives us the ability to do: wrapper['widget_name'].action()
  return self.glade_widgets.get_object(key)

   def __getattr__(self, attr):
  Gives us the ability to do: wrapper.widget_name.action()
  new_widget = self.glade_widgets.get_object(attr)
  if new_widget is None: raise AttributeError, 'Widget %r not found' %
attr
  setattr(self, attr, new_widget)
  return new_widget

.

class NautilusPyExtensions:
   The application's main window

   def __init__(self, store):
  ...
  # instantiate the Glade Widgets Wrapper
  self.glade = GladeWidgetsWrapper(cons.GLADE_PATH +
'nautilus-pyextensions.glade', self)

.

furthermode in the code you access the widgets with self.glade.widgetname,
all signals are connected.

Hope this helps.
Giuseppe.







On Mon, Jun 27, 2011 at 17:02, Mac Ryan quasipe...@gmail.com wrote:

 I posted the same question on Stack Overflow, but so far it only got 3
 views and no answers... :(

 http://stackoverflow.com/questions/6492000

 In the design of my program I would like to pass around the
 gkt.Builder() instance to various modules (each of them has
 some of the handlers for managing the GUI), but I found out
 that once the builder is instantiated one can only call the
 connect_signals() method once: if called more than once, any
 call after the second will return None (which would mean:
 all signals have been connected, which is a blatant lie!).

 I tried to see if I could understand how/where gtk.Builder
 stores the handler names that are assigned within the Glade
 GUI, in order to write my own method to overcome this limitation,
 but after more than an hour of console experiments I still
 haven't understand where this information is stored.

 Is there anybody on the list that is able to advice me? Basically I
 would be happy in any of these scenarios:

 * Find a way to re-use the same builder over and over.
 * Find an alternative method to *AUTO-assign* methods of various modules
  as callbacks to GUI-emitted signals (with the GUI being defined in a
  monolithic Glade Builder XML file).
 * Find a way to extract from the from the gtk.Builder (or in some other
  way) the pairs widget-instance-expected-handler-name as defined in
  the Glade editor.

 As for my previous mail on this list: I solved the problem myself:
 what I misunderstood was the correct use of the method dialogue.run().

 Thanks in advance for your time,
 /mac
 ___
 pygtk mailing list   pygtk@daa.com.au
 http://www.daa.com.au/mailman/listinfo/pygtk
 Read the PyGTK FAQ: http://faq.pygtk.org/

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] How to run gtk.Builder.connect_signals multiple times?

2011-06-27 Thread Mac Ryan
Thank you Giuseppe for your quick reply.

I'm looking through your code right now, but it's not evident to me how
this solves my problem. If I understand your code correctly, you call
gtk.Builder.connect_signals() only once in the __init__ method of
the GladeWidgetsWrapper class.

Further connections are explicit and happen at module level like for
example in the audacious plugin (line 75):

 item.connect('activate', self.run, source_path_list)

Maybe it's just me that don't understand it [in which case I
apologise and will be grateful for any further clarification] but I am
under the impression my scenario is quite different than the one in
the nautilus pyextension program. My situation looks like follows:

1. Single glade file that contains various top-level containers
   (windows, dialogues...)
2. The glade file also define the expected callbacks for a few events
   (like on_mybutton_clicked, etc...)
3. I have various modules (= different files = different classes) each
   of them containing *some* of these callbacks. For example I have a
   mainwindow.py module that have handlers like on_main_destroy_event
   or on_main_resize, but I also have a mainmenu.py one with handlers
   like on_file_open_activated or on_quite_activated.

What I am doing right now, is to pass to the __init__ of each of these
classes the same instance of gtk.Builder that I created in the class
acting as facade for the controller class. In the each of these
__init__ methods, the gtk.Builder instance is queried for widgets:

mywidget = mybuilder.get_object(widget_name)

and this work fine. But when I try to automagically connect the
callbacks by issuing:

mybuilder.connect_signals(self)

it only works in the first module (it returns - correctly - the list of
unconnected signals), but when I call it again from within the __init__
of my second module, it returns None, as if it connected all signals,
but this is not true: not even the callbacks in the second module have
been connected correctly :(

Any idea of how to get around this problem // explanation on how the
code in the pyextension would solve this?

Thank you in advance for your time and support! :)
/mac

On Mon, 27 Jun 2011 17:33:18 +0200
Giuseppe Penone gius...@gmail.com wrote:

 I invite you to take a look to the source code of my simplest
 application http://www.giuspen.com/nautilus-pyextensions/
 where as you can see gtk.Builder() is called only once and there's no
 need for further calls.
 
 the code that you have to look for:
 
 class GladeWidgetsWrapper:
Handles the retrieval of glade widgets
 
def __init__(self, glade_file_path, gui_instance):
   try:
  self.glade_widgets = gtk.Builder()
  self.glade_widgets.set_translation_domain(cons.APP_NAME)
  self.glade_widgets.add_from_file(glade_file_path)
  self.glade_widgets.connect_signals(gui_instance)
   except: print Failed to load the glade file
 
def __getitem__(self, key):
   Gives us the ability to do:
 wrapper['widget_name'].action() return
 self.glade_widgets.get_object(key)
 
def __getattr__(self, attr):
   Gives us the ability to do: wrapper.widget_name.action()
   new_widget = self.glade_widgets.get_object(attr)
   if new_widget is None: raise AttributeError, 'Widget %r not
 found' % attr
   setattr(self, attr, new_widget)
   return new_widget
 
 .
 
 class NautilusPyExtensions:
The application's main window
 
def __init__(self, store):
   ...
   # instantiate the Glade Widgets Wrapper
   self.glade = GladeWidgetsWrapper(cons.GLADE_PATH +
 'nautilus-pyextensions.glade', self)
 
 .
 
 furthermode in the code you access the widgets with
 self.glade.widgetname, all signals are connected.
 
 Hope this helps.
 Giuseppe.
 
 
 
 
 
 
 
 On Mon, Jun 27, 2011 at 17:02, Mac Ryan quasipe...@gmail.com wrote:
 
  I posted the same question on Stack Overflow, but so far it only
  got 3 views and no answers... :(
 
  http://stackoverflow.com/questions/6492000
 
  In the design of my program I would like to pass around the
  gkt.Builder() instance to various modules (each of them has
  some of the handlers for managing the GUI), but I found out
  that once the builder is instantiated one can only call the
  connect_signals() method once: if called more than once, any
  call after the second will return None (which would mean:
  all signals have been connected, which is a blatant lie!).
 
  I tried to see if I could understand how/where gtk.Builder
  stores the handler names that are assigned within the Glade
  GUI, in order to write my own method to overcome this limitation,
  but after more than an hour of console experiments I still
  haven't understand where this information is stored.
 
  Is there anybody on the list that is able to advice me? Basically I
  would be happy in any of these scenarios:
 
  * Find a way to re-use the same builder over and over.
  * Find an alternative method to 

Re: [pygtk] How to run gtk.Builder.connect_signals multiple times?

2011-06-27 Thread Giuseppe Penone
Hi,

I'm looking through your code right now, but it's not evident to me how
 this solves my problem. If I understand your code correctly, you call
 gtk.Builder.connect_signals() only once in the __init__ method of
 the GladeWidgetsWrapper class.


yes, this is enough to connect:

def on_window_delete_event(self, widget, event, data=None):
Before close the application: check the Consistence of the model
with the instanced Nautilus
return self.quit_application()

that is the only one that I specify in glade.
I don't like generally to use glade for signals but you can try to set all
signals you want and just define a function with the same name and it will
work.

1. Single glade file that contains various top-level containers
   (windows, dialogues...)


this is not a problem


 2. The glade file also define the expected callbacks for a few events
   (like on_mybutton_clicked, etc...)


ok


 3. I have various modules (= different files = different classes) each
   of them containing *some* of these callbacks. For example I have a
   mainwindow.py module that have handlers like on_main_destroy_event
   or on_main_resize, but I also have a mainmenu.py one with handlers
   like on_file_open_activated or on_quite_activated.


this is a problem.
I always defined the glade callbacks in the same class,
I'm afraid you can't split them in different modules unless you use
different glade files
for different classes.

Cheers,
Giuseppe.
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] porting gtk2 to gtk3

2011-06-27 Thread Giuseppe Penone
I looked there too but what I need has the mark introspectable=0
that, as described in http://live.gnome.org/PyGObject/IntrospectionPorting
means Non-introspectable functions/methods.

The problem is that there's not a solution for this.

There's an example

For example, Gtk.Menu.popup() is not introspectable in GTK, but the GTK
override implements this method in terms of Gtk.Menu.popup_for_device()

but I searched for similar functions printing dir(Gdk), dir(Gdk.Window) and
everything possible but I found nothing.




On Mon, Jun 27, 2011 at 18:44, Tomeu Vizoso to...@sugarlabs.org wrote:

 Hi,

 On Sat, Jun 25, 2011 at 22:45, Giuseppe Penone gius...@gmail.com wrote:
  Hi,
 
  I'm trying to understand what's the pygi code for:
  gdk_x11_window_foreign_new_for_display ()
  and
  gdk_x11_window_lookup_for_display ()
  but cannot find a working solution.

 I would try looking up the C symbol in GdkX11-3.0.gir.

 Regards,

 Tomeu

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] How to run gtk.Builder.connect_signals multiple times?

2011-06-27 Thread Mac Ryan
On Mon, 27 Jun 2011 19:58:07 +0200
Giuseppe Penone gius...@gmail.com wrote:

 I always defined the glade callbacks in the same class,
 I'm afraid you can't split them in different modules unless you use
 different glade files
 for different classes.

That's the same conclusion I arrived to, but I believe that when
using libglade files with gtk.glade.XML one can circumvent that
limitation.

If anybody on the list knows that, I would be interested to know why
this limitation has been enforced. It really escape my comprehension
what kind of advantages should this bring in. :)

Best,
/mac
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] strange warnings in gtk3

2011-06-27 Thread Just Fill Bugs

On 06/27/2011 02:00 AM, Timo wrote:

On 26-06-11 14:57, Giuseppe Penone wrote:

Hi,
I ported my first application to gtk3 but continue to read the
followig warning:

`menu_proxy_module_load': python: undefined symbol:
menu_proxy_module_load

anybody knows the reason?

Don't know the reason, but got the same warnings. I noticed that they
only appear in a program with menus (a menubar or popup menu), as soon
as you remove them, the messages disappear too.



I searched for that message before. Looks like some ubuntu thing. Ubuntu 
forced a system menu over gtk applications.


It's from appmenu-gtk package and can be removed by deleting 
/etc/X11/Xsession.d/80appmenu.


Ubuntu is definitely not for developers. It's an end user application. 
Debian or Fedora are much better for developing work.



___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/