PDA

View Full Version : Create a Customizable Dialog


wuench
01-21-2009, 01:08 PM
I decided I needed a little more feedback in my setup. Here is a dialog box I created for my system. It can be used for confirmations or just user notifications and is fully customizable by setting global variables before showing it. So with this I basically have one template that I can reuse throughout my whole setup for notifications, confirmations, and feedback and they will all have a consistent look and feel. Some examples of where I am using it are for playlist add/delete/clear confirmation, movie selection confirmation, etc.

Modes of Operation
Timer - By setting a timer value, the dialog will dismiss itself automatically. The new version uses the SetTimeout command. So you can now have a dialog that timesout as well as responds to command buttons. A timeout will return Timeout in the global variable GVar:Dlg_Result. Also, when the timer is set an animated throbber cursor will appear in the upper right corner.
Button - In this mode you can display 1 or 2 buttons with customizable text/values. When one is clicked the value will be returned in a Global Variable.
Template Click - You can also allow the dialog to be dismissed by clicking on the template itself. This can be enabled along with the 2 buttons above and a value will be returned.
Default Behavior - If you do not set a display time or any buttons, the dialog will automatically display a default Ok button.Global Variables Used
The following global variables are used to control the dialog's behavior. These are automatically deleted by the dialog after they are used, so you will need to set these everytime you invoke the dialog. The only one that isn't deleted is Dlg_Result.
GVar:Dlg_Message - This will be the text message displayed in the dialog.
GVar:Dlg_Title - This will set the dialog's title
GVar:Dlg_Image - This is a path to an icon to be displayed by the dialog (32x32).
GVar:Dlg_Button1Val - This the the text for button 1, if set the button will be displayed (unless DisplayTime is set). This will also be the result returned if Button 1 is clicked to close the dialog.
GVar:Dlg_Button2Val - This the the text for button 2, if set the button will be displayed (unless DisplayTime is set). This will also be the result returned if Button 2 is clicked to close the dialog.
GVar:Dlg_ButtonMainVal - If set the overlay button will be displayed (unless DisplayTime is set). This will also be the result returned if the user clicks anywhere in the dialog to close it.
GVar:Dlg_DisplayTime - This is the time to display the dialog in milliseconds before it auto-dismisses. If set, an animation will be displayed.
GVar:Dlg_Result - This is the result returned by the dialog. If a button is clicked it will be the button's value, otherwise it will be blank (for Timed Mode).Example Images

Ok/Cancel Dialog
http://www.wuench.com/cmine/albums/userpics/Dialog_Box.png

Yes/No Dialog
http://www.wuench.com/cmine/albums/userpics/Dialog_YesNo.png

Timed/Notification Dialog
http://www.wuench.com/cmine/albums/userpics/Timed_Dialog.png


With Buttons
--------------------------------------------------------------------------------
This code will display a dialog with the message "Are you sure you want to clear the
playlist?" and an OK and Cancel button. If the user clicks OK the playlist is cleared if
the user clicks Cancel, the dialog is dismissed and no action is taken.
--------------------------------------------------------------------------------
GlobalVars::SetVariable(GVar:Dlg_Title, Confirm Clear)
GlobalVars::SetVariable(GVar:Dlg_Button1Val, OK)
GlobalVars::SetVariable(GVar:Dlg_Button2Val, Cancel)
GlobalVars::SetVariable(GVar:Dlg_Message, Are you sure you want to clear the playlist?)
GlobalVars::SetVariable(GVar:Dlg_Image, /User/Hardware/Small Icons/Speaker Music)
IntfViewer::InvokePopup(BlueGlass-Pop_Dialog, 255, -1 -1)
If GlobalVars::Exists(GVar:Dlg_Result)
If System::Equals(%(GVar:Dlg_Result), OK)
Devices::FieldWrite(AudioPlayer.ClearPlaylist, True)
End
End


Timed / Auto Close
--------------------------------------------------------------------------------
This code will display a notification dialog with the message "You have a new email
message!" for 2.5 seconds and then the dialog will dismiss itself.
--------------------------------------------------------------------------------
GlobalVars::SetVariable(GVar:Dlg_Title, Email Notification)
GlobalVars::SetVariable(GVar:Dlg_Message, You have a new email message!)
GlobalVars::SetVariable(GVar:Dlg_Image, \User\Hardware\Small Icons\Document)
GlobalVars::SetVariable(GVar:Dlg_DisplayTime, 2500)
IntfViewer::InvokePopup(BlueGlass-Pop_Dialog, 255, -1 -1)

Templates
Here are the templates for the dialog and a template to test the features. These require 2.4.32+.

