Attachment 'orca-customizations.py'

Download

   1 """This script adds battery status, date, time, and weather functionality to Orca
   2 Time or date can be pasted from the clipboard
   3 Adapted by Storm Dragon from the script posted at:
   4 http://live.gnome.org/Orca/FrequentlyAskedQuestions#head-6a8c1c2511ba01d7397f68f754eec0d923d166f1
   5 feel free to modify and/or redistribute this script as you see fit."""
   6 import orca.input_event # watches for input that Orca recognizes
   7 import orca.keybindings # Handles binding keystrokes for Orca to use.
   8 import orca.orca # Imports the main screen reader
   9 import orca.speech # Handles Orca's speaking abilities
  10 import orca.braille # Displays information in Braille format
  11 
  12 #change the next line to your zip code:
  13 zipCode = 0
  14 
  15 #places text in the clipboard
  16 def setClipboardText(text):
  17   import gtk # import the gtk library
  18   cb = gtk.Clipboard()
  19   cb.set_text(text)
  20   cb.store()
  21 
  22 #getWeather function gets weather from Yahoo
  23 def getWeather(zip_code):
  24   if zip_code != 0:
  25     import urllib
  26     from xml.dom import minidom
  27     WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s'
  28     WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0'
  29     url = WEATHER_URL % zip_code
  30     dom = minidom.parse(urllib.urlopen(url))
  31     ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0]
  32     weatherReport = ycondition.getAttribute('temp') + ' | ' + ycondition.getAttribute('text')
  33   else:
  34     weatherReport = "No zip code set: Please edit .orca/orca-customizations.py"
  35   return weatherReport
  36 
  37 myKeyBindings = orca.keybindings.KeyBindings()
  38 
  39 #define the battery status function
  40 def sayBattery(script, inputEvent=None):
  41   import commands
  42   message = commands.getoutput("acpi")
  43   if len(message) == 0:
  44     message = "Battery not found."
  45   orca.speech.speak(message)
  46   orca.braille.displayMessage(message)
  47   return True
  48 #end battery status function
  49 
  50 #Define the sayTime function
  51 def sayTime(script, inputEvent=None):
  52   import time # imports the Python time library
  53   message = time.strftime("%I:%M%p", time.localtime())
  54   orca.speech.speak(message)
  55   orca.braille.displayMessage(message)
  56   setClipboardText(message)
  57   return True
  58 #end sayTime function
  59 
  60 #Define the sayDate function
  61 def sayDate(script, inputEvent=None):
  62   import time # imports the Python time library
  63   message = time.strftime("%A, %B %d, %Y", time.localtime())
  64   orca.speech.speak(message)
  65   orca.braille.displayMessage(message)
  66   setClipboardText(message)
  67   return True
  68 #end sayDate function
  69 
  70 #Define the sayWeather function
  71 def sayWeather(script, inputEvent=None):
  72   message = getWeather(zipCode)
  73   orca.speech.speak(message)
  74   orca.braille.displayMessage(message)
  75   return True
  76 #end sayWeather function
  77 
  78 #Set up sayBattery keys
  79 sayBatteryHandler = orca.input_event.InputEventHandler(
  80     sayBattery,
  81     "Speaks and Brailles battery status.") # Shows the function of the key press in learn mode
  82 
  83 myKeyBindings.add(orca.keybindings.KeyBinding(
  84     "a",
  85     1 << orca.settings.MODIFIER_ORCA,
  86     1 << orca.settings.MODIFIER_ORCA,
  87     sayBatteryHandler)) # Sets Orca-a as the battery status key
  88 
  89 #Set up sayTime keys
  90 sayTimeHandler = orca.input_event.InputEventHandler(
  91     sayTime,
  92     "Presents the time.") # Shows the function of the key press in learn mode
  93 
  94 myKeyBindings.add(orca.keybindings.KeyBinding(
  95     "t",
  96     1 << orca.settings.MODIFIER_ORCA,
  97     1 << orca.settings.MODIFIER_ORCA,
  98     sayTimeHandler)) # Sets Orca-t as the say time key
  99 
 100 #add sayDate info
 101 sayDateHandler = orca.input_event.InputEventHandler(
 102     sayDate,
 103     "Presents the date.") # Shows the function of the key press in learn mode
 104 
 105 myKeyBindings.add(orca.keybindings.KeyBinding(
 106     "d",
 107     1 << orca.settings.MODIFIER_ORCA,
 108     1 << orca.settings.MODIFIER_ORCA,
 109     sayDateHandler)) # Sets Orca-d as the say date key
 110 
 111 #add sayWeather info
 112 sayWeatherHandler = orca.input_event.InputEventHandler(
 113     sayWeather,
 114     "Get current temperature and conditions.") # Shows the function of the key press in learn mode
 115 
 116 myKeyBindings.add(orca.keybindings.KeyBinding(
 117     "w",
 118     1 << orca.settings.MODIFIER_ORCA,
 119     1 << orca.settings.MODIFIER_ORCA,
 120     sayWeatherHandler)) # Sets Orca-d as the say date key
 121 
 122 orca.settings.keyBindingsMap["default"] = myKeyBindings
 123 #end time, date, and weather code

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-12-05 03:58:54, 4.1 KB) [[attachment:orca-customizations.py]]
  • [get | view] (2007-10-13 19:26:44, 1.7 KB) [[attachment:orca-customizations.pyc]]

You are not allowed to attach a file to this page.