home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / UpdateManager / GtkProgress.py < prev    next >
Encoding:
Python Source  |  2006-08-24  |  4.5 KB  |  123 lines

  1. # GtkProgress.py 
  2. #  
  3. #  Copyright (c) 2004,2005 Canonical
  4. #  
  5. #  Author: Michael Vogt <michael.vogt@ubuntu.com>
  6. #  This program is free software; you can redistribute it and/or 
  7. #  modify it under the terms of the GNU General Public License as 
  8. #  published by the Free Software Foundation; either version 2 of the
  9. #  License, or (at your option) any later version.
  10. #  This program is distributed in the hope that it will be useful,
  11. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #  GNU General Public License for more details.
  14. #  You should have received a copy of the GNU General Public License
  15. #  along with this program; if not, write to the Free Software
  16. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. #  USA
  18.  
  19. import pygtk
  20. pygtk.require('2.0')
  21. import gtk
  22. import apt
  23. import apt_pkg
  24. from gettext import gettext as _
  25.  
  26. # intervals of the start up progress
  27. # 3x caching and menu creation
  28. STEPS_UPDATE_CACHE = [33, 66, 100]
  29.  
  30. class GtkOpProgress(apt.OpProgress):
  31.     def __init__(self, host_window, progressbar, status, parent,
  32.                  steps=STEPS_UPDATE_CACHE):
  33.         # used for the "one run progressbar"
  34.         self.steps = steps[:]
  35.         self.base = 0
  36.         self.old = 0
  37.         self.next = int(self.steps.pop(0))
  38.  
  39.         self._parent = parent
  40.         self._window = host_window
  41.         self._status = status
  42.         self._progressbar = progressbar
  43.         # Do not show the close button 
  44.         self._window.realize()
  45.         host_window.window.set_functions(gtk.gdk.FUNC_MOVE)
  46.         self._window.set_transient_for(parent)
  47.  
  48.     def update(self, percent):
  49.         #print percent
  50.         #print self.Op
  51.         #print self.SubOp
  52.         self._window.show()
  53.         self._parent.set_sensitive(False)
  54.         # if the old percent was higher, a new progress was started
  55.         if self.old > percent:
  56.             # set the borders to the next interval
  57.             self.base = self.next
  58.             try:
  59.                 self.next = int(self.steps.pop(0))
  60.             except:
  61.                 pass
  62.         progress = self.base + percent/100 * (self.next - self.base)
  63.         self.old = percent
  64.         self._status.set_markup("<i>%s</i>" % self.op)
  65.         self._progressbar.set_fraction(progress/100.0)
  66.         while gtk.events_pending():
  67.             gtk.main_iteration()
  68.  
  69.     def done(self):
  70.         self._parent.set_sensitive(True)
  71.     def hide(self):
  72.         self._window.hide()
  73.  
  74. class GtkFetchProgress(apt.progress.FetchProgress):
  75.     def __init__(self, parent, summary="", descr=""):
  76.         # if this is set to false the download will cancel
  77.         self._continue = True
  78.         # init vars here
  79.         # FIXME: find a more elegant way, this sucks
  80.         self.summary = parent.label_fetch_summary
  81.         self.status = parent.label_fetch_status
  82.         self.progress = parent.progressbar_fetch
  83.         self.window_fetch = parent.window_fetch
  84.         self.window_fetch.set_transient_for(parent.window_main)
  85.         self.window_fetch.realize()
  86.         self.window_fetch.window.set_functions(gtk.gdk.FUNC_MOVE)
  87.         # set summary
  88.         if self.summary != "":
  89.             self.summary.set_markup("<big><b>%s</b></big> \n\n%s" %
  90.                                     (summary, descr))
  91.     def start(self):
  92.         self.progress.set_fraction(0)
  93.         self.window_fetch.show()
  94.     def stop(self):
  95.         self.window_fetch.hide()
  96.     def on_button_fetch_cancel_clicked(self, widget):
  97.         self._continue = False
  98.     def pulse(self):
  99.         apt.progress.FetchProgress.pulse(self)
  100.         currentItem = self.currentItems + 1
  101.         if currentItem > self.totalItems:
  102.           currentItem = self.totalItems
  103.         if self.currentCPS > 0:
  104.             statusText = (_("Downloading file %li of %li with %s/s"
  105.                           % (currentItem, self.totalItems,
  106.                              apt_pkg.SizeToStr(self.currentCPS))))
  107.         else:
  108.             statusText = (_("Downloading file %li of %li with unknown "
  109.                           "speed") % (currentItem, self.totalItems))
  110.             self.progress.set_fraction(self.percent/100.0)
  111.         self.status.set_markup("<i>%s</i>" % statusText)
  112.         # TRANSLATORS: show the remaining time in a progress bar:
  113.         #self.progress.set_text(_("About %s left" % (apt_pkg.TimeToStr(self.eta))))
  114.     # FIXME: show remaining time
  115.         self.progress.set_text("")
  116.  
  117.         while gtk.events_pending():
  118.             gtk.main_iteration()
  119.         return self._continue
  120.