~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/eclib/pstatbar.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
"""
23
23
 
24
24
__author__ = "Cody Precord <cprecord@editra.org>"
25
 
__svnid__ = "$Id: pstatbar.py 62723 2009-11-26 18:43:20Z CJP $"
26
 
__revision__ = "$Revision: 62723 $"
 
25
__svnid__ = "$Id: pstatbar.py 66840 2011-02-03 21:05:28Z CJP $"
 
26
__revision__ = "$Revision: 66840 $"
27
27
 
28
28
__all__ = ["ProgressStatusBar",]
29
29
 
46
46
        @param parent: Frame this status bar belongs to
47
47
 
48
48
        """
49
 
        wx.StatusBar.__init__(self, parent, id_, style, name)
 
49
        super(ProgressStatusBar, self).__init__(parent, id_, style, name)
50
50
  
51
51
        # Attributes
52
52
        self._changed = False   # position has changed ?
87
87
            self.prog.SetSize((rect.width - 8, rect.height - 4))
88
88
        self._changed = False
89
89
 
 
90
    def _UpdateRange(self, range):
 
91
        """Update the internal progress gauges range
 
92
        @param range: int
 
93
 
 
94
        """
 
95
        self.range = range
 
96
        try:
 
97
            self.prog.SetRange(range)
 
98
        except OverflowError:
 
99
            # range too large, scale everything to 100
 
100
            self.prog.SetRange(100)
 
101
 
 
102
    def _UpdateValue(self, value):
 
103
        """Update the internal progress gauges value
 
104
        @param range: int
 
105
 
 
106
        """
 
107
        # Ensure value is within range
 
108
        range = self.prog.GetRange()
 
109
        if range != self.range: # need to scale value
 
110
            value = int((float(value) / float(range)) * 100)
 
111
        self.progress = value
 
112
        self.prog.SetValue(value)
 
113
 
90
114
    #---- Public Methods ----#
91
115
 
92
116
    def Destroy(self):
94
118
        if self.timer.IsRunning():
95
119
            self.timer.Stop()
96
120
        del self.timer
97
 
        wx.StatusBar.Destroy(self)
 
121
        super(ProgressStatusBar, self).Destroy()
98
122
 
99
123
    def DoStop(self):
100
124
        """Stop any progress indication action and hide the bar"""
162
186
        if self.busy or self.progress < 0:
163
187
            self.prog.Pulse()
164
188
        else:
165
 
            # Update the Rqnge if it has changed
 
189
            # Update the Range if it has changed
166
190
            if self.range >= 0 and self.range != self.prog.GetRange():
167
 
                self.prog.SetRange(self.range)
 
191
                self._UpdateRange(self.range)
168
192
 
169
193
            # Update the progress value if it is less than the range
170
194
            if self.progress <= self.range:
171
 
                self.prog.SetValue(self.progress)
 
195
                self._UpdateValue(self.progress)
172
196
 
173
197
    def Run(self, rate=100):
174
198
        """Start the bar's timer to check for updates to progress
188
212
        """
189
213
        self.progress = val
190
214
        if val > 0 and wx.Thread_IsMain():
191
 
            self.prog.SetValue(val)
 
215
            self._UpdateValue(val)
192
216
 
193
217
    def SetRange(self, val):
194
218
        """Set the what the range of the progress bar is. This method can safely
198
222
        """
199
223
        self.range = val
200
224
        if val > 0 and wx.Thread_IsMain():
201
 
            self.prog.SetRange(val)
 
225
            self._UpdateRange(val)
202
226
 
203
227
    def ShowProgress(self, show=True):
204
228
        """Manually show or hide the progress bar
241
265
        self.tmp = self.GetStatusText(bfield)
242
266
        # Clear the progress field so the text doesn't show behind
243
267
        # the progress indicator.
244
 
        super(ProgressStatusBar, self).SetStatusText('', bfield)
 
268
        super(ProgressStatusBar, self).SetStatusText(u'', bfield)
245
269
        self.stop = False
246
270
        self.ShowProgress(True)
247
271
        self.Run(rate)