2

I'm working on my python script as I would like to check on the value in the settings.xml that if they have the value is true or false. I want to check the value in xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<settings>
<category label="30101">
   <setting id="myidname.enabled" value="false"/>
</category>
</settings>

I have tried this:

import xbmc 
import xbmcgui
import xbmcplugin
ACTION_BACKSPACE = 110
def onAction(self, action):
if action == ACTION_BACKSPACE:
   if self.Settings == xbmc.getSetting("myidname.enabled") == True:
      self.settings.setSetting("id=myidname.enabled", "value=false")

It will not let me to check the value in settings.xml that if I have the value is true. How do you write the code for python using if statement that I want to check in the settings with the id if it have the value is set to true?

Secondly, I'm using this code to allow me to overwritten the value in the settings.xml:

self.settings.setSetting(id="myidname.enabled", value="true")

It will not let me to overwritten the value. How do you write the code for python to allow me to overwritten the value in settings.xml in the same line as the id?

The file location for settings.xml is in: c:\users\user\appdata\roaming\xbmc\addons\script.tvguide\resources.

Here's the update xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<settings>
    <category label="30101">
    <setting id="myid.enabled" value="false"/>
        <setting id="myid1.enabled" value="false"/>
        <setting id="myid2.enabled" value="false"/>
        <setting id="myid3.enabled" value="false"/>
        <setting id="myid4.enabled" value="false"/>
        <setting id="myid5.enabled" value="false"/>
        <setting id="myid6.enabled" value="false"/>
        <setting id="myid7.enabled" value="false"/>
    </category>
</settings>

1 Answers1

2

There are some strange things in your code.

First, it looks like that you use xbmc.getSetting() - these function does not exist in the xbmc module. To get (and set) settings for your add-on you need to use the methods getSetting() and setSetting() to an instance of xbmcaddon.Addon().

So to get the (bool) value for "myidname.enabled" (Is this really the defined settings ID? Please show me your settings.xml) you need to use:

import xbmcaddon
addon = xbmcaddon.Addon()
myidnmame_enabled = addon.getSetting('myidname.enabled') == 'true'

Note that getSetting() returns always strings! To get the boolean value for an bool defined settings I suggest comparing to 'true'.

To set a setting just use setSetting():

import xbmcaddon
addon = xbmcaddon.Addon()
addon.setSetting('setting_id', 'true')

For examples just have a look to other add-ons.

EDIT:

There are two settings.xml which are relevant:

  1. The settings.xml where the settings are defined. This is the file you (as the add-on author) need to define. It should be located at xbmc\addons\script.tvguide\resources\settings.xml.

  2. The (autogenerated) user related settings.xml where XBMC stores the chosen values. This is located at xbmc\userdata\addon_data\script.tvguide\resources\settings.xml. You should NOT modify it.

It seems that you mixed these files. The first one should not have a "value" property! Modify this file to e.g.:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<settings>
    <category label="30101">
    <setting id="myid.enabled" value="false"/>
        <setting id="myid1.enabled" type="bool" label="MY ID1" default="false"/>
        <setting id="myid2.enabled" type="bool" label="MY ID2" default="false"/>
        <setting id="myid3.enabled" type="bool" label="MY ID3" default="false"/>
        <setting id="myid4.enabled" type="bool" label="MY ID4" default="false"/>
        <setting id="myid5.enabled" type="bool" label="MY ID5" default="false"/>
        <setting id="myid6.enabled" type="bool" label="MY ID6" default="false"/>
        <setting id="myid7.enabled" type="bool" label="MY ID7" default="false"/>
    </category>
</settings>
sphere
  • 1,330
  • 13
  • 24
  • Yes, it is the defined settings ID. Please see the update XML code I have updated on my first post. I tried to use your code, but it will not let me to update the value to replace it from false to true. It sound like my settings is incorrect? –  Jan 19 '14 at 17:00
  • @user3208332: I updated my answer to match your updated question. Please consider accepting my answer when it was helpful. – sphere Jan 20 '14 at 10:29
  • I have tried to use your sample xml source and the python code, but it did not work. It will not save the settings in the xml value. Here is the logs where I have included the download link at the bottom of the line, so you could check it out to find out why it won't save. When you find the problem, could you please update your post with the correct source for python and xml that if you can get yours working. http://xbmclogs.com/show.php?id=113367 –  Jan 20 '14 at 17:42
  • @user3208332: Everything you need is already in my answer. From the log it seems that you missed instancing the "addon" with `addon = xbmcaddon.Addon()` – sphere Jan 21 '14 at 06:48