I am making a simple app that gives the user in depth information on a specific aircraft caution/warning when they press that specific button. I am pretty new and this is probably a very basic problem, but I simply don't know how to do it.
I'm not sure if the best way to organise the text data is to maybe put each caution/warning under its own string variable in a separate .py
file, or maybe make a class with different modules for each caution/warning with the module just being string info. Maybe a dictionary? Maybe the best way is to have it as a text file???
For each of the caution/warnings there will be approximately 200 words describing the problem associated with it and a solution.
A very short example of what I mean is: If someone pressed on the "Battery" caution, the button calls for the get_text
function in main.py
and sends it the button's id
. The get_text
uses that id
that was sent to it and then pulls the text from AOM.py
or .txt
or whatever. The information will then be displayed on the page and would be approximately 200 words about what the issue with the battery is and how to fix it. (I am purposely disregarding the need to change screens in my example here as I know how to do that). I'm just leaving as a print()
for now.
I have a min reproducible example here if someone could please help me out? Thank you very much.
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
import AOM
class CautionPanelScreen(Screen):
pass
class TextScreen(Screen):
pass
GUI = Builder.load_file("main.kv")
class MainApp(App):
def build(self):
return GUI
def change_screen(self):
# get the screen manager from the main.kv file
screen_manager = self.root.ids['screen_manager']
screen_manager.current = 'text_screen'
def get_text(self, caution):
print(AOM.caution) # this is where i am stuck, I dont know how to ref the data...
MainApp().run()
main.kv
#:include caution_panel_screen.kv
#:include text_screen.kv
GridLayout:
cols: 1
FloatLayout:
GridLayout:
canvas:
Color:
rgb: utils.get_color_from_hex("#EEEEEE")
Rectangle:
size: self.size
pos: self.pos
ScreenManager:
id: screen_manager
CautionPanelScreen:
name: "caution_panel_screen"
id: caution_panel_screen
caution_panel_screen.kv
#:import utils kivy.utils
<CautionPanelScreen>:
FloatLayout:
flt_data_recorder: flt_data_recorder.__self__
canvas:
Color:
rgb: utils.get_color_from_hex("#000000")
Rectangle:
size: self.size
pos: self.pos
GridLayout:
rows: 1
id: row_1
pos_hint: {"top": .9, "left": 1}
size_hint: 1, .1
spacing: 5, 5
Button:
pos_hint: {"top": 1, "left": 1}
markup: True
opacity: 1 if self.state == 'normal' else .5
font_size: '12sp'
id: pri_inv
halign: 'center'
text: "[color=#FFF300]PRI INV[/color]"
on_release:
app.get_text(pri_inv)
Button:
pos_hint: {"top": 1, "left": 1}
markup: True
opacity: 1 if self.state == 'normal' else .5
font_size: '12sp'
id: l_ac_bus
halign: 'center'
text: "[color=#FFF300]L AC BUS[/color]"
on_release:
app.get_text(l_ac_bus)
Button:
pos_hint: {"top": 1, "left": 1}
markup: True
opacity: 1 if self.state == 'normal' else .5
font_size: '12sp'
id: emer_lts_disarmed
halign: 'center'
text: "[color=#FFF300]EMER LTS\nDISARMED[/color]"
on_release:
app.get_text(emer_lts_disarmed)
AOM.py
#THIS IS JUST THE DATA PAGE AND CAN BE LAID OUT IN ANY WAY, dictionary, variables, txt, module, functions...
pri_inv = "all the things assosicated with primary inverter"
left_ac_bus = "all the stuff needed for info on left ac buses"
emer_lts_disarmed = "evertyhing on emergency lights"
EDIT: Will I have to store the text on my main.py? Or can I have it separate, like maybe in a word doc?
CodePudding user response:
I would keep it as dictionary
AOM.py
data = {
'pri_inv': "all the things assosicated with primary inverter",
'left_ac_bus': "all the stuff needed for info on left ac buses",
'emer_lts_disarmed': "evertyhing on emergency lights",
}
And Button
should use string in get_text()
in on_release
on_release:
app.get_text("pri_inv")
on_release:
root.get_text("left_ac_bus")
on_release:
app.get_text("emer_lts_disarmed")
and then code should use this string to get text from AOM.data
def get_text(self, caution):
print(AOM.data[caution])
Maybe later I would use AOM.data
to generate Button
so I would keep button's text also in AOM.data
data = {
'pri_inv': ["PRI INV", "all the things assosicated with primary inverter"],
'left_ac_bus': ["L AC BUS", "all the stuff needed for info on left ac buses"],
'emer_lts_disarmed': ["EMER LTS\nDISARMED", "evertyhing on emergency lights"],
}
and then it would need to use index [1]
to get text
def get_text(self, caution):
print(AOM.data[caution][1])
Or it could keep in nested dictionares
data = {
'pri_inv': {
"button_text": "PRI INV",
"text": "all the things assosicated with primary inverter",
},
'left_ac_bus': {
"button_text": "L AC BUS",
"text": "all the stuff needed for info on left ac buses",
},
'emer_lts_disarmed': {
"button_text": "EMER LTS\nDISARMED",
"text": "evertyhing on emergency lights",
},
}
and then it would need to use ["text"]
to get text
def get_text(self, caution):
print(AOM.data[caution]["text"])
if buttons would have other unique values then I would also keep them in dictionary.