Configtool: allow and use user friendly names for choices.
So far for choices based on boolean sets, only, because choices
for values typically need no more readable names.
This elegantly removes the somewhat ugly check for '(', too.
This commit is contained in:
parent
a0fa1bbeb6
commit
13c76244b6
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
# coding=utf-8
|
||||
|
||||
import wx
|
||||
from configtool.page import Page
|
||||
|
||||
|
|
@ -10,13 +12,19 @@ class DisplayPage(wx.Panel, Page):
|
|||
self.id = idPg
|
||||
|
||||
self.labels = {'DISPLAY_BUS': "Display Bus:",
|
||||
'DISPLAY_TYPE': "Display Type:"}
|
||||
'DISPLAY_TYPE': "Display Type:",
|
||||
'DISPLAY_BUS_4BIT': "Direct with 4 pins",
|
||||
'DISPLAY_BUS_8BIT': "Direct with 8 pins",
|
||||
'DISPLAY_BUS_I2C': "I²C ( = TWI)",
|
||||
'DISPLAY_BUS_SPI': "SPI",
|
||||
'DISPLAY_TYPE_SSD1306': "SSD1306 O-LED, 128x32",
|
||||
'DISPLAY_TYPE_LCD1302': "LCD 1302"}
|
||||
|
||||
sz = wx.GridBagSizer()
|
||||
sz.AddSpacer((20, 40), pos = (0, 0))
|
||||
|
||||
ch = self.addBoolChoice('DISPLAY_BUS', True, 100, self.onBusChoice,
|
||||
size = (140, -1))
|
||||
size = (160, -1))
|
||||
sz.Add(ch, pos = (1, 1))
|
||||
sz.AddSpacer((100, 10), pos = (1, 2))
|
||||
|
||||
|
|
@ -28,9 +36,10 @@ class DisplayPage(wx.Panel, Page):
|
|||
self.enableAll(False)
|
||||
|
||||
def onBusChoice(self, evt):
|
||||
if self.boolChoices['DISPLAY_BUS'].GetStringSelection().startswith('('):
|
||||
self.boolChoices['DISPLAY_TYPE'].Enable(False)
|
||||
else:
|
||||
choice = self.boolChoices['DISPLAY_BUS']
|
||||
if choice.GetClientData(choice.GetSelection()):
|
||||
self.boolChoices['DISPLAY_TYPE'].Enable(True)
|
||||
else:
|
||||
self.boolChoices['DISPLAY_TYPE'].Enable(False)
|
||||
|
||||
Page.onChoice(self, evt)
|
||||
|
|
|
|||
|
|
@ -271,9 +271,18 @@ class Page:
|
|||
# Add items found in this configuration.
|
||||
for cfg in cfgValues.keys():
|
||||
if cfg.startswith(k):
|
||||
if cfg in self.labels.keys():
|
||||
choice.Append(self.labels[cfg])
|
||||
else:
|
||||
choice.Append(cfg)
|
||||
|
||||
# As we want to write the configuration name later, not the user
|
||||
# friendly string, we store the configuration name as client data.
|
||||
n = choice.GetCount() - 1
|
||||
choice.SetClientData(n, cfg)
|
||||
|
||||
if cfgValues[cfg]:
|
||||
choice.SetSelection(choice.GetCount() - 1)
|
||||
choice.SetSelection(n)
|
||||
|
||||
self.assertModified(False)
|
||||
|
||||
|
|
@ -305,8 +314,8 @@ class Page:
|
|||
for k in self.boolChoices.keys():
|
||||
choice = self.boolChoices[k]
|
||||
for i in range(choice.GetCount()):
|
||||
s = choice.GetString(i)
|
||||
if not s.startswith('('):
|
||||
s = choice.GetClientData(i)
|
||||
if s:
|
||||
result[s] = (i == choice.GetSelection())
|
||||
|
||||
return result
|
||||
|
|
|
|||
Loading…
Reference in New Issue