~divmod-dev/divmod.org/no-addperson-2190

« back to all changes in this revision

Viewing changes to Imaginary/pottery/wiring/faucet.py

  • Committer: exarkun
  • Date: 2006-02-26 02:37:39 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:4991
Merge move-pottery-to-trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from twisted.conch.insults import window
 
3
 
 
4
class Faucet(window.ContainerWidget):
 
5
    _outputText = ''
 
6
    _toBottom = False
 
7
 
 
8
    def __init__(self, onInput):
 
9
        window.ContainerWidget.__init__(self)
 
10
 
 
11
        self._inputCallback = onInput
 
12
 
 
13
        place = window.TextOutputArea()
 
14
        things = window.TextOutputArea()
 
15
        place_things = window.HBox()
 
16
        place_things.addChild(window.Border(place))
 
17
        place_things.addChild(window.Border(things))
 
18
 
 
19
        output = window.TextOutputArea()
 
20
        scrolledOutput = window.ScrolledArea(output)
 
21
        input = window.TextInput(78, self._onInput)
 
22
        output_input = window.VBox()
 
23
        output_input.addChild(scrolledOutput)
 
24
        output_input.addChild(input)
 
25
 
 
26
        detail_interaction = window.VBox()
 
27
        detail_interaction.addChild(place_things)
 
28
        detail_interaction.addChild(output_input)
 
29
 
 
30
        self.addChild(detail_interaction)
 
31
 
 
32
        self._place = place
 
33
        self._things = things
 
34
        self._output = output
 
35
        self._scroll = scrolledOutput
 
36
        self._input = input
 
37
 
 
38
    def render(self, width, height, terminal):
 
39
        self._input.maxwidth = width - 2
 
40
        if self._toBottom:
 
41
            self._toBottom = False
 
42
            n = self._outputText.count('\n')
 
43
            m = ((height - 4) / 2 - 1)
 
44
            self._scroll._viewport.yOffset = max(0, n - m)
 
45
 
 
46
        return window.ContainerWidget.render(self, width, height, terminal)
 
47
 
 
48
    def _onInput(self, text):
 
49
        self._input.setText('')
 
50
        self.addOutputLine('> ' + text)
 
51
        self._inputCallback(text)
 
52
 
 
53
    def setPlace(self, text):
 
54
        self._place.setText(text)
 
55
 
 
56
    def setThings(self, text):
 
57
        self._things.setText(text)
 
58
 
 
59
    def addOutputLine(self, text):
 
60
        self._outputText += text + '\n'
 
61
        self._output.setText(self._outputText)
 
62
        self._toBottom = True