Hows it going guys. I have been looking for two days now and I cant seem to connect the dots. Please forgive me I am somewhat experienced with python but OOP concepts are still a little unclear. I have seen a couple similar posts but the python is a little over my head.
What I am trying to do is set the temperature (and eventually humidity) in a separate screen (Button called Set Temp). Then have that set temp value from that screen show up on my main screen. I tried to tie the temperature value to a global variable (tep). Then when one would hit main menu button (within the set temp screen) and call a method within the main screen class that would reference that global tep variable. But when I do this nothing happens. I have tired to call it by ID, create a method within the main menu to explicitly update that variable but to no avail and vice versa but nothing seems to work. I tried looking how to refresh the screen but the examples were over my head. If someone could shed some light on this issue that would be awesome.
Thanks for taking the time to read my post!
python file
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
from kivy.properties import ObjectProperty
from random import randint
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
Window.size = (600,250)
tep = 75
# Window Manager Class
class WindowManager(ScreenManager):
pass
# Main home menu Class
class MyTerrLayout(Screen):
internal_read = ObjectProperty(None)
external_read = ObjectProperty(None)
target_temp = ObjectProperty(None)
target_hum = ObjectProperty(None)
def set_temp(self):
global tep
self.ids._Target_Temp.text = str(tep)
print(str(tep))
# Temprature Screen Class / Window
class TempWindow(Screen):
temp_menu = ObjectProperty(None)
def sub_temp(self):
global tep
tep = tep - 1
self.temp_menu.text = str(tep)
def add_temp(self):
global tep
tep = tep + 1
self.temp_menu.text = str(tep)
def set_temp(self):
MyTerrLayout().set_temp()
# Humidity Class / Window
class HumWindow(Screen):
pass
# Builder Section
kv = Builder.load_file('terrlayoutV1.kv')
class TerrLayout(App):
def build(self):
return kv
if __name__=="__main__":
TerrLayout().run()
Kivy File
#:kivy 1.0.9
WindowManager:
MyTerrLayout:
TempWindow:
HumWindow:
<MyTerrLayout>:
name: "main"
internal_read: internal_reading
external_read: external_reading
target_temp: _Target_Temp
target_hum: _Target_Hum
GridLayout:
cols:2
RelativeLayout:
Label:
id: _internal
text: 'Internal Temp/Humidity'
size_hint: 0.5 , .166
pos_hint: {'x': .25, 'top': 1}
Label:
text: 'Target:'
font_size: 15
size_hint: 0.125 , .166
pos_hint: {'x': 0.1, 'top': 0.834}
Label:
id: _Target_Temp
size_hint: 0.125 , .166
pos_hint: {'x': .25, 'top': 0.834}
Label:
id: _Target_Hum
size_hint: 0.125 , .166
pos_hint: {'x': .38, 'top': 0.834}
Label:
text: 'Current:'
size_hint: 0.125 , .166
pos_hint: {'x': .55, 'top': 0.834}
Label:
id: internal_reading
text: '25C/35%'
size_hint: 0.125 , .166
pos_hint: {'x': .75, 'top': 0.834}
Label:
id: _external
text: 'External Temp/Humidity'
size_hint: 0.5, .166
pos_hint: {'x': .25, 'top': 0.668}
Label:
id: external_reading
size_hint: 0.5, .166
pos_hint: {'x': .25, 'top': 0.502}
Label:
id: _heatbed
text: 'Heatbed Temprature'
size_hint: 0.5, .166
pos_hint: {'x': 0.25, 'top': 0.336}
Label:
id: heatbed_reading
text: '80C'
size_hint: 0.5, .166
pos_hint: {'x': 0.25, 'top': 0.17}
StackLayout:
orientation: 'rl-tb'
spacing: 1.5
Button:
id: _Set_Temp
text: 'Set Temp'
size_hint: [.5, .25]
on_release: app.root.current = "Temp"
Button:
id: _Set_Hum
text: 'Set Humidity'
size_hint: [.5, .25]
on_release: app.root.current = "Hum"
Button:
id: _Set_Fan
text: 'Set Fan Time'
size_hint: [.5, .25]
Button:
id: _Set_Light
text: 'Set Light Time'
size_hint: [.5, .25]
Button:
id: _Tog_Light
text: 'Toggle Light'
size_hint: [.5, .25]
Button:
id: _Tog_Fan
text: 'Toggle Fan'
size_hint: [.5, .25]
Button:
id: _Dis_Mode
text: 'Display Mode'
size_hint: [1, .25]
<TempWindow>:
name: "Temp"
temp_menu: set_tep_menu
GridLayout:
cols: 2
Label:
id: set_tep_menu
size_hint: 1, .5
font_size: 32
StackLayout:
orientation: 'rl-tb'
Button:
text: "Increase Temp"
on_press: root.add_temp()
size_hint: [1, .3]
Button:
text: "Decrease Temp"
on_press: root.sub_temp()
size_hint: [1, .3]
Button:
text: "Main Menu"
on_release: app.root.current = "main"
on_release: root.set_temp() #calling method to set temp
size_hint: [1, .3]
<HumWindow>:
name: "Hum"
Button:
text: "Humidity"
on_release: app.root.current = "main"