-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
83 lines (61 loc) · 3.2 KB
/
config.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
import wx
class ConfigFrame(wx.Frame):
positions = ("Flat", "Inverted", "Straight Up", "Straight Down", "Knife Edge")
rotations = ("Aileron", "Elevator", "Yaw")
def __init__(self, config, version):
super(ConfigFrame, self).__init__(parent=None, title="Configurartion")
self.config = config
self.version = version
self.InitUI()
def InitUI(self):
self.posButtons = [wx.ToggleButton(self, wx.ID_ANY, pos) for pos in self.positions]
self.rotButtons = [wx.ToggleButton(self, wx.ID_ANY, rot) for rot in self.rotations]
self.button_start = wx.Button(self, wx.ID_ANY, "START Training")
self.Bind(wx.EVT_BUTTON, self.onStart, self.button_start)
self.SetTitle("Configuration")
self.SetBackgroundColour(wx.Colour(250, 250, 250))
# self.button_start.SetBackgroundColour(wx.Colour(0, 170, 0))
self.button_start.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
sizer_main = wx.BoxSizer(wx.VERTICAL)
sizer_buttons = wx.BoxSizer(wx.HORIZONTAL)
sizer_buttonrow2 = wx.BoxSizer(wx.VERTICAL)
sizer_buttonRow1 = wx.BoxSizer(wx.VERTICAL)
label_config = wx.StaticText(self, wx.ID_ANY, "RC Control Trainer v"+self.version+"\n\nConfiguration", style=wx.ALIGN_CENTER | wx.TE_MULTILINE)
label_config.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
sizer_main.Add(label_config, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 7)
for posButton in self.posButtons:
sizer_buttonRow1.Add(posButton, 0, wx.EXPAND, 0)
sizer_buttons.Add(sizer_buttonRow1, 1, wx.EXPAND, 0)
for rotButton in self.rotButtons:
sizer_buttonrow2.Add(rotButton, 0, wx.EXPAND, 0)
sizer_buttons.Add(sizer_buttonrow2, 1, wx.EXPAND, 0)
sizer_main.Add(sizer_buttons, 1, wx.ALL | wx.EXPAND, 5)
sizer_main.Add(self.button_start, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.EXPAND, 5)
self.SetSizer(sizer_main)
sizer_main.Fit(self)
self.Layout()
self.Centre()
self.Show(True)
def onStart(self, event):
gotAPos = False
gotARot = False
for idx, position in zip(range(len(self.positions)), self.positions):
value = self.posButtons[idx].GetValue()
gotAPos |= value
self.config.__setattr__(position.replace(" ",""), value)
for idx, rotation in zip(range(len(self.rotations)), self.rotations):
value = self.rotButtons[idx].GetValue()
gotARot |= value
self.config.__setattr__(rotation.replace(" ",""), value)
if not gotAPos or not gotARot:
wx.MessageBox("You need to select at least one options from the first column and one option from the second column", "Configuration Issue", wx.OK | wx.ICON_HAND)
event.Skip()
else:
self.Close()
class Config(object):
def __init__(self, version):
self.version = version
def showDialog(self):
ex = wx.App()
ConfigFrame(self, self.version)
ex.MainLoop()