1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 Gabriele N. Tornetta <phoenix1987@gmail.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
from gtumbler_lib.helpers import get_builder
22
from gettext import gettext as _
23
gettext.textdomain('gtumbler')
25
class ProgressDialog(gtk.Dialog):
26
__gtype_name__ = "ProgressDialog"
28
def __new__(cls, data = None):
29
"""Special static method that's automatically called by Python when
30
constructing a new instance of this class.
32
Returns a fully instantiated ProgressDialog object.
34
builder = get_builder('ProgressDialog')
35
new_object = builder.get_object('progress_dialog')
36
new_object.finish_initializing(builder)
39
def finish_initializing(self, builder):
40
"""Called when we're finished initializing.
42
finish_initalizing should be called after parsing the ui definition
43
and creating a ProgressDialog object with it in order to
44
finish initializing the start of the new ProgressDialog
47
# Get a reference to the builder and set up the signals.
48
self.builder = builder
49
self.ui = builder.get_ui(self)
54
def __exit__(self, exc_type, exc_value, traceback):
58
def __init__(self, thread = None):
72
### BEGIN LOCAL HELPERS
74
def get_fraction(self):
75
return self.ui.pb_task.get_fraction()
77
def set_current_task(self, task):
78
self.ui.lbl_current_task.set_text(task)
81
self.ui.pb_task.pulse()
83
def set_fraction(self, frac):
84
self.ui.pb_task.set_fraction(frac)
86
def set_max(self, fl):
89
def set_steps(self, n):
92
self.initial_frac = self.get_fraction()
95
self.current_step += 1
96
self.set_fraction(self.initial_frac + float(self.current_step) / self.steps * self.max)
98
def spinner(self, spin):
99
self.ui.spinner.set_visible(spin)
100
self.ui.spinner.start() if spin else self.ui.spinner.stop()
102
### END LOCAL HELPERS
104
### BEGIN SIGNAL HANDLERS
106
def on_btn_cancel_clicked(self, widget, data=None):
107
"""The user has elected cancel changes.
109
Called before the dialog returns gtk.RESPONSE_CANCEL for run()
114
### END SIGNAL HANDLERS