3
import gnomeapplet, gtk, gtk.gdk, gconf, gnomevfs, gobject, bonobo, ORBit
4
from gettext import gettext as _
6
import colorblind, colorblind.ui
7
from colorblind.ui.About import show_about
8
from colorblind.ui.ColorblindPreferencesUI import show_preferences
9
from colorblind.ColorblindAppletPreferences import ColorblindAppletPreferences
10
from colorblind.Keybinder import get_colorblind_keybinder_on_off, get_colorblind_keybinder_switch
11
from colorblind.ui.WindowUI import WindowUI
13
_magnifierAvailable = False
16
ORBit.load_typelib ('Accessibility')
17
ORBit.load_typelib ('GNOME_Magnifier')
18
import GNOME.Magnifier
19
_magnifierAvailable = True
23
class ColorblindApplet(object):
27
def __init__(self, applet):
28
if ColorblindApplet.__instance == None:
29
ColorblindApplet.__instance = self
35
self.zoomerPBag = None
39
self.start_query_id = 0
41
self.prefs = ColorblindAppletPreferences(applet)
43
gtk.window_set_default_icon_name("colorblind-applet")
45
self.ui = WindowUI(applet, self.prefs)
46
self.ui.connect('show-preferences', self.on_preferences, None)
47
self.ui.connect('show-about', self.on_about, None)
49
self.set_up_ui_signals ()
51
# Monitor global shortcut binding
52
get_colorblind_keybinder_on_off().connect('activated', self.on_keybinding_button_press, "on_off")
53
get_colorblind_keybinder_switch().connect('activated', self.on_keybinding_button_press, "switch")
54
self.applet.connect('change-background', self.on_change_background)
56
self.image = gtk.Image()
57
self.applet.add (self.image)
58
self.applet.setup_menu_from_file (
59
colorblind.SHARED_DATA_DIR, "Colorblind_Applet.xml",
61
("About", self.on_about),
62
("Prefs", self.on_preferences),
64
self.on_change_size (self.applet)
65
self.applet.show_all()
68
return ColorblindApplet.__instance
69
get_instance = staticmethod(get_instance)
71
def on_keyboard_shortcut (self, sender, qstring, shortcut):
72
for modctx in self.module_list:
73
if not modctx.enabled:
76
match = modctx.module.on_key_press(qstring, shortcut)
78
self.on_match_selected(sender, qstring, match)
81
def on_about (self, component, verb):
82
show_about(self.applet)
84
def on_preferences (self, component, verb):
85
show_preferences(self)
87
def active_actual_filter (self):
88
if self.enabled == True:
89
filter = colorblind.GCONF_CLIENT.get_int(colorblind.GCONF_COLORBLIND_FILTER)
90
bonobo.pbclient_set_short (self.zoomerPBag, "color-blind-filter", filter)
92
def enable_disable_filters (self):
93
global _magnifierAvailable
95
if _magnifierAvailable:
96
if self.enabled == True:
99
self.magnifier.clearAllZoomRegions ()
100
self.magnifier.dispose ()
101
self.magnifier = None
106
bonobo.pbclient_set_short (self.zoomerPBag, "color-blind-filter", 0)
108
self.shutdown = False
109
save_actual_filter = colorblind.GCONF_CLIENT.get_bool (colorblind.GCONF_CHECK_DEFAULT)
110
if save_actual_filter:
111
af = colorblind.GCONF_CLIENT.get_int (colorblind.GCONF_COLORBLIND_FILTER)
112
colorblind.GCONF_CLIENT.set_int (colorblind.GCONF_DEFAULT_FILTER, af)
114
self.magnifier = bonobo.get_object ("OAFIID:GNOME_Magnifier_Magnifier:0.9", "GNOME/Magnifier/Magnifier")
115
magPBag = self.magnifier.getProperties ()
116
tdb = magPBag.getValue ("target-display-bounds").value ()
117
if tdb.x1 == 0 and tdb.y1 == 0 and tdb.x2 == 0 and tdb.y2 == 0:
118
bonobo.pbclient_set_long (magPBag, "crosswire-size", 0)
119
self.zoomer = self.magnifier.createZoomRegion (1, 1, GNOME.Magnifier.RectBounds (0, 0, gtk.gdk.screen_width (), gtk.gdk.screen_height ()), GNOME.Magnifier.RectBounds (0, 0, gtk.gdk.screen_width (), gtk.gdk.screen_height ()))
120
self.magnifier.addZoomRegion (self.zoomer)
122
if self.zoomer == None:
123
self.zoomer = self.magnifier.getZoomRegions ()
124
self.zoomer = self.zoomer[0]
125
self.zoomerPBag = self.zoomer.getProperties ()
126
bonobo.pbclient_set_boolean (self.zoomerPBag, "draw-cursor", False)
127
cb_filter = colorblind.GCONF_CLIENT.get_int(colorblind.GCONF_DEFAULT_FILTER)
128
bonobo.pbclient_set_short (self.zoomerPBag, "color-blind-filter", cb_filter)
131
def next_filter (self):
133
cb_filter = colorblind.GCONF_CLIENT.get_int (colorblind.GCONF_COLORBLIND_FILTER)
134
cb_filter = ((cb_filter + 1) % 9)
137
colorblind.GCONF_CLIENT.set_int(colorblind.GCONF_COLORBLIND_FILTER, cb_filter)
138
bonobo.pbclient_set_short (self.zoomerPBag, "color-blind-filter", cb_filter)
140
def on_keybinding_button_press(self, widget, str):
141
print "Keybinding activated"
143
self.enable_disable_filters ()
144
elif str == "switch":
147
def on_keybinding_changed(self, binder, bound):
148
# FIXME: provide visual clue when not bound
149
# FIXME: should be used in the pref window
152
def set_up_ui_signals (self):
153
self.applet.connect('change-size', lambda applet, orient: self.on_change_size(applet))
155
def set_image_from_file (self, filename, size):
156
# We use an intermediate pixbuf to scale the image
157
if self.applet.get_orient in [gnomeapplet.ORIENT_DOWN, gnomeapplet.ORIENT_UP]:
158
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (filename, -1, size)
160
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (filename, size, -1)
161
self.image.set_from_pixbuf (pixbuf)
163
def on_change_size (self, applet):
164
# FIXME: This is ugly, but i don't know how to get it right
165
image_name = "colorblind-applet"
167
if applet.get_size() <= 36:
172
s = applet.get_size()-12
174
self.set_image_from_file (join(colorblind.ART_DATA_DIR, image_name), s)
176
def on_change_background (self, widget, background, colour, pixmap):
177
if background == gnomeapplet.NO_BACKGROUND or background == gnomeapplet.PIXMAP_BACKGROUND:
178
copy = self.applet.get_style().copy()
179
copy.bg_pixmap[gtk.STATE_NORMAL] = pixmap
180
copy.bg_pixmap[gtk.STATE_INSENSITIVE] = pixmap
181
self.applet.set_style(copy)
182
elif background == gnomeapplet.COLOR_BACKGROUND:
183
self.applet.modify_bg(gtk.STATE_NORMAL, colour)
185
def active_actual_filter ():
186
ColorblindApplet.get_instance ().active_actual_filter ()
b'\\ No newline at end of file'