Fixup tooltips. Still not working for the home page case, since

the active device logic is pretty broken.
This commit is contained in:
Marco Pesenti Gritti 2007-02-25 17:34:15 +01:00
parent b26ddc64ba
commit 66f26e4b8b
5 changed files with 45 additions and 12 deletions

View File

@ -75,6 +75,8 @@ class Network(gobject.GObject):
'init-failed' : (gobject.SIGNAL_RUN_FIRST, 'init-failed' : (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])), gobject.TYPE_NONE, ([])),
'strength-changed': (gobject.SIGNAL_RUN_FIRST, 'strength-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])),
'essid-changed' : (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])) gobject.TYPE_NONE, ([]))
} }
@ -109,6 +111,7 @@ class Network(gobject.GObject):
self._ssid, self._mode, self._strength)) self._ssid, self._mode, self._strength))
self.emit('strength-changed') self.emit('strength-changed')
self.emit('essid-changed')
def _update_error_cb(self, err): def _update_error_cb(self, err):
logging.debug("Net(%s): failed to update. (%s)" % (self._op, err)) logging.debug("Net(%s): failed to update. (%s)" % (self._op, err))
@ -142,6 +145,8 @@ class Device(gobject.GObject):
'strength-changed': (gobject.SIGNAL_RUN_FIRST, 'strength-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])), ([gobject.TYPE_PYOBJECT])),
'essid-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])),
'network-appeared': (gobject.SIGNAL_RUN_FIRST, 'network-appeared': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])), ([gobject.TYPE_PYOBJECT])),
@ -273,6 +278,7 @@ class Device(gobject.GObject):
for (op, net) in self._networks.items(): for (op, net) in self._networks.items():
if net.get_ssid() == ssid: if net.get_ssid() == ssid:
self._active_net = op self._active_net = op
self.emit('essid-changed')
def get_type(self): def get_type(self):
return self._type return self._type

View File

@ -24,6 +24,8 @@ from hardware import hardwaremanager
class AccessPointModel(gobject.GObject): class AccessPointModel(gobject.GObject):
__gproperties__ = { __gproperties__ = {
'name' : (str, None, None, None,
gobject.PARAM_READABLE),
'strength' : (int, None, None, 0, 100, 0, 'strength' : (int, None, None, 0, 100, 0,
gobject.PARAM_READABLE) gobject.PARAM_READABLE)
} }
@ -35,16 +37,18 @@ class AccessPointModel(gobject.GObject):
self._nm_network.connect('strength-changed', self._nm_network.connect('strength-changed',
self._strength_changed_cb) self._strength_changed_cb)
self._nm_network.connect('essid-changed',
self._essid_changed_cb)
def _strength_changed_cb(self, nm_network): def _strength_changed_cb(self, nm_network):
self.notify('strength') self.notify('strength')
def _essid_changed_cb(self, nm_network):
self.notify('name')
def get_id(self): def get_id(self):
return self._nm_network.get_op() return self._nm_network.get_op()
def get_name(self):
return self._nm_network.get_ssid()
def get_nm_device(self): def get_nm_device(self):
return self._nm_device return self._nm_device
@ -54,6 +58,8 @@ class AccessPointModel(gobject.GObject):
def do_get_property(self, pspec): def do_get_property(self, pspec):
if pspec.name == 'strength': if pspec.name == 'strength':
return self._nm_network.get_strength() return self._nm_network.get_strength()
elif pspec.name == 'name':
return self._nm_network.get_ssid()
class ActivityModel: class ActivityModel:
def __init__(self, activity, bundle, service): def __init__(self, activity, bundle, service):

View File

@ -4,6 +4,8 @@ from model.devices import device
class Device(device.Device): class Device(device.Device):
__gproperties__ = { __gproperties__ = {
'name' : (str, None, None, None,
gobject.PARAM_READABLE),
'strength' : (int, None, None, 0, 100, 0, 'strength' : (int, None, None, 0, 100, 0,
gobject.PARAM_READABLE) gobject.PARAM_READABLE)
} }
@ -14,23 +16,27 @@ class Device(device.Device):
self._nm_device.connect('strength-changed', self._nm_device.connect('strength-changed',
self._strength_changed_cb) self._strength_changed_cb)
self._nm_device.connect('essid-changed',
self._essid_changed_cb)
def _strength_changed_cb(self, nm_device, strength): def _strength_changed_cb(self, nm_device, strength):
self.notify('strength') self.notify('strength')
def _essid_changed_cb(self, nm_device):
self.notify('name')
def do_get_property(self, pspec): def do_get_property(self, pspec):
if pspec.name == 'strength': if pspec.name == 'strength':
return self._nm_device.get_strength() return self._nm_device.get_strength()
elif pspec.name == 'name':
active_net = self._nm_device.get_active_network()
if active_net:
return active_net.get_ssid()
else:
return None
def get_type(self): def get_type(self):
return 'wirelessnetwork' return 'wirelessnetwork'
def get_id(self): def get_id(self):
return self._nm_device.get_op() return self._nm_device.get_op()
def get_name(self):
active_net = self._nm_device.get_active_network()
if active_net:
return active_net.get_ssid()
else:
return None

View File

@ -5,14 +5,21 @@ class DeviceView(deviceview.DeviceView):
deviceview.DeviceView.__init__(self, model) deviceview.DeviceView.__init__(self, model)
self._model = model self._model = model
model.connect('notify::name', self._name_changed_cb)
model.connect('notify::strength', self._strength_changed_cb) model.connect('notify::strength', self._strength_changed_cb)
self.props.tooltip = model.get_name() self._update_name()
self._update_icon() self._update_icon()
def _strength_changed_cb(self, model, pspec): def _strength_changed_cb(self, model, pspec):
self._update_icon() self._update_icon()
def _name_changed_cb(self, model, pspec):
self._update_name()
def _update_name(self):
self.props.tooltip = self._model.props.name
def _update_icon(self): def _update_icon(self):
strength = self._model.props.strength strength = self._model.props.strength
if strength < 21: if strength < 21:

View File

@ -27,18 +27,23 @@ from view.BuddyIcon import BuddyIcon
class AccessPointView(CanvasIcon): class AccessPointView(CanvasIcon):
def __init__(self, model): def __init__(self, model):
CanvasIcon.__init__(self, tooltip=model.get_name()) CanvasIcon.__init__(self)
self._model = model self._model = model
self.connect('activated', self._activate_cb) self.connect('activated', self._activate_cb)
model.connect('notify::strength', self._strength_changed_cb) model.connect('notify::strength', self._strength_changed_cb)
model.connect('notify::name', self._name_changed_cb)
self._update_icon() self._update_icon()
self._update_name()
def _strength_changed_cb(self, model, pspec): def _strength_changed_cb(self, model, pspec):
self._update_icon() self._update_icon()
def _name_changed_cb(self, model, pspec):
self._update_name()
def _activate_cb(self, icon): def _activate_cb(self, icon):
network_manager = hardwaremanager.get_network_manager() network_manager = hardwaremanager.get_network_manager()
@ -47,6 +52,9 @@ class AccessPointView(CanvasIcon):
network_manager.set_active_device(device, network) network_manager.set_active_device(device, network)
def _update_name(self):
self.props.tooltip = self._model.props.name
def _update_icon(self): def _update_icon(self):
strength = self._model.props.strength strength = self._model.props.strength
if strength < 21: if strength < 21: