Преглед на файлове

GUI and protocol separeted from libraries and implemented in the application

mod_update
Dirk Alders преди 4 години
родител
ревизия
8dd3ee46b9
променени са 5 файла, в които са добавени 303 реда и са изтрити 192 реда
  1. 1
    1
      garage_protocol
  2. 158
    0
      gui.py
  3. 50
    12
      gui.wxg
  4. 93
    178
      smarthome.py
  5. 1
    1
      wetation_protocol

+ 1
- 1
garage_protocol

@@ -1 +1 @@
1
-Subproject commit 88c3b5676f0f670e1b68bb327d844e9d67dddda6
1
+Subproject commit ae391a4698abc0834519cfade3c96b06a59a22d9

+ 158
- 0
gui.py Целия файл

@@ -0,0 +1,158 @@
1
+#!/usr/bin/env python
2
+# -*- coding: UTF-8 -*-
3
+#
4
+# generated by wxGlade 0.9.3 on Mon Sep  7 11:55:26 2020
5
+#
6
+
7
+import wx
8
+
9
+# begin wxGlade: dependencies
10
+# end wxGlade
11
+
12
+# begin wxGlade: extracode
13
+# end wxGlade
14
+
15
+
16
+class Wetation(wx.Frame):
17
+    def __init__(self, *args, **kwds):
18
+        # begin wxGlade: Wetation.__init__
19
+        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
20
+        wx.Frame.__init__(self, *args, **kwds)
21
+        self.SetSize((800, 628))
22
+        self.date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT)
23
+        self.time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT)
24
+        self.heading_out_envdata = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur")
25
+        self.out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
26
+        self.out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
27
+        self.out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
28
+        self.out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
29
+        self.out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
30
+        self.heading_in_envdata = wx.StaticText(self, wx.ID_ANY, "Innentemperatur")
31
+        self.in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
32
+        self.in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
33
+        self.in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
34
+        self.in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
35
+        self.in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
36
+        self.heading_garage = wx.StaticText(self, wx.ID_ANY, "Garage")
37
+        self.gate_oc = wx.Button(self, wx.ID_ANY, "Garage")
38
+        self.gate_close = wx.StaticText(self, wx.ID_ANY, "Close")
39
+        self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100)
40
+        self.gate_open = wx.StaticText(self, wx.ID_ANY, "Open")
41
+
42
+        self.__set_properties()
43
+        self.__do_layout()
44
+
45
+        self.Bind(wx.EVT_BUTTON, self.gate_oc_evt, self.gate_oc)
46
+        # end wxGlade
47
+
48
+    def __set_properties(self):
49
+        # begin wxGlade: Wetation.__set_properties
50
+        self.SetTitle("frame")
51
+        self.SetBackgroundColour(wx.Colour(250, 249, 255))
52
+        self.SetForegroundColour(wx.Colour(35, 35, 142))
53
+        self.date.SetBackgroundColour(wx.Colour(35, 35, 142))
54
+        self.date.SetForegroundColour(wx.Colour(255, 255, 255))
55
+        self.date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
56
+        self.time.SetBackgroundColour(wx.Colour(35, 35, 142))
57
+        self.time.SetForegroundColour(wx.Colour(255, 255, 255))
58
+        self.time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
59
+        self.heading_out_envdata.SetBackgroundColour(wx.Colour(35, 35, 142))
60
+        self.heading_out_envdata.SetForegroundColour(wx.Colour(250, 249, 255))
61
+        self.heading_out_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
62
+        self.out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
63
+        self.out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
64
+        self.out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
65
+        self.out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
66
+        self.out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
67
+        self.heading_in_envdata.SetBackgroundColour(wx.Colour(35, 35, 142))
68
+        self.heading_in_envdata.SetForegroundColour(wx.Colour(250, 249, 255))
69
+        self.heading_in_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
70
+        self.in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
71
+        self.in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
72
+        self.in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
73
+        self.in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
74
+        self.in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
75
+        self.heading_garage.SetBackgroundColour(wx.Colour(35, 35, 142))
76
+        self.heading_garage.SetForegroundColour(wx.Colour(250, 249, 255))
77
+        self.heading_garage.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
78
+        self.heading_garage.Hide()
79
+        self.gate_oc.Hide()
80
+        self.gate_close.Hide()
81
+        self.gate_position.Enable(False)
82
+        self.gate_position.Hide()
83
+        self.gate_open.Hide()
84
+        # end wxGlade
85
+
86
+    def __do_layout(self):
87
+        # begin wxGlade: Wetation.__do_layout
88
+        sizer_main = wx.BoxSizer(wx.VERTICAL)
89
+        sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
90
+        sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL)
91
+        sizer_9 = wx.BoxSizer(wx.VERTICAL)
92
+        sizer_5 = wx.BoxSizer(wx.VERTICAL)
93
+        sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL)
94
+        sizer_7 = wx.BoxSizer(wx.VERTICAL)
95
+        sizer_4 = wx.BoxSizer(wx.VERTICAL)
96
+        sizer_date_time = wx.BoxSizer(wx.HORIZONTAL)
97
+        spacer_1 = wx.StaticText(self, wx.ID_ANY, "")
98
+        spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142))
99
+        spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
100
+        sizer_main.Add(spacer_1, 0, wx.EXPAND, 0)
101
+        sizer_date_time.Add(self.date, 1, wx.EXPAND | wx.LEFT, 0)
102
+        sizer_date_time.Add(self.time, 1, wx.EXPAND | wx.RIGHT, 0)
103
+        sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0)
104
+        spacer_2 = wx.StaticText(self, wx.ID_ANY, "")
105
+        spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142))
106
+        spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
107
+        sizer_main.Add(spacer_2, 0, wx.EXPAND, 0)
108
+        sizer_main.Add((20, 20), 0, 0, 0)
109
+        sizer_main.Add(self.heading_out_envdata, 0, wx.EXPAND, 0)
110
+        sizer_4.Add(self.out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
111
+        sizer_4.Add(self.out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
112
+        sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0)
113
+        sizer_7.Add(self.out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
114
+        sizer_7.Add(self.out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
115
+        sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0)
116
+        sizer_env_data_out.Add((50, 20), 0, 0, 0)
117
+        sizer_env_data_out.Add(self.out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
118
+        sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0)
119
+        sizer_main.Add((20, 20), 0, 0, 0)
120
+        sizer_main.Add(self.heading_in_envdata, 0, wx.EXPAND, 0)
121
+        sizer_5.Add(self.in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
122
+        sizer_5.Add(self.in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
123
+        sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0)
124
+        sizer_9.Add(self.in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
125
+        sizer_9.Add(self.in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
126
+        sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0)
127
+        sizer_env_data_in.Add((50, 20), 0, 0, 0)
128
+        sizer_env_data_in.Add(self.in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
129
+        sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0)
130
+        sizer_main.Add((10, 10), 1, 0, 0)
131
+        sizer_main.Add(self.heading_garage, 0, wx.EXPAND, 0)
132
+        sizer_8.Add(self.gate_oc, 0, 0, 0)
133
+        sizer_8.Add(self.gate_close, 0, wx.ALIGN_CENTER, 0)
134
+        sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0)
135
+        sizer_8.Add(self.gate_open, 0, wx.ALIGN_CENTER, 0)
136
+        sizer_main.Add(sizer_8, 0, wx.EXPAND, 0)
137
+        self.SetSizer(sizer_main)
138
+        self.Layout()
139
+        # end wxGlade
140
+
141
+    def gate_oc_evt(self, event):  # wxGlade: Wetation.<event_handler>
142
+        print("Event handler 'gate_oc_evt' not implemented!")
143
+        event.Skip()
144
+
145
+# end of class Wetation
146
+
147
+class MyApp(wx.App):
148
+    def OnInit(self):
149
+        self.wetation = Wetation(None, wx.ID_ANY, "")
150
+        self.SetTopWindow(self.wetation)
151
+        self.wetation.Show()
152
+        return True
153
+
154
+# end of class MyApp
155
+
156
+if __name__ == "__main__":
157
+    app = MyApp(0)
158
+    app.MainLoop()

smarthome.wxg → gui.wxg Целия файл

@@ -1,9 +1,9 @@
1 1
 <?xml version="1.0"?>
2
-<!-- generated by wxGlade 0.9.3 on Sun Sep  6 14:34:01 2020 -->
2
+<!-- generated by wxGlade 0.9.3 on Mon Sep  7 11:55:31 2020 -->
3 3
 
4
-<application class="MyApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="0" path="./smarthome.py" source_extension=".cpp" top_window="wetation" use_gettext="0" use_new_namespace="1">
4
+<application class="MyApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="./gui.py" source_extension=".cpp" top_window="wetation" use_gettext="0" use_new_namespace="1">
5 5
     <object class="Wetation" name="wetation" base="EditFrame">
6
-        <size>800, 600</size>
6
+        <size>800, 628</size>
7 7
         <background>#faf9ff</background>
8 8
         <foreground>#23238e</foreground>
9 9
         <title>frame</title>
@@ -49,6 +49,7 @@
49 49
                             </font>
50 50
                             <style>wxALIGN_LEFT</style>
51 51
                             <label>xx.xx.xxxx</label>
52
+                            <attribute>1</attribute>
52 53
                         </object>
53 54
                     </object>
54 55
                     <object class="sizeritem">
@@ -68,6 +69,7 @@
68 69
                             </font>
69 70
                             <style>wxALIGN_RIGHT</style>
70 71
                             <label>xx:xx</label>
72
+                            <attribute>1</attribute>
71 73
                         </object>
72 74
                     </object>
73 75
                 </object>
@@ -88,12 +90,20 @@
88 90
                     </font>
89 91
                 </object>
90 92
             </object>
93
+            <object class="sizeritem">
94
+                <option>0</option>
95
+                <border>0</border>
96
+                <object class="spacer" name="spacer" base="EditSpacer">
97
+                    <width>20</width>
98
+                    <height>20</height>
99
+                </object>
100
+            </object>
91 101
             <object class="sizeritem">
92 102
                 <option>0</option>
93 103
                 <border>0</border>
94 104
                 <flag>wxEXPAND</flag>
95
-                <object class="wxStaticText" name="spacer_3" base="EditStaticText">
96
-                    <background>#000000</background>
105
+                <object class="wxStaticText" name="heading_out_envdata" base="EditStaticText">
106
+                    <background>#23238e</background>
97 107
                     <foreground>#faf9ff</foreground>
98 108
                     <font>
99 109
                         <size>12</size>
@@ -104,6 +114,7 @@
104 114
                         <face />
105 115
                     </font>
106 116
                     <label>Außentemperatur</label>
117
+                    <attribute>1</attribute>
107 118
                 </object>
108 119
             </object>
109 120
             <object class="sizeritem">
@@ -133,6 +144,7 @@
133 144
                                     </font>
134 145
                                     <style>wxALIGN_RIGHT</style>
135 146
                                     <label>- %</label>
147
+                                    <attribute>1</attribute>
136 148
                                 </object>
137 149
                             </object>
138 150
                             <object class="sizeritem">
@@ -150,6 +162,7 @@
150 162
                                     </font>
151 163
                                     <style>wxALIGN_RIGHT</style>
152 164
                                     <label>- mbar</label>
165
+                                    <attribute>1</attribute>
153 166
                                 </object>
154 167
                             </object>
155 168
                         </object>
@@ -175,6 +188,7 @@
175 188
                                     </font>
176 189
                                     <style>wxALIGN_RIGHT</style>
177 190
                                     <label>-.- °C</label>
191
+                                    <attribute>1</attribute>
178 192
                                 </object>
179 193
                             </object>
180 194
                             <object class="sizeritem">
@@ -192,6 +206,7 @@
192 206
                                     </font>
193 207
                                     <style>wxALIGN_RIGHT</style>
194 208
                                     <label>-.- °C</label>
209
+                                    <attribute>1</attribute>
195 210
                                 </object>
196 211
                             </object>
197 212
                         </object>
@@ -219,16 +234,25 @@
219 234
                             </font>
220 235
                             <style>wxALIGN_RIGHT</style>
221 236
                             <label>-.- °C</label>
237
+                            <attribute>1</attribute>
222 238
                         </object>
223 239
                     </object>
224 240
                 </object>
225 241
             </object>
242
+            <object class="sizeritem">
243
+                <option>0</option>
244
+                <border>0</border>
245
+                <object class="spacer" name="spacer" base="EditSpacer">
246
+                    <width>20</width>
247
+                    <height>20</height>
248
+                </object>
249
+            </object>
226 250
             <object class="sizeritem">
227 251
                 <option>0</option>
228 252
                 <border>0</border>
229 253
                 <flag>wxEXPAND</flag>
230
-                <object class="wxStaticText" name="spacer_4" base="EditStaticText">
231
-                    <background>#000000</background>
254
+                <object class="wxStaticText" name="heading_in_envdata" base="EditStaticText">
255
+                    <background>#23238e</background>
232 256
                     <foreground>#faf9ff</foreground>
233 257
                     <font>
234 258
                         <size>12</size>
@@ -239,6 +263,7 @@
239 263
                         <face />
240 264
                     </font>
241 265
                     <label>Innentemperatur</label>
266
+                    <attribute>1</attribute>
242 267
                 </object>
243 268
             </object>
244 269
             <object class="sizeritem">
@@ -268,6 +293,7 @@
268 293
                                     </font>
269 294
                                     <style>wxALIGN_RIGHT</style>
270 295
                                     <label>- %</label>
296
+                                    <attribute>1</attribute>
271 297
                                 </object>
272 298
                             </object>
273 299
                             <object class="sizeritem">
@@ -285,6 +311,7 @@
285 311
                                     </font>
286 312
                                     <style>wxALIGN_RIGHT</style>
287 313
                                     <label>- mbar</label>
314
+                                    <attribute>1</attribute>
288 315
                                 </object>
289 316
                             </object>
290 317
                         </object>
@@ -310,6 +337,7 @@
310 337
                                     </font>
311 338
                                     <style>wxALIGN_RIGHT</style>
312 339
                                     <label>-.- °C</label>
340
+                                    <attribute>1</attribute>
313 341
                                 </object>
314 342
                             </object>
315 343
                             <object class="sizeritem">
@@ -327,6 +355,7 @@
327 355
                                     </font>
328 356
                                     <style>wxALIGN_RIGHT</style>
329 357
                                     <label>-.- °C</label>
358
+                                    <attribute>1</attribute>
330 359
                                 </object>
331 360
                             </object>
332 361
                         </object>
@@ -354,6 +383,7 @@
354 383
                             </font>
355 384
                             <style>wxALIGN_RIGHT</style>
356 385
                             <label>-.- °C</label>
386
+                            <attribute>1</attribute>
357 387
                         </object>
358 388
                     </object>
359 389
                 </object>
@@ -370,8 +400,8 @@
370 400
                 <option>0</option>
371 401
                 <border>0</border>
372 402
                 <flag>wxEXPAND</flag>
373
-                <object class="wxStaticText" name="spacer_5" base="EditStaticText">
374
-                    <background>#000000</background>
403
+                <object class="wxStaticText" name="heading_garage" base="EditStaticText">
404
+                    <background>#23238e</background>
375 405
                     <foreground>#faf9ff</foreground>
376 406
                     <font>
377 407
                         <size>12</size>
@@ -381,7 +411,9 @@
381 411
                         <underlined>0</underlined>
382 412
                         <face />
383 413
                     </font>
414
+                    <hidden>1</hidden>
384 415
                     <label>Garage</label>
416
+                    <attribute>1</attribute>
385 417
                 </object>
386 418
             </object>
387 419
             <object class="sizeritem">
@@ -393,10 +425,11 @@
393 425
                     <object class="sizeritem">
394 426
                         <option>0</option>
395 427
                         <border>0</border>
396
-                        <object class="wxButton" name="garage_oc" base="EditButton">
428
+                        <object class="wxButton" name="gate_oc" base="EditButton">
397 429
                             <events>
398
-                                <handler event="EVT_BUTTON">garage_oc_evt</handler>
430
+                                <handler event="EVT_BUTTON">gate_oc_evt</handler>
399 431
                             </events>
432
+                            <hidden>1</hidden>
400 433
                             <label>Garage</label>
401 434
                         </object>
402 435
                     </object>
@@ -404,8 +437,10 @@
404 437
                         <option>0</option>
405 438
                         <border>0</border>
406 439
                         <flag>wxALIGN_CENTER</flag>
407
-                        <object class="wxStaticText" name="gate__open" base="EditStaticText">
440
+                        <object class="wxStaticText" name="gate_close" base="EditStaticText">
441
+                            <hidden>1</hidden>
408 442
                             <label>Close</label>
443
+                            <attribute>1</attribute>
409 444
                         </object>
410 445
                     </object>
411 446
                     <object class="sizeritem">
@@ -414,6 +449,7 @@
414 449
                         <flag>wxEXPAND</flag>
415 450
                         <object class="wxSlider" name="gate_position" base="EditSlider">
416 451
                             <disabled>1</disabled>
452
+                            <hidden>1</hidden>
417 453
                             <style>wxSL_HORIZONTAL</style>
418 454
                             <range>0, 100</range>
419 455
                             <value>50</value>
@@ -424,7 +460,9 @@
424 460
                         <border>0</border>
425 461
                         <flag>wxALIGN_CENTER</flag>
426 462
                         <object class="wxStaticText" name="gate_open" base="EditStaticText">
463
+                            <hidden>1</hidden>
427 464
                             <label>Open</label>
465
+                            <attribute>1</attribute>
428 466
                         </object>
429 467
                     </object>
430 468
                 </object>

+ 93
- 178
smarthome.py Целия файл

@@ -1,184 +1,119 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: UTF-8 -*-
3 3
 #
4
-# generated by wxGlade 0.9.4 on Fri Sep  4 13:21:47 2020
5
-#
6
-
7
-import wx
8 4
 
9 5
 import config
6
+import rpi_envsens as envsens
7
+import garage_protocol
8
+import gui
10 9
 import logging
11 10
 import os
12
-
13
-import time
14
-import garage_protocol
15
-import wetation_protocol
16 11
 import report
17
-import tcp_socket
18 12
 import task
19
-from config import FULL_SCRREN
20
-
21
-# begin wxGlade: dependencies
22
-# end wxGlade
13
+import tcp_socket
14
+import time
15
+import wetation_protocol
16
+import wx
23 17
 
24
-# begin wxGlade: extracode
25
-# end wxGlade
18
+logger = logging.getLogger('APP')
26 19
 
27 20
 
28
-class Wetation(wx.Frame):
21
+class WetationFrameProt(gui.Wetation):
29 22
     def __init__(self, *args, **kwds):
30
-        # begin wxGlade: Wetation.__init__
31
-        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
32
-        wx.Frame.__init__(self, *args, **kwds)
33
-        self.SetSize((800, 600))
34
-        self.garage_oc = wx.Button(self, wx.ID_ANY, "Garage")
35
-        self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100)
36
-
37
-        self.__set_properties()
38
-        self.__do_layout()
39
-
40
-        self.Bind(wx.EVT_BUTTON, self.garage_oc_evt, self.garage_oc)
41
-        # end wxGlade
42
-        self.ShowFullScreen(FULL_SCRREN)
43
-
44
-    def __set_properties(self):
45
-        # begin wxGlade: Wetation.__set_properties
46
-        self.SetTitle("frame")
47
-        self.SetBackgroundColour(wx.Colour(250, 249, 255))
48
-        self.SetForegroundColour(wx.Colour(35, 35, 142))
49
-        self.gate_position.Enable(False)
50
-        # end wxGlade
51
-
52
-    def __do_layout(self):
53
-        # begin wxGlade: Wetation.__do_layout
54
-        sizer_main = wx.BoxSizer(wx.VERTICAL)
55
-        sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
56
-        sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL)
57
-        sizer_9 = wx.BoxSizer(wx.VERTICAL)
58
-        sizer_5 = wx.BoxSizer(wx.VERTICAL)
59
-        sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL)
60
-        sizer_7 = wx.BoxSizer(wx.VERTICAL)
61
-        sizer_4 = wx.BoxSizer(wx.VERTICAL)
62
-        sizer_date_time = wx.BoxSizer(wx.HORIZONTAL)
63
-        spacer_1 = wx.StaticText(self, wx.ID_ANY, "")
64
-        spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142))
65
-        spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
66
-        sizer_main.Add(spacer_1, 0, wx.EXPAND, 0)
67
-        date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT)
68
-        date.SetBackgroundColour(wx.Colour(35, 35, 142))
69
-        date.SetForegroundColour(wx.Colour(255, 255, 255))
70
-        date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
71
-        sizer_date_time.Add(date, 1, wx.EXPAND | wx.LEFT, 0)
72
-        time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT)
73
-        time.SetBackgroundColour(wx.Colour(35, 35, 142))
74
-        time.SetForegroundColour(wx.Colour(255, 255, 255))
75
-        time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
76
-        sizer_date_time.Add(time, 1, wx.EXPAND | wx.RIGHT, 0)
77
-        sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0)
78
-        spacer_2 = wx.StaticText(self, wx.ID_ANY, "")
79
-        spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142))
80
-        spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
81
-        sizer_main.Add(spacer_2, 0, wx.EXPAND, 0)
82
-        spacer_3 = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur")
83
-        spacer_3.SetBackgroundColour(wx.Colour(0, 0, 0))
84
-        spacer_3.SetForegroundColour(wx.Colour(250, 249, 255))
85
-        spacer_3.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
86
-        sizer_main.Add(spacer_3, 0, wx.EXPAND, 0)
87
-        out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
88
-        out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
89
-        sizer_4.Add(out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
90
-        out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
91
-        out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
92
-        sizer_4.Add(out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
93
-        sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0)
94
-        out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
95
-        out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
96
-        sizer_7.Add(out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
97
-        out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
98
-        out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
99
-        sizer_7.Add(out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
100
-        sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0)
101
-        sizer_env_data_out.Add((50, 20), 0, 0, 0)
102
-        out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
103
-        out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
104
-        sizer_env_data_out.Add(out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
105
-        sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0)
106
-        spacer_4 = wx.StaticText(self, wx.ID_ANY, "Innentemperatur")
107
-        spacer_4.SetBackgroundColour(wx.Colour(0, 0, 0))
108
-        spacer_4.SetForegroundColour(wx.Colour(250, 249, 255))
109
-        spacer_4.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
110
-        sizer_main.Add(spacer_4, 0, wx.EXPAND, 0)
111
-        in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
112
-        in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
113
-        sizer_5.Add(in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
114
-        in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
115
-        in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
116
-        sizer_5.Add(in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
117
-        sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0)
118
-        in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
119
-        in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
120
-        sizer_9.Add(in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
121
-        in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
122
-        in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
123
-        sizer_9.Add(in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
124
-        sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0)
125
-        sizer_env_data_in.Add((50, 20), 0, 0, 0)
126
-        in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
127
-        in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
128
-        sizer_env_data_in.Add(in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
129
-        sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0)
130
-        sizer_main.Add((10, 10), 1, 0, 0)
131
-        spacer_5 = wx.StaticText(self, wx.ID_ANY, "Garage")
132
-        spacer_5.SetBackgroundColour(wx.Colour(0, 0, 0))
133
-        spacer_5.SetForegroundColour(wx.Colour(250, 249, 255))
134
-        spacer_5.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
135
-        sizer_main.Add(spacer_5, 0, wx.EXPAND, 0)
136
-        sizer_8.Add(self.garage_oc, 0, 0, 0)
137
-        gate__open = wx.StaticText(self, wx.ID_ANY, "Close")
138
-        sizer_8.Add(gate__open, 0, wx.ALIGN_CENTER, 0)
139
-        sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0)
140
-        gate_open = wx.StaticText(self, wx.ID_ANY, "Open")
141
-        sizer_8.Add(gate_open, 0, wx.ALIGN_CENTER, 0)
142
-        sizer_main.Add(sizer_8, 0, wx.EXPAND, 0)
143
-        self.SetSizer(sizer_main)
144
-        self.Layout()
145
-        # end wxGlade
146
-        self.date = date
147
-        self.time = time
148
-        #
149
-        self.out_humidity = out_humidity
150
-        self.out_pressure = out_pressure
23
+        gui.Wetation.__init__(self, *args, **kwds)
24
+        self.__task_data_request__ = task.periodic(10, self.__initiate_data_request__)
25
+        self.__init__communication__()
151 26
 
152
-        self.out_temperature = out_temperature
153
-        self.out_temperature_min = out_temperature_min
154
-        self.out_temperature_max = out_temperature_max
27
+    def __init__communication__(self):
155 28
         #
156
-        self.in_humidity = in_humidity
157
-        self.in_pressure = in_pressure
158
-
159
-        self.in_temperature = in_temperature
29
+        # Start TCP-Clients
30
+        c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG)
31
+        self.prot_out = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_out_secret)
32
+        self.prot_out.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_out)
33
+        if config.server_out_secret is not None:
34
+            self.prot_out.authentificate()
35
+
36
+        c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG)
37
+        self.prot_in = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_in_secret)
38
+        self.prot_in.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_in)
39
+        if config.server_in_secret is not None:
40
+            self.prot_in.authentificate()
41
+
42
+        c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG)
43
+        self.prot_garage = garage_protocol.my_base_protocol_tcp(c_tcp, config.server_garage_secret)
44
+        self.prot_garage.register_callback(garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, garage_protocol.my_base_protocol_tcp.GATE_POSITION, self.update_gate_position)
45
+        if config.server_garage_secret is not None:
46
+            self.prot_garage.authentificate()
47
+
48
+    def __update_current_envdata__(self, msg, temperature, humidity, pressure):
49
+        if msg.get_status() == wetation_protocol.my_base_protocol_tcp.STATUS_OKAY:
50
+            env_data = msg.get_data()
51
+            wx.CallAfter(temperature.SetLabel, "%.1f °C" % env_data[envsens.KEY_TEMPERATURE])
52
+            wx.CallAfter(humidity.SetLabel, "%.1f %%" % env_data[envsens.KEY_HUMIDITY])
53
+            wx.CallAfter(pressure.SetLabel, "%.0f mbar" % env_data[envsens.KEY_PRESSURE])
54
+            wx.CallAfter(self.Layout)
55
+            return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
56
+        else:
57
+            logger.error('No environmental data received! MSG_STATUS was %s', wetation_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())))
58
+            return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
59
+
60
+    def update_current_env_data_out(self, msg):
61
+        return self.__update_current_envdata__(msg, self.out_temperature, self.out_humidity, self.out_pressure)
62
+
63
+    def update_current_env_data_in(self, msg):
64
+        return self.__update_current_envdata__(msg, self.in_temperature, self.in_humidity, self.in_pressure)
65
+
66
+    def update_gate_position(self, msg):
67
+        if msg.get_status() == garage_protocol.my_base_protocol_tcp.STATUS_OKAY:
68
+            #
69
+            # show gate section in GUI
70
+            #
71
+            self.heading_garage.show(True)
72
+            self.gate_oc.show(True)
73
+            self.gate_open.show(True)
74
+            self.gate_position.show(True)
75
+            self.gate_close.show(True)
76
+            #
77
+            # update gate position
78
+            #
79
+            wx.CallAfter(self.gate_position.SetValue, msg.get_data() * 100)
80
+            wx.CallAfter(self.Layout)
81
+            return garage_protocol.my_base_protocol_tcp.STATUS_OKAY, None
82
+        else:
83
+            logger.error('No gate position received! MSG_STATUS was %s', garage_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status())))
84
+            return garage_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
160 85
 
