-
Notifications
You must be signed in to change notification settings - Fork 0
/
hubrpi.py
142 lines (123 loc) · 4.47 KB
/
hubrpi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
import wx
from modules import m_tabAgenda
from modules import m_tabBitcoin
from modules import m_tabFortune
from modules import m_tabEle
from modules import m_tabEnergie
from modules import m_tabGas
from modules import m_tabMuziek
from modules import m_tabTools
from modules import m_tabWat
from modules import m_tabWeer
from multiprocessing import Process
# Dictionary van Notebook die tabbladen bijhoudt
dict = {"nb": wx.Notebook}
sec_switch = 31 # 31 (=prime) ongeveer halve minuut
sec_count = 0
pbar = None
class hubrpiApp(wx.App):
def __init__(self):
super().__init__(clearSigInt=True)
# init frame
frame = MyFrame()
frame.Show()
class MyFrame(wx.Frame):
def __init__(self, title="Hub Rpi"):
super().__init__(None, title=title)
# initialize the frame's contents
self.InitFrame()
def InitFrame(self):
self.panel = MyPanel(self)
self.SetSize((800, 480))
self.Fit()
class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent=parent)
self.InitPanel()
self._on_clock_timer(None)
self.update_timer = wx.Timer(self, -1)
self.update_timer.Start(1000)
self.Bind(wx.EVT_TIMER, self._on_clock_timer, self.update_timer)
def _on_clock_timer(self, event):
global sec_count
if m_tabTools.B_ROTATE:
if sec_count == 0:
self.switchTab()
if sec_count < sec_switch:
pbar.SetValue(sec_count)
sec_count += 1
else:
pbar.SetValue(sec_count)
sec_count = 0
else:
sec_count = 0
pbar.SetValue(0)
def StartWeerTab(self):
tabWeer = m_tabWeer.TabWeer(dict['nb'])
dict['nb'].AddPage(tabWeer, "Weer")
def StartAgendaTab(self):
tabAgenda = m_tabAgenda.TabAgenda(dict['nb'])
dict['nb'].AddPage(tabAgenda, "Agenda")
def StartFortuneTab(self):
tabFortune = m_tabFortune.TabFortune(dict['nb'])
dict['nb'].AddPage(tabFortune, "Fortune")
def InitPanel(self):
global pbar
pbar = wx.Gauge(self, -1, range=sec_switch, style=wx.GA_VERTICAL,
size=(5, 480))
# Tabbladen toevoegen aan Notebook
dict['nb'] = wx.Notebook(self)
p1 = Process(target=self.StartWeerTab())
p1.start()
p2 = Process(target=self.StartAgendaTab())
p2.start()
p3 = Process(target=self.StartFortuneTab())
p3.start()
# tabWeer = m_tabWeer.TabWeer(dict['nb'])
# tabAgenda = m_tabAgenda.TabAgenda(dict['nb'])
# tabFortune = m_tabFortune.TabFortune(dict['nb'])
tabBitcoin = m_tabBitcoin.TabBitcoin(dict['nb'])
tabGas = m_tabGas.TabGas(dict['nb'])
tabEle = m_tabEle.TabEle(dict['nb'])
tabWat = m_tabWat.TabWat(dict['nb'])
tabEnergie = m_tabEnergie.TabEnergie(dict['nb'])
tabMuziek = m_tabMuziek.TabMuziek(dict['nb'])
tabTools = m_tabTools.TabTools(dict['nb'])
p1.join()
p2.join()
p3.join()
# dict['nb'].AddPage(tabWeer, "Weer")
# dict['nb'].AddPage(tabAgenda, "Agenda")
# dict['nb'].AddPage(tabFortune, "Fortune")
dict['nb'].AddPage(tabBitcoin, "Bitcoin")
dict['nb'].AddPage(tabGas, "Gas")
dict['nb'].AddPage(tabEle, "Elektriciteit")
dict['nb'].AddPage(tabWat, "Water")
dict['nb'].AddPage(tabEnergie, "Energie")
dict['nb'].AddPage(tabMuziek, "Muziek")
dict['nb'].AddPage(tabTools, "Tools")
# Laatste 'wissel'tab instellen, zodat app bij openen netjes
# de eerste tab selecteert ;-)
dict['nb'].ChangeSelection(3)
# Sizers initialiseren
mainSizer = wx.BoxSizer(wx.VERTICAL)
centerSizer = wx.BoxSizer(wx.HORIZONTAL)
centerSizer.Add(pbar, 0, wx.ALL, 0)
centerSizer.Add(dict['nb'], 1, wx.EXPAND)
mainSizer.Add(centerSizer, 1, wx.EXPAND | wx.ALL, 5)
self.SetSizerAndFit(mainSizer)
self.Layout()
# Wisselen van tabblad
def switchTab(self):
selected_page = dict['nb'].GetSelection()
new_page = 0
# Automatisch roteren bij selectie van eerste drie tabbladen
if selected_page < 4:
if selected_page < 3:
new_page = selected_page + 1
dict['nb'].ChangeSelection(new_page)
# Hoofdcode van app starten
if __name__ == "__main__":
app = hubrpiApp()
app.MainLoop()