Req conditional visibility based on 'select' when using lvalues
#1
Hi,

I may be doing this wrong so, correct me if I am.
Using settings.xml I am trying to set the conditional visibility of items based on a previous 'select' control that uses lvalues.

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<settings>
  <category label="lvalues example">
      <setting label="The selector below uses lvalues to provide localized choices" type="lsep" />
      <setting ldefault="32003" id="myid" label="Selector" type="select" lvalues="32003|32004|32005" />
      <setting label="The line below uses visible='eq(-2,Task1)' so you will see it" type="lsep" />
      <setting label="You can see me" type="lsep" visible="eq(-2,Task1)" />
      <setting label="The line below uses visible='eq(-4,32003)' so you won't see it" type="lsep" />
      <setting label="You can't see me" type="lsep" visible="eq(-4,32003)" />

  </category>
</settings>

<!--32003 = 'Task1', 32004 = 'Task2', 32005 = 'Task3'-->

Image

So for me the issue is that although the choices of the 'select' can use localized strings via lvalues, the subsequent lines cannot have conditional visibility without hard-coding the string.
The wiki says to look at the source code for undocumented features, but with my limited amount of c++ knowledge it's like reading a menu only written in Chinese.
I did discover that ldefault works to set the default value of a 'select' using lvalues.

I have tried 'lvisible' which doesn't work. I tried using the index of the lvalue (ie. eq(-4,0)) but this doesn't work as it does if the control is 'lablelenum'.
I thought about just switching to using labelenum, but with 23 choices, that makes for a bad user experience.
FYI I hard coded the other labels for illustration purposes so that I didn't need to give you a whole strings.po file to refer to.

If this is indeed a missing feature, I would love to see a 'labelselect' control added to the API or 'lvisible' and 'lenable' to use conditionals with lvalues.

Before someone replies to just write it myself and submit, believe me I would if I could.

If you wan't to play around with this I put it up on GitHub: https://github.com/KenV99/script.lvalues_example
Reply
#2
known issue: http://trac.kodi.tv/ticket/16474
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Ok. Thx.
Reply
#4
Well I came up with a workaround for this issue.
You can run a script that displays a selection dialog box that shows the localized strings and then sets a hidden text value which the user then compares against.
The main caveat is that you need two separate lines - one for the clickable 'action' and another to display the chosen value.
Full working demo: https://github.com/KenV99/script.lvalues_example

Details:
Code:
import xbmcaddon
import xbmcgui

def selectordialog(args):
    """
    Emulates a selector control that is lvalues compatible for subsequent conditionals in Kodi settings
    args is a list of strings that is kwarg 'like'.
    'id=myid': (Required) where myid is the settings.xml id that will be updated
        The plain id will contain the actual index value and is expected to be a hidden text element.
        This is the value to be tested against in subsequent conitionals.
        The string passed will be appended with '-v' i.e. myid-v. It is expected that this refers to a
        disabled selector element with the same lvalues as passed to the script.
        NOTE: There is an undocumented feature of type="select" controls to set the default based on an lvalue:
        ldefault="lvalue" where lvalue is a po string id.
    'useindex=bool': (Optional)If True, the zero based index of the subsequent lvalues will be stored in the hidden test
        element.
        If False or not provided, will store the actual lvalue in the hidden field.
    'heading=lvalue': (Optional) String id for heading of dialog box.
    'lvalues=int|int|int|...': (Required) The list of lvalues to display as choices.

    Usage example for settings.xml:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <settings>
      <category label="lvalues example">
          <setting label="The selector below calls a script that sets a setting" type="lsep" />
          <setting label="32001" type="action" action="RunScript(script.lvalues_example, lselector, id=choice, heading=32007, lvalues=32006|32003|32004|32005)" />
          <setting ldefault="32006" label="32002" type="select" id="choice-v" enable="false" lvalues="32006|32003|32004|32005" />
          <setting label="" type="text" id="choice" visible="false" default="" />
          <setting label="The line below uses visible='eq(-2,32003)' matching the hidden value" type="lsep" />
          <setting label="You can see me if you choose Task 1" type="lsep" visible="eq(-2,32003)" />
      </category>
    </settings>

    <!--32001 = 'Choose:', 32002 = 'Choice', 32003 = 'Task1', 32004 = 'Task2', 32005 = 'Task3'-->
    <!--32006 = 'None', 32007 = 'Choose wisely'-->

    :param args: List of string args
    :type args: list
    :return: True is selected, False if cancelled
    :rtype: bool
    """

    settingid = None
    useindex = False
    lvalues_str = None
    heading = ''
    for arg in args:
        splitarg = arg.split('=')
        kw = splitarg[0].strip()
        value = splitarg[1].strip()
        if kw == 'id':
            settingid = value
        elif kw == 'useindex':
            useindex = value.lower() == 'true'
        elif kw == 'lvalues':
            lvalues_str = value.split('|')
        elif kw == 'heading':
            heading = value
    if lvalues_str is None or settingid is None:
        raise SyntaxError('Selector Dialog: Missing elements from args')
    lvalues = []
    choices = []
    for lvalue in lvalues_str:
        try:
            lvalues.append(int(lvalue))
        except TypeError:
            raise TypeError('Selector Dialog: lvalue not int')
        else:
            choices.append(xbmcaddon.Addon().getLocalizedString(int(lvalue)))
    if heading != '':
        try:
            lheading = int(heading)
        except TypeError:
            raise TypeError('Selector Dialog: heading lvalue not int')
    else:
        lheading = ''
    result = xbmcgui.Dialog().select(heading=xbmcaddon.Addon().getLocalizedString(lheading), list=choices)
    if result != -1:
        if useindex:
            xbmcaddon.Addon().setSetting(settingid, str(result))
        else:
            xbmcaddon.Addon().setSetting(settingid, str(lvalues[result]))
        xbmcaddon.Addon().setSetting('%s-v' % settingid, str(result))
        return True
    else:
        return False
Reply

Logout Mark Read Team Forum Stats Members Help
conditional visibility based on 'select' when using lvalues0