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:
Markus Hitter 2016-04-11 21:19:00 +02:00
parent a0fa1bbeb6
commit 13c76244b6
2 changed files with 27 additions and 9 deletions

View File

@ -1,4 +1,6 @@
# coding=utf-8
import wx import wx
from configtool.page import Page from configtool.page import Page
@ -10,13 +12,19 @@ class DisplayPage(wx.Panel, Page):
self.id = idPg self.id = idPg
self.labels = {'DISPLAY_BUS': "Display Bus:", 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 = wx.GridBagSizer()
sz.AddSpacer((20, 40), pos = (0, 0)) sz.AddSpacer((20, 40), pos = (0, 0))
ch = self.addBoolChoice('DISPLAY_BUS', True, 100, self.onBusChoice, ch = self.addBoolChoice('DISPLAY_BUS', True, 100, self.onBusChoice,
size = (140, -1)) size = (160, -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))
@ -28,9 +36,10 @@ class DisplayPage(wx.Panel, Page):
self.enableAll(False) self.enableAll(False)
def onBusChoice(self, evt): def onBusChoice(self, evt):
if self.boolChoices['DISPLAY_BUS'].GetStringSelection().startswith('('): choice = self.boolChoices['DISPLAY_BUS']
self.boolChoices['DISPLAY_TYPE'].Enable(False) if choice.GetClientData(choice.GetSelection()):
else:
self.boolChoices['DISPLAY_TYPE'].Enable(True) self.boolChoices['DISPLAY_TYPE'].Enable(True)
else:
self.boolChoices['DISPLAY_TYPE'].Enable(False)
Page.onChoice(self, evt) Page.onChoice(self, evt)

View File

@ -271,9 +271,18 @@ class Page:
# Add items found in this configuration. # Add items found in this configuration.
for cfg in cfgValues.keys(): for cfg in cfgValues.keys():
if cfg.startswith(k): if cfg.startswith(k):
choice.Append(cfg) 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]: if cfgValues[cfg]:
choice.SetSelection(choice.GetCount() - 1) choice.SetSelection(n)
self.assertModified(False) self.assertModified(False)
@ -305,8 +314,8 @@ class Page:
for k in self.boolChoices.keys(): for k in self.boolChoices.keys():
choice = self.boolChoices[k] choice = self.boolChoices[k]
for i in range(choice.GetCount()): for i in range(choice.GetCount()):
s = choice.GetString(i) s = choice.GetClientData(i)
if not s.startswith('('): if s:
result[s] = (i == choice.GetSelection()) result[s] = (i == choice.GetSelection())
return result return result