Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / build / lib / pgu / gui / keysym.py
1 """
2 """
3 import pygame
4 from pygame.locals import *
5
6 from .const import *
7 from . import widget
8
9 class Keysym(widget.Widget):
10     """A keysym input. This is deprecated and is scheduled to be removed from PGU."""
11
12     _value = None
13
14     def __init__(self,value=None,**params):
15         params.setdefault('cls','keysym')
16         widget.Widget.__init__(self,**params)
17         self.value = value
18         
19         self.font = self.style.font
20         w,h = self.font.size("Right Super") #"Right Shift")
21         self.style.width,self.style.height = w,h
22         #self.rect.w=w+self.style.padding_left+self.style.padding_right
23         #self.rect.h=h+self.style.padding_top+self.style.padding_bottom
24     
25     def event(self,e):
26         used = None
27         if e.type == FOCUS or e.type == BLUR: self.repaint()
28         elif e.type == KEYDOWN:
29             if e.key != K_TAB:
30                 self.value = e.key
31                 self.repaint()
32                 self.send(CHANGE)
33                 used = True
34             self.next()
35         self.pcls = ""
36         if self.container.myfocus is self: self.pcls = "focus"
37         return used
38     
39     def paint(self,s):
40         r = pygame.rect.Rect(0,0,self.rect.w,self.rect.h)
41         #render_box(s,self.style.background,r)
42         if self.value == None: return
43         name = ""
44         for p in pygame.key.name(self.value).split(): name += p.capitalize()+" "
45         #r.x = self.style.padding_left;
46         #r.y = self.style.padding_bottom;
47         s.blit(self.style.font.render(name, 1, self.style.color), r)
48
49     @property
50     def value(self):
51         return self._value
52
53     @value.setter
54     def value(self, val):
55         if (val != None):
56             val = int(val)
57         oldval = self._value
58         self._value = val
59         if (oldval != val):
60             self.send(CHANGE)
61             self.repaint()
62
63

UCC git Repository :: git.ucc.asn.au