161 86
     def garage_oc_evt(self, event):  # wxGlade: Wetation.<event_handler>
162
-        self.prot_garage.send(prot_garage.SID_EXECUTE_REQUEST, prot_garage.OPEN_CLOSE_GATE, None)
87
+        self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None)
163 88
         event.Skip()
164
-# end of class Wetation
89
+
90
+    def __initiate_data_request__(self, rt):
91
+        self.prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
92
+        self.prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
93
+        self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None)
94
+        # TODO: Move the following three lines to the wx idle task
95
+        wx.CallAfter(self.time.SetLabel, time.strftime("%H:%M"))
96
+        wx.CallAfter(self.date.SetLabel, time.strftime("%d.%m.%Y"))
97
+        wx.CallAfter(self.Layout)
98
+
99
+    def run(self):
100
+        self.__task_data_request__.run()
101
+
102
+    def close(self):
103
+        self.__task_data_request__.stop()
104
+        self.__task_data_request__.join()
105
+
106
+    def __del__(self):
107
+        self.close()
108
+
165 109
 
166 110
 class MyApp(wx.App):
167 111
     def OnInit(self):
168
-        self.frame = Wetation(None, wx.ID_ANY, "")
112
+        self.frame = WetationFrameProt(None, wx.ID_ANY, "")
169 113
         self.SetTopWindow(self.frame)
