def set_tracker(self, tracker, changes_only = False): """Initialize this instance with the package tracker to visualize @param tracker a PackageMetaDataChangeTracker instance @param changes_only if True, only changed packages will be shown, not all the tracked packages @return self""" self.reset() changes = tracker.changes() packages = dict(((name, data) for data, name in tracker.iter_package_data())) previous_packages = dict(((name, data) for data, name in tracker.iter_package_data(previous=True))) hide_message = lambda: self.ui.message.setVisible(False) if not changes and not packages: log.warn("Input tracker was empty") return self # end bail out if there is nothing to display if changes: hide_message() # new packages added = set(packages.keys()) - set(previous_packages.keys()) self.ui.pnew.setVisible(bool(added)) self._update_packages(self.ui.pnew, packages, previous_packages, lambda name: name in added) # removed packges removed = set(previous_packages.keys()) - set(packages.keys()) self.ui.premoved.setVisible(bool(removed)) self._update_packages(self.ui.premoved, previous_packages, packages, lambda name: name in removed) # remaining packages remaining = set(changes.packages.keys()) - added self.ui.pchanged.setVisible(bool(remaining)) self._update_packages(self.ui.pchanged, packages, previous_packages, lambda name: name in remaining) # end handle gui if changes_only: return self # end bail out if there where changes # fill in all packages hide_message() self.ui.pall.setVisible(True) self.ui.pall.setTitle("%s Packages" % capitalize(tracker.package_name())) self._update_packages(self.ui.pall, packages)
def set_package(self, name, data, previous_data = None): """Set the widget to display information based on the given package data, which must match the schema of the PackageMetaDataChangeTracker @param name package name @param data package scheme compliant data of the current package state @param previous_data similar to data, but the last values we have seen, and only those who have changed @return self""" self.ui.package_label.setText("<b>%s@%s</b>" % (capitalize(data.name or name), data.version)) self.ui.help.setVisible(bool(data.url)) self.ui.version_previous.setHidden(True) self._url = data.url self.ui.description.setText(data.description) self.ui.description_group.setVisible(bool(data.description)) if previous_data: # anything could have changed, make sure it is the version indeed if previous_data.version != data.version: self.ui.version_previous.setHidden(False) self.ui.version_previous.setText("Previous Version: %s" % str(previous_data.version)) # end handle version change # end handle version return self