55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import nanogui
|
||
|
from nanogui import glfw
|
||
|
from nanogui import BoxLayout, Button, Label, Orientation, Screen, Window
|
||
|
|
||
|
|
||
|
class HelloWorldApp(Screen):
|
||
|
def __init__(self, size=(400, 300)):
|
||
|
super().__init__(size, "NanoGUI Hello World")
|
||
|
self.win = Window(self, "Demo Window")
|
||
|
|
||
|
self.win.set_layout(BoxLayout(Orientation.Vertical, margin=20, spacing=20))
|
||
|
self.resize_event(size)
|
||
|
|
||
|
Label(self.win, "NanoGUI Demo", "sans-bold")
|
||
|
b = Button(self.win, "Say hello!")
|
||
|
|
||
|
def cb():
|
||
|
print("Well, 'ello there!")
|
||
|
|
||
|
b.set_callback(cb)
|
||
|
|
||
|
self.set_visible(True)
|
||
|
self.perform_layout()
|
||
|
|
||
|
def resize_event(self, size):
|
||
|
self.win.set_fixed_size(size)
|
||
|
self.win.set_size(size)
|
||
|
self.win.center()
|
||
|
self.win.perform_layout(self.nvg_context())
|
||
|
super().resize_event(size)
|
||
|
return True
|
||
|
|
||
|
def keyboard_event(self, key, scancode, action, modifiers):
|
||
|
if super().keyboard_event(key, scancode, action, modifiers):
|
||
|
return True
|
||
|
|
||
|
if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
|
||
|
self.set_visible(False)
|
||
|
return True
|
||
|
|
||
|
return False
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
import gc
|
||
|
|
||
|
nanogui.init()
|
||
|
app = HelloWorldApp()
|
||
|
nanogui.mainloop(refresh=1 / 60.0 * 1000)
|
||
|
del app
|
||
|
gc.collect()
|
||
|
nanogui.shutdown()
|