def show_snapshots(self, selected_app=False): """ Show and update the snapshots window. Can be called while already open to update the UI. """ if selected_app != False: self.selected_app = selected_app if self.selected_app: def snap_cmp(arg1, arg2): return cmp(self.selected_app.snapshots[arg1][1], self.selected_app.snapshots[arg2][1]) self.selected_app.load_snapshots() self.lst_snapshots.clear() # sort by most recent sorted_keys = sorted(self.selected_app.snapshots, cmp=snap_cmp, reverse=True) for snapshot in sorted_keys: snap_date = datetime.datetime.fromtimestamp( self.selected_app.snapshots[snapshot][1]).strftime( "%Y-%m-%d %H:%M:%S") snap_size = format_size(self.selected_app.snapshots[snapshot][2]) self.lst_snapshots.append(( snapshot, snap_date, snap_size, )) else: self.lst_snapshots.clear() self.update_ui()
def update_ui(self, *args, **kwargs): """ Update the bottom panel with information about the selected application. Disable certain buttons if their features are not available for use on the application. """ model, treeiter = self.apps_treeview_sel.get_selected() if treeiter: # find the selected application selected = self.lst_applications.get_value(treeiter, 0) app = self.selected_app = self.userdata.applications[selected] # update the title & icon self.lbl_title.props.label = app.full_name self.img_appicon.set_from_pixbuf(app.icon) # check if it's running running = self.selected_app.check_running() txt = [] if running: txt.append("<b>" + _("Please close %(application)s before managing it.") % {'application': self.selected_app.full_name} + "</b>") self.item_delete.props.sensitive = False else: self.item_delete.props.sensitive = True # grab the size app.calculate_size() if app.data_size > 0: size = format_size(app.data_size) size_info = _("This application is using %(size)s of space.") % {'size': "<b>" + size + "</b>"} else: size_info = _("This application is not storing any data.") self.item_delete.props.sensitive = False # find the number of snapshots app.load_snapshots() num_snapshots = len(app.snapshots) if num_snapshots == 1: size_info += "\n" + _("One snapshot is available.") elif num_snapshots > 1: size_info += "\n" + _("%(num)d snapshots are available.") % {'num': num_snapshots} txt.append(size_info) # check for errors if app.errors: txt = ["<b>" + _("A problem occurred. This application cannot be managed.") + "</b>"] self.item_delete.props.sensitive = False self.lbl_app_details.props.label = "\n\n".join(txt) self.item_details.props.sensitive = True # show & update snapshots self.snapshots_ui.show_snapshots(self.selected_app) else: self.selected_app = None self.lbl_app_details.props.label = "" self.lbl_title.props.label = _("Select an Application") self.img_appicon.set_from_stock('gtk-dialog-question', gtk.ICON_SIZE_DND); self.item_delete.props.sensitive = False self.item_details.props.sensitive = False self.snapshots_ui.show_snapshots(None)