~zedtux/naturalscrolling/trunk

« back to all changes in this revision

Viewing changes to naturalscrolling/NaturalscrollingIndicator.py

  • Committer: Charalampos Emmanouilidis
  • Date: 2012-02-19 07:36:16 UTC
  • mfrom: (32.1.9)
  • Revision ID: git-v1:500b295ff3100528b352e6e5e7a364495946e39a
merge from 0.4 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import sys
3
3
import os
4
4
import gtk
5
 
import gobject
6
5
import appindicator
7
6
 
8
7
from naturalscrolling_lib import naturalscrollingconfig
17
16
class NaturalscrollingIndicator:
18
17
    
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
29
27
        )
30
 
        
 
28
        self.settings = GConfSettings()
 
29
 
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")
34
33
        
35
34
        self.menu_setup()
36
35
        self.ind.set_menu(self.menu)
37
 
        
38
 
       
 
36
 
39
37
    def get_slave_pointer(self):
40
38
        xinput_reader = SwissKnife.XinputReader()
41
39
        xinput = SwissKnife.Xinput()
42
40
 
43
 
        #return xinput_reader.get_slave_pointer(xinput.list())[0]
44
 
        return xinput_reader.get_slave_pointer(xinput.list())
45
 
 
 
41
        return xinput_reader.get_slave_pointer(xinput.list())[0]
46
42
 
47
43
    def menu_setup(self):
48
44
        self.menu = gtk.Menu()
49
45
        
50
46
        #natural scrolling
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()
 
50
        )
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()
62
61
 
63
62
        self.menu_item_preferences = gtk.MenuItem(_('Preferences'))
64
63
        self.menu_item_start_at_login = gtk.CheckMenuItem(_('Start at login'))
65
 
       
 
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)
94
94
 
95
 
 
96
 
        if os.path.isfile(naturalscrollingconfig.get_auto_start_file_path()):
97
 
            self.menu_item_start_at_login.set_active(True)
98
 
 
99
 
        self.enable_natural_scrolling(
100
 
            self.settings.key(GCONF_NATURAL_SCROLLING_KEY).is_enable()
101
 
        )
102
 
       
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()
106
 
            
107
 
            if enabled == True:
108
 
                map = map.replace('4 5', '5 4')
109
 
                
110
 
            else:
111
 
                map = map.replace('5 4', '4 5')
112
 
            
113
 
            os.system('xinput set-button-map %s %s' %(id, map))
114
 
 
 
96
        """
 
97
        Global method to apply or not Natural Scrolling
 
98
        """
 
99
        map = os.popen('xinput get-button-map %s' % self.mouseid).read().strip()
 
100
        
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)
118
106
        else:
 
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)
121
 
 
122
 
        self.ind.set_status(appindicator.STATUS_ATTENTION)
 
111
        
123
112
        self.menu_item_natural_scrolling.set_active(enabled)
124
 
            
125
 
        return False
 
113
        
 
114
        os.system('xinput set-button-map %s %s' %(self.mouseid, map))
126
115
 
127
116
    def on_natural_scrolling_toggled(self, widget, data=None):
128
117
        """