On Wed, 22 Sep 2004 19:04:19 +0200
Danny Milosavljevic <[EMAIL PROTECTED]> threw this fish to the penguins:
> 
> Am Mittwoch, den 22.09.2004, 12:51 -0400 schrieb george young:
> > [pygtk-1.99.17 , gtk+-2.2.4, python-2.3.3]
> > >From my "Print View" menu callback I want to run a screengrab:
> > 
> > ag = gtk.AccelGroup()
> > self.itemf = gtk.ItemFactory(gtk.MenuBar, "<main>", ag)
> > self.topwin.add_accel_group(ag)
> > menu_items = ((('/_File/_Print View', '<control>V', self.print_view, 21, '')))
> > self.itemf.create_items(menu_items)
> > 
> >     def print_view(self, dummy, unused):
> >         parent_win = self.topwin.window.get_parent()
> >         os.system("convert -page 588x740-14+335 X:0x%x 'PS2:|lpr'" % 
> > self.topwin.window.xid)
> > 
> > [the "convert" linux command is from the ImageMagick package; very handy]
> > 
> > When I select the menu item, the menu disappears, but the underlying
> > window is not repainted until the menu callback returns.  Thus the window
> > I'm trying to print is partially obscured while the screengrab is taking
> > place.  Is there something I can do in
> > the menu callback to force the mainwindow to repaint?  I tried putting in
> > a time.sleep(1) and gtk.gdk.flush() but those did not help.
> > 
> > The function works OK when called via the menu accelerator key sequence,
> > since the menu does not pop down and there's no obscuration.
> > But I have a lot of naive users that are not comfortble with accelerators.
> 
> you should add the function as a idle callback with gtk.idle_add and
> there probably try running gtk.main_iteration()...
> 
> (untested)
> 
> def idle_cb():
>       while gtk.events_pending(): gtk.main_iteration() 
>         parent_win = self.topwin.window.get_parent()
>         os.system("convert -page 588x740-14+335 X:0x%x 'PS2:|lpr'" % 
> self.topwin.window.xid)
>   
> def print_view(self, dummy, unused):
>       gtk.idle_add(idle_cb) 
> 
> if you want to be fancy you can also connect to the "hide" or "unmap"
> signal of the gtk.Menu that is shown and do the idle_add there. Then
> technically the menu should be gone. To make the main window repaint the
> main_iteration stuff should be enough.

The simple solution works fine, so I'll stick with that.
Thanks very much!

-- George Young
-- 
"Are the gods not just?"  "Oh no, child.
What would become of us if they were?" (CSL)
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to