File: progressbar.py

package info (click to toggle)
ocempgui 0.2.8-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,464 kB
  • ctags: 1,849
  • sloc: python: 9,304; ansic: 6,849; makefile: 179
file content (71 lines) | stat: -rw-r--r-- 2,065 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
# ProgressBar examples.
from ocempgui.widgets import *
from ocempgui.widgets.Constants import *

def _update_bar (bar, button):
    if bar.value == 0:
        while bar.value < 100:
            bar.increase ()
        button.text = "Clean the progressbar"
    else:
        while bar.value > 0:
            bar.decrease ()
        button.text = "Fill the progressbar"

def _update_text (bar):
    bar.text = "%.2f" % bar.value + "%"

def _create_vframe (text):
    frame = VFrame (Label (text))
    frame.spacing = 5
    frame.align = ALIGN_LEFT
    return frame

def create_progressbar_view ():
    table = Table (1, 3)
    table.spacing = 5
    
    # Create and display a simple ProgressBar.
    frame = _create_vframe ("ProgressBar")
    progress = ProgressBar ()
    progress.step = 0.5

    # Create a button to start filling.
    btn = Button ("#Fill the ProgressBar")
    btn.connect_signal ("clicked", _update_bar, progress, btn)
    frame.add_child (progress, btn)
    table.add_child (0, 0, frame)

    # ProgressBar with text.
    frame = _create_vframe ("Progressbar with text")
    progress = ProgressBar ()
    progress.text = "0.00%"
    progress.step = 0.5
    progress.connect_signal (SIG_VALCHANGED, _update_text, progress)
                             
    # Create a button to start filling.
    btn = Button ("Fill the ProgressBar")
    btn.connect_signal ("clicked", _update_bar, progress, btn)
    frame.add_child (progress, btn)
    table.add_child (0, 1, frame)

    # Insensitive progressbar.
    frame = _create_vframe ("Insensitive Progressbar")
    progress = ProgressBar ()
    progress.value = 50.0
    progress.text = "50.00%"
    progress.sensitive = False
    frame.add_child (progress)
    table.add_child (0, 2, frame)
    
    return table

if __name__ == "__main__":
    # Initialize the drawing window.
    re = Renderer ()
    re.create_screen (450, 150)
    re.title = "ProgressBar examples"
    re.color = (234, 228, 223)
    re.add_widget (create_progressbar_view ())
    # Start the main rendering loop.
    re.start ()