summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 15:37:05 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 15:37:05 +0000
commit1b514e848902f609cba9b2247702fc6d714d2456 (patch)
treea035975b8d2378a48dc2d8942147836be3d9ec4a
parent19fb3bc6a6fc6328dfa90dac3e4066d931eaf129 (diff)
downloadpython-apt-1b514e848902f609cba9b2247702fc6d714d2456.tar.gz
* beefed up the gui examples
-rw-r--r--doc/examples/gui-inst.py62
1 files changed, 50 insertions, 12 deletions
diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py
index ededab5f..26164b0c 100644
--- a/doc/examples/gui-inst.py
+++ b/doc/examples/gui-inst.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
# example how to install in a custom terminal widget
+# see also gnome bug: #169201
import apt_pkg
import sys, os
@@ -13,12 +14,50 @@ import time
from progress import OpProgress, FetchProgress, InstallProgress
-class TermInstallProgress(InstallProgress):
+class GuiFetchProgress(gtk.Window, FetchProgress):
+ def __init__(self):
+ gtk.Window.__init__(self)
+ self.vbox = gtk.VBox()
+ self.vbox.show()
+ self.add(self.vbox)
+ self.progress = gtk.ProgressBar()
+ self.progress.show()
+ self.label = gtk.Label()
+ self.label.show()
+ self.vbox.pack_start(self.progress)
+ self.vbox.pack_start(self.label)
+ self.resize(300,100)
+ def Start(self):
+ self.progress.set_fraction(0)
+ self.show()
+ def Stop(self):
+ self.hide()
+ def Pulse(self):
+ self.label.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.CurrentCPS))
+ self.progress.set_fraction(self.CurrentBytes/self.TotalBytes)
+ while gtk.events_pending():
+ gtk.main_iteration()
+
+class TermInstallProgress(InstallProgress, gtk.Window):
+ def __init__(self):
+ gtk.Window.__init__(self)
+ self.show()
+ self.term = vte.Terminal()
+ self.term.show()
+ self.add(self.term)
+ def Start(self):
+ self.progress.set_fraction(0)
+ self.show()
+ def Stop(self):
+ self.hide()
def UpdateInterface(self):
while gtk.events_pending():
gtk.main_iteration()
def FinishUpdate(self):
- sys.stdin.readline()
+ sys.stdin.readline()
+ def fork(self):
+ return self.term.forkpty()
+
# init
apt_pkg.init()
@@ -27,24 +66,23 @@ progress = OpProgress()
cache = apt_pkg.GetCache(progress)
print "Available packages: %s " % cache.PackageCount
+
# get depcache
depcache = apt_pkg.GetDepCache(cache)
depcache.ReadPinFile()
depcache.Init(progress)
-# do something
-fprogress = FetchProgress()
+# update the cache
+fprogress = GuiFetchProgress()
iprogress = TermInstallProgress()
+# update the cache
+#cache.Update(fprogress)
+#cache = apt_pkg.GetCache(progress)
+#depcache = apt_pkg.GetDepCache(cache)
+#depcache.ReadPinFile()
+#depcache.Init(progress)
-window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-window.show()
-term = vte.Terminal()
-term.show()
-window.add(term)
-# can be used to set a custom fork method (like vte.Terminal.forkpty)
-# see also gnome bug: #169201
-iprogress.fork = term.forkpty
# show the interface
while gtk.events_pending():