Configtool: introduce boolChoices.
This handles sets of booleans "magically" and is now used for DISPLAY_BUS and DISPLAY_TYPE.
This commit is contained in:
parent
a95a1c8855
commit
2541d7a82c
|
|
@ -9,55 +9,20 @@ class DisplayPage(wx.Panel, Page):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.id = idPg
|
self.id = idPg
|
||||||
|
|
||||||
self.displayBusKeys = ['DISPLAY_BUS_4BIT', 'DISPLAY_BUS_8BIT',
|
|
||||||
'DISPLAY_BUS_I2C', 'DISPLAY_BUS_SPI']
|
|
||||||
|
|
||||||
self.displayTypeKeys = ['DISPLAY_TYPE_SSD1306', 'DISPLAY_TYPE_LCD1302']
|
|
||||||
|
|
||||||
self.labels = {'DISPLAY_BUS': "Display Bus:",
|
self.labels = {'DISPLAY_BUS': "Display Bus:",
|
||||||
'DISPLAY_TYPE': "Display Type:"}
|
'DISPLAY_TYPE': "Display Type:"}
|
||||||
|
|
||||||
sz = wx.GridBagSizer()
|
sz = wx.GridBagSizer()
|
||||||
sz.AddSpacer((20, 40), pos = (0, 0))
|
sz.AddSpacer((20, 40), pos = (0, 0))
|
||||||
|
|
||||||
k = 'DISPLAY_BUS'
|
ch = self.addBoolChoice('DISPLAY_BUS', True, 100, self.onChoice,
|
||||||
ch = self.addChoice(k, ['(disabled)'] + self.displayBusKeys, 0, 100,
|
size = (140, -1))
|
||||||
self.onChoice, size = (140, -1))
|
|
||||||
sz.Add(ch, pos = (1, 1))
|
sz.Add(ch, pos = (1, 1))
|
||||||
sz.AddSpacer((100, 10), pos = (1, 2))
|
sz.AddSpacer((100, 10), pos = (1, 2))
|
||||||
|
|
||||||
k = 'DISPLAY_TYPE'
|
ch = self.addBoolChoice('DISPLAY_TYPE', False, 100, self.onChoice,
|
||||||
ch = self.addChoice(k, self.displayTypeKeys, 0, 100, self.onChoice,
|
size = (200, -1))
|
||||||
size = (200, -1))
|
|
||||||
sz.Add(ch, pos = (1, 3))
|
sz.Add(ch, pos = (1, 3))
|
||||||
|
|
||||||
self.SetSizer(sz)
|
self.SetSizer(sz)
|
||||||
self.enableAll(False)
|
self.enableAll(False)
|
||||||
|
|
||||||
def insertValues(self, cfgValues):
|
|
||||||
Page.insertValues(self, cfgValues)
|
|
||||||
|
|
||||||
k = 'DISPLAY_BUS'
|
|
||||||
for tag in self.displayBusKeys:
|
|
||||||
if tag in cfgValues.keys() and cfgValues[tag]:
|
|
||||||
self.setChoice(k, cfgValues, tag)
|
|
||||||
break
|
|
||||||
|
|
||||||
k = 'DISPLAY_TYPE'
|
|
||||||
for tag in self.displayTypeKeys:
|
|
||||||
if tag in cfgValues.keys() and cfgValues[tag]:
|
|
||||||
self.setChoice(k, cfgValues, tag)
|
|
||||||
break
|
|
||||||
|
|
||||||
def getValues(self):
|
|
||||||
result = Page.getValues(self)
|
|
||||||
|
|
||||||
# Convert values to a set of booleans.
|
|
||||||
for k in self.choices:
|
|
||||||
del result[k]
|
|
||||||
|
|
||||||
choice = self.choices[k]
|
|
||||||
for i in range(choice.GetCount()):
|
|
||||||
result[choice.GetString(i)] = (i == choice.GetSelection())
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class Page:
|
||||||
self.radioButtonBoxes = {}
|
self.radioButtonBoxes = {}
|
||||||
self.choices = {}
|
self.choices = {}
|
||||||
self.choicesOriginal = {}
|
self.choicesOriginal = {}
|
||||||
|
self.boolChoices = {}
|
||||||
self.deco = Decoration()
|
self.deco = Decoration()
|
||||||
self.font = font
|
self.font = font
|
||||||
|
|
||||||
|
|
@ -116,6 +117,30 @@ class Page:
|
||||||
|
|
||||||
return lsz
|
return lsz
|
||||||
|
|
||||||
|
# addChoice handles #defines with value, this handles choices for
|
||||||
|
# sets of boolean #defines.
|
||||||
|
def addBoolChoice(self, name, allowBlank, labelWidth, validator,
|
||||||
|
size = (-1, -1)):
|
||||||
|
lsz = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
st = wx.StaticText(self, wx.ID_ANY, self.labels[name],
|
||||||
|
size = (labelWidth, -1), style = wx.ALIGN_RIGHT)
|
||||||
|
st.SetFont(self.font)
|
||||||
|
lsz.Add(st, 1, wx.TOP, offsetChLabel)
|
||||||
|
|
||||||
|
ch = wx.Choice(self, wx.ID_ANY, size = size, name = name)
|
||||||
|
ch.SetBackgroundColour(self.deco.getBackgroundColour())
|
||||||
|
ch.SetFont(self.font)
|
||||||
|
ch.Bind(wx.EVT_CHOICE, validator)
|
||||||
|
|
||||||
|
if allowBlank:
|
||||||
|
ch.Append("(none)")
|
||||||
|
ch.SetSelection(0)
|
||||||
|
|
||||||
|
lsz.Add(ch)
|
||||||
|
self.boolChoices[name] = ch
|
||||||
|
|
||||||
|
return lsz
|
||||||
|
|
||||||
def setChoice(self, name, cfgValues, default):
|
def setChoice(self, name, cfgValues, default):
|
||||||
if name in cfgValues.keys() and cfgValues[name][1] == True:
|
if name in cfgValues.keys() and cfgValues[name][1] == True:
|
||||||
bv = cfgValues[name][0]
|
bv = cfgValues[name][0]
|
||||||
|
|
@ -235,6 +260,21 @@ class Page:
|
||||||
else:
|
else:
|
||||||
print "Key " + k + " not found in config data."
|
print "Key " + k + " not found in config data."
|
||||||
|
|
||||||
|
for k in self.boolChoices.keys():
|
||||||
|
choice = self.boolChoices[k]
|
||||||
|
|
||||||
|
# Remove items left behind from the previous configuration.
|
||||||
|
while (choice.GetCount() and
|
||||||
|
not choice.GetString(choice.GetCount() - 1).startswith('(')):
|
||||||
|
choice.Delete(choice.GetCount() - 1)
|
||||||
|
|
||||||
|
# Add items found in this configuration.
|
||||||
|
for cfg in cfgValues.keys():
|
||||||
|
if cfg.startswith(k):
|
||||||
|
choice.Append(cfg)
|
||||||
|
if cfgValues[cfg]:
|
||||||
|
choice.SetSelection(choice.GetCount() - 1)
|
||||||
|
|
||||||
self.assertModified(False)
|
self.assertModified(False)
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
|
|
@ -262,6 +302,13 @@ class Page:
|
||||||
v = self.choices[k].GetSelection()
|
v = self.choices[k].GetSelection()
|
||||||
result[k] = self.choices[k].GetString(v), True
|
result[k] = self.choices[k].GetString(v), True
|
||||||
|
|
||||||
|
for k in self.boolChoices.keys():
|
||||||
|
choice = self.boolChoices[k]
|
||||||
|
for i in range(choice.GetCount()):
|
||||||
|
s = choice.GetString(i)
|
||||||
|
if not s.startswith('('):
|
||||||
|
result[s] = (i == choice.GetSelection())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def assertModified(self, flag):
|
def assertModified(self, flag):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue