Re: [pygtk] pygtk fatal exceptions

2009-05-29 Thread Gabriele Lanaro
Hi I've found a good solution in a site that solved all my debug and testing 
problems...
the trick is to not invoke gtk.main(), but use this function:

def refresh_gui(delay=0):
while gtk.events_pending():
gtk.main_iteration_do(block=False)
time.sleep(delay)

Every time you have to catch an event, invoke this function, for example:

somebutton.emit("clicked")
refresh_gui()
justanotherbutton.emit("clicked")
refresh_gui()

It also gives you a perfect synchronous control of the application ( testing 
and debugging within the main may cause unexpected problems).

I hope it's useful for you :)


On Fri, 29 May 2009 15:39:12 +0200
Guillaume Bouchard  wrote:

> On Fri, May 29, 2009 at 02:43:06PM +0200, Alessandro Dentella wrote:
> > > My aim is to be able to directly "jump" to the exception with "python -m
> > > pdb myprogram.py" and then '(c)ontinue' and wait for the exception to be
> > > catch by pdb.
> > 
> > I'm not really following you, but I debug gtk program using 'ipython
> > -gthread'. When you hit an exception you are jumped into a pdb interpreter
> >  run from ipython (i.e. you have completion available that you dont have in
> >  a normal pdb session). Try:
> > 
> >   ipython -gthread -pdb -- your_script.py
> 
> This really solve my problem, but :
> 
> 1) It forces me to learn ipython (ok, I'm a geek, I'll do it)
> 2) I need to have ipython installed on my computer, it's not that easy.
> 
> Thank for you help, I'm still waiting for a *pure* python/pdb solution,
> but I'm quite happy now.
> 
> PS: I put the list and you as receivers because perhaps my thanks does
> not interests others, but the quotation of your answer is quite
> interesting ;)
> 
> -- 
> Guillaume
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/


-- 
Gabriele Lanaro 
___
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] Problem communicating two class

2009-05-29 Thread Alexandre González
Thanks for the reply and lot of thanks for the autoconnection doc, I didn't
know about it.

About the __init__ it doesn't work:
Traceback (most recent call last):
  File "/home/alex/Escritorio/pymoc/stuff/events.py", line 21, in
on_about_activate
self.parent['aboutdialog'].show()
NameError: global name 'self' is not defined

I'm new at class programming in python, os perhaps be a stupid question as I
said before.

Thanks again Guillaume

2009/5/29 Guillaume Bouchard 

> Hello,
>
> On Fri, May 29, 2009 at 05:23:50PM +0200, Alexandre González wrote:
> > Hi! Perhaps this could be a stupid question, but I'm trying to do it and
> I
> > can't.
> >
> > I did a skeleton of a pygtk application to learn about use it, but i have
> a
> > problem... I create a parent class [1] to procedure the events (it create
> > the events connections with instrospection and it works very well ;) but
> I
> > load the glade file here, and the events handlers are in the child class
> > [2]. So when I click on the about button in the application, I can't show
> > the about dialog loaded at parent class because I can't access it.
>
> As I told you on IRC (but you look away when my response come), You only
> need to set the "parent" class in the "child class"
>
> def __init__(self,parent):
>self.parent = parent
>
> And when you init your Event class, do it like that :
>
> events = Events(self)
>
> Then you can access the parent in every event method with self.parent.
>
> > I tried with super but it doesn't work, and I tried to send from parent
> to
> > child the parent object doing this on the parent code: child =
> Child(self)
> > but it doesn't work too.
>
> Super does work when you inherit, it's not the case here.
>
> But I'm wondering how you really did your "child = Child(self)" because
> it's the way to go.
>
> By the way, did you know that pygtk and glade/builder have a very handy
> way to connect signal to methods with introspection ?
>
> you can use the glade or builder method signal_autoconnect()
>
>
> http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html#method-gtkbuilder--connect-signals
>
> You only need to name the signal handler in glade and it will
> automatically connect it to the right method (and you can use the
> optional data argument if you really need an events object which is
> unbound from the "parent class")
>
> Good luck.
>
> --
> Guillaume
>



