With the Gadget Designer application for Windows, you can easily create a Desktop gadget from scratch. Gadget Designer is also useful for modifying existing gadgets, such as when you need to change a gadget's user interface or repackage a gadget.
This tutorial leads you through the process of creating a simple gadget. After completing this tutorial, you should be comfortable using Gadget Designer's major features.
Do this:
Note: During the installation process, a window asks you to choose desktop features. You can change most of the default settings (especially "Improve Google Desktop"!), but make sure the checkbox under Sidebar with Gadgets stays selected.
Do this:
api\tools
folder of the SDK.designer_en.exe
file.
Note:
If you see a message warning that the application failed
to start because a .dll file could not be found,
unzip the SDK again.
Then make sure you execute the copy of designer_en.exe
that is in the
api\tools
folder of the unzipped SDK,
so that Gadget Designer can find all the files it needs.
My New Gadget
in the File name field,
and click the Save button.
Gadget Designer creates a folder for your gadget
and populates it with files and folders your gadget is likely to need.
A typical setup
is shown to the right.
If you look at the same folder outside of Gadget Designer,
you can see that the Gadget Settings item
represents a file named gadget.gmanifest
.
<view height="150" width="250" onopen="view_onOpen()"> <img src="stock_images\background.png"/> <script src="main.js" /> </view>
view_onOpen()
—
in a file named main.js
.
You'll edit main.js
later.
The Preview tab is a good way to check on your gadget.
However, to see how your gadget behaves and looks
under normal running conditions,
you still need to run the gadget in Google Desktop.
You can install and run your gadget in Google Desktop
by double-clicking the gadget.gmanifest
file
in your gadget's folder.
Gadget Designer lets you drag user interface (UI) elements such as labels and buttons into your gadget. You can then use the Properties pane to edit each element's properties so that it looks the way you want.
Do this:
Note: Save often! If you make a mistake, you can use Edit > Undo (or Ctrl+Z) to undo your changes. If you undo too much, use Edit > Redo (or Ctrl+Y) to reapply changes.
label
item in the Elements pane.
The Properties pane shows the values of
the selected element's properties.
For example, the label's align
property
is initially left
.
Property | New Value | Explanation |
---|---|---|
align | center |
Centers the text within the label. |
innerText | Hello World |
Sets the text displayed by the label. |
width | 100% |
Makes the label as wide as the entire gadget. |
x | 0 |
Positions the label at the left edge of the gadget. |
label
properties,
see the API reference documentation for
label
.
<view height="150" width="250" onopen="view_onOpen()">
<img src="stock_images\background.png"/>
<label height="16" name="label1" width="100%" x="0" y="58" align="center"
>Hello World
</label>
<script src="main.js" />
</view>
label
element
(shown in orange)
that you added.
Besides changing the XML through direct manipulation,
as you did in this step,
you can also edit the text of the main.xml
file
in Gadget Designer.
Caution:
Don't put comments or JavaScript in main.xml
.
Because Gadget Designer regenerates the XML,
any non-XML markup disappears.
In this step, you add event-handling code to make your gadget respond to user clicks.
Do this:
main.js
),
and that includes the skeleton of a function
(label1_onclick()
)
to handle click events.
If you go back to the main.xml tab
and look at the label's properties,
you can see that the enabled
property
is now set to True
,
and the onclick
property
is set to label1_onclick()
.main.js
:
function view_onOpen() {
}
function label1_onclick() {
view.alert("hello world!");
}
Clicks are just one kind of
event supported by all elements.
To learn about other events such as focus events,
read the
basicElement API reference.
Gadget Designer makes it especially easy to register handlers for click events,
but it's simple to register any other kind of event handler.
Just make sure the element's enabled
property is true,
add a function to main.js
that reacts to the event,
and connect the function by setting the value of
an event property (such as onfocusin
)
in main.xml
.
Your gadget can produce debugging strings using the
gadget.debug
object.
The Debug Console lets you view these strings
Do this:
main.js
,
either by clicking the main.js tab or
by double-clicking main.js
in the Gadget Explorer.
view_onOpen()
method:
function view_onOpen() {
debug.info("starting...");
}
debug.info
method ("starting...").
If Show message times is selected,
the line also contains
the time when the message was created.
A gadget's debugging strings are generated
only when the gadget is in debug mode.
To execute a gadget in debug mode,
preview the gadget in Gadget Designer
or double-click the gadget's gadget.gmanifest
file.
In this step, you customize your gadget's standard strings —
no more "New Gadget" in window titles!
You also specify settings for
the gadget.gmanifest
file.
Do this:
en
folder
and double-click strings.xml
.
strings.xml
file
appear in the display area.
This file defines default strings
for the elements
GADGET_NAME
,
GADGET_DESCRIPTION
, and
GADGET_ABOUT_TEXT
,
which are used for gadget settings.
strings.xml
to customize the strings for this gadget, as
shown below in orange.
<strings> <GADGET_NAME>Hello World</GADGET_NAME> <GADGET_DESCRIPTION>The canonical first program</GADGET_DESCRIPTION> <GADGET_ABOUT_TEXT>Hello World © 2008 This gadget puts up an alert when you click the label.</GADGET_ABOUT_TEXT> </strings>Defining user-visible strings in
strings.xml
helps make your gadget easier to translate.
GADGET_NAME
)
defined in the strings.xml
file.
All other fields must have either no value
or the actual string value.
See The
about element for details.
Jo Wu
,
jowu.feedback+MyNewGadget@gmail.com
author
and authorEmail
elements in
the gadget.gmanifest
file.
Providing good values for these elements
helps you get
credit
and feedback
for all of the gadgets you develop!
For information about these and other fields,
see What Goes into a gadget.gmanifest File.
You're almost done.
A finished gadget needs to be packaged
into a single file for distribution.
In this step, you use Gadget Designer
to create the gadget's .gg
file.
Users can then double-click the .gg
file
to run the gadget.
Do this:
stock_images
.stock_images
except for background.png
.gg
file smaller,
reducing gadget download time.
.gg
file.
.gg
file out
of your gadget's folder,
and double-click the .gg
file to run the gadget.
This tutorial introduced you to all the major features of Gadget Designer, from creating a gadget to implementing, debugging, and packaging it.
If you want to keep on playing with the gadget you just created, here are some ideas:
debug.error()
and
debug.warning()
,
and try unselecting checkboxes in the Debug Console.
api\tools\gdpconsole.exe
instead of Gadget Designer to view debugging output.
Remember to run the gadget in debug mode
by double-clicking the .gmanifest
file.
Here are some ideas for when you're ready to move on from this gadget: