Updating gtk

6854933580_2c8b688306_z

More eloquently, in the words of the great Malcolm Tredinnick, 'this requires using what should be called "Secret Technique #1 For Making Your Application Look Responsive"(tm): Of course, if your callback has a single instruction that takes a long time to process, this isn't an option.

/usr/bin/env python import pygtk,time pygtk.require('2.0') import gtk, gobject def timeout(instan): instan.data=str(time.time()) #Here the will change print instan.pr() return 1 class ui: def butt(s): s.w=gtk. Label() s.b.set_label(s.data) s.w.set_title="baskar" s.w.set_size_request(250, 200) s.w.connect("destroy",s.destroy, None) s.b.show() s.w.add(s.b) s.timer=gobject.timeout_add (1000, timeout, s) s.w.show() def refresher(s): s.w.queue_draw() print s.data,"$$$$$$$$$$$$$$$$$$$$$$$$$$$$" while gtk.events_pending(): print "refreshing" #gtk.main_iteration_do(True) gtk.main_iteration_do(False) def destroy(s, widget, data=None): gobject.source_remove(s.timer) s.timer = 0 gtk.main_quit() def loop(): gtk.main() return 0 UI=ui() UI.butt() loop()#! Doug Quale remarks on how this applies even to idle_add()ed functions: Note that running a mainiteration inside an idle, io (input_add) or timeout handler is generally considered `a bad idea' because it doesn't work very well. Moreover if during the computation you want to lock the GUI (no operation can be performed) without making all the widget insensitive you can use the other secret technique called "Yeti"...[1] import gtk from time import sleep def response(widget, response_id): if response_id ! RESPONSE_APPLY: gtk.main_quit() else: i=0 n=1000 progress = dialog.get_data("progress") progress.set_text("Calculating....") progress.grab_add() while i This way the GUI does not freeze and you cannot interact with widgets, if you like you can unlock one widget (e.g.This is by design: all gtk events (including window refreshing and updates) are handled in the mainloop, and while your application or callback code is running the mainloop can't handle window update events.Therefore nothing will happen in the application windows./usr/bin/env python import pygtk,time pygtk.require('2.0') import gtk, gobject #This function only for calling refresh in UI def timeout(j): j.refresh() return 1 class ui: def butt(s): s.w=gtk. Label() s.b.set_label('baskassssss') s.w.set_size_request(250, 200) s.w.connect("destroy",s.destroy, None) s.b.show() s.w.add(s.b) s.timer=gobject.timeout_add (700, timeout, s) s.w.show() def refresh(s): s.b.set_label(time.strftime("%s")) #----DATA change here #time.sleep(0.3) #s.b.queue_draw() print s.data,"$$$$$$$$$$$$$$$$$$$$$$$$$$$$" while gtk.events_pending(): print "refreshing" gtk.main_iteration_do(True) def destroy(s, widget, data=None): gobject.source_remove(s.timer) s.timer = 0 gtk.main_quit() def loop(): gtk.main() return 0 UI=ui() UI.butt() loop() i have readed the faq. Call this when there are changes in the content of a row (node) in your model.

You must have an account to comment. Please register or login here!