-- 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.com
___
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] Problem communicating two class

2009-05-29 Thread Guillaume Bouchard
Hello,

On Fri, May 29, 2009 at 05:23:50PM +0200, Alexandre González wrote:
> Hi! Perhaps this could be a stupid question, but I'm trying to do it and I
> can't.
> 
> I did a skeleton of a pygtk application to learn about use it, but i have a
> problem... I create a parent class [1] to procedure the events (it create
> the events connections with instrospection and it works very well ;) but I
> load the glade file here, and the events handlers are in the child class
> [2]. So when I click on the about button in the application, I can't show
> the about dialog loaded at parent class because I can't access it.

As I told you on IRC (but you look away when my response come), You only
need to set the "parent" class in the "child class"

def __init__(self,parent):
self.parent = parent

And when you init your Event class, do it like that :

events = Events(self)

Then you can access the parent in every event method with self.parent.

> I tried with super but it doesn't work, and I tried to send from parent to
> child the parent object doing this on the parent code: child = Child(self)
> but it doesn't work too.

Super does work when you inherit, it's not the case here.

But I'm wondering how you really did your "child = Child(self)" because
it's the way to go.

By the way, did you know that pygtk and glade/builder have a very handy
way to connect signal to methods with introspection ?

you can use the glade or builder method signal_autoconnect()

http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html#method-gtkbuilder--connect-signals

You only need to name the signal handler in glade and it will
automatically connect it to the right method (and you can use the
optional data argument if you really need an events object which is
unbound from the "parent class")

Good luck.

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


[pygtk] Problem communicating two class

2009-05-29 Thread Alexandre González
Hi! Perhaps this could be a stupid question, but I'm trying to do it and I
can't.

I did a skeleton of a pygtk application to learn about use it, but i have a
problem... I create a parent class [1] to procedure the events (it create
the events connections with instrospection and it works very well ;) but I
load the glade file here, and the events handlers are in the child class
[2]. So when I click on the about button in the application, I can't show
the about dialog loaded at parent class because I can't access it.

I tried with super but it doesn't work, and I tried to send from parent to
child the parent object doing this on the parent code: child = Child(self)
but it doesn't work too.

Any suggestion?

Thanks!
Álex González

[1] http://pastebin.com/f4636edb4
[2] http://pastebin.com/f6d40e579

-- 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.com
___
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] pygtk fatal exceptions

2009-05-29 Thread Guillaume Bouchard
On Fri, May 29, 2009 at 02:43:06PM +0200, Alessandro Dentella wrote:
> > My aim is to be able to directly "jump" to the exception with "python -m
> > pdb myprogram.py" and then '(c)ontinue' and wait for the exception to be
> > catch by pdb.
> 
> I'm not really following you, but I debug gtk program using 'ipython
> -gthread'. When you hit an exception you are jumped into a pdb interpreter
>  run from ipython (i.e. you have completion available that you dont have in
>  a normal pdb session). Try:
> 
>   ipython -gthread -pdb -- your_script.py

This really solve my problem, but :

1) It forces me to learn ipython (ok, I'm a geek, I'll do it)
2) I need to have ipython installed on my computer, it's not that easy.

Thank for you help, I'm still waiting for a *pure* python/pdb solution,
but I'm quite happy now.

PS: I put the list and you as receivers because perhaps my thanks does
not interests others, but the quotation of your answer is quite
interesting ;)

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


[pygtk] reply address for this list - retry

2009-05-29 Thread Alessandro Dentella
I did it again, so I repost the same request as some months ago. Even if you
are not the person in the position to modify it, I'd like to know if there
are any objections to setting a default reply to the list.

sandro
*:-)


Hi,

  I found mysel many times answering to the original author rather than to
  the list. I think that this doesn't only happen to me as is pretty normal
  for public mailing list to have reply address set to the list.

  I think this is inconvenient as many answers of public interest don't
  arrive to the list.

  Is it possible to change this  setting?

  sandro
  *:-)



  
