summaryrefslogtreecommitdiff
path: root/lib/snack/__init__.py
blob: 33b908ed94936955ea0aa3debcbe6019624721a4 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python

"""
Written by Igor Pashev <pashev.igor@gmail.com>

The author has placed this work in the Public Domain,
thereby relinquishing all copyrights. Everyone is free
to use, modify, republish, sell or give away this work
without prior consent from anybody.
"""

from snack import *

class ProgressMessage(object):
    _text = None

    @property
    def text(self):
        return self._text
    @text.setter
    def text(self, text):
        self._text = text
        self._textbox.setText(self._text)
        self._refresh()

    def _refresh(self):
        self._form.draw()
        self._screen.refresh()

    def __init__(self, screen, width=40, title='', text=''):
        self._screen = screen

        self._textbox = TextboxReflowed(width, text)

        self._grid = Grid(1, 1)
        self._grid.setField(self._textbox, 0, 0)

        self._screen.gridWrappedWindow(self._grid, title)

        self._form = Form()
        self._form.add(self._textbox)
        self._refresh()
    
    def __del__(self):
        self._screen.popWindow()

class ProgressBar(object):
    _progress = 0
    _top = 0
    _text = None
    _textbox = None
    _screen = None
    _form = None
    _scale = None
    _grid = None

    @property
    def text(self):
        return self._text
    @text.setter
    def text(self, text):
        self._text = text
        self._textbox.setText(self._text)
        self._refresh()

    @property
    def progress(self):
        return self._progress
    @text.setter
    def progress(self, i):
        self._progress = i
        self._scale.set(self._progress)
        self._refresh()

    def advance(self, increment = 1):
        self.progress = self._progress + increment



    def _refresh(self):
        self._form.draw()
        self._screen.refresh()


    def __init__(self, screen, width=40, title='', text=' ', top=100):
        self._screen = screen
        self._top = top

        self._textbox = TextboxReflowed(width, text)

        self._scale = Scale(width, self._top)
        self._scale.set(0)

        self._grid = Grid(1, 2)
        self._grid.setField(self._textbox, 0, 0)
        self._grid.setField(self._scale, 0, 1)

        self._screen.gridWrappedWindow(self._grid, title)

        self._form = Form()
        self._form.add(self._textbox)
        self._form.add(self._scale)

    
    def __del__(self):
        self._screen.popWindow()