def on_action_remove_activate(self, action): """Remove the selected group""" selected_row = get_treeview_selected_row(self.ui.tvw_groups) group_name = self.model.get_key(selected_row) if selected_row else '' if selected_row and group_name and show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.dialog_groups, message_type=Gtk.MessageType.WARNING, title=None, msg1=_('Remove the group'), msg2=_('Remove the group «%s»?') % group_name, is_response_id=Gtk.ResponseType.YES): group_path = os.path.join(DIR_HOSTS, group_name) # Check for directory not empty if len(os.listdir(group_path)) and not show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.dialog_groups, message_type=Gtk.MessageType.WARNING, title=None, msg1=_('The group is not empty'), msg2='%s\n%s\n\n%s' % ( text('If you delete an item, it will ' 'be permanently lost.'), _('All the hosts defined for the group will be lost.'), _('Are you sure you want to delete the ' 'group «%s»?') % group_name, ), is_response_id=Gtk.ResponseType.YES): # Exit immediately without deleting the group return # Delete all the contained files and the directory for the group for filename in os.listdir(group_path): os.remove(os.path.join(group_path, filename)) os.rmdir(group_path) self.model.remove(selected_row)
def on_action_remove_activate(self, action): """Remove the selected devices""" selected_row = get_treeview_selected_row(self.ui.tvw_devices) if selected_row and show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.dialog_devices, message_type=Gtk.MessageType.WARNING, title=None, msg1=_("Remove device"), msg2=_("Remove the selected device?"), is_response_id=Gtk.ResponseType.YES): self.model.remove(selected_row)
def on_action_delete_activate(self, action): """Remove the selected host""" selected_row = get_treeview_selected_row(self.ui.tvw_connections) if selected_row and show_message_dialog( class_=UIMessageDialogNoYes, parent=self.ui.win_main, message_type=Gtk.MessageType.QUESTION, title=None, msg1=_("Remove host"), msg2=_("Remove the selected host?"), is_response_id=Gtk.ResponseType.YES): self.remove_host(self.model_hosts.get_key(selected_row))