Domanda

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>
È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top