From 9c79d017ffb9ce501ba0ae3218f2cfa612e88fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Sat, 20 Mar 2021 19:44:01 +0100 Subject: [PATCH] Initial Kivy test. --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 61 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..6cdcac7 --- /dev/null +++ b/main.py @@ -0,0 +1,60 @@ +from kivy.app import App +from kivy.core.window import Window +from kivy.modules import inspector +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.button import Button +from kivy.uix.gridlayout import GridLayout +from kivy.uix.scrollview import ScrollView +from kivy.uix.textinput import TextInput + + +class TestApp(App): + def __init__(self): + App.__init__(self) + self.results = [] + + def on_omnibox_change(self, _instance, value): + print("⇒", value) + while self.results: + btn = self.results.pop() + self.layout.remove_widget(btn) + + for i in range(100): + btn = Button(text=value + str(i), height=40, size_hint_y=None) + self.layout.add_widget(btn) + self.results.append(btn) + + def build(self): + self.root = BoxLayout(orientation="vertical", spacing=5) + # Make sure the height is such that there is something to scroll. + self.root.bind(minimum_height=self.root.setter("height")) + + self.omnibox = TextInput( + text="", + hint_text="Search here files and headlines", + multiline=False, + write_tab=False, + size_hint_y=None, + height=40, + focus=False, + ) + self.omnibox.bind(text=self.on_omnibox_change) + self.root.add_widget(self.omnibox) + + self.viewer = ScrollView( + size_hint=(1, 1), size=(Window.width / 2, Window.height / 2) + ) + self.layout = BoxLayout(orientation="vertical", spacing=2, size_hint_y=None) + self.layout.bind(minimum_height=self.layout.setter("height")) + for i in range(100): + btn = Button(text=str(i), height=40, size_hint_y=None) + self.layout.add_widget(btn) + self.results.append(btn) + + self.viewer.add_widget(self.layout) + self.root.add_widget(self.viewer) + inspector.create_inspector(Window, self.root) + return self.root + + +TestApp().run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c098fc2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +kivy[base]