summaryrefslogtreecommitdiffstats
path: root/iw/progress_gui.py
blob: ec987c240d1a68f1bc4ca653bac107a3c08997a6 (plain)
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
132
133
134
135
136
137
138
139
140
#
# progress_gui.py: install/upgrade progress window setup.
#
# Copyright 2000-2007 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import os, sys, string
import glob

import gtk
import pango

import gui
from flags import flags
from iw_gui import *
from rhpl.translate import _, N_
from constants import *
import language

import logging
log = logging.getLogger("anaconda")

class InstallProgressWindow (InstallWindow):
    windowTitle = N_("Installing Packages")

    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)
        ics.setPrevEnabled (False)
        ics.setNextEnabled (False)

        self._updateChange = 0.01
        self._showPercentage = False

    def processEvents(self):
        gui.processEvents()

    def get_fraction(self):
        return self.progress.get_fraction()
    def set_fraction(self, pct):
        cur = self.get_fraction()
        if pct - cur > self._updateChange:
            self.progress.set_fraction(pct)
            if self._showPercentage:
                self.progress.set_text("%d %" %(pct * 100,))
            self.processEvents()

    def set_label(self, txt):
        self.infolabel.set_markup(txt)
        self.infolabel.set_ellipsize(pango.ELLIPSIZE_END)
        self.processEvents()

    def set_text(self, txt):
        if self._showPercentage:
            log.debug("Setting progress text with showPercentage set")
            return
        self.progress.set_text(txt)
        self.processEvents()

    def renderCallback(self):
        self.intf.icw.nextClicked()

    def setShowPercentage(self, val):
        if val not in (True, False):
            raise ValueError, "Invalid value passed to setShowPercentage"
        self._showPercentage = val

    def _getRnotes(self):
        langs = []
        pixmaps = []
        if (os.environ.has_key('LANG')):
            langs = language.expandLangs(os.environ['LANG'])
        langs.append('')

        pixmaps = []
        paths = ("/tmp/product/pixmaps/rnotes/%s/*.png",
                 "/usr/share/anaconda/pixmaps/rnotes/%s/*.png")
        for p in paths:
            for lang in langs:
                path = p % lang
                pixmaps = glob.glob(path)
                if len(pixmaps) > 0:
                    break

        if len(pixmaps) > 0:
            files = pixmaps
        else:
            files = ["progress_first.png"]

        if self.intf.runres != '800x600':
            files = ["progress_first-lowres.png"]

        return files
        

    def getScreen (self, anaconda):
	self.intf = anaconda.intf
	if anaconda.dir == DISPATCH_BACK:
	    self.intf.icw.prevClicked()
	    return

        self.pixmaps = self._getRnotes()

	# Create vbox to contain components of UI
        vbox = gtk.VBox (False, 12)

        # Create rnote area
        self.adpix = None
        self.adbox = None
        pix = gui.readImageFromFile ("progress_first.png")
        if pix:
            frame = gtk.Frame()
            frame.set_shadow_type(gtk.SHADOW_NONE)
            box = gtk.EventBox()
            self.adpix = pix
            box.add(self.adpix)
            self.adbox = box
            frame.add(box)
            vbox.pack_start(frame);


	self.progress = gtk.ProgressBar()
        vbox.pack_start(self.progress, False)

        self.infolabel = gui.WrappingLabel("")
        vbox.pack_start(self.infolabel)

	# All done with creating components of UI
	self.intf.setPackageProgressWindow(self)
	anaconda.id.setInstallProgressClass(self)

	vbox.set_border_width(6)

	return vbox