From 43071cfc9b86564376efd2c358ce317f69386ee2 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Tue, 1 Apr 2014 16:39:54 -0700 Subject: [PATCH] Simplify RadarWindow.delete_profile Again, move the core logic to main and simplify the UI processing. Signed-off-by: Sean Robinson --- wifiradar/__init__.py | 7 +++++++ wifiradar/gui/g2/__init__.py | 40 ++++++++-------------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/wifiradar/__init__.py b/wifiradar/__init__.py index 98a612b..df19193 100644 --- a/wifiradar/__init__.py +++ b/wifiradar/__init__.py @@ -127,6 +127,13 @@ def main(config): config.auto_profile_order.insert(0, apname) msg_pipe.send(Message('PROFILE-UPDATE', profile)) #msg_pipe.send(Message('PROFILE-MOVE', profile, 0)) + elif msg.topic == 'PROFILE-REMOVE': + apname = msg.details + if apname in config.profiles(): + profile = config.get_profile(apname) + config.remove_section(apname) + self.config.auto_profile_order.remove(apname) + msg_pipe.send(Message('PROFILE-UNLIST', profile)) else: logger.warning('unrecognized Message: "{}"'.format(msg)) ui_proc.join() diff --git a/wifiradar/gui/g2/__init__.py b/wifiradar/gui/g2/__init__.py index f371c85..9d488ac 100644 --- a/wifiradar/gui/g2/__init__.py +++ b/wifiradar/gui/g2/__init__.py @@ -268,6 +268,8 @@ class RadarWindow: self.config = msg.details elif msg.topic == 'PROFILE-UPDATE': self.update_plist_items(msg.details) + elif msg.topic == 'PROFILE-UNLIST': + self.remove_profile(msg.details) elif msg.topic == 'PREFS-EDIT': self.edit_preferences() else: @@ -515,7 +517,7 @@ class RadarWindow: # Find where old profile was in auto order old_index = self.config.auto_profile_order.index(old_ap) # Remove old profile and get its place in AP list - row = self.delete_profile(selected_iter, old_ap) + row = self.delete_profile(old_ap) self.msg_pipe.send(Message('PROFILE-REMOVE', old_ap)) # Add AP to the list displayed to user self.msg_pipe.send(Message('PROFILE-UPDATE', edited_profile)) @@ -559,37 +561,11 @@ class RadarWindow: profile['bssid'] = self.pstore.get_value(selected_iter, 1) self.create_new_profile(widget, profile, data) - def delete_profile(self, selected_iter, apname): - """ Delete an AP profile (i.e. make profile unknown) - - Parameters: - - 'selected_iter' -- gtk.TreeIter - The selected row. - - 'apname' -- string - The configuration file section to remove - - Returns: - - gtk.TreeIter -- the iter for the row removed from the gtk.ListStore + def delete_profile(self, apname): + """ Delete the profile associated with :data:`apname` (i.e. make + the profile unknown). """ - # Remove it - del self.access_points[apname] - self.config.remove_section(apname) - logger.info(apname) - if apname in self.config.auto_profile_order: - self.config.auto_profile_order.remove(apname) - self.pstore.remove(selected_iter) - # Let's save our current state - self.update_auto_profile_order() - try: - self.config.write() - except IOError as e: - if e.errno == errno.ENOENT: - error_dlg = transients.ErrorDialog(self.window, "Could not save configuration file:\n%s\n\n%s" % (self.config.filename, e.strerror)) - del error_dlg - else: - raise e - return selected_iter + self.msg_pipe.send(Message('PROFILE-REMOVE', apname)) def delete_profile_with_check(self, widget=None, data=None): """ Respond to a request to delete an AP profile (i.e. make the @@ -619,7 +595,7 @@ class RadarWindow: del dlg if res == gtk.RESPONSE_NO: return - self.delete_profile(selected_iter, apname) + self.delete_profile(apname) def connect_profile(self, widget, profile, data=None): """ Respond to a request to connect to an AP. -- 2.11.4.GIT