-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy
___
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] pygtk fatal exceptions

2009-05-29 Thread Alessandro Dentella
On Fri, May 29, 2009 at 02:22:12PM +0200, Guillaume Bouchard wrote:
> Hello,
> 
> I want to debug a pygtk program with PDB (the internal python debuger)
> because the program raise an exception.
> 
> My aim is to be able to directly "jump" to the exception with "python -m
> pdb myprogram.py" and then '(c)ontinue' and wait for the exception to be
> catch by pdb.

I'm not really following you, but I debug gtk program using 'ipython
-gthread'. When you hit an exception you are jumped into a pdb interpreter
 run from ipython (i.e. you have completion available that you dont have in
 a normal pdb session). Try:

  ipython -gthread -pdb -- your_script.py

I think and hope this should be (more) than what you where looking for.

*:-)

-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] pygtk fatal exceptions

2009-05-29 Thread Guillaume Bouchard
Hello,

I want to debug a pygtk program with PDB (the internal python debuger)
because the program raise an exception.

My aim is to be able to directly "jump" to the exception with "python -m
pdb myprogram.py" and then '(c)ontinue' and wait for the exception to be
catch by pdb.

But the pygtk main loop catch every exception, print it and continue
it's life.

Is there an option to change this behavior ? I have found on the
internet about PYGTK_FATAL_EXCEPTIONS, but this does not still work,
there is a patch :

2001-12-12  Matt Wilson  

* gtk/pygtk.h (PyGtk_FatalExceptions): remove.

* gtk/pygtk-private.h (PyGtk_FatalExceptions): remove.

* gtk/gtkmodule.c (init_gtk): don't bother with
PYGTK_FATAL_EXCEPTIONS.
(pygtk_main_quit): remove unused code.

I had read about the use of sys.excepthook, but it only allow me to look
at the exception, but even if I raise it again, the main loop still
catch it.

This is an example program :

import gtk,gobject

def callback():
raise ValueError

gobject.idle_add(callback)
gtk.main()

and the PDB session :

$ python -m pdb gtk_test.py
> /home/gbouchard/gtk_test.py(1)()
-> import gtk,gobject
(Pdb) continue
Traceback (most recent call last):
  File "gtk_test.py", line 4, in callback
raise ValueError
ValueError

.. here PDB hang and the gtk_main_loop continue to live. I want the
exception to pass through gtk.main_loop and finish in PDB.

Be able to use pdb to jump directly on an exception is really needed
when you debug pygtk code.

Thank, and sorry for my writing skills...

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


[pygtk] [ANNOUNCE] Gaphas 0.4.0

2009-05-29 Thread Arjan Molenaar
Hi all,

I'm pleased to announce the next release of Gaphas, a diagram widget  
for GTK+/Python.

Gaphas is a MVC canvas that uses Cairo for rendering. One of the nicer  
things of this widget is that the user (model) is not bothered with  
bounding box calculations: this is all done through Cairo.


Features


- Each item has it's own separate coordinate space (easy when items  
are rotated).
- Items on the canvas can be connected to each other. Connections are  
maintained by a linear constraint solver.
- Multiple views on one Canvas.
- What is drawn is determined by Painters. Multiple painters can be  
used and painters can be chained.
- User interaction is handled by Tools. Tools can be chained.
- Versatile undo/redo system


What's new
--

- allow to define connectable parts of item's (ports feature)
- implemented default connection tool (thanks to ports feature)
- line segment tool implemented (code taken from gaphor)
- implemented Item.constraint method to simplify item's constraint
   creation
- The canvas (-view) is no longer tied to the (0, 0) position.  
Scrolling can
   be done quite fluidly with the new PanTool implementation.
- Canvas can be serialized (pickled)
- API changes
   - use positions instead of "x, y" pairs in all method calls

You can find it at the Python Cheese shop: http://pypi.python.org/pypi/gaphas

Homepage: http://gaphor.devjavu.com/wiki/Subprojects/Gaphas


Kind regard,

Arjan

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