Re: [pygtk] handling events

2006-10-22 Thread Radomir Dopieralski
Dnia Sun, Oct 22, 2006 at 09:57:47AM +0200, napisale(a)s: 
 Hi,
  
  I am looking for a way to handle events through classes.
  I have a main window with a statusbar at the bottom.
  In the window I put a notebook to which I can add/remove pages (they are 
 instances of a notebook_page_class).
  Each page contains a set of widgets that can be clicked and handled by 
 connected methods/functions belonging to the notebook_page_class.
  My question is : when the widgets contained in these notebook pages are 
 clicked and handled, how can the result(s) generated by the callback 
 meth/func be passed to the main window statusbar ?
  I could add a status bar to each notebook page but this is no elegent way...

If you want the notebook pages to be able to affect something
outside them, you need to give them a reference to it...

For example, you could pass the status bar as a parameter to
the notebook page constructor, and save the reference in the
notebook page.

Example:


class MainWindow:
def __init__(self):
self.status = gtk.StatusBar()
...

def add_notebook_page(self):
...
page = NotebookPage(self.status)
...


class NotebookPage:
def __init__(self, status=None):
self.status = status
...

def on_widgets_clicked(self, widget):
self.status.push(
self.status.get_context_id('page cliked'),
'Splorf!')

-- 
Radomir `The Sheep' Dopieralski

When in doubt, use brute force. [Ken Thompson]

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


Re: [pygtk] handling events

2006-10-22 Thread David M. Cook
On Sun, Oct 22, 2006 at 09:57:47AM +0200, Pascal DUCHATELLE wrote:

  I could add a status bar to each notebook page but this is no elegent way...

I'd put the status bar handling code in its own module.  Then import that
module wherever it's needed.

If you want to reduce coupling in your code, you could adapt one of the
publish/subscribe examples from the Python Cookbook.

Dave Cook


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


Re: [pygtk] Handling events in a timeout thread

2001-12-27 Thread Matt Wilson

Either take the gtk lock in your idle handler or disable threads using
the snapshot of stable pygtk and using gtk._disable_threading() before
you call the mainloop for the first time.

Cheers,

Matt

On Wed, Dec 26, 2001 at 10:15:20AM -0700, Don Allingham wrote:
 I've tried adding a autosave backup option to my program by using
 gtk.timeout_add(). When the timer expires, I jump to my save routine
 and the file is save. However, during that time, the screen is not
 updated, and the program seems to hang until the save is done. Since the
 save process can be long at times, I would like to have the screen
 update so I can give some type of progress indicator.
 
 I've put:
 
   while gtk.events_pending():
   gtk.mainiteration()
 
 In the callback, but that updates the screen until the timer-called
 routine completes, and then the entire application freezes.
 
 Any ideas on how do fix this? 
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk