The program below aims to use kivy to extract and output data based on keywords from the database.
The problem is that the Top_Screen that starts first is not displayed.
I would like to know why this is happening.
I deleted build=Builder.load_file("design.kv")
because UnicodeDecodeError: 'cp932'
.
Here's the source code:
mobiDB_ver1.2.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
import threading
from kivy.core.window import Window
Class Top_Screen (Screen):
"""Top Screen"""
def press_enter_button(self):
sm.add_widget(Search_Screen(name='search'))# Add screen just before transition to move initial processing
sm.remove_widget(self)
sm.current='search'# transition
class Search_Screen (Screen):
"""search screen"""
def__init__(self,**kwargs):
super(Search_Screen,self).__init__(**kwargs)
self.text='# Get search keywords
self.btn_mythread=threading.Thread(target=self.search_to_uniprot_thread)
def press_search_button(self):
# Start thread when button is pressed
print ("begin")
sm.add_widget(Search_Screen(name='wait'))# Add screen just before transition to move initial processing
sm.current='wait'# transition
self.btn_mythread.start()#Threadstart
def search_to_uniprot_thread(self):
# Connect to Uniprot
from bioservices import UniProt
service=UniProt()
# Replace search value as query
query=self.ids ["text_box"].text
# extract and output data
result=service.search("keyword:"+query)
print(result)
print("finish")
sm.add_widget(Output_Screen(name='output')))# Add screen just before transition to move initial processing
sm.current='output'
class Wait_Screen (Screen):
"""Wait screen during data extraction"""
def press_cancel_button(self):
# Return to Search screen when button is pressed
sm.remove_widget(self)
sm.current='search'
classOutput_Screen (Screen):
"""output screen"""
def press_return_button(self):
# Return to Search screen when button is pressed
temp=sm.get_screen('select')
sm.remove_widget(temp)
sm.remove_widget(self)
sm.current='search'
sm=ScreenManager()#ScreenManager
class MobiDBApp (App):
def build (self):
sm.add_widget(Top_Screen(name='top')
sm.current='top'
return sm
if__name__=='__main__':
Window.size= (400,220)
MobiDBApp().run()
design.kv
<Top_Screen>:
BoxLayout:
size —root.size
Button:
size:50,50
size_hint —None, None
text: 'To Search Screen'
on_press —Root.press_enter_button()#Top_Screen method is executed
<Search_Screen>:
BoxLayout:
orientation:'vertical'
size —root.size
Label:
text_size —self.size
text: 'Searching in MobiDB'
align:'left'
size_hint_x:1
size_hint_y —0.5
font_size —24
Label:
size_hint_y —0.1
text:'
BoxLayout:
size_hint_x —0.9
size_hint_y —0.4
orientation:'horizontal'
TextInput:
id:text_box
font_size —22
focus —True
on_text_validate —root.btnClicked_text()
Label:
size_hint_y —0.1
text:'
FloatLayout:
Button:
text: "Search"
size_hint_x —0.23
size_hint_y —0.3
pos_hint: {"x": 0.75, "y":0}
font_size —20
on_press:
root.manager.transition.direction='RiseInTransition'
root.press_search_button()
<Wait_Screen>:
BoxLayout:
orientation:'vertical'
size —root.size
Label:
size_hint_y —0.1
text:'
Label:
text_size —self.size
text: 'Searching Now'
align:'left'
size_hint_x:1
size_hint_y —0.8
font_size —24
Label:
size_hint_y —0.1
text:'
Button:
size:50,50
size_hint —None, None
text:"cancel"
on_press —The method root.press_cancel_button()#Top_Screen is executed.
<Output_Screen>:
BoxLayout:
size —root.size
Button:
size:50,50
size_hint —None, None
text:'finish'
on_press —The method root.press_return_button()#Top_Screen is executed.
In order to automatically load the kv file, the file name should be mobidb.kv...
© 2024 OneMinuteCode. All rights reserved.