[orca-list] New method of orcacustomizations



Hi,
I have been working on a ew method for handling orca-customizations scripts. It's not a lot of code, but it keeps giving me an error, so I thought I would post it and see if anyone can help find the problem. Here's the idea behind the change. If someone wants to add to the existing method, they have to modify an existing file of quite large size, insert their code, and make changes in other places in the file to get it working. This can cause for some problems with debugging, or getting overwhelmed with the code and not knowing where to add the new code. Also, some people may not want all the scripts in the file. there may, for example, be some people for whatever reason who do not want the weather script. With the old method, if they installed the script, they were stuck with the code in there even if they didn't use it. The new method will allow for users to pick and choose scripts, downloading and using only what they want. All scripts must be saved to ~/.orca/customizations/. The new orca-customizations.py file watches the customizations directory and imports any new file automatically. The code keeps giving a syntax error though when trying to import. Here's the new orca-customizations.py file:
"""This file watches for new customizations to orca
Place scripts in ~/.orca/customizations/
Feel free to modify and/or redistribute this script as you see fit."""
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")
for i in customScripts:
    exec("import customizations/" + i)
#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

And here is a modified version of the weather script. In theory, all you should have to do to get it working is change the postCode variable to your postal code and then place the script in ~/.orca/customizations/weather.py. I haven't been able to debug it because the error in the orca-customizations.py script, but there weren't many changes reuired, so it should work:
from xml.dom import minidom
import urllib
import urllib2
#Postal code for weather information:
zipCode = "28624"

#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
Thanks
Storm

-- 
Follow me on Twitter:
http://www.twitter.com/stormdragon2976
My blog, Thoughts of a Dragon:
http://www.stormdragon.us/
What color dragon are you?
http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/
Install Windows Vista in under 2 minutes:
http://is.gd/am6TD




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]