Initial Kivy test.

This commit is contained in:
Sergio Martínez Portela 2021-03-20 19:44:01 +01:00
commit 9c79d017ff
2 changed files with 61 additions and 0 deletions

60
main.py Normal file
View File

@ -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()

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
kivy[base]