Desktopx 3 Journal: Day 3
Creating your own preferences dialog
Thursday, February 17, 2005 by Frogboy | Discussion: DesktopX
If you want to make a program that you plan to give to other people to use, you will probably find that they will want some sort of preferences dialog. Something to change the settings of the program to match their particular set up. In today's example, we want users to be able to make an email checker. The email checker is different for each user. They have their server, user name and password. So how do we let users of our widget set these things?
In DesktopX 2, you would do this on your own by creating your own special panels that you designed yourself. This had the benefit of letting the author have a lot more control over presentation but it was very time consuming. Some widget enabling programs do all this in a separate XML file that the program then uses to create a standard preferences dialog. This is, in my view, superior to what was in DesktopX 2.
But with DesktopX 3, it was decided to take the next logical step - do all of this in script (VB Script, JavaScript, whatever). When the user starts the script, the first thing they do is create their preferences dialog (if applicable). You don't have to create a preferences dialog this way but it does make things much much easier.
So let's think about how we want users to enter in their User Name, Password, and Server name. In DesktopX 3 you create a widget like this:
Widget.Preference(PREFERENCENAME).Type = TYPE
So we authors would fill in PREFRENCENAME and TYPE . For the former, you can call it anything like "Password". For the latter, you have to pick one of the control types DesktopX 3 supports which are:
|
So in this case I would pick two text fields for the server name and user name and the password field for the password (password being the same as text but obfuscated).
The screenshot above contains the example code for our mail preference. There's a second piece we need, and that is, what we do when someone actually does something in the preferences:
Sub Widget_OnPreferencesChange RefreshData CheckMail End Sub |
A new call is added by the system: Widget_OnPreferenceChange. In this case, we call a function called RefreshData that we've written and another one called CheckMail that we've written.
Sub RefreshData sLogin = Widget.Preference("User").Value 'object.localstorage("MailLogin") sPass = Widget.Preference("Password").Value 'object.localstorage("MailPass") sServer = Widget.Preference("Server").Value 'object.localstorage("MailServer") sType = Widget.Preference("Type").Value 'object.localstorage("Type") End Sub |
In this function, we save the data from our preferences dialog with the DesktopX storage system so that you don't have to keep entering this data every time you load the widget.
When the widget is made, the preferences tab becomes part of the properties dialog for that widget. So now I can not only control how the widget looks and behaves and set the hot key to activate it, but I can now configure it right from the same place.
Reply #2 Thursday, February 17, 2005 5:29 PM
Reply #3 Thursday, February 24, 2005 7:29 PM
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!
Reply #1 Thursday, February 17, 2005 5:01 PM
Keep it coming!