17
16
class NaturalscrollingIndicator:
19
18
def __init__(self):
20
self.settings = GConfSettings()
21
19
self.AboutDialog = AboutNaturalscrollingDialog
22
20
self.mouseids = self.get_slave_pointer()
23
21
self.pingfrequency = 1 # in seconds
27
25
"natural-scrolling-status-not-activated",
28
26
appindicator.CATEGORY_APPLICATION_STATUS
28
self.settings = GConfSettings()
31
30
media_path = "%s/media/" % naturalscrollingconfig.get_data_path()
32
31
self.ind.set_icon_theme_path(media_path)
33
32
self.ind.set_attention_icon("natural-scrolling-status-activated")
36
35
self.ind.set_menu(self.menu)
39
37
def get_slave_pointer(self):
40
38
xinput_reader = SwissKnife.XinputReader()
41
39
xinput = SwissKnife.Xinput()
43
#return xinput_reader.get_slave_pointer(xinput.list())[0]
44
return xinput_reader.get_slave_pointer(xinput.list())
41
return xinput_reader.get_slave_pointer(xinput.list())[0]
47
43
def menu_setup(self):
48
44
self.menu = gtk.Menu()
51
47
self.menu_item_natural_scrolling = gtk.CheckMenuItem(_('Natural Scrolling'))
48
self.enable_natural_scrolling(
49
self.settings.key(GCONF_NATURAL_SCROLLING_KEY).is_enable()
52
51
self.menu_item_natural_scrolling.connect('activate', self.on_natural_scrolling_toggled)
53
52
self.settings.server().fire_me_when_update_on_key(GCONF_NATURAL_SCROLLING_KEY, self.enable_natural_scrolling)
54
53
self.menu_item_natural_scrolling.show()
63
62
self.menu_item_preferences = gtk.MenuItem(_('Preferences'))
64
63
self.menu_item_start_at_login = gtk.CheckMenuItem(_('Start at login'))
64
if os.path.isfile(naturalscrollingconfig.get_auto_start_file_path()):
65
self.menu_item_start_at_login.set_active(True)
66
66
self.menu_item_start_at_login.connect("activate", self.on_start_at_login_clicked)
67
67
self.menu_sub.append(self.menu_item_start_at_login)
68
68
self.menu_item_preferences.set_submenu(self.menu_sub)
92
92
self.menu.append(self.menu_item_seperator2)
93
93
self.menu.append(self.menu_item_quit)
96
if os.path.isfile(naturalscrollingconfig.get_auto_start_file_path()):
97
self.menu_item_start_at_login.set_active(True)
99
self.enable_natural_scrolling(
100
self.settings.key(GCONF_NATURAL_SCROLLING_KEY).is_enable()
103
95
def enable_natural_scrolling(self, enabled):
104
for id in self.mouseids:
105
map = os.popen('xinput get-button-map %s' % id).read().strip()
108
map = map.replace('4 5', '5 4')
111
map = map.replace('5 4', '4 5')
113
os.system('xinput set-button-map %s %s' %(id, map))
97
Global method to apply or not Natural Scrolling
99
map = os.popen('xinput get-button-map %s' % self.mouseid).read().strip()
115
101
if enabled == True:
102
map = map.replace('4 5', '5 4')
103
map = map.replace('6 7', '7 6')
116
104
self.settings.key(GCONF_NATURAL_SCROLLING_KEY).enable()
117
105
self.ind.set_status(appindicator.STATUS_ATTENTION)
107
map = map.replace('5 4', '4 5')
108
map = map.replace('7 6', '6 7')
119
109
self.settings.key(GCONF_NATURAL_SCROLLING_KEY).disable()
120
110
self.ind.set_status(appindicator.STATUS_ACTIVE)
122
self.ind.set_status(appindicator.STATUS_ATTENTION)
123
112
self.menu_item_natural_scrolling.set_active(enabled)
114
os.system('xinput set-button-map %s %s' %(self.mouseid, map))
127
116
def on_natural_scrolling_toggled(self, widget, data=None):