mirror of https://github.com/kivy/kivy.git
kvrun: press F5 to reload app
This commit is contained in:
parent
edd69d63ff
commit
3e0443a2d3
|
@ -3,13 +3,24 @@
|
||||||
from kivy.app import App
|
from kivy.app import App
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from kivy.lang import Builder
|
from kivy.lang import Builder
|
||||||
|
from kivy.core.window import Window
|
||||||
|
|
||||||
class KvApp(App):
|
class KvApp(App):
|
||||||
def _print_fps(self, *largs):
|
def _print_fps(self, *largs):
|
||||||
print 'FPS: %2.4f (real draw: %d)' % (
|
print 'FPS: %2.4f (real draw: %d)' % (
|
||||||
Clock.get_fps(), Clock.get_rfps())
|
Clock.get_fps(), Clock.get_rfps())
|
||||||
|
|
||||||
|
def _reload_keypress(self, instance, code, *largs):
|
||||||
|
if code != 286:
|
||||||
|
return
|
||||||
|
for child in Window.children[:]:
|
||||||
|
Window.remove_widget(child)
|
||||||
|
root = Builder.load_file(self.options['filename'])
|
||||||
|
Window.add_widget(root)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
Clock.schedule_interval(self._print_fps, 1)
|
Clock.schedule_interval(self._print_fps, 1)
|
||||||
|
Window.bind(on_keyboard=self._reload_keypress)
|
||||||
return Builder.load_file(self.options['filename'])
|
return Builder.load_file(self.options['filename'])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue