1 """GNUmed - Richard Terry style GUI elements
2
3 TODO:
4 - implement user defined rgb colours
5 - implement flashing text on the rest of the panel!
6 - add font size/style as option
7
8 copyright: author
9 dependencies: wxPython (>= version 2.3.1)
10 """
11
12
13 __version__ = "$Revision: 1.6 $"
14 __author__ = 'Dr. Richard Terry'
15 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
16
17 try:
18 import wxversion
19 import wx
20 except ImportError:
21 from wxPython import wx
22
23
25 """Bottom left hand pane alert panel.
26
27 This panel consists constructs a simple heading to be used at the bottom
28 of the screen, in the form of capitalised word on user defined foreground
29 and background colours. The heading is left justified curently. The
30 default colours are black text on intermediate grey so as to not make it
31 too intrusive. The alert text will appear in flashing red text
32 """
33
34
36 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0 )
37 self.SetBackgroundColour(wx.Colour(222,222,222))
38 sizer = wx.BoxSizer(wx.HORIZONTAL)
39
40
41
42
43
44
45 captionpanel = wx.Panel(self,-1,size = (400,10))
46 captionpanel.SetBackgroundColour(wx.Colour(197,194,197))
47 caption = wx.StaticText(captionpanel,-1, title,style = wx.ALIGN_CENTRE_VERTICAL)
48 caption.SetForegroundColour(wx.Colour(0,0,0))
49
50 caption.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL, wx.BOLD,False,''))
51 sizer.Add(captionpanel,1,wx.EXPAND|wx.ALL,2)
52 sizer.Add(0,9,6)
53 self.SetSizer(sizer)
54 sizer.Fit(self)
55 self.SetAutoLayout(True)
56
57
59 self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green))
60 return
62 self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green))
63 return
64
65
67 """This panel consists of one or more headings on a horizontal panel and is
68
69 used to divide/head sections of the screenel There are user defined foreground
70 and background colours. The captions are centred in the available space. The
71 default colours are purple panel with white bold text
72 words (sounds yuk doesn't it - but I like it and it works well!!!!!
73 """
74
75
77 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0)
78 sizer = wx.BoxSizer(wx.HORIZONTAL)
79 self.SetBackgroundColour(wx.Colour(197,194,255))
80
81 caption = wx.StaticText(self,-1, title,style = wx.ALIGN_CENTRE)
82 caption.SetForegroundColour(wx.WHITE)
83
84 caption.SetFont(wx.Font(13,wx.SWISS,wx.NORMAL, wx.BOLD,False,''))
85 sizer.Add(caption,1,wx.EXPAND)
86 self.SetSizer(sizer)
87 sizer.Fit(self)
88 self.SetAutoLayout(True)
89
90
92 self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green))
93
95 self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green))
96 return
97
98
100 """This panel consists constructs a simple heading to be used at the top
101
102 of a panel, in the form of capitalised word on user defined foreground
103 and background colours. The heading is left justified curently. The
104 default colours are purple panel, orange label with yellow capitalised
105 words (sounds yuk doesn't it - but I like it and it works well!!!!!
106 """
107 - def __init__ (self, parent, id, text, bgC = wx.Colour (197,194,255), hdrC = wx.Colour (255, 129, 131), txtC = wx.Colour (255, 255, 0)):
108 self.text = text
109 self.bgC = bgC
110 self.hdrC = hdrC
111 self.txtC = txtC
112 wx.Panel.__init__(self, parent, id)
113 wx.EVT_PAINT (self, self.OnPaint)
114 wx.EVT_SIZE (self, self.OnSize)
115 self.w = 0
116 self.h = 0
117
119 self.redraw (wxPaintDC (self))
120
122 self.w, self.h = self.GetClientSizeTuple ()
123
125 dc.SetBrush (wx.Brush (self.bgC, wx.SOLID))
126 dc.SetPen (wx.TRANSPARENT_PEN)
127 dc.DrawRectangle (0, 0, self.w, self.h)
128 dc.SetTextBackground (self.hdrC)
129 dc.SetFont (wx.Font (12, wx.SWISS, wx.NORMAL, wx.BOLD))
130 dc.SetTextForeground (self.txtC)
131 txtw, txth = dc.GetTextExtent (self.text)
132 bufx = txtw / 10
133 if bufx + txtw > self.w:
134 bufx = 0
135 bufy = (self.h - txth)/2
136 if bufy < 0:
137 bufy = 0
138 dc.SetBrush (wx.Brush (self.hdrC, wx.SOLID))
139 dc.DrawRectangle (bufx, bufy, txtw, txth)
140 dc.DrawText (self.text, bufx, bufy)
141
142 def SetCaptionBackgroundColor(self, bgC):
143 self.bgC = bgC
144 self.redraw (wx.ClientDC (self))
145
146 def SetCaptionForegroundColor(self, hdrC):
147 self.hdrC = hdrC
148 self.redraw (wx.ClientDC (self))
149
150
151 if __name__ == "__main__":
152 app = wxPyWidgetTester(size = (50, 20))
153 app.SetWidget(cAlertCaption, -1," Alerts ")
154 app.MainLoop()
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183