Re: [orca-list] orca-customizations.py
- From: chrys87 <chrys87 web de>
- To: orca-list gnome org
- Subject: Re: [orca-list] orca-customizations.py
- Date: Wed, 25 Sep 2013 22:27:05 +0200
Hi all,
I updated my orca-customizations.py and wanna share with the world.
changelog:
- It braille/speak only if in settings enabled
- it works with more than 1 batterys and get the batterys (in fedora19)
by itselfs
- since Gnome-shell cant speak the current workspace anymore: it reads
the virtual desktop number. for this you need a tool installed called
"xprop"
- the clipboard does not only read if text in the clipoard. it also
displays if a image content or Files/Folders/Links/Mountpoints(and the
number of objects) in the clipbard
If someone have other good ideas for :), just share.
#<script>
# display Clipboard (Orca + r)
# display Battery (Orca + a)
# display Workspace (Orca + d)
# display Version (Orca + v)
# for Orca Screenreader
# -*- coding: utf-8 -*-
#Python
from __future__ import division
import glob
import os
#GTK/GDK
from gi.repository import Gtk, Gdk
# Orca
import orca.orca
import orca.input_event
import orca.settings
import orca.keybindings
import orca.speech
import orca.braille
##########
Version = "0.7"#
##########
#Bind Function to key-------------------------
myKeyBindings = orca.keybindings.KeyBindings()
def DefineShortcut(pHandle,pShortcut):
myKeyBindings.add(orca.keybindings.KeyBinding(
pShortcut,
1 << orca.settings.MODIFIER_ORCA,
1 << orca.settings.MODIFIER_ORCA,
pHandle))
orca.settings.keyBindingsMap["default"] = myKeyBindings
#Bind Function to key+++++++++++
#Display Message ----------------------------
# Speak or Braille
def outputMessage(Message):
if (orca.settings.enableSpeech):
orca.speech.speak(Message)
if (orca.settings.enableBraille):
orca.braille.displayMessage(Message)
#Display Message +++++++++++++
#Display Version-----------------------------
def displayVersion(script, inputEvent=None):
outputMessage("Version " + Version)
# define VersionHandler
displayVersionHandler = orca.input_event.InputEventHandler(
displayVersion, "Gebe die Version der orca-customizations.py aus")
#Speak Version of orca-customizations
#Display Version++++++++++++++
#Display Clipboard-------------------------------
def displayClipboard(script, inputEvent=None):
Message = ""
FoundClipboardContent = False
# Get Clipboard
ClipboardObj = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
ClipboardText = ClipboardObj.wait_for_text()
ClipboardImage = ClipboardObj.wait_for_image()
if (ClipboardText != None):
FoundClipboardContent = True
if (ClipboardObj.wait_is_uris_available()):
UriList = ClipboardText.split() # this wont work with
spaces in filenames
ObjectNo = 0
for Uri in UriList:
ObjectNo += 1
if (os.path.isdir(Uri)):
Message = Message + "Ordner " #Folder
if (os.path.isfile(Uri)):
Message = Message + "Datei " #File
if (os.path.ismount(Uri)):
Message = Message + "Datenträger " #Mountpoint
if (os.path.islink(Uri)):
Message = Message + "Verknüpfung " #Link
Message = Message + " " + Uri[Uri.rfind('/') + 1:]
if (ObjectNo > 1):
Message = str(ObjectNo) + " Objekte in der
Zwischenablage " + Message # X Objects in Clipboard Object Object
else:
Message = str(ObjectNo) + " Objekt in der
Zwischenablage " + Message # 1 Object in Clipboard Object
else:
Message = "Text in Zwischenablage " + ClipboardText # Text
in Clipboard
if (ClipboardImage != None):
FoundClipboardContent = True
Message = "Ein Bild ist in der Zwischenablage" # Image is in
Clipboard
if (not FoundClipboardContent):
Message = "Zwischenablage ist leer" #Clipboard is empty
# Say/braille something.
outputMessage(Message)
# Consume the event so it will not go to an application.
return True
# define ClipboardHandler
displayClipboardHandler = orca.input_event.InputEventHandler(
displayClipboard, "Gebe Inhalt der Zwischenabglage wieder") #Speak
Content of the Clipboard
#Display Clipboard++++++++++++++++++++++++++++++
#Display Battery State-----------------------------------
def displayBatteryStatus(script, inputEvent=None):
Battery = 0
for BatteryPath in glob.glob("/sys/class/power_supply/BAT?"):
Battery += 1
try:
BatteryStatus = open(BatteryPath + "/status", "r")
Status = BatteryStatus.read()
BatteryStatus.close()
Message = Status
if Status.find("Full") == 0:
# Battery is Full
Message = "Akku " + str(Battery) + " ist voll geladen"
#Battery is full
else:
BatteryFull = open(BatteryPath + "/charge_full", "r")
Full = int( BatteryFull.read())
BatteryFull.close()
BatteryCurrent = open(BatteryPath + "/charge_now", "r")
Current = int( BatteryCurrent.read())
if Status.find("Charging") == 0:
# Label for Battery Charging
Status = "Akku " +str(Battery)+" " + " laden" #
Charging
if Status.find("Discharging") == 0:
# Label for Battery Discharging
Status = "Akku " +str(Battery)+" " + " entladen"
# Discharging
Percent = int( Current / Full * 100)
# Charging/Discharging XX Percent
Message = Status + " "+ str( Percent) + " Prozent" #Percent
#print Message #Debugging
#print Percent #Debugging
#print Status #Debugging
except IOError:
# Battery not found or cant open.
Message = "Akku " +str(Battery) + " kann nicht geöffnent
werden." # Battery can not open
outputMessage(Message)
if (Battery == 0):
Message = "Kein Akku gefunden."
outputMessage(Message)
# Consume the event so it will not go to an application.
return True
# define BatteryStatusHandler
displayBatteryStatusHandler = orca.input_event.InputEventHandler(
displayBatteryStatus, "Spreche den Status des Akkus") # Speak state
of battery
#Display Battery State+++++++++++++++++++++++++++++++++++
#Display Workspace No-------------------------------
def displayWorkspaceNo(script, inputEvent=None):
Message = "Desktop "
try:
xprop = os.popen('xprop -root _NET_CURRENT_DESKTOP').read()
if xprop != '':
xprop = xprop[xprop.find("=")+ 2 :]
else:
xprop = "konnte nicht ermittelt werden" # cant get
desktop number
Message = Message + xprop
except IOError:
# xprop evtl. not installed
Message = "Bitte xprop installieren." #please install xprop
# Say/braille something.
outputMessage(Message)
# Consume the event so it will not go to an application.
return True
# define WorkspaceNoHandler
displayWorkspaceNoHandler = orca.input_event.InputEventHandler(
displayWorkspaceNo, "Aktuelle Desktopnummer sprechen") #display
current workspace
#Display Workspace No++++++++++++++++++++++++++++++
#define shortcuts
DefineShortcut(displayClipboardHandler,"r") # Shortcut Orca + r
DefineShortcut(displayWorkspaceNoHandler,"d")# Shortcut Orca + d
DefineShortcut(displayBatteryStatusHandler,"a")# Shortcut Orca + a
DefineShortcut(displayVersionHandler,"v")# Shortcut Orca + v
#</script>
- a little more modularisation
Am 20.09.2013 07:01, schrieb chrys87:
Hi out there,
I made (based on the gnome wiki) a orca-customizations.py
Wiki code wont work for me. I think its outdated.
I share it with the list. maybe someone need this funktionality or
need a working demo.
the script can read the battery status (orca + a) and the content of
the clippboard (orca + r).
This works for me with fedora 19.
Here the script:
# Say Clipboard (Orca + r)
# Say Battery (Orca + a)
# for Orca Screenreader
# Version: 0.2
#Python
from __future__ import division
#GTK/GDK
from gi.repository import Gtk, Gdk
# Orca
import orca.braille
import orca.input_event
import orca.keybindings
import orca.orca
import orca.speech
myKeyBindings = orca.keybindings.KeyBindings()
#Say Clipboard-------------------------------
def sayClipboard(script, inputEvent=None):
Message = "Zwischenablage "
# Get Clipboard
ClipboardObj = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
ClipboardText = ClipboardObj.wait_for_text()
if (ClipboardText != None):
Message = Message + ClipboardText
else:
Message = + "ist leer"
# Say/braille something.
orca.speech.speak(Message)
#orca.braille.displayMessage(Message)
# Consume the event so it will not go to an application.
return True
sayClipboardHandler = orca.input_event.InputEventHandler(
sayClipboard, "Spreche Inhalt der Zwischenabglage")
# Shortcut Orca + a
myKeyBindings.add(orca.keybindings.KeyBinding(
"r",
1 << orca.settings.MODIFIER_ORCA,
1 << orca.settings.MODIFIER_ORCA,
sayClipboardHandler))
#Say Clipboard++++++++++++++++++++++++++++++
#Say Battery State-----------------------------------
def sayBatteryStatus(script, inputEvent=None):
try:
BatteryStatus = open("/sys/class/power_supply/BAT1/status", "r")
Status = BatteryStatus.read()
BatteryStatus.close()
Message = Status
if Status.find("Full") == 0:
# Battery is Full
Message = "Akku ist voll geladen"
else:
BatteryFull =
open("/sys/class/power_supply/BAT1/charge_full", "r")
Full = int( BatteryFull.read())
BatteryFull.close()
BatteryCurrent =
open("/sys/class/power_supply/BAT1/charge_now", "r")
Current = int( BatteryCurrent.read())
if Status.find("Charging") == 0:
# Label for Battery Charging
Status = "Lade "
if Status.find("Discharging") == 0:
# Label for Battery Discharging
Status = "Entlade "
Percent = int( Current / Full * 100)
# Charging/Discharging XX Percent
Message = Status + str( Percent) + " Prozent"
#print Message #Debugging
#print Percent #Debugging
#print Status #Debugging
except IOError:
# Battery not found or cant open.
Message = "Batterie nicht gefunden oder kann nicht geoeffnent
werden."
orca.speech.speak(Message)
#orca.braille.displayMessage(Message)
# Consume the event so it will not go to an application.
return True
sayBatteryStatusHandler = orca.input_event.InputEventHandler(
sayBatteryStatus, "Spreche den Status des Akkus")
# Shortcut Orca + a
myKeyBindings.add(orca.keybindings.KeyBinding(
"a",
1 << orca.settings.MODIFIER_ORCA,
1 << orca.settings.MODIFIER_ORCA,
sayBatteryStatusHandler))
#Say Battery State+++++++++++++++++++++++++++++++++++
orca.settings.keyBindingsMap["default"] = myKeyBindings
_______________________________________________
orca-list mailing list
orca-list gnome org
https://mail.gnome.org/mailman/listinfo/orca-list
Visit http://live.gnome.org/Orca for more information on Orca.
The manual is at
http://library.gnome.org/users/gnome-access-guide/nightly/ats-2.html
The FAQ is at http://live.gnome.org/Orca/FrequentlyAskedQuestions
Log bugs and feature requests at http://bugzilla.gnome.org
Find out how to help at http://live.gnome.org/Orca/HowCanIHelp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]