2022-07-30 21:03:15 +00:00
|
|
|
import native_ui
|
|
|
|
import sys
|
|
|
|
|
|
|
|
native_ui.set_runtime_platform("gnome", "org.surferlul.native-ui.ExampleApp")
|
|
|
|
from native_ui import native, abstract
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
window = native.Window()
|
|
|
|
window.set(
|
|
|
|
child=None
|
|
|
|
)
|
|
|
|
|
|
|
|
app = native.Application(
|
|
|
|
window=native.Window(
|
2022-07-30 23:13:00 +00:00
|
|
|
title="Example native-ui app",
|
|
|
|
width=350,
|
|
|
|
height=200,
|
2022-07-30 21:03:15 +00:00
|
|
|
child=native.Container(
|
|
|
|
layout=abstract.Layout.VERTICAL,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
cont = app.window.child
|
|
|
|
|
2022-07-30 23:13:00 +00:00
|
|
|
def window_update(self, container):
|
|
|
|
splt = self.title.split()
|
|
|
|
if self.title[-1].isdigit():
|
|
|
|
splt = splt[:-1]
|
|
|
|
else:
|
|
|
|
splt.append("Buttons:")
|
|
|
|
splt.append(str(len(container.children)))
|
|
|
|
self.title = " ".join(splt)
|
|
|
|
|
|
|
|
app.window.update = window_update
|
|
|
|
app.window.update_args = [cont]
|
|
|
|
|
|
|
|
def on_pressed(self, container, window):
|
2022-07-30 21:03:15 +00:00
|
|
|
print("Hello world")
|
2022-07-30 23:13:00 +00:00
|
|
|
self.label = f"Clicked {self.runtime_data.get('clicked', 1)}"
|
|
|
|
self.runtime_data["clicked"] = self.runtime_data.get('clicked', 1) + 1
|
|
|
|
container.add_child(
|
2022-07-30 21:03:15 +00:00
|
|
|
native.Button(
|
|
|
|
label="Hello",
|
|
|
|
pressed=on_pressed,
|
2022-07-30 23:13:00 +00:00
|
|
|
pressed_args=[container, window]
|
2022-07-30 21:03:15 +00:00
|
|
|
))
|
2022-07-30 23:13:00 +00:00
|
|
|
# test removing container children feature
|
|
|
|
container.children = container.children
|
|
|
|
window.update()
|
2022-07-30 21:03:15 +00:00
|
|
|
|
|
|
|
cont.add_child(native.Button(
|
|
|
|
label="Hello",
|
|
|
|
pressed=on_pressed,
|
2022-07-30 23:13:00 +00:00
|
|
|
pressed_args=[cont, app.window],
|
2022-07-30 21:03:15 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
app.build()
|
|
|
|
app.run(sys.argv)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|