123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
- #
- # generated by wxGlade 0.9.4 on Fri Sep 4 13:21:47 2020
- #
-
- import wx
-
- import config
- import logging
- import os
-
- import time
- import garage_protocol
- import wetation_protocol
- import report
- import tcp_socket
- import task
- from config import FULL_SCRREN
-
- # begin wxGlade: dependencies
- # end wxGlade
-
- # begin wxGlade: extracode
- # end wxGlade
-
-
- class Wetation(wx.Frame):
- def __init__(self, *args, **kwds):
- # begin wxGlade: Wetation.__init__
- kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
- wx.Frame.__init__(self, *args, **kwds)
- self.SetSize((800, 600))
- self.garage_oc = wx.Button(self, wx.ID_ANY, "Garage")
- self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100)
-
- self.__set_properties()
- self.__do_layout()
-
- self.Bind(wx.EVT_BUTTON, self.garage_oc_evt, self.garage_oc)
- # end wxGlade
- self.ShowFullScreen(FULL_SCRREN)
-
- def __set_properties(self):
- # begin wxGlade: Wetation.__set_properties
- self.SetTitle("frame")
- self.SetBackgroundColour(wx.Colour(250, 249, 255))
- self.SetForegroundColour(wx.Colour(35, 35, 142))
- self.gate_position.Enable(False)
- # end wxGlade
-
- def __do_layout(self):
- # begin wxGlade: Wetation.__do_layout
- sizer_main = wx.BoxSizer(wx.VERTICAL)
- sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
- sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL)
- sizer_9 = wx.BoxSizer(wx.VERTICAL)
- sizer_5 = wx.BoxSizer(wx.VERTICAL)
- sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL)
- sizer_7 = wx.BoxSizer(wx.VERTICAL)
- sizer_4 = wx.BoxSizer(wx.VERTICAL)
- sizer_date_time = wx.BoxSizer(wx.HORIZONTAL)
- spacer_1 = wx.StaticText(self, wx.ID_ANY, "")
- spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142))
- spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_main.Add(spacer_1, 0, wx.EXPAND, 0)
- date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT)
- date.SetBackgroundColour(wx.Colour(35, 35, 142))
- date.SetForegroundColour(wx.Colour(255, 255, 255))
- date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_date_time.Add(date, 1, wx.EXPAND | wx.LEFT, 0)
- time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT)
- time.SetBackgroundColour(wx.Colour(35, 35, 142))
- time.SetForegroundColour(wx.Colour(255, 255, 255))
- time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_date_time.Add(time, 1, wx.EXPAND | wx.RIGHT, 0)
- sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0)
- spacer_2 = wx.StaticText(self, wx.ID_ANY, "")
- spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142))
- spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_main.Add(spacer_2, 0, wx.EXPAND, 0)
- spacer_3 = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur")
- spacer_3.SetBackgroundColour(wx.Colour(0, 0, 0))
- spacer_3.SetForegroundColour(wx.Colour(250, 249, 255))
- spacer_3.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_main.Add(spacer_3, 0, wx.EXPAND, 0)
- out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
- out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_4.Add(out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
- out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_4.Add(out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0)
- out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_7.Add(out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_7.Add(out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0)
- sizer_env_data_out.Add((50, 20), 0, 0, 0)
- out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_env_data_out.Add(out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
- sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0)
- spacer_4 = wx.StaticText(self, wx.ID_ANY, "Innentemperatur")
- spacer_4.SetBackgroundColour(wx.Colour(0, 0, 0))
- spacer_4.SetForegroundColour(wx.Colour(250, 249, 255))
- spacer_4.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_main.Add(spacer_4, 0, wx.EXPAND, 0)
- in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
- in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_5.Add(in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
- in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_5.Add(in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0)
- in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_9.Add(in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_9.Add(in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
- sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0)
- sizer_env_data_in.Add((50, 20), 0, 0, 0)
- in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
- in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_env_data_in.Add(in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
- sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0)
- sizer_main.Add((10, 10), 1, 0, 0)
- spacer_5 = wx.StaticText(self, wx.ID_ANY, "Garage")
- spacer_5.SetBackgroundColour(wx.Colour(0, 0, 0))
- spacer_5.SetForegroundColour(wx.Colour(250, 249, 255))
- spacer_5.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
- sizer_main.Add(spacer_5, 0, wx.EXPAND, 0)
- sizer_8.Add(self.garage_oc, 0, 0, 0)
- gate__open = wx.StaticText(self, wx.ID_ANY, "Close")
- sizer_8.Add(gate__open, 0, wx.ALIGN_CENTER, 0)
- sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0)
- gate_open = wx.StaticText(self, wx.ID_ANY, "Open")
- sizer_8.Add(gate_open, 0, wx.ALIGN_CENTER, 0)
- sizer_main.Add(sizer_8, 0, wx.EXPAND, 0)
- self.SetSizer(sizer_main)
- self.Layout()
- # end wxGlade
- self.date = date
- self.time = time
- #
- self.out_humidity = out_humidity
- self.out_pressure = out_pressure
-
- self.out_temperature = out_temperature
- self.out_temperature_min = out_temperature_min
- self.out_temperature_max = out_temperature_max
- #
- self.in_humidity = in_humidity
- self.in_pressure = in_pressure
-
- self.in_temperature = in_temperature
-
- def garage_oc_evt(self, event): # wxGlade: Wetation.<event_handler>
- self.prot_garage.send(prot_garage.SID_EXECUTE_REQUEST, prot_garage.OPEN_CLOSE_GATE, None)
- event.Skip()
- # end of class Wetation
-
- class MyApp(wx.App):
- def OnInit(self):
- self.frame = Wetation(None, wx.ID_ANY, "")
- self.SetTopWindow(self.frame)
- self.frame.Show()
- return True
-
- # end of class MyApp
-
- def initiate_update(rt, frame, prot_out, prot_in, prot_garage):
- prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
- prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
- prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None)
- wx.CallAfter(frame.time.SetLabel, time.strftime("%H:%M"))
- wx.CallAfter(frame.date.SetLabel, time.strftime("%d.%m.%Y"))
- wx.CallAfter(frame.Layout)
-
-
-
- if __name__ == "__main__":
- report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, config.loggers)
- #
- app = MyApp(0)
- #
- # Start TCP-Clients
- c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG)
- prot_out = wetation_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.out_temperature, app.frame.out_humidity, app.frame.out_pressure, app.frame.Layout, config.server_out_secret)
- if config.server_out_secret is not None:
- prot_out.authentificate()
- c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG)
- prot_in = wetation_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.in_temperature, app.frame.in_humidity, app.frame.in_pressure, app.frame.Layout, config.server_in_secret)
- if config.server_in_secret is not None:
- prot_in.authentificate()
- c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG)
- prot_garage = garage_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.gate_position, app.frame.Layout, config.server_garage_secret)
- if config.server_garage_secret is not None:
- prot_garage.authentificate()
- app.frame.prot_garage = prot_garage
- pt = task.periodic(10, initiate_update, app.frame, prot_out, prot_in, prot_garage)
- pt.run()
- app.MainLoop()
- pt.stop()
- try:
- pt.join()
- finally:
- pt.stop()
|