Help with xbmcgui.Dialog().multiselect
#1
Hello to all!!

Need some help with multiselect dialog:

I have this piece of code:

Code:
genre_list = [x.split('.')[0] for x in genre_list_ext]
sDialog = xbmcgui.Dialog().multiselect('Select Genre', genre_list)
new_value_str = sDialog

This code gives me this dialog:

Image

This list comes from a folder with json files, which are created when the database is created. So this list will change as new genres are created:

Image

But when I select for example "Action" and "Kids", "new_value_str" returns "0, 2".
I know "0" is the first item and "2" is the third item in the list.

But I would like instead of returning "0, 2", return to "Action, Kids" It's possible?
Reply
#2
You've already got the genre_list, you just need to build a new list using that and the list of indices from the dialog:-

Code:
genre_list = [x.split('.')[0] for x in genre_list_ext]
sDialog = xbmcgui.Dialog().multiselect('Select Genre', genre_list)

out_list = [genre_list[x] for x in sDialog]

You'll probably also want to check for None before hand in case nothing was selected in the list. My Python skills are rusty but I think that should work.
Reply
#3
(2022-10-01, 20:53)roidy Wrote: You've already got the genre_list, you just need to build a new list using that and the list of indices from the dialog:-

Code:
genre_list = [x.split('.')[0] for x in genre_list_ext]
sDialog = xbmcgui.Dialog().multiselect('Select Genre', genre_list)

out_list = [genre_list[x] for x in sDialog]

You'll probably also want to check for None before hand in case nothing was selected in the list. My Python skills are rusty but I think that should work.

I knew it that I was missing one last step!
Works like a charm!!!! But the return is ["Action", "Kids"]. How do I change this to only Action, Kids (no square brackets and no quotes in each item)
Reply
#4
(2022-10-01, 22:17)sagrath Wrote: I knew it that I was missing one last step!
Works like a charm!!!! But the return is ["Action", "Kids"]. How do I change this to only Action, Kids (no square brackets and no quotes in each item)

A Python list to string conversion is needed: 

out_string = ','.join([genre_list[x] for x in sDialog])

or

out_list = [genre_list[x] for x in sDialog]
out_string = ','.join(out_list)

The second example is in case you need both out_list and out_string.  Note .joins won't work if genre_list[x] contains integers.  In which case you need to convert them to strings for .join to work.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#5
(2022-10-01, 23:35)jbinkley60 Wrote: out_string = ','.join([genre_list[x] for x in sDialog])

This is more than enough!! THANK YOU SO MUCH!!!
Reply
#6
(2022-10-01, 23:49)sagrath Wrote:
(2022-10-01, 23:35)jbinkley60 Wrote: out_string = ','.join([genre_list[x] for x in sDialog])

This is more than enough!! THANK YOU SO MUCH!!!

No problem. Happy to help. As was pointed out previiusly you should check for None in case the user cancels out. Othwise your code will likely break or give undesirable results.

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#7
(2022-10-01, 23:55)jbinkley60 Wrote: No problem. Happy to help. As was pointed out previiusly you should check for None in case the user cancels out. Othwise your code will likely break or give undesirable results.

OH yeah, already did:

genre_list = [x.split('.')[0] for x in genre_list_ext]
sDialog = xbmcgui.Dialog().multiselect('Select Genre', genre_list)
if sDialog is None: 
        kodi_notify('{} not changed'.format(prop_name))
        return False
out_string = ','.join([genre_list[x] for x in sDialog])

this works like a charm
Reply

Logout Mark Read Team Forum Stats Members Help
Help with xbmcgui.Dialog().multiselect0