From 30d9695dbe3c70ab692ec32b6f8452ca0232ac0b Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 20 Jun 2008 16:25:43 +0100 Subject: [PATCH] Added "0store manage" command to show the GTK cache viewer. The "Show Cache" button has been removed from the "0launch --gui" dialog box, since it didn't really belong there. --- zeroinstall/0launch-gui/mainwindow.py | 10 +-- zeroinstall/0launch-gui/zero-install.glade | 79 -------------------- zeroinstall/gtkui/cache.glade | 114 +++++++++++++++++++++++++++++ zeroinstall/gtkui/cache.py | 73 +++++++++--------- zeroinstall/zerostore/cli.py | 16 +++- 5 files changed, 172 insertions(+), 120 deletions(-) create mode 100644 zeroinstall/gtkui/cache.glade diff --git a/zeroinstall/0launch-gui/mainwindow.py b/zeroinstall/0launch-gui/mainwindow.py index 2a6784b..7a3d672 100644 --- a/zeroinstall/0launch-gui/mainwindow.py +++ b/zeroinstall/0launch-gui/mainwindow.py @@ -37,10 +37,6 @@ class MainWindow: widgets.get_widget('stop').connect('clicked', lambda b: policy.handler.abort_all_downloads()) - cache = widgets.get_widget('show_cache') - cache.connect('clicked', - lambda b: os.spawnlp(os.P_WAIT, sys.argv[0], sys.argv[0], '-c')) - self.refresh_button = widgets.get_widget('refresh') # Tree view @@ -203,7 +199,7 @@ bug if necessary, or switch to using a different version of the library. ('The cache', """ Each version of a program that is downloaded is stored in the Zero Install cache. This \ -means that it won't need to be downloaded again each time you run the program. Click on \ -the 'Show Cache' button to see what is currently in the cache, or to remove versions \ -you no longer need to save disk space."""), +means that it won't need to be downloaded again each time you run the program. The \ +"0store manage" command can be used to view the cache. +"""), ) diff --git a/zeroinstall/0launch-gui/zero-install.glade b/zeroinstall/0launch-gui/zero-install.glade index 7d1a68d..c66dc1d 100644 --- a/zeroinstall/0launch-gui/zero-install.glade +++ b/zeroinstall/0launch-gui/zero-install.glade @@ -121,85 +121,6 @@ 4 - - True - Show all components currently stored on this computer. - True - GTK_RELIEF_NORMAL - True - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-open - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Sho_w cache - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - 0 - False - False - - - - True Check all the components for updates. diff --git a/zeroinstall/gtkui/cache.glade b/zeroinstall/gtkui/cache.glade new file mode 100644 index 0000000..d175948 --- /dev/null +++ b/zeroinstall/gtkui/cache.glade @@ -0,0 +1,114 @@ + + + + + + + True + Zero Install cache + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-help + True + GTK_RELIEF_NORMAL + True + -11 + + + + + + True + True + True + gtk-delete + True + GTK_RELIEF_NORMAL + True + 0 + + + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + -7 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + True + False + True + False + False + False + + + + + 0 + True + True + + + + + + + diff --git a/zeroinstall/gtkui/cache.py b/zeroinstall/gtkui/cache.py index 751ffae..b1c601f 100644 --- a/zeroinstall/gtkui/cache.py +++ b/zeroinstall/gtkui/cache.py @@ -1,17 +1,21 @@ +"""Display the contents of the implementation cache.""" # Copyright (C) 2008, Thomas Leonard # See the README file for details, or visit http://0install.net. import os, shutil -import gtk, gobject +import gtk -from dialog import Dialog, alert from zeroinstall.injector.iface_cache import iface_cache from zeroinstall.injector import namespaces, model from zeroinstall.zerostore import BadDigest, manifest from zeroinstall import support from zeroinstall.support import basedir from zeroinstall.gtkui.treetips import TreeTips -from zeroinstall.gtkui import help_box +from zeroinstall.gtkui import help_box, gtkutils + +_ = lambda x: x + +__all__ = ['CacheExplorer'] ROX_IFACE = 'http://rox.sourceforge.net/2005/interfaces/ROX-Filer' @@ -208,24 +212,17 @@ class KnownImplementation(CachedImplementation): return self.impl.__cmp__(other.impl) return -1 -class CacheExplorer(Dialog): +class CacheExplorer: + """A graphical interface for viewing the cache and deleting old items.""" def __init__(self): - Dialog.__init__(self) - self.set_title('Zero Install Cache') - self.set_default_size(gtk.gdk.screen_width() / 2, gtk.gdk.screen_height() / 2) + widgets = gtkutils.Template(os.path.join(os.path.dirname(__file__), 'cache.glade'), 'cache') + self.window = window = widgets.get_widget('cache') + window.set_default_size(gtk.gdk.screen_width() / 2, gtk.gdk.screen_height() / 2) # Model self.model = gtk.TreeStore(str, int, str, str, object) - self.tree_view = gtk.TreeView(self.model) - - # Tree view - swin = gtk.ScrolledWindow() - swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) - swin.set_shadow_type(gtk.SHADOW_IN) - swin.add(self.tree_view) - self.vbox.pack_start(swin, True, True, 0) - self.tree_view.set_rules_hint(True) - swin.show_all() + self.tree_view = widgets.get_widget('treeview') + self.tree_view.set_model(self.model) column = gtk.TreeViewColumn('Item', gtk.CellRendererText(), text = ITEM) column.set_resizable(True) @@ -269,11 +266,7 @@ class CacheExplorer(Dialog): self.tree_view.connect('leave-notify-event', lambda tv, ev: tips.hide()) # Responses - - self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP) - self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_OK) - self.add_button(gtk.STOCK_DELETE, DELETE) - self.set_default_response(gtk.RESPONSE_OK) + window.set_default_response(gtk.RESPONSE_OK) selection = self.tree_view.get_selection() def selection_changed(selection): @@ -281,24 +274,24 @@ class CacheExplorer(Dialog): for x in get_selected_paths(self.tree_view): obj = self.model[x][ITEM_OBJECT] if obj is None or not obj.may_delete: - self.set_response_sensitive(DELETE, False) + window.set_response_sensitive(DELETE, False) return any_selected = True - self.set_response_sensitive(DELETE, any_selected) + window.set_response_sensitive(DELETE, any_selected) selection.set_mode(gtk.SELECTION_MULTIPLE) selection.connect('changed', selection_changed) selection_changed(selection) def response(dialog, resp): if resp == gtk.RESPONSE_OK: - self.destroy() + window.destroy() elif resp == gtk.RESPONSE_HELP: cache_help.display() elif resp == DELETE: - self.delete() - self.connect('response', response) + self._delete() + window.connect('response', response) - def delete(self): + def _delete(self): errors = [] model = self.model @@ -313,12 +306,26 @@ class CacheExplorer(Dialog): errors.append(str(ex)) else: model.remove(model.get_iter(path)) - self.update_sizes() + self._update_sizes() if errors: - alert(self, "Failed to delete:\n%s" % '\n'.join(errors)) + gtkutils.show_message_box(self, "Failed to delete:\n%s" % '\n'.join(errors)) - def populate_model(self): + def show(self): + """Display the window and scan the caches to populate it.""" + self.window.show() + self.window.window.set_cursor(gtkutils.get_busy_pointer()) + gtk.gdk.flush() + try: + self._populate_model() + i = self.model.get_iter_root() + while i: + self.tree_view.expand_row(self.model.get_path(i), False) + i = self.model.iter_next(i) + finally: + self.window.window.set_cursor(None) + + def _populate_model(self): # Find cached implementations unowned = {} # Impl ID -> Store @@ -401,9 +408,9 @@ class CacheExplorer(Dialog): None]) for item in ok_interfaces: item.append_to(self.model, iter) - self.update_sizes() + self._update_sizes() - def update_sizes(self): + def _update_sizes(self): """Set PRETTY_SIZE to the total size, including all children.""" m = self.model def update(itr): diff --git a/zeroinstall/zerostore/cli.py b/zeroinstall/zerostore/cli.py index 52b6533..7669eb5 100644 --- a/zeroinstall/zerostore/cli.py +++ b/zeroinstall/zerostore/cli.py @@ -178,4 +178,18 @@ def do_copy(args): copy_tree_with_verify(source, target, manifest_data, required_digest) -commands = [do_add, do_copy, do_find, do_list, do_manifest, do_optimise, do_verify] +def do_manage(args): + """manage""" + if args: + raise UsageError("manage command takes no arguments") + + import pygtk + pygtk.require('2.0') + import gtk + from zeroinstall.gtkui import cache + cache_explorer = cache.CacheExplorer() + cache_explorer.window.connect('destroy', gtk.main_quit) + cache_explorer.show() + gtk.main() + +commands = [do_add, do_copy, do_find, do_list, do_manifest, do_optimise, do_verify, do_manage] -- 2.11.4.GIT