class NetworkManager(gtk.VBox): """Network Manager gtk's main widget""" def __init__(self): """init""" gtk.VBox.__init__(self, homogeneous=False, spacing=5) self._dbus_loop() self.iface = NetworkIface() self.get_state = lambda p,c:self.iface.info(p,c)[u"state"] self._create_ui() self._listen_signals() def _dbus_loop(self): #runs dbus main loop DBusGMainLoop(set_as_default=True) def _create_ui(self): #creates ui elements self._new_btn = gtk.Button(_('New Connection')) self.pack_start(self._new_btn, expand=False) self._holder = ProfilesHolder() self._holder.set_connection_signal(self._connection_callback) self.pack_start(self._holder, expand=True, fill=True) self._get_profiles() def _connection_callback(self, widget, data): """listens ConnectionWidget's signals Arguments: - `widget`: widget - `data`: {'action':(toggle | edit | delete) 'package':package_name, 'connection':connection_name} """ action = data["action"] if action == "toggle": self.iface.toggle(data["package"], data["connection"]) elif action == "edit": EditWindow(self.iface, data["package"], data["connection"]).show() else: m = _("Do you want to delete the connection '%s' ?") % \ data['connection'] dialog = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_YES_NO, message_format=m) response = dialog.run() if response == gtk.RESPONSE_YES: try: self.iface.deleteConnection(data['package'], data['connection']) except Exception, e: print "Exception:",e dialog.destroy()
def __init__(self): """init""" gtk.VBox.__init__(self, homogeneous=False, spacing=5) self._dbus_loop() self.iface = NetworkIface() self.get_state = lambda p,c:self.iface.info(p,c)[u"state"] self._create_ui() self._listen_signals()