Не знаю, что делать, все перепробовал, но не получается.
Код: Выделить всё
import os
import time
import subprocess
import schedule
from kivy.clock import Clock
from kivy.properties import ObjectProperty, StringProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivymd.uix.list import MDList, OneLineListItem, BaseListItem
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu
import json
Window.size = (360, 600)
# the problem is somewhere in this piece of code
KV = '''
MDScreen:
MDBoxLayout:
orientation: 'vertical'
MDTopAppBar:
title: 'UUnit'
type_height: "small"
theme_font_styles: 'Display'
md_bg_color: 0, 0, 100, 1
left_action_items: [["menu", lambda x: nav_drawer_left.set_state('open')]]
Widget:
MDNavigationLayout:
MDScreenManager:
id: screen_manager
MDScreen:
name: "main_screen"
MDBoxLayout:
md_bg_color: 255, 74, 73, 1
orientation: 'vertical'
padding: '20dp'
spacing: '5dp'
radius: "10dp"
size_hint_x: 1
size_hint_y: .25
pos_hint: {"center_x": .5, "top": .88}
MDLabel:
text: "Enter data"
text_font_style: "Display"
halign: "center"
size_hint_x: 1
MDTextField:
id: search
text_font_style: "Display"
helper_text: "Example: IS-22"
helper_text_mode: "persistent"
size_hint_x: 1
multiline: False
on_text: app.main_screen.search_query = self.text
MDFillRoundFlatButton:
text: "OK"
text_font_style: "Display"
theme_text_color: "Custom"
size_hint_x: 1
on_release: app.main_screen.search_data()
MDBoxLayout:
orientation: 'vertical'
padding: '20dp'
radius: "10dp"
size_hint_x: 1
size_hint_y: .62
pos_hint: {"center_x": .5}
ScrollView:
MDList:
id: result_list
size_hint_y: None
height: self.minimum_height
Widget:
Код: Выделить всё
class MainScreen(Screen):
search_query = StringProperty()
result_list = ObjectProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.result_list = MDList()
self.data = None
def load_data(self):
"""Downloading data from a JSON file"""
try:
with open('data.json', 'r', encoding='utf-8') as f:
self.data = json.load(f)
os.system('the_parsing_script.py')
except FileNotFoundError:
os.system('parser.py')
time.sleep(20)
with open('data.json', 'r', encoding='utf-8') as f:
self.data = json.load(f)
def search_data(self):
"""Search for data on request"""
results = []
for item in self.data:
if self.search_query.lower() in item['id'].lower() or self.search_query.lower() in item['text'].lower():
day = item['day']
data = item['data']
para = item['para']
text = item['text']
results.append({"day": day, "data": data, "para": para, "text": text})
self.update_results(results)
def update_results(self, results):
self.result_list.clear_widgets()
for result in results:
item_day = OneLineListItem(text=f"{result['day']} - {result['data']}\n{result['para']} : {result['text']}")
self.result_list.add_widget(item_day)
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Light"
sm = ScreenManager()
main_screen = MainScreen(name='main_screen')
sm.add_widget(main_screen)
main_screen.load_data()
self.main_screen = main_screen
return Builder.load_string(KV)
def handle_search(self, query):
"""Processing the search button click"""
self.main_screen.search_query = query
self.main_screen.search_data()
Example().run()
Подробнее здесь: https://stackoverflow.com/questions/785 ... -in-kivymd