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