Skip navigation.
Home

Handling keys on the Icon

Here is an introduction to handling keyboard events using the Icon keypad. Responding to Icon keypad events is very easy. You just need to set up the function to handle a particular key event. For Example:

class TestWidget(widget.Widget):
  def __init__(self,id=None,title=None, brailleTitle=None):
    widget.Widget.__init__(self,id=id,title=title,brailleTitle=brailleTitle)

    self.setKeySetHandler('select',self.handleselect)

  def handleselect(self):
    self.app.say("Select Key Handled")

setKeySetHandler takes two arguments. The first is a label for the key being pressed. The second in the name of the function to be called when the key is pressed.

A Tic Tac Toe Skeleton

Here is a skeleton for Tic Tac Toe. It is far from complete, but illustrates subclassing the widget, and handling keyboard presses, and adding children to app.App.

If you have any questions on any part, just post them in the comments below and I'll try to answer them.

Anyone want to take a crack at finishing this game??

#/usr/bin/env python

from levelstar.sbtk import *

class TicTacToeWidget(widget.Widget):
  def __init__(self,id=None,title=None, brailleTitle=None):
    widget.Widget.__init__(self,id=id,title=title,brailleTitle=brailleTitle)
    self.board=[["Empty","Empty","Empty"],["Empty","Empty","Empty"],["Empty","Empty","Empty"]]

Hello World for the Icon

Our first introduction for programming for the Icon will be Hello World. It will launch an application and connect to the Icon Shell and contain one menu item.

To run this on the Icon, first copy the code below into a file and save it as hello.py
Copy the file over to the Icon
Either log into the console through ssh or go into the console through the utils menu
Go to the directory where you put hello.py and run the following command:
python hello.py

If your Icon said Hello World, then Congratulations you have begun developing for the Icon.


#!/usr/bin/env python

from levelstar.sbtk import *

Welcome to Icon Developer

Icon Developer is a site for anyone wishing to develop for the Icon or Icon Braille +. Hopefully over time this will grow into a strong community to share and develop applications, games, scripts and more for the Icon.

Syndicate content