summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
a38fa6f)
Follow what explained in
http://wiki.laptop.org/go/PyGTK/Smooth_Animation_with_PyGTK about
"Taking over the Event loop".
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gio
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gio
import math
import colorsys
import math
import colorsys
self.set_size_request(width, height)
self.connect('draw', self.do_draw_cb)
self.connect('configure-event', self.do_configure_event_cb)
self.set_size_request(width, height)
self.connect('draw', self.do_draw_cb)
self.connect('configure-event', self.do_configure_event_cb)
+ self.connect('destroy', self.on_destroy)
- fps = 30
- GObject.timeout_add(1000 / fps, self.update)
+ self.fps = 30
+ GObject.timeout_add(50, self.mainloop)
+
+ def on_destroy(self, event):
+ self.running = False
+
+ def tick(self):
+ self.update()
+ self.queue_draw()
+
+ def mainloop(self):
+ self.running = True
+ while self.running:
+ time.sleep(1.0 / self.fps)
+ self.tick()
+ while Gtk.events_pending():
+ Gtk.main_iteration()
+
+ return False
def update(self):
if self.x - self.radius - self.border < 0 or \
def update(self):
if self.x - self.radius - self.border < 0 or \
self.x += self.x_offset
self.y += self.y_offset
self.x += self.x_offset
self.y += self.y_offset
- self.queue_draw()
- return True
-
def do_configure_event_cb(self, widget, event):
self.width = event.width
self.height = event.height
def do_configure_event_cb(self, widget, event):
self.width = event.width
self.height = event.height