source: projects/pygtk-rpminstall/trunk/src/progress.py @ 5093

Revision 5093, 3.5 KB checked in by yasumichi, 13 years ago (diff)

fixed gettext related.

Line 
1# progress-rpminstall.py
2#
3# Copyright (C) 2011 - Yasumichi Akahoshi
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
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#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18from gi.repository import Gtk, GdkPixbuf, Gdk
19import os, sys, rpm
20
21UI_FILE = "ui/progress.ui"
22
23class ProgressDialog:
24        def __init__(self, parent, ts):
25                # Build user interface
26                self.builder = Gtk.Builder()
27                self.builder.set_translation_domain('rpminstall')
28                self.builder.add_from_file(os.path.join (os.path.dirname(__file__), UI_FILE))
29                self.builder.connect_signals(self)
30
31                self.dialog = self.builder.get_object('progress_dialog')
32                self.ts = ts
33                self.dialog.show()
34
35        def run(self):
36                self.ts.run (self.runCallback, None)
37                return  Gtk.ResponseType.OK
38
39        def runCallback(self, reason, amount, total, key, client_data):
40                if reason == rpm.RPMCALLBACK_TRANS_START:
41                        progressbar2 = self.builder.get_object('progressbar2')
42                        progressbar2.set_pulse_step (1.0 / total)
43                        self.total = total
44                        self.step = 0
45                        print "Transaction start", amount, total, key
46
47                elif reason == rpm.RPMCALLBACK_TRANS_PROGRESS:
48                        print "Transaction progress", amount, total, key
49
50                elif reason == rpm.RPMCALLBACK_TRANS_STOP:
51                        print "Transaction stop", amount, total, key
52
53                elif reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
54                        print "Opening file. ", reason, amount, total, key, client_data
55                        self.rpmtsCallback_fd = os.open(str(key), os.O_RDONLY)
56                        label1 = self.builder.get_object('label1')
57                        label1.set_text(_("Install ") + key)
58                        Gtk.main_iteration()
59                        return self.rpmtsCallback_fd
60
61                elif reason == rpm.RPMCALLBACK_INST_START:
62                        print "Install Start"
63
64                elif reason == rpm.RPMCALLBACK_INST_CLOSE_FILE:
65                        print "Closing file. ", reason, amount, total, key, client_data
66                        os.close(self.rpmtsCallback_fd)
67                        progressbar2 = self.builder.get_object('progressbar2')
68                        progressbar2.pulse()
69                        Gtk.main_iteration()
70                        self.step += 1
71                        if self.step == self.total:
72                                self.dialog.destroy()
73
74                elif reason == rpm.rpm.RPMCALLBACK_INST_PROGRESS:
75                        progressbar1 = self.builder.get_object('progressbar1')
76                        progressbar1.set_fraction(float(amount) / total)
77                        Gtk.main_iteration()
78
79                elif reason == rpm.RPMCALLBACK_TRANS_STOP:
80                        print "stop"
81
82                elif reason == rpm.RPMCALLBACK_UNKNOWN:
83                        Gtk.main_iteration()
84                        print "problem"
85
86                elif reason == rpm.RPMCALLBACK_UNINST_PROGRESS:
87                        print "RPMCALLBACK_UNINST_PROGRESS"
88
89                elif reason == rpm.RPMCALLBACK_UNINST_START:
90                        print "RPMCALLBACK_UNINST_START"
91
92                elif reason == rpm.RPMCALLBACK_UNINST_STOP:
93                        print "RPMCALLBACK_UNINST_STOP"
94
95                elif reason == rpm.RPMCALLBACK_REPACKAGE_PROGRESS:
96                        print "RPMCALLBACK_REPACKAGE_PROGRESS"
97
98                elif reason == rpm.RPMCALLBACK_REPACKAGE_START:
99                        print "RPMCALLBACK_REPACKAGE_START"
100
101                elif reason == rpm.RPMCALLBACK_REPACKAGE_STOP:
102                        print "RPMCALLBACK_REPACKAGE_STOP"
103
104                elif reason == rpm.RPMCALLBACK_UNPACK_ERROR:
105                        print "RPMCALLBACK_UNPACK_ERROR"
106
107                elif reason == rpm.RPMCALLBACK_CPIO_ERROR:
108                        print "RPMCALLBACK_CPIO_ERROR"
109
110                else:
111                        print reason
112
Note: See TracBrowser for help on using the repository browser.