3
# Author: Laudeci Oliveira <laudeci@gmail.com>
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License as
7
# published by the Free Software Foundation; either version 2 of the
8
# 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.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
class ProgressDialog(gtk.Window):
27
ProgressWindow returns a window that contains a number of properties to
28
access what a common Progress window should have.
30
def __init__(self, title = "", description = "", parent = None, task = ""):
31
# Creating the windows and its properties
32
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
33
self.parentui = parent
34
if self.parentui != None:
35
self.set_transient_for(parent)
36
self._create_ui(title, description, task)
37
self.cancel_status = False
39
def _create_ui(self, title, description, task):
40
self.set_border_width(6)
41
self.set_resizable(False)
42
#self.set_has_separator(False)
43
self.set_skip_taskbar_hint(True)
44
self.set_type_hint(gtk.WINDOW_POPUP)
45
self.set_size_request(520,190)
48
self.window.set_functions(gtk.gdk.FUNC_MOVE)
49
# prevent the window from closing with the delete button (there is
50
# a cancel button in the window)
51
self.connect("delete_event", lambda e,w: True);
54
vbox.set_border_width(6)
58
self.labelTitle = label = gtk.Label('<big><b>%s</b></big>' % title)
59
label.set_use_markup(True)
60
label.set_alignment(0.0, 0.0)
62
vbox.pack_start(label, False)
64
self.labelDesc = label = gtk.Label(description)
65
label.set_line_wrap(True)
66
label.set_alignment(0.5, 0.0)
67
label.set_padding(0, 12)
69
vbox.pack_start(label, False)
71
self.progress = progress = gtk.ProgressBar()
73
vbox.pack_start(progress, False)
75
self.progresstext = label = gtk.Label('<i>%s</i>' % task)
76
label.set_use_markup(True)
77
label.set_alignment(0.0, 0.0)
79
vbox.pack_start(label,False)
81
hbbox =gtk.HButtonBox()
82
hbbox.set_border_width(5)
83
hbbox.set_layout( gtk.BUTTONBOX_END)
85
vbox.pack_start(hbbox,False)
87
self.btnCancel = btnCancel =gtk.Button(gtk.STOCK_CANCEL)
88
btnCancel.set_use_stock(True)
90
hbbox.pack_start(btnCancel)
94
def connectEvent(self,functionEvent):
95
self.btnCancel.connect("clicked",functionEvent)
98
def set_windowtitle(self,title):
101
def set_tasktitle(self,title):
102
self.labelTitle.set_markup('<big><b>%s</b></big>' % title)
104
def set_task(self,task):
105
self.progresstext.set_markup('<i>%s</i>' % task)
107
def set_description(self,description):
108
self.labelDesc.set_text(description)
110
class AptOnCDProgressDialog(ProgressDialog):
112
def __init__(self, parent = None, start = 0, stop = 0):
115
ProgressDialog.__init__(self,(msg.MESSAGE_0052),
117
parent,(msg.MESSAGE_0054))
121
self.cancel_status = False
122
self.btnCancel.connect("clicked", self.click)
125
def click(self, *args):
126
self.cancel_status = True
129
def TaskLenght(self,lenWork):
131
self.update(self.start)
133
def TaskTitle(self,title):
134
self.set_tasktitle(title)
136
def Title(self,title):
137
self.set_windowtitle(title)
142
def Description(self,description):
143
self.set_description(description)
145
def isCancelEnabled(self,value = True):
146
self.btnCancel.set_sensitive(value)
147
self.btnCancel.set_property('visible',value)
149
def set_text(self,value):
150
self.progress.set_text(value)
153
def updateFraction(self,value):
154
self.progress.set_fraction(value)
155
self.progress.set_text(('%d%%' % (value * 100)))
158
def set_fraction(self, value):
159
self.progress.set_text(('%d%%' % (value * 100)))
160
self.progress.set_fraction(value)
163
def update(self, pos):
165
pos = min(max(pos, self.start), self.stop)
166
remaining = self.stop - pos
167
self.progress.set_text((msg.MESSAGE_0055 % (remaining, self.stop)))
168
self.progress.set_fraction(1.0 - float(remaining) / (self.stop - self.start))
169
except ZeroDivisionError:
170
self.progress.set_fraction(self.start)