~ubuntu-app-review-contributors/ubuntu-app-reviews/gtumbler

« back to all changes in this revision

Viewing changes to gtumbler/ProgressDialog.py

  • Committer: App Bot
  • Author(s): Gabriele N. Tornetta
  • Date: 2012-07-09 21:32:00 UTC
  • Revision ID: appbot@holba.ch-20120709213200-ezm1clcugzgrc7vq
Tags: 12.07.1
New release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
### BEGIN LICENSE
 
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.
 
7
 
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.
 
12
 
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/>.
 
15
### END LICENSE
 
16
 
 
17
import gtk
 
18
 
 
19
from gtumbler_lib.helpers import get_builder
 
20
 
 
21
import gettext
 
22
from gettext import gettext as _
 
23
gettext.textdomain('gtumbler')
 
24
 
 
25
class ProgressDialog(gtk.Dialog):
 
26
    __gtype_name__ = "ProgressDialog"
 
27
 
 
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.
 
31
        
 
32
        Returns a fully instantiated ProgressDialog object.
 
33
        """
 
34
        builder = get_builder('ProgressDialog')
 
35
        new_object = builder.get_object('progress_dialog')
 
36
        new_object.finish_initializing(builder)
 
37
        return new_object
 
38
 
 
39
    def finish_initializing(self, builder):
 
40
        """Called when we're finished initializing.
 
41
 
 
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
 
45
        instance.
 
46
        """
 
47
        # Get a reference to the builder and set up the signals.
 
48
        self.builder = builder
 
49
        self.ui = builder.get_ui(self)
 
50
 
 
51
        def __enter__(self):
 
52
                return self
 
53
                
 
54
        def __exit__(self, exc_type, exc_value, traceback):
 
55
                self.destroy()
 
56
                return False
 
57
 
 
58
    def __init__(self, thread = None):
 
59
        self.thread = thread
 
60
        self.steps = 0
 
61
        self.current_step = 0
 
62
        self.max = 0
 
63
        self.initial_Frac = 0
 
64
       
 
65
    def start(self):
 
66
        self.thread.start()
 
67
        return self.run()
 
68
        
 
69
    def stop(self):
 
70
        self.thread.stop()
 
71
        
 
72
### BEGIN LOCAL HELPERS
 
73
 
 
74
    def get_fraction(self):
 
75
        return self.ui.pb_task.get_fraction()
 
76
 
 
77
    def set_current_task(self, task):
 
78
        self.ui.lbl_current_task.set_text(task)
 
79
        
 
80
    def pulse(self):
 
81
        self.ui.pb_task.pulse()
 
82
        
 
83
    def set_fraction(self, frac):
 
84
        self.ui.pb_task.set_fraction(frac)
 
85
 
 
86
    def set_max(self, fl):
 
87
        self.max = fl
 
88
 
 
89
    def set_steps(self, n):
 
90
        self.steps = n
 
91
        self.current_step = 0
 
92
        self.initial_frac = self.get_fraction()
 
93
        
 
94
    def stepit(self):
 
95
        self.current_step += 1
 
96
        self.set_fraction(self.initial_frac + float(self.current_step) / self.steps * self.max)
 
97
        
 
98
    def spinner(self, spin):
 
99
                self.ui.spinner.set_visible(spin)
 
100
                self.ui.spinner.start() if spin else self.ui.spinner.stop()
 
101
                
 
102
### END LOCAL HELPERS
 
103
 
 
104
### BEGIN SIGNAL HANDLERS
 
105
 
 
106
    def on_btn_cancel_clicked(self, widget, data=None):
 
107
        """The user has elected cancel changes.
 
108
 
 
109
        Called before the dialog returns gtk.RESPONSE_CANCEL for run()
 
110
        """
 
111
        pass
 
112
 
 
113
 
 
114
### END SIGNAL HANDLERS