Skip to content

Commit

Permalink
-replaced extraneous tabs with spaces
Browse files Browse the repository at this point in the history
-textarea fixes (expanding problem, cursor placement)
  • Loading branch information
peter.rogers committed Feb 20, 2011
1 parent 59cc210 commit 0202496
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions examples/gui5.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
c.td(gui.Label("Keysym"))
c.td(gui.Keysym(),colspan=3)

#c.tr()
#c.td(gui.Label("Text Area"), colspan=4, align=-1)
c.tr()
c.td(gui.Label("Text Area"), colspan=4, align=-1)

#c.tr()
#c.td(gui.TextArea(value="Cuzco the Goat", width=150, height=70), colspan=4)
c.tr()
c.td(gui.TextArea(value="Cuzco the Goat", width=150, height=70), colspan=4)

app.run(c)
4 changes: 2 additions & 2 deletions pgu/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def loop(self):

for e in pygame.event.get():
#NOTE: this might break API?
#if self.event(e): return
if not self.event(e):
#if self.event(e): return
if not self.event(e):
if self.fnc('event',e): return

self.tick()
Expand Down
15 changes: 8 additions & 7 deletions pgu/gui/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ def __init__(self, width, height, **params):
self.group = g
g.connect(CHANGE,self._change,None)
self.value = self.group.value = None
self.add = self._add
self.remove = self._remove

self.add = self._add
self.remove = self._remove

def clear(self):
"""Clear the list."""
Expand All @@ -415,17 +415,18 @@ def clear(self):
self.blur(self.myfocus)

def _add(self, label, image = None, value=None):
item = _List_Item(label,image=image,value=value)
item = _List_Item(label,image=image,value=value)
self.table.tr()
self.table.add(item)
self.items.append(item)
item.group = self.group
item.group.add(item)

def _remove(self, item):
for i in self.items:
if i.value == item: item = i
if item not in self.items: return
for i in self.items:
if i.value == item: item = i
if item not in self.items:
return
item.blur()
self.items.remove(item)
self.group.widgets.remove(item)
Expand Down
2 changes: 1 addition & 1 deletion pgu/gui/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class HSlider(_slider):
def __init__(self,value,min,max,size,step=1,**params):
params.setdefault('cls','hslider')
_slider.__init__(self,value,_SLIDER_HORIZONTAL,min,max,size,step,**params)

class HScrollBar(table.Table):
"""A horizontal scroll bar."""

