~ubuntu-branches/ubuntu/natty/mago/natty

« back to all changes in this revision

Viewing changes to mago/application/deskex.py

  • Committer: Bazaar Package Importer
  • Author(s): Ara Pulido
  • Date: 2010-04-14 14:05:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414140534-grv0bwv9wv97khir
Tags: 0.2-0ubuntu1
* Mago tests updated for Lucid
  + Fixes arguments handling (LP: #562965)
  + Fixes seahorse tests (LP: #552618)
  + Fixes ubuntu-menu tests (LP: #551492)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    indicate = None
15
15
 
16
16
class IndicatorApplet(Application):
 
17
    """
 
18
    Indicator Applet manages the new indicator messages applet
 
19
    """
17
20
    IA_TOPLEVEL = "embindicator-applet"
18
21
    def __init__(self):
19
22
        Application.__init__(self, 'indicator-applet')
24
27
        pass
25
28
    
26
29
    def add_server(self, desktop_file):
 
30
        """
 
31
        Add a new server to the indicator applet.
 
32
 
 
33
        @type desktop_file: string
 
34
        @param desktop_file: The path to the file describing the server.
 
35
            Example of format:
 
36
 
 
37
            [Desktop Entry]
 
38
            Encoding=UTF-8
 
39
            Name=Phony Internet Messenger
 
40
            GenericName=Internet Messenger
 
41
            Comment=Send instant messages over phony protocols
 
42
            Exec=phony
 
43
            StartupNotify=true
 
44
            Terminal=false
 
45
            Type=Application
 
46
            Categories=Network;InstantMessaging;
 
47
 
 
48
        """
 
49
 
27
50
        if not self.server:
28
51
            try:
29
52
                self.server = indicate.indicate_server_ref_default()
37
60
            gtk.main_iteration()
38
61
 
39
62
    def show_indicator(self, sender):
 
63
        """
 
64
        It shows a basic indicator without needing to provide a desktop file
 
65
 
 
66
        @type sender: string
 
67
        @param sender: The name of the indicator to be shown in the applet.
 
68
        """
40
69
        def _timeout_cb():
41
70
            gtk.main_quit()
42
71
            return False
54
83
        gtk.main()
55
84
 
56
85
    def capture_applet_icon(self):
 
86
        """
 
87
        It captures a screenshot of the indicator applet icon
 
88
 
 
89
        @return: The path of the file containing the screenshot
 
90
        """
57
91
        x, y, w, h = ldtp.getobjectsize(self.TOP_PANEL, self.IA_TOPLEVEL)
58
92
        
59
93
        ldtp_one_six = version.StrictVersion('1.6.0')
71
105
        return screeny
72
106
 
73
107
    def is_server_shown(self, sender, already_shown=True):
74
 
        # We need a way to distinguish between the normal menu and the indicator-applet menu
75
 
        # Workaround in the mean time:
76
 
        # Set already_shown as True, if there is already a menu with the same name
77
 
        # (in that case we will look for mnuServer1
78
 
        # or to False, if there is no already a menu with the same name
 
108
        """
 
109
        It says if a server is being shown or not
 
110
 
 
111
        @type sender: string
 
112
        @param sender: The name of the Indicator server to check
 
113
 
 
114
        @type already_shown: boolean
 
115
        @param already_shown: We need a way to distinguish between the normal menu and the indicator-applet menu
 
116
            Workaround in the mean time:
 
117
            Set already_shown as True, if there is already a menu with the same name
 
118
            (in that case we will look for mnuServer1
 
119
            or to False, if there is no already a menu with the same name
 
120
 
 
121
        @return: True, if the server is being shown; False, otherwise.
 
122
        """
79
123
        if already_shown:
80
124
            return ldtp.objectexist(self.TOP_PANEL, 
81
125
                    'mnu' + sender.replace(' ','') + '1')
84
128
                    'mnu' + sender.replace(' ',''))
85
129
            
86
130
    def is_indicator_shown(self, sender):
 
131
        """
 
132
        It says if an indicator is being shown or not
 
133
 
 
134
        @type sender: string
 
135
        @param sender: The name of the indicator to check
 
136
        
 
137
        @return: True, if the indicator is being shown; False, otherwise
 
138
        """
87
139
        return ldtp.objectexist(self.TOP_PANEL, 
88
140
                    'mnu' + sender.replace(' ',''))
89
141
 
90
142
    def select_indicator(self, sender):
 
143
        """
 
144
        It selects the menu item of an indicator 
 
145
 
 
146
        @type sender: string
 
147
        @param sender: The name of the indicator to select 
 
148
        """
91
149
        ldtp.selectmenuitem(self.TOP_PANEL, 'mnu' + sender.replace(' ',''))
92
150
 
93
151
    def select_server(self, sender, already_shown=True):
94
 
        # We need a way to distinguish between the normal menu and the indicator-applet menu
95
 
        # Workaround in the mean time:
96
 
        # Set already_shown as True, if there is already a menu with the same name
97
 
        # (in that case we will look for mnuServer1
98
 
        # or to False, if there is no already a menu with the same name
 
152
        """
 
153
        It selects the menu item of a server indicator 
 
154
 
 
155
        @type sender: string
 
156
        @param sender: The name of the Indicator server to select 
 
157
 
 
158
        @type already_shown: boolean
 
159
        @param already_shown: We need a way to distinguish between the normal menu and the indicator-applet menu
 
160
            Workaround in the mean time:
 
161
            Set already_shown as True, if there is already a menu with the same name
 
162
            (in that case we will look for mnuServer1
 
163
            or to False, if there is no already a menu with the same name
 
164
        """
 
165
 
99
166
        if already_shown:
100
167
            ldtp.selectmenuitem(self.TOP_PANEL, 'mnu' + sender.replace(' ',''), + '1')
101
168
        else:
159
226
        sleep(1)
160
227
 
161
228
class NotifyOSD(Application):
 
229
    """
 
230
    NotifyOSD class manages the notifications produced by notify-osd
 
231
    """
 
232
 
162
233
    def __init__(self):
163
234
        self.focus_desktop = False
164
235
        self.screenshots = []
187
258
                os.remove(screenshot)
188
259
 
189
260
    def notify(self, summary, body="", icon=None):
190
 
        n = pynotify.Notification (summary, body, icon)
191
 
        n.show ()
 
261
        """
 
262
        Giving a summary, body and icon, it creates a notification bubble
 
263
 
 
264
        @type summary: string
 
265
        @param summary: The header of the notification
 
266
 
 
267
        @type body: string
 
268
        @param body: The text to show as body of the notification
 
269
 
 
270
        @type icon: string
 
271
        @param icon: The name of the icon to show
 
272
        """
 
273
        n = pynotify.Notification (summary, body, icon)
 
274
        n.show ()
192
275
 
193
276
    def notify_synchronous(self, summary, body="", icon=None, value=-1):
194
 
        n = pynotify.Notification (summary, body, icon)
 
277
        """
 
278
        Giving a summary, body, icon and value it creates a confirmation bubble
 
279
 
 
280
        @type summary: string
 
281
        @param summary: The header of the notification
 
282
 
 
283
        @type body: string
 
284
        @param body: The text to show as body of the notification
 
285
 
 
286
        @type icon: string
 
287
        @param icon: The name of the icon to show
 
288
 
 
289
        @type value: int
 
290
        @param value: The value of the quantity of the confirmation bubble (i.e. volume)
 
291
        """
 
292
        n = pynotify.Notification (summary, body, icon)
195
293
        n.set_hint("synchronous", "volume")
196
294
        n.set_hint("value", value)
197
 
        n.show ()
 
295
        n.show ()
198
296
 
199
297
    def grab_image_and_wait(self, summary, timeOut=30):
 
298
        """
 
299
        It waits for a notification to appear and grabs a screenshot
 
300
 
 
301
        @type summary: string
 
302
        @param summary: The summary of the notification to look for
 
303
 
 
304
        @type timeOut: int
 
305
        @param timeOut: The number of seconds to wait for the notification to appear
 
306
 
 
307
        @return: List with the time elapsed and the path to the screenshot
 
308
        """
200
309
        ldtp.waittillguiexist(summary, guiTimeOut=timeOut)
201
310
        start_time = time()
202
311
        sleep(1)
207
316
 
208
317
        if ldtp_current < ldtp_one_six:
209
318
            screenshot = \
210
 
                ldtputils.imagecapture(outFile=tempfile.mktemp('.png', 'nosd_'),
 
319
                ldtputils.imagecapture(out_file=tempfile.mktemp('.png', 'nosd_'),
211
320
                                   x=x+3, y=y+3, 
212
321
                                   resolution1=w-6, 
213
322
                                   resolution2=h-6)
214
323
        else:
215
324
            screenshot = \
216
 
                ldtputils.imagecapture(outFile=tempfile.mktemp('.png', 'nosd_'),
 
325
                ldtputils.imagecapture(out_file=tempfile.mktemp('.png', 'nosd_'),
217
326
                                   x=x+3, y=y+3, 
218
327
                                   width=w-6, 
219
328
                                   height=h-6)
224
333
        return (end_time, screenshot)
225
334
 
226
335
    def get_extents(self, summary, wait=False):
 
336
        """
 
337
        It gets the limits of the bubble
 
338
 
 
339
        @type summary: string
 
340
        @param summary: The summary of the bubble to get the size
 
341
 
 
342
        @return: (x, y, width, height)
 
343
        """
227
344
        if wait:
228
345
            exists = ldtp.waittillguiexist(summary)            
229
346
        else: