Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created April 5, 2020 19:47
Show Gist options
  • Save tshirtman/885f74dd7da689efa471e28d03a686b9 to your computer and use it in GitHub Desktop.
Save tshirtman/885f74dd7da689efa471e28d03a686b9 to your computer and use it in GitHub Desktop.
from threading import Thread
import wikipedia
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.properties import ListProperty, BooleanProperty
KV = '''
<Result@Label>:
text_size: self.size
font_size: 20
shorten: True
color: rgba('#11111F')
canvas.before:
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
TextInput:
multiline: False
size_hint_y: None
height: self.minimum_height
font_size: 20
on_text_validate: app.search(self.text)
FloatLayout:
RecycleView:
pos_hint: {'pos': (0, 0)}
data: app.search_results
viewclass: 'Result'
RecycleBoxLayout:
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
default_size_hint: 1, None
default_size: 0, 50
padding: 10, 10
spacing: 10
Image:
pos_hint: {'pos': (0, 0)}
source: 'data/images/image-loading.zip'
opacity: 1 if app.loading else 0
canvas.before:
Color:
rgba: 0, 0, 0, .5
Rectangle:
pos: self.pos
size: self.size
'''
class Application(App):
search_results = ListProperty()
loading = BooleanProperty(False)
def build(self):
return Builder.load_string(KV)
def search(self, text):
t = Thread(target=self._search, args=[text]).start()
self.loading = True
def _search(self, text):
self.search_results = [
{'text': text}
for text in
wikipedia.search(text, results=20)
]
self.loading = False
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment