2012-03-26, 18:11
Is it possible to create a dynamic enum in the addon settings that I populate from python code?
def scan(self):
"""scan for available ports. return a list of tuples (num, name)"""
available_ports = ""
sep = ""
available = []
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.portstr))
available_ports = available_ports + sep + s.portstr
sep = "|"
s.close()
except serial.SerialException:
pass
# If no com ports exists, we save a - to avoid errors
if available_ports is "":
available_ports = "-"
# CMainFile is a helper class with some useful functions based on Eldorados/eldorado-xbmc-addons
settings_file = os.path.join(CMainFile.addon.get_path(), 'resources', "settings.xml")
print "SETTING FILE %s" % settings_file
tree = ET.ElementTree(file=settings_file)
#Search for the entry in the settings file
for elems in tree.iterfind(".//setting[@id='{0}']/..".format("arduino_port")):
for elem in elems:
if elem.tag == 'setting':
if elem.attrib['id'] == 'arduino_port':
elem.set('values', available_ports)
tree.write(settings_file)
return available
for elem in root.findall(".//setting[@id='arduino_port']"):
elem.set('values', available_ports)
(2014-08-24, 22:25)drJoju Wrote: where is the fileenum type in the page http://wiki.xbmc.org/index.php?title=Add-on_settings?
(2014-08-23, 20:18)emveepee Wrote: Thanks for the post drJoju that got me to something I've been trying to do for a while. Rather than iterating it might be worth trying this, the logic works for me.
Code:for elem in root.findall(".//setting[@id='arduino_port']"):
elem.set('values', available_ports)
Martin