File: rpprogress.py

package info (click to toggle)
routeplanner 0.17
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,836 kB
  • ctags: 264
  • sloc: python: 3,282; makefile: 58; sh: 40
file content (66 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Code for the progress bar in RoutePlanner/RouteEdit
#
# Copyright (C) 1996-2004 Chris Lawrence
# This file may be freely distributed under the terms of the RoutePlanner
# license.  A copy should appear as 'LICENSE' in the archive that this
# file was included in.
#
# $Id: rpprogress.py,v 1.6 2004/06/20 09:35:55 lordsutch Exp $

from __future__ import division
import gtk

def render():
    while gtk.events_pending():
        gtk.main_iteration(False)

class ProgressWin:
    def __init__(self, title='', parent=None):
        self.current, self.max = 0, 1
        self.window = gtk.Window()
        if parent:
            self.window.set_transient_for(parent)
        self.window.set_title(title)
        self.bartitle = gtk.Frame()
        self.bar = gtk.ProgressBar()
        self.bartitle.add(self.bar)
        self.window.set_title(title)
        self.window.connect("delete_event", self.close_clicked)
        self.window.add(self.bartitle)
        self.window.set_default_size(200, -1)
        self.window.set_modal(True)
        self.bar.show()
        self.bartitle.show()

    def set_label(self, label):
        self.bartitle.set_label(label)
        render()

    def set_max(self, maxval):
        self.max = maxval
        self.bar.set_fraction(self.current/self.max)
        render()

    def set_current(self, current):
        self.current = current
        if self.max:
            self.bar.set_fraction(current/self.max)
        else:
            self.bar.set_fraction(0.0)
        render()

    def close_clicked(self, *args):
        self.hide()
        render()
        return True

    def hide(self):
        render()
        self.window.hide()

    def destroy(self):
        self.window.destroy()

    def show(self):
        self.window.show()
        render()