(Difference between revisions)

Archived:Hello World in WidSets

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
m (1 revision(s))

Revision as of 08:23, 16 June 2008


About this widget

This is a basic Hello World demo widget.

WidSets Scripting Language code: hello_world.he

class hello_world
  //It is recommended to store command ids to static constants
  const int CMD_BACK = 1;
  //MenuItems are displayed over phone's softkeys
  //Usually to go back, ok, open options menu etc
  MenuItem BACK = new MenuItem(CMD_BACK, "Back");

  //WidSets framework calls createElement() per
  //each script-element it finds from views being
  //created by createView()
  Component createElement(String viewName,
                         String elementName,
                         Style style,
                         Object context)
    //return simple label with style defined in widget.xml,
    //in this case "text"
    if (elementName.equals("hello")) {
      //to get the label aligned in the middle of the
      //view you need to contain it inside a Flow which
      //you then return here
      return new Label(style, "Hello World");
    return null;

  void startWidget()
    //instantiate minimized view in startup
    setMinimizedView(createView("viewMini", getStyle("bg")));

  Shell openWidget()
    //instantiate maximized view when user opens this widget
    Flow view = createView("viewMaxi", getStyle("bg"));
    return new Shell(view);

  MenuItem getSoftKey(Shell shell, Component focused, int key)
    //return the key to be displayed at position=SOFTKEY_BACK
    //this is usually the right softkey, for other key
    //positions return null

    if (key == SOFTKEY_BACK) {
      return BACK;
    return null;
  void actionPerformed(Shell shell, Component source, int action)
    //when CMD_BACK event comes in, pop the current shell (this widget)
    if (action == CMD_BACK) {


<?xml version="1.0" encoding="utf-8"?>
<widget spec_version="2.0">

    <shortdescription>Very simple widget</shortdescription>
    <longdescription>Simplest possible widget saying hello to the world.</longdescription>
    <tags>test example hello world</tags>
    <parameter type="string" name="widgetname">Hello World</parameter>
    <code src="hello_world.he"/>
      bg {
        color-1: white;
        background: solid black;
        align: hcenter vcenter;
        border: 1 1 1 1;
        border-type: rectangle white;

      text {
        color-1: white;
        padding: 2 2 2 2;
  <layout minimizedheight="65sp">
    <view id="viewMini" class="bg">
      <label class="text">${widgetname}</label>
    <view id="viewMaxi" class="bg">
      <script id="hello" class="text"/>
      <weblabel class="top: 0px; left: 10px;" style="color: black;">${widgetname}</weblabel>


See also

55 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.