~ubuntu-branches/ubuntu/oneiric/wicd/oneiric-updates

« back to all changes in this revision

Viewing changes to wicd/wicd-client.py

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2008-12-24 17:37:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081224173713-l9o484a46w2bq2eb
Tags: 1.5.7-1
* New upstream release (Closes: #503737)
* debian/control:
  - added some runtime dependencies (not really, but used by most 
    users) to wicd (Closes: #503739)
  - added Conflicts: network-manager (Closes: #509051)
  - added Suggests on pm-utils, since we now also have those
    functionalities
  - update Vcs-* and Maintainer fields to reflect injection into
    PAPT
* debian/postrm added:
  - removes runtime-generated files (Closes: #503747)
* debian/patches:
  - 02-fix_logfile_perms.patch added, sets permissions of 
    /var/log/wicd/wicd.log to root:adm (Closes: #503749)
  - 03-fix_lintian_manpage_warning.patch added, gives a more
    meaningful whatis entry
* debian/rules:
  - get-orig-source target to ease upstream tarball fetch
  - ensure right permissions are set in install target
  - using dh7-style rules
* debian/README.source added
* debian/docs removed
* debian/copyright fixed:
  - added copyright year to in/man*
  - removed useless escaping of '=' in filenames
  - fixed pointer to GPL-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
import wicd.misc as misc
50
50
import wicd.gui as gui
51
51
 
 
52
ICON_AVAIL = True
 
53
USE_EGG = False
52
54
# Import egg.trayicon if we're using an older gtk version
53
 
if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10):
 
55
if not hasattr(gtk, "StatusIcon"):
54
56
    try:
55
57
        import egg.trayicon
56
58
        USE_EGG = True
57
59
    except ImportError:
58
 
        print 'Unable to load wicd-client.py: Missing egg.trayicon module.'
59
 
        sys.exit(1)
60
 
else:
61
 
    USE_EGG = False
 
60
        print 'Unable to load tray icon: Missing egg.trayicon module.'
 
61
        ICON_AVAIL = False
62
62
 
63
63
if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0):
64
64
    import dbus.glib
88
88
language['wired'] = _('Wired Network')
89
89
 
90
90
 
91
 
class TrayIcon:
 
91
class TrayIcon(object):
92
92
    """ Base Tray Icon class.
93
93
    
94
94
    Base Class for implementing a tray icon to display network status.
101
101
            self.tr = self.StatusTrayIconGUI(use_tray)
102
102
        self.icon_info = self.TrayConnectionInfo(self.tr, use_tray, animate)
103
103
        
 
104
    def is_embedded(self):
 
105
        if USE_EGG:
 
106
            raise NotImplementedError
 
107
        else:
 
108
            return self.tr.is_embedded()
 
109
        
104
110
 
105
 
    class TrayConnectionInfo:
 
111
    class TrayConnectionInfo(object):
106
112
        """ Class for updating the tray icon status. """
107
113
        def __init__(self, tr, use_tray=True, animate=True):
108
114
            """ Initialize variables needed for the icon status methods. """
290
296
            return (active, max_gain, last_bytes)
291
297
 
292
298
 
293
 
    class TrayIconGUI:
 
299
    class TrayIconGUI(object):
294
300
        """ Base Tray Icon UI class.
295
301
        
296
302
        Implements methods and variables used by both egg/StatusIcon
346
352
            """ Opens the About Dialog. """
347
353
            dialog = gtk.AboutDialog()
348
354
            dialog.set_name('wicd tray icon')
349
 
            dialog.set_version('1.5')
 
355
            # VERSIONNUMBER
 
356
            dialog.set_version('1.5.7')
350
357
            dialog.set_comments('An icon that shows your network connectivity')
351
358
            dialog.set_website('http://wicd.net')
352
359
            dialog.run()
370
377
                self.gui_win.exit()
371
378
                return True
372
379
        
373
 
 
374
 
    class EggTrayIconGUI(TrayIconGUI):
375
 
        """ Tray Icon for gtk < 2.10.
376
 
        
377
 
        Uses the deprecated egg.trayicon module to implement the tray icon.
378
 
        Since it relies on a deprecated module, this class is only used
379
 
        for machines running versions of GTK < 2.10.
380
 
        
381
 
        """
382
 
        def __init__(self, use_tray=True):
383
 
            """Initializes the tray icon"""
384
 
            TrayIcon.TrayIconGUI.__init__(self, use_tray)
385
 
            self.use_tray = use_tray
386
 
            if not use_tray: 
387
 
                self.toggle_wicd_gui()
388
 
                return
389
 
 
390
 
            self.tooltip = gtk.Tooltips()
391
 
            self.eb = gtk.EventBox()
392
 
            self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
393
 
            self.pic = gtk.Image()
394
 
            self.tooltip.set_tip(self.eb, "Initializing wicd...")
395
 
            self.pic.set_from_file("images/no-signal.png")
396
 
 
397
 
            self.eb.connect('button_press_event', self.tray_clicked)
398
 
            self.eb.add(self.pic)
399
 
            self.tray.add(self.eb)
400
 
            self.tray.show_all()
401
 
 
402
 
        def tray_clicked(self, widget, event):
403
 
            """ Handles tray mouse click events. """
404
 
            if event.button == 1:
405
 
                self.toggle_wicd_gui()
406
 
            elif event.button == 3:
407
 
                self.menu.popup(None, None, None, event.button, event.time)
408
 
 
409
 
        def set_from_file(self, val=None):
410
 
            """ Calls set_from_file on the gtk.Image for the tray icon. """
411
 
            if not self.use_tray: return
412
 
            self.pic.set_from_file(val)
413
 
 
414
 
        def set_tooltip(self, val):
415
 
            """ Set the tooltip for this tray icon.
416
 
            
417
 
            Sets the tooltip for the gtk.ToolTips associated with this
418
 
            tray icon.
419
 
 
420
 
            """
421
 
            if not self.use_tray: return
422
 
            self.tooltip.set_tip(self.eb, val)
423
 
 
424
 
 
425
 
    class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
426
 
        """ Class for creating the wicd tray icon on gtk > 2.10.
427
 
        
428
 
        Uses gtk.StatusIcon to implement a tray icon.
429
 
        
430
 
        """
431
 
        def __init__(self, use_tray=True):
432
 
            TrayIcon.TrayIconGUI.__init__(self, use_tray)
433
 
            self.use_tray = use_tray
434
 
            if not use_tray: 
435
 
                self.toggle_wicd_gui()
436
 
                return
437
 
 
438
 
            gtk.StatusIcon.__init__(self)
439
 
 
440
 
            self.current_icon_path = ''
441
 
            self.set_visible(True)
442
 
            self.connect('activate', self.on_activate)
443
 
            self.connect('popup-menu', self.on_popup_menu)
444
 
            self.set_from_file(wpath.images + "no-signal.png")
445
 
            self.set_tooltip("Initializing wicd...")
446
 
 
447
 
        def on_popup_menu(self, status, button, timestamp):
448
 
            """ Opens the right click menu for the tray icon. """
449
 
            self.menu.popup(None, None, None, button, timestamp)
450
 
 
451
 
        def set_from_file(self, path = None):
452
 
            """ Sets a new tray icon picture. """
453
 
            if not self.use_tray: return
454
 
            if path != self.current_icon_path:
455
 
                self.current_icon_path = path
456
 
                gtk.StatusIcon.set_from_file(self, path)
 
380
    if USE_EGG:
 
381
        class EggTrayIconGUI(TrayIconGUI):
 
382
            """ Tray Icon for gtk < 2.10.
 
383
            
 
384
            Uses the deprecated egg.trayicon module to implement the tray icon.
 
385
            Since it relies on a deprecated module, this class is only used
 
386
            for machines running versions of GTK < 2.10.
 
387
            
 
388
            """
 
389
            def __init__(self, use_tray=True):
 
390
                """Initializes the tray icon"""
 
391
                TrayIcon.TrayIconGUI.__init__(self, use_tray)
 
392
                self.use_tray = use_tray
 
393
                if not use_tray: 
 
394
                    self.toggle_wicd_gui()
 
395
                    return
 
396
    
 
397
                self.tooltip = gtk.Tooltips()
 
398
                self.eb = gtk.EventBox()
 
399
                self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
 
400
                self.pic = gtk.Image()
 
401
                self.tooltip.set_tip(self.eb, "Initializing wicd...")
 
402
                self.pic.set_from_file("images/no-signal.png")
 
403
    
 
404
                self.eb.connect('button_press_event', self.tray_clicked)
 
405
                self.eb.add(self.pic)
 
406
                self.tray.add(self.eb)
 
407
                self.tray.show_all()
 
408
    
 
409
            def tray_clicked(self, widget, event):
 
410
                """ Handles tray mouse click events. """
 
411
                if event.button == 1:
 
412
                    self.toggle_wicd_gui()
 
413
                elif event.button == 3:
 
414
                    self.menu.popup(None, None, None, event.button, event.time)
 
415
    
 
416
            def set_from_file(self, val=None):
 
417
                """ Calls set_from_file on the gtk.Image for the tray icon. """
 
418
                if not self.use_tray: return
 
419
                self.pic.set_from_file(val)
 
420
    
 
421
            def set_tooltip(self, val):
 
422
                """ Set the tooltip for this tray icon.
 
423
                
 
424
                Sets the tooltip for the gtk.ToolTips associated with this
 
425
                tray icon.
 
426
    
 
427
                """
 
428
                if not self.use_tray: return
 
429
                self.tooltip.set_tip(self.eb, val)
 
430
 
 
431
    if hasattr(gtk, "StatusIcon"):
 
432
        class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
 
433
            """ Class for creating the wicd tray icon on gtk > 2.10.
 
434
            
 
435
            Uses gtk.StatusIcon to implement a tray icon.
 
436
            
 
437
            """
 
438
            def __init__(self, use_tray=True):
 
439
                TrayIcon.TrayIconGUI.__init__(self, use_tray)
 
440
                self.use_tray = use_tray
 
441
                if not use_tray: 
 
442
                    self.toggle_wicd_gui()
 
443
                    return
 
444
    
 
445
                gtk.StatusIcon.__init__(self)
 
446
    
 
447
                self.current_icon_path = ''
 
448
                self.set_visible(True)
 
449
                self.connect('activate', self.on_activate)
 
450
                self.connect('popup-menu', self.on_popup_menu)
 
451
                self.set_from_file(wpath.images + "no-signal.png")
 
452
                self.set_tooltip("Initializing wicd...")
 
453
    
 
454
            def on_popup_menu(self, status, button, timestamp):
 
455
                """ Opens the right click menu for the tray icon. """
 
456
                self.menu.popup(None, None, None, button, timestamp)
 
457
    
 
458
            def set_from_file(self, path = None):
 
459
                """ Sets a new tray icon picture. """
 
460
                if not self.use_tray: return
 
461
                if path != self.current_icon_path:
 
462
                    self.current_icon_path = path
 
463
                    gtk.StatusIcon.set_from_file(self, path)
457
464
 
458
465
 
459
466
def usage():
 
467
    # VERSIONNUMBER
460
468
    """ Print usage information. """
461
469
    print """
462
 
wicd 1.50
 
470
wicd 1.5.7
463
471
wireless (and wired) connection daemon front-end.
464
472
 
465
473
Arguments:
527
535
    print 'Loading...'
528
536
    connect_to_dbus()
529
537
 
530
 
    if not use_tray:
 
538
    if not use_tray or not ICON_AVAIL:
531
539
        the_gui = gui.appGui()
532
540
        the_gui.standalone = True
533
541
        mainloop = gobject.MainLoop()