Package pyanaconda :: Package textw :: Module progress_text
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.textw.progress_text

  1  # 
  2  # progress_text.py: text mode install/upgrade progress dialog 
  3  # 
  4  # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007  Red Hat, Inc. 
  5  # All rights reserved. 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation; either version 2 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20   
 21  from pyanaconda.constants import * 
 22  from snack import * 
 23  from constants_text import * 
 24  from pyanaconda.iutil import strip_markup 
 25   
 26  import gettext 
 27  _ = lambda x: gettext.ldgettext("anaconda", x) 
 28   
 29  import logging 
 30  log = logging.getLogger("anaconda") 
 31   
32 -class InstallProgressWindow:
33 - def __init__(self, screen):
34 self.screen = screen 35 self.drawn = False 36 37 self.pct = 0
38
39 - def __del__ (self):
40 if self.drawn: 41 self.screen.popWindow ()
42
43 - def _setupScreen(self):
44 screen = self.screen 45 46 self.grid = GridForm(self.screen, _("Package Installation"), 1, 6) 47 48 self.width = 65 49 self.progress = Scale(self.width, 100) 50 self.grid.add (self.progress, 0, 1, (0, 1, 0, 0)) 51 52 self.label = Label("") 53 self.grid.add(self.label, 0, 2, (0, 1, 0, 0), anchorLeft = 1) 54 55 self.info = Textbox(self.width, 4, "", wrap = 1) 56 self.grid.add(self.info, 0, 3, (0, 1, 0, 0)) 57 58 self.grid.draw() 59 screen.refresh() 60 self.drawn = True
61
62 - def processEvents(self):
63 if not self.drawn: 64 return 65 self.grid.draw() 66 self.screen.refresh()
67
68 - def setShowPercentage(self, val):
69 pass
70
71 - def get_fraction(self):
72 return self.pct
73
74 - def set_fraction(self, pct):
75 if not self.drawn: 76 self._setupScreen() 77 78 if pct > 1.0: 79 pct = 1.0 80 81 self.progress.set(int(pct * 100)) 82 self.pct = pct 83 self.processEvents()
84
85 - def set_label(self, txt):
86 if not self.drawn: 87 self._setupScreen() 88 89 self.info.setText(strip_markup(txt)) 90 self.processEvents()
91
92 - def set_text(self, txt):
93 if not self.drawn: 94 self._setupScreen() 95 96 if len(txt) > self.width: 97 txt = txt[:self.width] 98 else: 99 spaces = (self.width - len(txt)) / 2 100 txt = (" " * spaces) + txt 101 102 self.label.setText(strip_markup(txt)) 103 self.processEvents()
104
105 -class setupForInstall:
106
107 - def __call__(self, screen, anaconda):
108 if anaconda.dir == DISPATCH_BACK: 109 anaconda.intf.setInstallProgressClass(None) 110 return INSTALL_BACK 111 112 anaconda.intf.setInstallProgressClass(InstallProgressWindow(screen)) 113 return INSTALL_OK
114 115 if __name__ == "__main__": 116 screen = SnackScreen() 117 ipw = InstallProgressWindow(screen) 118 119 import time 120 ipw._setupScreen() 121 time.sleep(2) 122 123 ipw.set_label("testing blah\n<b>blahblahb</b>lahbl ahalsdfkj") 124 ipw.set_text("blah blah blah") 125 ipw.set_fraction(0.25) 126 time.sleep(2) 127 128 p = ipw.get_fraction() 129 130 screen.finish() 131 print(p) 132