How do I use DefaultPrefs.json?
Could someone post an example format of the file.
Am I right in thinking that this will do the hard work of managing user inputted preferences?
Thanks in advance
EDIT:
I’m still struggling with preferences…
It looks like the __container method of Prefs should automatically build the menus?
here’s the code i have:
[codebox]from PMS import *
from PMS.Objects import *
from PMS.Shortcuts import *
Plugin.__logFilePath = “nzb.log”
def Start():
# Add the MainMenu prefix handler
Plugin.AddPrefixHandler("/video/nzblockbuster/", MainMenu, L(“nzblockbuster”))
# Set up view groups
Plugin.AddViewGroup(“List”, viewMode=“List”, mediaType=“items”)
Plugin.AddViewGroup(“Info”, viewMode=“InfoList”, mediaType=“items”)
# Set the default MediaContainer attributes
MediaContainer.title1 = L(“nzblockbuster”)
MediaContainer.viewGroup = “List”
MediaContainer.art = R(“art-default.png”)
def MainMenu():
dir = MediaContainer()
dir.Append(Function(DirectoryItem(Movies, title=L(“movies”))))
dir.Append(Function(DirectoryItem(Sabnzbd, title=L(“sabnzbd”))))
dir.Append(Function(DirectoryItem(Preferences, title=L(“preferences”))))
return dir
def Movies(sender):
dir = MediaContainer(title2=L(“movies”), viewGroup=“Info”)
return dir
def Sabnzbd(sender):
dir = MediaContainer(title2=L(“sabnzbd”), viewGroup=“Info”)
return dir
def Preferences(sender):
return Prefs.__container()[/codebox]
and my DefaultPrefs.json:
[codebox][
{id:“1”, type:“string”, default:“1”, label:“1”, value:“1”},
{id:“2”, type:“string”, default:“2”, label:“2”, values:“2|3”}
][/codebox]
I’m stumped! Have i missed the point completely or should this work? Help! 
Cheers
sorry if it’s rude to bump like this but i edited my original post with more pleas for help, see above 
Hey! Sorry for the delayed response, your original post must’ve slipped under the radar 
The good news is that you’re almost there. The format of the file is correct (it’s an array of dictionaries). For the second preference, if you want to give the user a list of options to choose from, the type should be “enum” not “string”.
The main thing you’re missing is how to display the preference dialog - any functions within the framework starting with “__” aren’t meant to be called by the developer, they’re just for use internally.
To add an item that displays the preferences dialog, just append a PrefsItem to the MediaContainer. The constructor accepts the standard DirectoryItem attributes, excluding the key, e.g. dir.Append(PrefsItem(title=L(“preferences”))).
Hopefully that should work
Let us know if you have any other questions, we’ll try & respond faster next time!
Excellent, the pane is showing up a treat. 
Not sure about my DefaultPrefs.json yet tho, only the enums are showing up, with some strange values.
I’ll have a play around and might quiz you again
Cheers
EDIT:
OK now my enums work great with the following json, but my strings don’t show up at all:
[codebox]
[
{id:“pref1”, type:“string”, default:“one”, label:“Pref One”, value:“one”},
{id:“pref2”, type:“string”, default:“two”, label:“Pref Two”, value:“two”},
{id:“pref3”, type:“enum”, default:“three”, label:“Pref Three”, values:“three|four”},
{id:“pref4”, type:“enum”, default:“four”, label:“Pref Four”, values:“three|four”}
]
[/codebox]
And I get a full plex crash when trying to save the prefs - are there any other files i need or could this be related to the dodgy strings?
Thanks again
Try changing “string” to “text”. Also, don’t set the “value” property in the defaults file, just the “default” one.
I can’t think what could be causing the crash - could you post the Plex.log file if it happens again? Thanks 
Changing from string to text worked great, and no more crashes on save :D
I discovered the bool type too which is handy - is there a password type, i.e. text that shows up as asterisks etc? Not essential but would be a nice touch
Thanks for your help
No problem! Happy to help
Things will be easier once all the documentation is complete. For passwords, use the text type, then add an extra property called “options” to the preference & set the value to “hidden”.
Awesome stuff option:"hidden" works great.
I have yet another question about URL encoding, one of my prefs is a URL and plex seems to be url encoding it before it saves it, but does not urldecode when it displays it, so every time you view the pref it gets double urlencoded then double double urlencoded and so on... Is there an easy fix for this? another option or another datatype maybe?
Cheers
No, that would be a framework bug
I’ll look in to it & try to get a fix pushed later tonight. I’ll let you know when I’ve made some progress.
Ta :)
Any news?
Cheers
Sorry for not getting back to you sooner. Check your App Store update history - you might already have the fix. If not, you can manually update 
All looks good now, lovely job :)
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.