4 from pygame
.locals import *
9 class Keysym(widget
.Widget
):
12 <p>This widget records the keysym of the key pressed while this widget is in focus.</p>
14 <pre>Keysym(value=None)</pre>
17 <dt>value<dd>initial keysym, see <a href="http://www.pygame.org/docs/ref/key.html">pygame keysyms</a> </dl>
19 <strong>Example</strong>
21 w = Input(value=pygame.locals.K_g)
23 w = Input(pygame.locals.K_g)
30 def __init__(self
,value
=None,**params
):
31 params
.setdefault('cls','keysym')
32 widget
.Widget
.__init
__(self
,**params
)
35 self
.font
= self
.style
.font
36 w
,h
= self
.font
.size("Right Super") #"Right Shift")
37 self
.style
.width
,self
.style
.height
= w
,h
38 #self.rect.w=w+self.style.padding_left+self.style.padding_right
39 #self.rect.h=h+self.style.padding_top+self.style.padding_bottom
43 if e
.type == FOCUS
or e
.type == BLUR
: self
.repaint()
44 elif e
.type == KEYDOWN
:
52 if self
.container
.myfocus
is self
: self
.pcls
= "focus"
56 r
= pygame
.rect
.Rect(0,0,self
.rect
.w
,self
.rect
.h
)
57 #render_box(s,self.style.background,r)
58 if self
.value
== None: return
60 for p
in pygame
.key
.name(self
.value
).split(): name
+= p
.capitalize()+" "
61 #r.x = self.style.padding_left;
62 #r.y = self.style.padding_bottom;
63 s
.blit(self
.style
.font
.render(name
, 1, self
.style
.color
), r
)
65 def __setattr__(self
,k
,v
):
66 if k
== 'value' and v
!= None:
68 _v
= self
.__dict
__.get(k
,NOATTR
)
70 if k
== 'value' and _v
!= NOATTR
and _v
!= v
: