2
# This file is part of GNU Enterprise.
4
# GNU Enterprise is free software; you can redistribute it
5
# and/or modify it under the terms of the GNU General Public
6
# License as published by the Free Software Foundation; either
7
# version 2, or (at your option) any later version.
9
# GNU Enterprise is distributed in the hope that it will be
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with program; see the file COPYING. If not,
16
# write to the Free Software Foundation, Inc., 59 Temple Place
17
# - Suite 330, Boston, MA 02111-1307, USA.
19
# Copyright 2002-2005 Free Software Foundation
32
from constants import *
33
from Control import Control
35
class TextBox(Control):
37
An example textbox control. Allows the user to enter text. Only
40
def __init__(self, Parent, TextboxName, Y, X, W, DefaultValue="", Password=0,
42
Control.__init__(self, Parent, TextboxName, **properties)
44
self.CLASS = "TEXTBOX"
45
self.PASSWORD = Password
50
self.TEXT = str(DefaultValue)
53
self.DEPTH = 0 # our position in the text: 0..N
54
self.MAXLENGTH = -1 # if -1, text length is unlimited
56
self.SetMethod("SYSPAINT", self.Paint)
57
self.SetMethod("SYSGOTFOCUS", self.GotFocus)
58
self.SetMethod("SYSLOSTFOCUS", self.LostFocus)
59
self.SetMethod("SYSRUN", self.Run)
60
self.SetMethod("VERIFY", self.BogusVerify)
61
self.SetMethod("LOSTFOCUS", None)
62
self.SetMethod("GOTFOCUS", None)
63
self.last_act = 1 # 1 = forward, 0 = backward
67
self.SetColor('TEXTBOX', 'TEXTBOX_FOCUS')
69
def Run(self, v1, v2, v3):
70
Container = self.PARENT.Screen()
79
offset = (v3 - self.X)
80
textlen = len(self.TEXT)
84
Depth = Depth - (self.W- offset)
92
ch = Container.GetChar()
94
if self.PARENT.BreakOrder(ch) :
101
ch = self.PARENT.KeystrokeHook(ch)
119
if ch in (Container.TokDownArrow, Container.TokNextField, Container.TokActivate, Container.TokUpArrow):
121
if ch == Container.TokUpArrow:
123
if self.ExecMethod( "VERIFY", self.TEXT, None, None) :
125
## curses.curs_set(0)
129
elif ch == Container.TokLeftArrow:
134
elif ch == Container.TokHomeKey:
136
elif ch == Container.TokEndKey:
138
elif ch == Container.TokRightArrow:
141
if Depth > len(Text):
143
elif ch == Container.TokBackspace:
147
Text = Text[0:Depth] + Text[Depth+1:len(Text)]
149
if ch <= 256 and self.EDITABLE:
150
if Depth == len(Text): # at end
151
Text = Text + chr(ch)
152
elif Depth == 0: # at the beginning
156
Text = chr(ch) + Text
158
Text = Text[:Depth] + chr(ch) + Text[Depth:]
163
self.Paint(None, None, None)
165
def BogusVerify(self, TheControl, TheText, v3):
168
def Paint(self, v1, v2, v3):
169
Container = self.PARENT.SCREEN
172
TextLen = len(self.TEXT)
178
color = self.FOCUSCOLOR
189
if TextLen <= W or Depth < W:
190
Visuals = Text + ((W - TextLen) * "_")
192
Visuals = Visuals[:W-1] + ">"
193
Container.PrintAt(self.Y, self.X, Visuals, color)
194
Container.GotoYX(self.Y, self.X+ Depth)
197
Visuals = "<" + Text[Depth - (W - 1):] + (((W - 1) - TextLen) * "_")
199
Visuals = Visuals[:W]
200
Container.PrintAt(self.Y, self.X, Visuals, self.FOCUS and self.FOCUSCOLOR or self.COLOR)
201
Container.GotoYX(self.Y, self.X+ W)
203
def SetCursor(self, location):
204
self.DEPTH = location
205
Container = self.PARENT.Screen()
207
Container.GotoYX(self.Y, self.X+ self.DEPTH)
208
self.Paint(None, None, None)
210
def LostFocus(self, v1, v2, v3):
213
if self.PARENT.VISIBLE:
216
def GotFocus(self, v1, v2, v3):
218
Container = self.PARENT.Screen()
220
Container.GotoYX(self.Y, self.X+ self.DEPTH)
221
self.Paint(None, None, None)
223
def SetValue(self, newText, repaint=1):
225
if self.PARENT.VISIBLE: