mirror of
https://github.com/gryf/wicd.git
synced 2026-02-17 06:35:45 +01:00
experimental branch:
- Tray icon fixes from trunk - Handle possible failure in wpactrl - Format some docstrings
This commit is contained in:
@@ -394,7 +394,12 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
MAX_DISCONNECTED_TIME = 3
|
MAX_DISCONNECTED_TIME = 3
|
||||||
disconnected_time = 0
|
disconnected_time = 0
|
||||||
while (time.time() - auth_time) < MAX_TIME:
|
while (time.time() - auth_time) < MAX_TIME:
|
||||||
status = wpa.request("STATUS").split("\n")
|
try:
|
||||||
|
status = wpa.request("STATUS").split("\n")
|
||||||
|
except:
|
||||||
|
print "wpa_supplicant status query failed."
|
||||||
|
return False
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print 'wpa_supplicant ctrl_interface status query is %s' % str(status)
|
print 'wpa_supplicant ctrl_interface status query is %s' % str(status)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 1999-2006 Keith Dart <keith@kdart.com>
|
# Copyright (C) 1999-2006 Keith Dart <keith@kdart.com>
|
||||||
# Copyright (C) 2008 Dan O'Reilly <oreilldf@gmail.com>
|
# Copyright (C) 2008 Dan O'Reilly <oreilldf@gmail.com>
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Managing logfile rotation. A ManagedLog object is a file-like object that
|
Managing logfile rotation. A ManagedLog object is a file-like object that
|
||||||
rotates itself when a maximum size is reached.
|
rotates itself when a maximum size is reached.
|
||||||
|
|
||||||
@@ -30,8 +32,11 @@ class SizeError(IOError):
|
|||||||
|
|
||||||
class LogFile(file):
|
class LogFile(file):
|
||||||
"""LogFile(name, [mode="w"], [maxsize=360000])
|
"""LogFile(name, [mode="w"], [maxsize=360000])
|
||||||
Opens a new file object. After writing <maxsize> bytes a SizeError will be
|
|
||||||
raised. """
|
Opens a new file object. After writing <maxsize> bytes a SizeError
|
||||||
|
will be raised.
|
||||||
|
|
||||||
|
"""
|
||||||
def __init__(self, name, mode="a", maxsize=360000):
|
def __init__(self, name, mode="a", maxsize=360000):
|
||||||
super(LogFile, self).__init__(name, mode)
|
super(LogFile, self).__init__(name, mode)
|
||||||
self.maxsize = maxsize
|
self.maxsize = maxsize
|
||||||
@@ -79,13 +84,17 @@ class LogFile(file):
|
|||||||
return rotate(self)
|
return rotate(self)
|
||||||
|
|
||||||
def note(self, text):
|
def note(self, text):
|
||||||
"""Writes a specially formated note text to the file.The note starts
|
"""Writes a specially formated note text to the file.
|
||||||
with the string '\\n#*=' so you can easily filter them. """
|
|
||||||
|
The note starts with the string '\\n#*=' so you can easily filter them.
|
||||||
|
|
||||||
|
"""
|
||||||
self.write("\n#*===== %s =====\n" % (text,))
|
self.write("\n#*===== %s =====\n" % (text,))
|
||||||
|
|
||||||
|
|
||||||
class ManagedLog(object):
|
class ManagedLog(object):
|
||||||
"""ManagedLog(name, [maxsize=360000], [maxsave=9])
|
"""ManagedLog(name, [maxsize=360000], [maxsave=9])
|
||||||
|
|
||||||
A ManagedLog instance is a persistent log object. Write data with the
|
A ManagedLog instance is a persistent log object. Write data with the
|
||||||
write() method. The log size and rotation is handled automatically.
|
write() method. The log size and rotation is handled automatically.
|
||||||
|
|
||||||
|
|||||||
@@ -52,18 +52,15 @@ from wicd import gui
|
|||||||
from wicd import dbusmanager
|
from wicd import dbusmanager
|
||||||
|
|
||||||
ICON_AVAIL = True
|
ICON_AVAIL = True
|
||||||
|
USE_EGG = False
|
||||||
# Import egg.trayicon if we're using an older gtk version
|
# Import egg.trayicon if we're using an older gtk version
|
||||||
if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10):
|
if not hasattr(gtk, "StatusIcon"):
|
||||||
class Dummy(object): pass
|
|
||||||
gtk.StatusIcon = Dummy
|
|
||||||
try:
|
try:
|
||||||
import egg.trayicon
|
import egg.trayicon
|
||||||
USE_EGG = True
|
USE_EGG = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print 'Unable to load tray icon: Missing egg.trayicon module.'
|
print 'Unable to load tray icon: Missing egg.trayicon module.'
|
||||||
ICON_AVAIL = False
|
ICON_AVAIL = False
|
||||||
else:
|
|
||||||
USE_EGG = False
|
|
||||||
|
|
||||||
misc.RenameProcess("wicd-client")
|
misc.RenameProcess("wicd-client")
|
||||||
|
|
||||||
@@ -534,91 +531,93 @@ class TrayIcon(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class EggTrayIconGUI(TrayIconGUI):
|
if USE_EGG:
|
||||||
""" Tray Icon for gtk < 2.10.
|
class EggTrayIconGUI(TrayIconGUI):
|
||||||
|
""" Tray Icon for gtk < 2.10.
|
||||||
|
|
||||||
Uses the deprecated egg.trayicon module to implement the tray icon.
|
Uses the deprecated egg.trayicon module to implement the tray icon.
|
||||||
Since it relies on a deprecated module, this class is only used
|
Since it relies on a deprecated module, this class is only used
|
||||||
for machines running versions of GTK < 2.10.
|
for machines running versions of GTK < 2.10.
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self, use_tray=True):
|
|
||||||
"""Initializes the tray icon"""
|
|
||||||
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
|
||||||
self.use_tray = use_tray
|
|
||||||
if not use_tray:
|
|
||||||
self.toggle_wicd_gui()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.tooltip = gtk.Tooltips()
|
|
||||||
self.eb = gtk.EventBox()
|
|
||||||
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
|
|
||||||
self.pic = gtk.Image()
|
|
||||||
self.tooltip.set_tip(self.eb, "Initializing wicd...")
|
|
||||||
self.pic.set_from_file(wpath.images + "no-signal.png")
|
|
||||||
|
|
||||||
self.eb.connect('button_press_event', self.tray_clicked)
|
|
||||||
self.eb.add(self.pic)
|
|
||||||
self.tray.add(self.eb)
|
|
||||||
self.tray.show_all()
|
|
||||||
|
|
||||||
def tray_clicked(self, widget, event):
|
|
||||||
""" Handles tray mouse click events. """
|
|
||||||
if event.button == 1:
|
|
||||||
self.toggle_wicd_gui()
|
|
||||||
elif event.button == 3:
|
|
||||||
self.init_network_menu()
|
|
||||||
self.menu.popup(None, None, None, event.button, event.time)
|
|
||||||
|
|
||||||
def set_from_file(self, val=None):
|
|
||||||
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
|
||||||
if not self.use_tray: return
|
|
||||||
self.pic.set_from_file(val)
|
|
||||||
|
|
||||||
def set_tooltip(self, val):
|
|
||||||
""" Set the tooltip for this tray icon.
|
|
||||||
|
|
||||||
Sets the tooltip for the gtk.ToolTips associated with this
|
|
||||||
tray icon.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.use_tray: return
|
def __init__(self, use_tray=True):
|
||||||
self.tooltip.set_tip(self.eb, val)
|
"""Initializes the tray icon"""
|
||||||
|
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
||||||
|
self.use_tray = use_tray
|
||||||
|
if not use_tray:
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.tooltip = gtk.Tooltips()
|
||||||
|
self.eb = gtk.EventBox()
|
||||||
|
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
|
||||||
|
self.pic = gtk.Image()
|
||||||
|
self.tooltip.set_tip(self.eb, "Initializing wicd...")
|
||||||
|
self.pic.set_from_file(wpath.images + "no-signal.png")
|
||||||
|
|
||||||
|
self.eb.connect('button_press_event', self.tray_clicked)
|
||||||
|
self.eb.add(self.pic)
|
||||||
|
self.tray.add(self.eb)
|
||||||
|
self.tray.show_all()
|
||||||
|
|
||||||
|
def tray_clicked(self, widget, event):
|
||||||
|
""" Handles tray mouse click events. """
|
||||||
|
if event.button == 1:
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
elif event.button == 3:
|
||||||
|
self.init_network_menu()
|
||||||
|
self.menu.popup(None, None, None, event.button, event.time)
|
||||||
|
|
||||||
|
def set_from_file(self, val=None):
|
||||||
|
""" Calls set_from_file on the gtk.Image for the tray icon. """
|
||||||
|
if not self.use_tray: return
|
||||||
|
self.pic.set_from_file(val)
|
||||||
|
|
||||||
|
def set_tooltip(self, val):
|
||||||
|
""" Set the tooltip for this tray icon.
|
||||||
|
|
||||||
|
Sets the tooltip for the gtk.ToolTips associated with this
|
||||||
|
tray icon.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not self.use_tray: return
|
||||||
|
self.tooltip.set_tip(self.eb, val)
|
||||||
|
|
||||||
|
|
||||||
class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
|
if hasattr(gtk, "StatusIcon"):
|
||||||
""" Class for creating the wicd tray icon on gtk > 2.10.
|
class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
|
||||||
|
""" Class for creating the wicd tray icon on gtk > 2.10.
|
||||||
|
|
||||||
Uses gtk.StatusIcon to implement a tray icon.
|
Uses gtk.StatusIcon to implement a tray icon.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, use_tray=True):
|
def __init__(self, use_tray=True):
|
||||||
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
TrayIcon.TrayIconGUI.__init__(self, use_tray)
|
||||||
self.use_tray = use_tray
|
self.use_tray = use_tray
|
||||||
if not use_tray:
|
if not use_tray:
|
||||||
self.toggle_wicd_gui()
|
self.toggle_wicd_gui()
|
||||||
return
|
return
|
||||||
|
|
||||||
gtk.StatusIcon.__init__(self)
|
gtk.StatusIcon.__init__(self)
|
||||||
|
|
||||||
self.current_icon_path = ''
|
self.current_icon_path = ''
|
||||||
self.set_visible(True)
|
self.set_visible(True)
|
||||||
self.connect('activate', self.on_activate)
|
self.connect('activate', self.on_activate)
|
||||||
self.connect('popup-menu', self.on_popup_menu)
|
self.connect('popup-menu', self.on_popup_menu)
|
||||||
self.set_from_file(wpath.images + "no-signal.png")
|
self.set_from_file(wpath.images + "no-signal.png")
|
||||||
self.set_tooltip("Initializing wicd...")
|
self.set_tooltip("Initializing wicd...")
|
||||||
|
|
||||||
def on_popup_menu(self, status, button, timestamp):
|
def on_popup_menu(self, status, button, timestamp):
|
||||||
""" Opens the right click menu for the tray icon. """
|
""" Opens the right click menu for the tray icon. """
|
||||||
self.init_network_menu()
|
self.init_network_menu()
|
||||||
self.menu.popup(None, None, None, button, timestamp)
|
self.menu.popup(None, None, None, button, timestamp)
|
||||||
|
|
||||||
def set_from_file(self, path=None):
|
def set_from_file(self, path=None):
|
||||||
""" Sets a new tray icon picture. """
|
""" Sets a new tray icon picture. """
|
||||||
if not self.use_tray: return
|
if not self.use_tray: return
|
||||||
if path != self.current_icon_path:
|
if path != self.current_icon_path:
|
||||||
self.current_icon_path = path
|
self.current_icon_path = path
|
||||||
gtk.StatusIcon.set_from_file(self, path)
|
gtk.StatusIcon.set_from_file(self, path)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
|
|||||||
Reference in New Issue
Block a user