ellisr63
01-21-2009, 02:39 PM
thinking... would this work as a set of instructions... ie message says "what zone" and you push Family... then message says "what source" ..etc or am I losing the concept?

wuench
01-21-2009, 03:06 PM
Sure, but you'll probably need to expand it with more buttons. Right now it only supports 2.

LesAuber
04-01-2009, 04:48 PM
Thanks, I'll have to play some to see what else I don't get.

LesAuber
04-04-2009, 02:08 PM
This was a big help even though it was far more complex than I needed. I got what I needed done.

Instead of an animation has anyone done a straight 5 or 10 second countdown timer? I'd like to do it with the same font as the rest of the pop up. I suppose I could just make the requisite images and do it like you did this animation.
Thanks,

wuench
04-04-2009, 02:26 PM
I tried to come up with a way to do a countdown timer so the user would have good feedback on how long the dialog is going to hang around, but I haven't found a way yet. At first I thought I could just call SetTimeout and then change the count in the OnTimeout, but the minimum SetTimeout value is 5 seconds so the counter would count down in 5's.

Today I tried to use the Timer Driver, but there is no formatted output for the countdown timers. So you can't get seconds out, you get ticks instead. There is a format for count up, so you could do a count up timer. We need a formatted field for the countdowns as well.

Short of writing my own timer driver I don't think there is a way to do it.

jrlewis
04-04-2009, 02:58 PM
A countdown timer and a time field widget will do it for you. The countdown isn't real smooth, but it works.

wuench
04-05-2009, 06:01 AM
The Field Time Text widget shows the year (1970). There's no way to format it down to just show seconds....

jrlewis
04-05-2009, 07:35 AM
For the Field Time Text widget select the Time Fmt tab. For the Format String type in %(s,2,0) for straight seconds or %(u,2,0):%(s,2,0) for an mm:ss format. Works like a charm.

LesAuber
04-05-2009, 08:53 AM
How do you set the time? Say to countdown from 10s?

jrlewis
04-05-2009, 09:06 AM
You would issue a reset command via the InvokeCmd field. If you were using CDTimer1 you would use the InvokeCmd field and write ResetCD 1 Seconds 10.

wuench
04-05-2009, 11:30 AM
For the Field Time Text widget select the Time Fmt tab. For the Format String type in %(s,2,0) for straight seconds or %(u,2,0):%(s,2,0) for an mm:ss format. Works like a charm.

That tab appears to be missing in the version I am on. (2.4.32)

Dean Roddey
04-05-2009, 09:07 PM
Yeh, looks like that one got left out when the tabs were moved up to the designer. I'll get that fixed in the next drop.

LesAuber
04-16-2009, 12:30 PM
You would issue a reset command via the InvokeCmd field. If you were using CDTimer1 you would use the InvokeCmd field and write ResetCD 1 Seconds 10.

I'm obviously missing something. I set up a countdown timer driver and have a field time text widget associated with it. But nowhere can I find the InvokeCmd field to reset it. What am I missing? I've tried the field time widget cmds, the popup cmds, and the cmds on the widget that invokes the popup.
TIA,

wuench
04-16-2009, 12:32 PM
Invokecmd is a field in the timers driver. Look at the timers driver doc for details, but basically you write a string to it telling it which counter to reset.

LesAuber
04-16-2009, 01:36 PM
Thanks. By telling me what I already knew you reminded me of what I was forgetting to do, insert a cmd:fieldwrite at the same time as setting the pop up time out. Sort of a duh moment. :D

It does work but describing the countdown as not really smooth is an understatement. From 10 it goes something like this: 10, 8, 7, 4, 2, ????, 1, and executes. It certainly conveys the idea but doesn't look to hot. I'm not sure to go ahead and implement for real or not.

Dean Roddey
04-16-2009, 02:21 PM
I could always I guess implement a 'local countdown' widget for those sorts of things.

LesAuber
04-16-2009, 02:53 PM
I honestly don't know how much benefit there is to this. I'd like it but in the grand scheme just don't know. All I was trying to do was system shutdown in 10, 9, 8, ... though I'll probably switch to a 5 second wait.

My system is pretty simple so it's not like there are hundreds of tasks going in the background. It also seemed to be the same whether I was on the console or over an RDP session.

LesAuber
04-25-2009, 08:20 AM
Dean, if you can do a local countdown widget without to much trouble and think others might use it, it would be appreciated. The countdown is pretty ragged. Doesn't look professional at all.

Dean Roddey
04-25-2009, 10:02 AM
I might be able to slip it in at some point for the 3.0 release. Hard to say. If not, then in the next one easily enough.

LesAuber
04-26-2009, 07:30 AM
Thanks. Hopefully it will be useful to more than just me.