Expand Down
2 changes: 1 addition & 1 deletion pgu/gui/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def subsurface(s,r):
r = pygame.Rect(r)
if r.x < 0 or r.y < 0:
raise Exception("rectangle out of bounds: surface=%dx%d, rect=%s" % (
s.get_width(),s.get_height(),r))
s.get_width(),s.get_height(),r))
w,h = s.get_width(),s.get_height()
if r.right > w:
r.w -= r.right-w
Expand Down
55 changes: 27 additions & 28 deletions pgu/gui/textarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class TextArea(widget.Widget):
w = TextArea("Groucho\nHarpo\nChico\nGummo\nZeppo\n\nMarx", 200, 400, 12)
"""

_value = None

def __init__(self,value="",width = 120, height = 30, size=20,**params):
params.setdefault('cls','input')
params.setdefault('width', width)
Expand All @@ -33,10 +30,13 @@ def __init__(self,value="",width = 120, height = 30, size=20,**params):
if not self.style.height: self.style.height = h
if not self.style.width: self.style.width = w

def resize(self,width=None,height=None):
if (width != None) and (height != None):
self.rect = pygame.Rect(self.rect.x, self.rect.y, width, height)
return self.rect.w, self.rect.h
## BUG: This causes textarea to grow every time table._Table_td calculates its
## size.
## def resize(self,width=None,height=None):
## if (width != None) and (height != None):
## print 'TextArea RESIZE'
## self.rect = pygame.Rect(self.rect.x, self.rect.y, width, height)
## return self.rect.w, self.rect.h

def paint(self,s):

Expand Down Expand Up @@ -140,7 +140,8 @@ def setCursorByHVPos(self):
# If we're on the proper line
if (line_cnt == self.vpos):
# Make sure that we're not trying to go over the edge of the current line
if ( self.hpos >= len(line) ):
## if ( self.hpos >= len(line) ):
if ( self.hpos > len(line) ):
self.hpos = len(line) - 1
# Set the cursor position
self.pos = line_char_start + self.hpos
Expand Down Expand Up @@ -182,6 +183,9 @@ def doLines(self, max_line_w):
# Then make sure we added the last of the line
if (line_start < len( self.value ) ):
self.lines.append( self.value[ line_start : len( self.value ) ] )
## NEW: next 2 lines
else:
self.lines.append('')
# If we reached a hard line break
elif (self.value[inx] == "\n"):
# Then make a line break here as well.
Expand All @@ -195,13 +199,13 @@ def doLines(self, max_line_w):
pass

def _setvalue(self,v):
#self.__dict__['value'] = v
self._value = v
self.__dict__['value'] = v
self.send(CHANGE)

def event(self,e):
used = None
if e.type == KEYDOWN:
used = True
if e.key == K_BACKSPACE:
if self.pos:
self._setvalue(self.value[:self.pos-1] + self.value[self.pos:])
Expand All @@ -221,10 +225,10 @@ def event(self,e):
self.pos = newPos
elif e.key == K_LEFT:
if self.pos > 0: self.pos -= 1
used = True
# used = True
elif e.key == K_RIGHT:
if self.pos < len(self.value): self.pos += 1
used = True
# used = True
elif e.key == K_UP:
self.vpos -= 1
self.setCursorByHVPos()
Expand All @@ -238,6 +242,7 @@ def event(self,e):
# pass
else:
#c = str(e.unicode)
used = None
try:
if (e.key == K_RETURN):
c = "\n"
Expand All @@ -246,6 +251,7 @@ def event(self,e):
else:
c = (e.unicode).encode('latin-1')
if c:
used = True
self._setvalue(self.value[:self.pos] + c + self.value[self.pos:])
self.pos += len(c)
except: #ignore weird characters
Expand All @@ -264,22 +270,15 @@ def event(self,e):
if self.container.myfocus is self: self.pcls = "focus"

return used

@property
def value(self):
return self._value

@value.setter
def value(self, val):
if val == None:
val = ''
val = str(val)
self.pos = len(val)

oldval = self._value
self._value = val
print oldval, "VS", val
if (oldval != val):

def __setattr__(self,k,v):
if k == 'value':
if v == None: v = ''
v = str(v)
self.pos = len(v)
_v = self.__dict__.get(k,NOATTR)
self.__dict__[k]=v
if k == 'value' and _v != NOATTR and _v != v:
self.send(CHANGE)
self.repaint()

Expand Down
10 changes: 5 additions & 5 deletions pgu/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

def write(s,font,pos,color,text,border=1):
"""Write text to a surface with a black border"""
# Render the text in black, at various offsets to fake a border
# Render the text in black, at various offsets to fake a border
tmp = font.render(text,1,(0,0,0))
dirs = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
for dx,dy in dirs:
s.blit(tmp,(pos[0]+dx*border,pos[1]+dy*border))
# Now render the text properly, in the proper color
s.blit(tmp,(pos[0]+dx*border,pos[1]+dy*border))
# Now render the text properly, in the proper color
tmp = font.render(text,1,color)
s.blit(tmp,pos)

def writec(s,font,color,text,border=1):
"""Write centered text to a surface with a black border"""
# Center the text within the destination surface
# Center the text within the destination surface
w,h = font.size(text)
x = (s.get_width()-w)/2
y = (s.get_height()-h)/2
Expand All @@ -36,7 +36,7 @@ def writewrap(s, font, rect, color, text, maxlines=None, wrapchar=False):
"""Write wrapped text on a pygame surface.
maxlines -- specifies the maximum number of lines to write
before stopping
before stopping
wrapchar -- whether to wrap at the character level, or
word level
"""
Expand Down

0 comments on commit 0202496

Please sign in to comment.