Skip to content

Commit

Permalink
✨ Allow preselect to use a string
Browse files Browse the repository at this point in the history
  • Loading branch information
jurialmunkey committed Oct 8, 2023
1 parent bd7e2a8 commit 1fda075
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions resources/lib/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ def _get_path_or_str(string):
from jurialmunkey.futils import load_filecontent
return str(load_filecontent(string))

def _get_preselected_items(string):
if not string:
return -1
try:
return int(string)
except TypeError:
return -1
except ValueError:
pass
items = _split_items(kwargs.get('list') or '')
if not items:
return -1
if len(items) == 0:
return -1
if string not in items:
return -1
return items.index(string)

dialog = xbmcgui.Dialog()

dialog_standard_routes = {
Expand Down Expand Up @@ -145,14 +163,14 @@ def _get_path_or_str(string):
'params': (
('heading', str, ''),
('list', _split_items, ''),
('autoclose', int, 0), ('preselect', int, 0), ('useDetails', boolean, False), )
('autoclose', int, 0), ('preselect', _get_preselected_items, -1), ('useDetails', boolean, False), )
},
'multiselect': {
'func': dialog.select,
'params': (
('heading', str, ''),
('list', _split_items, ''),
('autoclose', int, 0), ('preselect', int, 0), ('useDetails', boolean, False), )
('autoclose', int, 0), ('preselect', _get_preselected_items, -1), ('useDetails', boolean, False), )
},
}

Expand Down

0 comments on commit 1fda075

Please sign in to comment.