[orca-list] New orca-customizations, actually made some progress
- From: Storm Dragon <stormdragon2976 gmail com>
- To: Accessible Linux <accessiblelinux freelists org>, Vinux Development <vinux-development googlegroups com>, Orca-list <orca-list gnome org>
- Subject: [orca-list] New orca-customizations, actually made some progress
- Date: Sun, 28 Mar 2010 17:18:08 -0400
Hi,
Well, it works, kind of. Now it only gives errors when it trys to set the keybinding: Here's the new code along with the code for the weather script. I don't know how to fix this little problem, I think the keybinding is in the wrong scope or something, but not sure how to fix it.
#orca-customizations.py
"""This file watches for new customizations to orca
Place scripts in ~/.orca/customizations/
Distributed under the terms of the GNU GPL."""
import orca.input_event # watches for input that Orca recognizes
import orca.keybindings # Handles binding keystrokes for Orca to use.
import orca.orca # Imports the main screen reader
import orca.speech # Handles Orca's speaking abilities
import orca.braille # Displays information in Braille format
import commands
import gtk
import os
import pygtk
#Dynamic Import section
customScripts = os.listdir("customizations")
if '__init__.py' in customScripts:
customScripts.remove('__init__.py')
for i in customScripts:
if i[-3:] == ".py":
exec("from customizations.%s import *" % i[:-3])
#end dynamic import section
myKeyBindings = orca.keybindings.KeyBindings()
#places text in the clipboard
def setClipboardText(text):
cb = gtk.Clipboard()
cb.set_text(text)
cb.store()
orca.settings.keyBindingsMap["default"] = myKeyBindings
#end orca-customizations.py
#weather.py place in ~/.orca/customizations/weather.py
import orca.input_event # watches for input that Orca recognizes
import orca.keybindings # Handles binding keystrokes for Orca to use.
import orca.orca # Imports the main screen reader
import orca.speech # Handles Orca's speaking abilities
import orca.braille # Displays information in Braille format
from xml.dom import minidom
import urllib
import urllib2
#Postal code for weather information:
zipCode = "12345"
#getWeather function gets weather from Yahoo
def getWeather(zip_code, forecast = False):
if zip_code != "0":
WEATHER_URL = '
http://xml.weather.yahoo.com/forecastrss?p=%s'
WEATHER_NS = '
http://xml.weather.yahoo.com/ns/rss/1.0'
url = "" % zip_code
dom = minidom.parse(urllib.urlopen(url))
forecasts = []
for node in dom.getElementsByTagNameNS(WEATHER_NS, 'forecast'):
forecasts.append(node.getAttribute('text'))
forecasts.append(node.getAttribute('high'))
forecasts.append(node.getAttribute('low'))
ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0]
weatherReport = "It is currently " + ycondition.getAttribute('temp') + " degrees and " + ycondition.getAttribute('text') + "."
if forecast == True: weatherReport = "Today's forecast is " + str(forecasts[0]) + " with a high temperature of " + forecasts[1] + " and a low of " + forecasts[2] + " degrees."
weatherReport = weatherReport.replace("AM", " morning ")
weatherReport = weatherReport.replace("PM", " evening ")
weatherReport = weatherReport.replace("/", " and ")
weatherReport = weatherReport.capitalize()
else:
weatherReport = "No zip code set: Please edit .orca/orca-customizations.py"
setClipboardText(weatherReport)
return weatherReport
#Define the sayWeather function
def sayWeather(script, inputEvent=None):
message = getWeather(zipCode)
orca.speech.speak(message)
orca.braille.displayMessage(message)
return True
#end sayWeather function
#Define the sayForecast function
def sayForecast(script, inputEvent=None):
message = getWeather(zipCode, True)
orca.speech.speak(message)
orca.braille.displayMessage(message)
return True
#end sayForecast function
#add sayWeather info
sayWeatherHandler = orca.input_event.InputEventHandler(
sayWeather,
"Get current temperature and conditions.") # Shows the function of the key press in learn mode
myKeyBindings.add(orca.keybindings.KeyBinding(
"w",
1 << orca.settings.MODIFIER_ORCA,
1 << orca.settings.MODIFIER_ORCA,
sayWeatherHandler)) # Sets the say weather key
#add sayForecast info
sayForecastHandler = orca.input_event.InputEventHandler(
sayForecast,
"Get extended weather information.") # Shows the function of the key press in learn mode
myKeyBindings.add(orca.keybindings.KeyBinding(
"w",
1 << orca.settings.MODIFIER_ORCA,
1 << orca.settings.MODIFIER_ORCA,
sayForecastHandler, 2)) # Sets the say weather key
#end weather.py
The error comes in line 57 of weather.py the myKeyBindings line. Thanks for any help, we are very close to having drop-in scripts. It should make life easier.
Thanks
Storm
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]