Package Gnumed :: Package wxpython :: Module gmTerryGuiParts
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmTerryGuiParts

  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  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/gmTerryGuiParts.py,v $ 
 13  __version__ = "$Revision: 1.6 $" 
 14  __author__  = 'Dr. Richard Terry' 
 15  __license__ = 'GPL v2 or later (details at http://www.gnu.org)' 
 16   
 17  import wx 
 18   
 19  #=========================================================================== 
20 -class cAlertCaption(wx.Panel):
21 """Bottom left hand pane alert panel. 22 23 This panel consists constructs a simple heading to be used at the bottom 24 of the screen, in the form of capitalised word on user defined foreground 25 and background colours. The heading is left justified curently. The 26 default colours are black text on intermediate grey so as to not make it 27 too intrusive. The alert text will appear in flashing red text 28 """ 29 # def __init__(self, parent, id, title, bg_red, bg_blue, bg_green,fg_red, fg_blue, fg_green): 30 # this to be used once the rgb thingy is fixed
31 - def __init__(self, parent, id, title):
32 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0 ) 33 self.SetBackgroundColour(wx.Colour(222,222,222)) #set main panel background color 34 sizer = wx.BoxSizer(wx.HORIZONTAL) 35 #SetCaptionBackgroundColor() #set background colour with rgb TODO 36 #----------------------------------------------- 37 #create a panel which will hold the caption 38 #add the title to it, set the colours 39 #stick it on a sizer with a cap above and below 40 #---------------------------------------------- 41 captionpanel = wx.Panel(self,-1,size = (400,10)) 42 captionpanel.SetBackgroundColour(wx.Colour(197,194,197)) #intermediate gray 43 caption = wx.StaticText(captionpanel,-1, title,style = wx.ALIGN_CENTRE_VERTICAL) # static text for the caption 44 caption.SetForegroundColour(wx.Colour(0,0,0)) #black as... 45 #SetCaptionForegroundColor() #set caption text colour rgb TODO 46 caption.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) 47 sizer.Add(captionpanel,1,wx.EXPAND|wx.ALL,2) 48 sizer.Add(0,9,6) 49 self.SetSizer(sizer) #set the sizer 50 sizer.Fit(self) #set to minimum size as calculated by sizer 51 self.SetAutoLayout(True) #tell frame to use the sizer
52 #self.Show(True) #showing done by manager! #show the panel 53
54 - def SetCaptionBackgroundColor(self, bg_red, bg_blue, bg_green):
55 self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green)) 56 return
57 - def SetCaptionForegroundColor(self, fg_red, fg_blue, fg_green):
58 self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green)) 59 return
60 61 #===========================================================================
62 -class cDividerCaption(wx.Panel):
63 """This panel consists of one or more headings on a horizontal panel and is 64 65 used to divide/head sections of the screenel There are user defined foreground 66 and background colours. The captions are centred in the available space. The 67 default colours are purple panel with white bold text 68 words (sounds yuk doesn't it - but I like it and it works well!!!!! 69 """ 70 # def __init__(self, parent, id, title, bg_red, bg_blue, bg_green,fg_red, fg_blue, fg_green): 71 # this to be used once the rgb thingy is fixed
72 - def __init__(self, parent, id, title):
73 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0) 74 sizer = wx.BoxSizer(wx.HORIZONTAL) 75 self.SetBackgroundColour(wx.Colour(197,194,255)) #set panel background to light purple! 76 #SetCaptionBackgroundColor() #set panel background colour rgb 77 caption = wx.StaticText(self,-1, title,style = wx.ALIGN_CENTRE) #static text control for the caption 78 caption.SetForegroundColour(wx.WHITE) #white foreground text colour 79 #SetCaptionForegroundColor() #set caption text colour to rgb 80 caption.SetFont(wx.Font(13,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) #TODO implement font size parameter 81 sizer.Add(caption,1,wx.EXPAND) #add caption to the sizer 82 self.SetSizer(sizer) #set the sizer 83 sizer.Fit(self) #set to minimum size as calculated by sizer 84 self.SetAutoLayout(True) #tell frame to use the sizer
85 #self.Show(True) #show the panel 86
87 - def SetCaptionBackgroundColor(self, bg_red, bg_blue, bg_green):
88 self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green))
89
90 - def SetCaptionForegroundColor(self, fg_red, fg_blue, fg_green):
91 self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green)) 92 return
93 94 #===========================================================================
95 -class cHeadingCaption(wx.Panel):
96 """This panel consists constructs a simple heading to be used at the top 97 98 of a panel, in the form of capitalised word on user defined foreground 99 and background colours. The heading is left justified curently. The 100 default colours are purple panel, orange label with yellow capitalised 101 words (sounds yuk doesn't it - but I like it and it works well!!!!! 102 """
103 - def __init__ (self, parent, id, text, bgC = wx.Colour (197,194,255), hdrC = wx.Colour (255, 129, 131), txtC = wx.Colour (255, 255, 0)):
104 self.text = text 105 self.bgC = bgC 106 self.hdrC = hdrC 107 self.txtC = txtC 108 wx.Panel.__init__(self, parent, id) 109 wx.EVT_PAINT (self, self.OnPaint) 110 wx.EVT_SIZE (self, self.OnSize) 111 self.w = 0 112 self.h = 0
113
114 - def OnPaint (self, event):
115 self.redraw (wxPaintDC (self))
116
117 - def OnSize (self, event):
118 self.w, self.h = self.GetClientSize()
119
120 - def redraw (self, dc):
121 dc.SetBrush (wx.Brush (self.bgC, wx.SOLID)) 122 dc.SetPen (wx.TRANSPARENT_PEN) 123 dc.DrawRectangle (0, 0, self.w, self.h) 124 dc.SetTextBackground (self.hdrC) 125 dc.SetFont (wx.Font (12, wx.SWISS, wx.NORMAL, wx.BOLD)) 126 dc.SetTextForeground (self.txtC) 127 txtw, txth = dc.GetTextExtent (self.text) 128 bufx = txtw / 10 # buffer to left of text 129 if bufx + txtw > self.w: 130 bufx = 0 131 bufy = (self.h - txth)/2 132 if bufy < 0: 133 bufy = 0 134 dc.SetBrush (wx.Brush (self.hdrC, wx.SOLID)) 135 dc.DrawRectangle (bufx, bufy, txtw, txth) 136 dc.DrawText (self.text, bufx, bufy)
137
138 - def SetCaptionBackgroundColor(self, bgC):
139 self.bgC = bgC 140 self.redraw (wx.ClientDC (self))
141
142 - def SetCaptionForegroundColor(self, hdrC):
143 self.hdrC = hdrC 144 self.redraw (wx.ClientDC (self))
145 146 #=========================================================================== 147 if __name__ == "__main__": 148 app = wxPyWidgetTester(size = (50, 20)) 149 app.SetWidget(cAlertCaption, -1," Alerts ") 150 app.MainLoop() 151 152 #=========================================================================== 153 # $Log: gmTerryGuiParts.py,v $ 154 # Revision 1.6 2005-09-28 21:27:30 ncq 155 # - a lot of wx2.6-ification 156 # 157 # Revision 1.5 2005/09/28 19:47:01 ncq 158 # - runs until login dialog 159 # 160 # Revision 1.4 2005/09/28 15:57:48 ncq 161 # - a whole bunch of wx.Foo -> wx.Foo 162 # 163 # Revision 1.3 2005/09/26 18:01:51 ncq 164 # - use proper way to import wx26 vs wx2.4 165 # - note: THIS WILL BREAK RUNNING THE CLIENT IN SOME PLACES 166 # - time for fixup 167 # 168 # Revision 1.2 2004/07/18 19:55:29 ncq 169 # - true/false -> True/False 170 # - indentation fix 171 # 172 # Revision 1.1 2004/07/17 20:48:19 ncq 173 # - aggregate Richard space GUI parts 174 # 175 # 176 # 177 # old change log: 178 # 10.06.2002 rterry initial implementation, untested 179