170 114
         self.frame.Show()
171 115
         return True
172 116
 
173
-# end of class MyApp
174
-
175
-def initiate_update(rt, frame, prot_out, prot_in, prot_garage):
176
-    prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
177
-    prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
178
-    prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None)
179
-    wx.CallAfter(frame.time.SetLabel, time.strftime("%H:%M"))
180
-    wx.CallAfter(frame.date.SetLabel, time.strftime("%d.%m.%Y"))
181
-    wx.CallAfter(frame.Layout)
182 117
 
183 118
 
184 119
 
@@ -186,26 +121,6 @@ if __name__ == "__main__":
186 121
     report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, config.loggers)
187 122
     #
188 123
     app = MyApp(0)
189
-    #
190
-    # Start TCP-Clients
191
-    c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG)
192
-    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)
193
-    if config.server_out_secret is not None:
194
-        prot_out.authentificate()
195
-    c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG)
196
-    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)
197
-    if config.server_in_secret is not None:
198
-        prot_in.authentificate()
199
-    c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG)
200
-    prot_garage = garage_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.gate_position, app.frame.Layout, config.server_garage_secret)
201
-    if config.server_garage_secret is not None:
202
-        prot_garage.authentificate()
203
-    app.frame.prot_garage = prot_garage
204
-    pt = task.periodic(10, initiate_update, app.frame, prot_out, prot_in, prot_garage)
205
-    pt.run()
124
+    app.frame.run()
206 125
     app.MainLoop()
207
-    pt.stop()
208
-    try:
209
-        pt.join()
210
-    finally:
211
-        pt.stop()
126
+    app.frame.close()

+ 1
- 1
wetation_protocol

@@ -1 +1 @@
1
-Subproject commit 4a2f461be4ac53984aded6e4b7d128f3fb5b0c39
1
+Subproject commit 53e4523c140b5f51dedb3b128048eb59c1a5da4c

Loading…
Отказ
Запис