Settingsmgr.py
#1
i have uploaded my first version of settingsmgr.py to http://www.xbmcscripts.com . you can use it if you want to add a control panel so that users can customize your script settings.

it works like this:
Quote:fname=scriptpath+'settings.xml'
settings=settingsmgr.readsettings(fname)
timeout=settings['timeout'] #the dictionary key is the id of the param tag.
print('timeout:'+str(timeout))
settingsmgr.opencontrolpanel(fname) #here a window is opened and the user can change settings.

settings.xml looks like this:
Quote:<?xml version="1.0" ?>
<settings name="ooba settings...">
      <settings name="connection">
              <param id="hostadress" name="host address" type="string">
                      <value><![cdata[monkey.com]]></value>
              </param>
              <param id="secure" name="secure" type="boolean">
                      <value>false</value>
              </param>
              <param id="timeout" name="timeout" type="float">
                      <value>7.0</value>
                      <desc>socket timeout (seconds)</desc>
              </param>
              <param id="mode" name="mode" type="select">
                      <option>server</option>
                      <option>client</option>
                      <option>server+client</option>
                      <value>1</value>
              </param>
      </settings>
      <param id="phase" name="phaseangle" type="select">
              <option>0 degrees</option>
              <option>90 degrees</option>
              <option>180 degrees</option>
              <option>-90 degrees</option>
              <value>3</value>
      </param>      
</settings>

note, i'm aware of the "name: xxx" bug in v0.1. it is purely visual and will be fixed in the nest version.

please let me know if you find it useful.
Reply
#2
is there a way to have a *list* type, probably a list of any of the existing data types? if you could manage a list of favorites from this that might be good.

i would actually need a list of lists but that might be too complicated.
Reply
#3
that is a good idea. but as you say list of lists makes it quite alot more difficult. i have to think about how to do that, because i'm sure it will be critical to the design.

it could be done in a simple way by adding an additional listdepth attribute on the param tag... if it is zero(default) then it means a normal param, if it is 1 then it is a list, if it is 2 then it is a list of lists.

you might also want to have a list of address/port combinations. that is a a string together with an int. optimally then you could write like this:

port=settings['favlist'][7]['port']

that wouldn't be possible with the above solution. however, it could be made with a new <param type="list"> containing a <template> tag saying how the a new element should look.

yes i need to think a little more.
Reply
#4
well even if you don't support lists writers always have the option of using a comma seperated string instead (provided none of the values has a comma already)
here's a super easy way to do this and back if anyone didnt know.

Quote:list = ['this','is','a','list','of','things']
strlist = ','.join(list) #creates a string of the values in list sep by ','
list2 = strlist.split(',') #creates a list of values in the string deliminated by ','

assert (list == list2)

this and the cachedhttp download manager should probably be in a standard place... like a 'tool' or 'util' folder or something in q:\scripts..
Reply
#5
hi phunk,

i tested your settings manager and it works well, except for it always gives back "true" for a boolean and also doesn´t save the changes to a boolean.
do you think you can fix this? :bowdown:
Reply
#6
i fixed it and uploaded it to xbmcscripts (it is v0.4)
Reply
#7
hi phunk,

i have version 0.4. did you ever add a list.

i modified it to include type list. you had all the code there basically.

types are:
'list-int'
'list-float'
'list' with anything else defaults to string. (ie 'list', 'listint')

i didn't do a boolean and i'm not sure if you want to force a type so unknown could be returned or not.

also i didn't modify the input areas as i wasn't sure if you already had added this or if you didn't want it in.

Quote:def getparamvalue(pnode):
type=getnodevalue(pnode,"type")
if type=='string': return str(getnodevalue(pnode,'value'))
if type=='float': return float(getnodevalue(pnode,'value'))
if type=='int': return int(getnodevalue(pnode,'value'))
if type=='boolean':
val=getnodevalue(pnode,'value').lower();
return (not((val=='false') or (val=='0')))
if type=='select': return int(getnodevalue(pnode,'value'))
if type[0:4]=='list':
options=getselectoptions(pnode, type[5:])
return options

return "unknown type:"+str(getnodevalue(pnode,'value'))

Quote:def getselectoptions(pnode, type = 'string'):
options=[]
for child in pnode.childnodes:
if child.nodename=='option':
if type=='int':
options.append(int(getnodetext(child)))
elif type=='float':
options.append(float(getnodetext(child)))
else:
options.append(str(getnodetext(child)))

return options
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#8
Sad 
what do you guys think about a central "control panel" that was one central place to edit/store settings for all scripts?

i'd love to see a more streamlined way to setup scripts vs the current, change each one separately method.

we need a central repository (folder) that all the config files for each script goes into. this way the scripts can reference thier specific config and we can also have another script (or maybe even convince the devs to build it into the source) to be able to edit the configs in a centralized and managed way.

thoughts?
I'm not an expert but I play one at work.
Reply
#9
i'd be tickled if the xbe had an internal editor, the notepad script is a bit buggy.
Image
Reply
#10
harsh,
i'm not talking about an editor like notepad, that just maintains the problem we have today and moves it from the pc to the xbox, useless when talking about making things more efficient.

i'm talking about creating a format for config files (this is what xml is good for) that a "smart editor" would read and create fields for on the screen that can be setup... or maybe even a "smart wizard" could walk the user through the setup.
I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
Settingsmgr.py0