[orca-list] New orca-customizations.py File




Hi,
The Orca scripting tutorial is coming along quite nicely.  Well, maybe slowly but surely is more like it.  Anyway, I have an orca-customizations.py file that, hopefully, someone will find useful.  The file adds the following functionality to Orca.
Orca-t Speaks and/or Brailles the current time.  It also places the current time in the clipboard so it can be pasted if desired.
Orca-d Speaks and/or Brailles the current date.  The date is also placed into the clipboard so that it can be pasted if desired.
Here's examples of the paste functions.  I have just pressed insert-t  when I press ctrl-v to paste I get 06:54PM
Now, for the date, I press ins-d and when I press ctrl-v to paste, it will paste Monday, October 06, 2008
I need to go back and add in some better documentation for the code, but as it stands, everything works (at least on my system).  Please send me some feedback, suggestions for improvement, if it's maybe the koolest thing ever!, etc.  There will be another hopefully more improved customizations.py in the near future.  Also, if you happen to have scripts you would like included in the tutorial please send them my way.  And now! drum roll please!  Here's the orca-customizations.py code.  Simply copy the text below and paste it into .orca/orca-customizations.py If this file exists already, you may want to replace it because I am not sure if there will be conflicts with your current customizations.
#start code below this line:
"""This script adds time and date functionality to Orca
New in this script, time or date can be pasted from the clipboard
Adapted by Storm Dragon from the script posted at:
http://live.gnome.org/Orca/FrequentlyAskedQuestions#head-6a8c1c2511ba01d7397f68f754eec0d923d166f1
feel free to modify and/or redistribute this script as you see fit."""
#import gets code that has already been written.
#think of it as using wheels instead of trying to reinvent them.
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 re # Not sure
import gtk # import the gtk library

#places text in the clipboard
def setClipboardText(text):
  cb = gtk.Clipboard()
  cb.set_text(text)
  cb.store()

myKeyBindings = orca.keybindings.KeyBindings()

#Define the sayTime function
def sayTime(script, inputEvent=None):
  import time # imports the Python time library
  message = time.strftime("%I:%M%p", time.localtime())
  orca.speech.speak(message)
  orca.braille.displayMessage(message)
  setClipboardText(message)
  return True
#end sayTime function

#Define the sayDate function
def sayDate(script, inputEvent=None):
  import time # imports the Python time library
  message = time.strftime("%A, %B %d, %Y", time.localtime())
  orca.speech.speak(message)
  orca.braille.displayMessage(message)
  setClipboardText(message)
  return True
#end sayDate function

#Set up sayTime keys
sayTimeHandler = orca.input_event.InputEventHandler(
    sayTime,
    "Presents the time.") # Shows the function of the key press in learn mode

myKeyBindings.add(orca.keybindings.KeyBinding(
    "t",
    1 << orca.settings.MODIFIER_ORCA,
    1 << orca.settings.MODIFIER_ORCA,
    sayTimeHandler)) # Sets Orca-t as the say time key

#add sayDate info
sayDateHandler = orca.input_event.InputEventHandler(
    sayDate,
    "Presents the date.") # Shows the function of the key press in learn mode

myKeyBindings.add(orca.keybindings.KeyBinding(
    "d",
    1 << orca.settings.MODIFIER_ORCA,
    1 << orca.settings.MODIFIER_ORCA,
    sayDateHandler)) # Sets Orca-d as the say date key

orca.settings.keyBindingsMap["default"] = myKeyBindings
#end time and date code

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