Step 1: Getting Started
- A computer with Mac OS X or Windows Xp/Vista
- A text editing program. (Notepad is perfect.)
- An image editing program. (Microsoft Paint is fine.)
- Patience and time.
- Yahoo Widgets
- Widget Converter Widget
Once you have these programs and widgets, you are ready to move on to step two.
Step 2: Creating Folder Structure
The structure looks like this:
All of the images the widget will use
You can download this widget to automatically create the folder structure
Structure - Reinier Kaper
Set the preferences of a widget by right-clicking on any part of it, and click on preferences.
Change the preferences of Structure to the following:
root: Navigate to your widget folder. (Located in 'My Documents' on Windows)
Now you can click on the widget and a dialog box will pop up, asking you for the name of the widget.
Step 3: Creating All of the Necessary Files
Download a template a have created for you to use. Download link below. Place the file in the 'Contents' folder located in the folder titled the name you chose earlier. Open the file with the text editor of you choice and replace YourNameHere with your name. Save and close.
Next we will create the .kon file which is the main file that tells the widget what to do. The .kon file is just an XML file with a renamed extension. Download this basic widget.kon file and also place it in the 'Contents' folder. Again, open up the file with a text editor. The first line signifies that the file is an XML file created with the UTF-8 encoding. The next tag to add is the widget tag; <widget>
Then you declare your settings, like debug; <settings><setting name="debug" value="on"/></settings>. Now you are ready to add your window elements; <window>. Widgets have multiple objects that do certain things and have certain properties. For example the text object,<text ..../>, creates text. Here are a list of some of the properties of the text object:
-data (text to display)
-hOffset (a.k.a x)
-vOffset (a.k.a. y)
With that said, let's start coding. Add the following code to the kon file, in the <window> tags:
In english, this sets up a text object named myText, that displays "Hello World!" in font Arial, color blue, and size 12.
Save your kon file, and continue to step four.
Step 4: Rejoyce!
Step 5: Adding Function
Open your text editor and create a file called main.js. To add the time, we will use "the Date object". To setup the date object, you create a function. Add this function to the js file:
theTime = new Date();
theHour = String(theTime.getHours());
theMinutes = String(theTime.getMinutes());
myText.data = "The time is: "+ theHour+":"+theMinutes;
Your widget will not show the time yet, because it doesn't know what to do with the js file. To take care of this, we add this event handler to the Kon file, in the <widget> tags but not in the <window> tags:
To make the time update, we need to create a timer, which goes in the Kon file, in the <widget> tags but not in the <window> tags:
<timer name="myTimer" interval="1" onTimerFired="updateText()" ticking="true"/>
Save the files and load the widget. It should show the time. If it doesn't work, download both the kon and js from below and replace with the old ones.
Step 6: Summing It All Up
Here are a list of things that you can try to accomplish with your widget:
-Add preferences to control the font using the <preference> tag, and the <type>font</font> sub-tag
-Add some event handlers like onClick using the <onClick> or <onMultiClick> tags.
-Display an image from a local file using the image object
Hope you found this tutorial useful and you will enjoy the endless possibilities of widgets,