~marmuta/onboard/onboard-ignore-bad-translations

« back to all changes in this revision

Viewing changes to Onboard/KeyCommon.py

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Fumanti
  • Date: 2010-08-20 17:11:12 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100820171112-dofabf23w2x6hgsz
Tags: 0.94.0-0ubuntu1
  * Feature freeze exception request to update to new release (LP: #621374)
  * Make onboard follow keyboard layout changes (LP: 526791, LP: 65626)
  * Save onboard geometry on quit instead on configure-events (LP: #596248)
  * Improve handling of missing dependency for the clicks (LP: #524148):
      - Use soname instead of linker for libXi in X11.py
      - Add dependency on libxi6 to break package build if necessary
      - Get current version of soname for libx11 from environment
      - Respect DISPLAY environment variable in KeyboardGTK.py
      - Add debian/README.source with info about libxi6 and libx11
  * Do not crash if icon of IconPalette is missing (LP: #538109)
  * Fix Menu key, Delete key and Insert key
  * Qualify the import of our X11 module
  * Make strings in our X11 module translatable
  * Some cleanup by remove trailing spaces
  * debian/control:
      - Update email address of original maintainer
      - Set minimal required version for python-virtkey to 0.60.0
      - Add libxi6 to Build-Depends
      - Add libxi6 and libx11-6 to Depends
  * debian/copyright:
      - Add hosting site
      - Add section with upstream authors
      - Update license information to GPL 3
  * debian/watch:
      - Add watch file
  * debian/README.source
      - Add README.source file

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
 
23
23
class KeyCommon:
24
 
    """ a library-independent key class. Specific 
 
24
    """ a library-independent key class. Specific
25
25
        rendering options are stored elsewhere. """
26
26
 
27
27
    action_type = None
75
75
                self.label_index = 1
76
76
            else:
77
77
                self.label_index = 0
78
 
        
 
78
 
79
79
        elif mods[128] and self.labels[3]:
80
80
            self.label_index = 3
81
 
        
 
81
 
82
82
        elif mods[2]:
83
83
            if self.labels[1]:
84
84
                self.label_index = 1
98
98
    """ class for those tabs up the right hand side """
99
99
    def __init__(self, keyboard, width, pane):
100
100
        KeyCommon.__init__(self)
101
 
        
 
101
 
102
102
        self.pane = pane
103
103
        self.width = width
104
104
        self.keyboard = keyboard
106
106
        self.sticky = True
107
107
 
108
108
    def pointWithinKey(self, widget, mouseX, mouseY):
109
 
        """ does exactly what the name says - checks for the 
 
109
        """ does exactly what the name says - checks for the
110
110
            mouse within a key. returns bool. """
111
 
        if (mouseX > self.keyboard.kbwidth 
112
 
            and mouseY > self.height*self.index + BASE_PANE_TAB_HEIGHT 
 
111
        if (mouseX > self.keyboard.kbwidth
 
112
            and mouseY > self.height*self.index + BASE_PANE_TAB_HEIGHT
113
113
            and mouseY < self.height*(self.index + 1)+ BASE_PANE_TAB_HEIGHT):
114
114
            return True
115
115
        else:
119
119
        """ paints the TabKey object """
120
120
        self.height = (self.keyboard.height / len(self.keyboard.panes)) - (BASE_PANE_TAB_HEIGHT / len(self.keyboard.panes))
121
121
        self.index = self.keyboard.panes.index(self.pane)
122
 
    
123
 
    
 
122
 
 
123
 
124
124
class BaseTabKeyCommon(KeyCommon):
125
125
 
126
126
    pane = None
129
129
    """ class for the tab that brings you to the base pane """
130
130
    def __init__(self, keyboard, width):
131
131
        KeyCommon.__init__(self)
132
 
       
 
132
 
133
133
        self.width = width
134
134
        self.keyboard = keyboard
135
135
        self.modifier = None # what for?
136
136
        self.sticky = False
137
137
 
138
138
    def pointWithinKey(self, widget, mouseX, mouseY):
139
 
        if (mouseX > self.keyboard.kbwidth 
 
139
        if (mouseX > self.keyboard.kbwidth
140
140
            and mouseY < BASE_PANE_TAB_HEIGHT):
141
141
            return True
142
142
        else:
143
143
            return False
144
144
 
145
 
   
 
145
 
146
146
    def paint(self,context=None):
147
147
        """Don't draw anything for this key"""
148
148
        pass
149
149
 
150
150
class LineKeyCommon(KeyCommon):
151
151
    """ class for keyboard buttons made of lines """
152
 
    
 
152
 
153
153
    name = None
154
154
    """ Unique identifier for the key """
155
155
 
159
159
        self.coordList = coordList
160
160
        self.fontCoord = fontCoord
161
161
        self.rgba = rgba
162
 
        
 
162
 
163
163
    def pointCrossesEdge(self, x, y, xp1, yp1, sMouseX, sMouseY):
164
164
        """ Checks whether a point, when scanning from top left crosses edge"""
165
 
        return ((((y <= sMouseY) and ( sMouseY < yp1)) or  
166
 
            ((yp1 <= sMouseY) and (sMouseY < y))) and 
 
165
        return ((((y <= sMouseY) and ( sMouseY < yp1)) or
 
166
            ((yp1 <= sMouseY) and (sMouseY < y))) and
167
167
            (sMouseX < (xp1 - x) * (sMouseY - y) / (yp1 - y) + x))
168
 
        
169
 
    
 
168
 
 
169
 
170
170
    def point_within_key(self, location, scale):
171
171
        """Checks whether point is within shape.
172
172
           Currently does not bother trying to work out
179
179
        c = 2
180
180
        coordLen = len(self.coordList)
181
181
        within = False
182
 
        
 
182
 
183
183
        sMouseX = location[0] / scale[0]
184
184
        sMouseY = location[1] / scale[1]
185
 
        
 
185
 
186
186
        while not c == coordLen:
187
187
 
188
188
            xp1 = self.coordList[c+1]
189
189
            yp1 = self.coordList[c+2]
190
190
            try:
191
191
                if self.coordList[c] == "L":
192
 
                    within = (self.pointCrossesEdge(x,y,xp1,yp1,sMouseX,sMouseY) ^ within) # a xor        
 
192
                    within = (self.pointCrossesEdge(x,y,xp1,yp1,sMouseX,sMouseY) ^ within) # a xor
193
193
                    c +=3
194
194
                    x = xp1
195
195
                    y = yp1
196
 
                        
197
 
                else:   
 
196
 
 
197
                else:
198
198
                    xp2 = self.coordList[c+3]
199
199
                    yp2 = self.coordList[c+4]
200
200
                    xp3 = self.coordList[c+5]
201
201
                    yp3 = self.coordList[c+6]
202
 
                    within = (self.pointCrossesEdge(x,y,xp3,yp3,sMouseX,sMouseY) ^ within) # a xor 
 
202
                    within = (self.pointCrossesEdge(x,y,xp3,yp3,sMouseX,sMouseY) ^ within) # a xor
203
203
                    x = xp3
204
204
                    y = yp3
205
205
                    c += 7
208
208
                print strerror
209
209
                print "x: %f, y: %f, yp1: %f" % (x,y,yp1)
210
210
        return within
211
 
        
 
211
 
212
212
    def paint(self, scale, context = None):
213
 
        """ 
 
213
        """
214
214
        This class is quite hard to abstract, so all of its
215
 
        processing lies now in the UI-dependent class. 
 
215
        processing lies now in the UI-dependent class.
216
216
        """
217
 
               
 
217
 
218
218
    def paint_font(self, scale):
219
 
        KeyCommon.paint_font(self, scale, 
 
219
        KeyCommon.paint_font(self, scale,
220
220
            (self.coordList[0], self.coordList[1]))
221
 
            
222
 
    
223
 
    
 
221
 
 
222
 
 
223
 
224
224
class RectKeyCommon(KeyCommon):
225
225
    """ An abstract class for rectangular keyboard buttons """
226
226
 
241
241
        self.name = name
242
242
        self.location = location
243
243
        self.geometry = geometry
244
 
        self.rgba = rgba      
245
 
      
 
244
        self.rgba = rgba
 
245
 
246
246
    def point_within_key(self, point_location, scale):
247
247
        return  point_location[0] / scale[0] > self.location[0] \
248
248
            and (point_location[0] / scale[0]
250
250
            and point_location[1] / scale[1] > self.location[1] \
251
251
            and (point_location[1] / scale[1]
252
252
                < (self.location[1] + self.geometry[1]))
253
 
    
 
253
 
254
254
    def paint(self, scale, context = None):
255
255
        pass