Gnumed.wxpython.gmTerryGuiParts

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  try:
     18          import wxversion
     19          import wx
     20  except ImportError:
     21          from wxPython import wx
     22
     23  #===========================================================================
     24 -class cAlertCaption(wx.Panel):
     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  #   def __init__(self, parent, id, title, bg_red, bg_blue, bg_green,fg_red, fg_blue, fg_green):
     34  #   this to be used once the rgb thingy is fixed
     35 -        def __init__(self, parent, id, title):
     36                  wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0 )
     37                  self.SetBackgroundColour(wx.Colour(222,222,222))                            #set main panel background color
     38                  sizer  = wx.BoxSizer(wx.HORIZONTAL)
     39                  #SetCaptionBackgroundColor()                                               #set background colour with rgb  TODO
     40                  #-----------------------------------------------
     41                  #create a panel which will hold the caption
     42                  #add the title to it, set the colours
     43                  #stick it on a sizer with a cap above and below
     44                  #----------------------------------------------
     45                  captionpanel = wx.Panel(self,-1,size = (400,10))
     46                  captionpanel.SetBackgroundColour(wx.Colour(197,194,197))                    #intermediate gray
     47                  caption = wx.StaticText(captionpanel,-1, title,style = wx.ALIGN_CENTRE_VERTICAL)   # static text for the caption
     48                  caption.SetForegroundColour(wx.Colour(0,0,0))                              #black as...
     49                  #SetCaptionForegroundColor()                                               #set caption text colour rgb TODO
     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)                                               #set the sizer
     54                  sizer.Fit(self)                                                    #set to minimum size as calculated by sizer
     55                  self.SetAutoLayout(True)                                           #tell frame to use the sizer
     56                  #self.Show(True) #showing done by manager!                                                    #show the panel
     57
     58 -        def SetCaptionBackgroundColor(self, bg_red, bg_blue, bg_green):
     59                  self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green))
     60                  return
     61 -        def SetCaptionForegroundColor(self, fg_red, fg_blue, fg_green):
     62                  self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green))
     63                  return
     64
     65  #===========================================================================
     66 -class cDividerCaption(wx.Panel):
     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          #   def __init__(self, parent, id, title, bg_red, bg_blue, bg_green,fg_red, fg_blue, fg_green):
     75          #   this to be used once the rgb thingy is fixed
     76 -        def __init__(self, parent, id, title):
     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))                            #set panel background to light purple!
     80                  #SetCaptionBackgroundColor()                                               #set panel background colour  rgb
     81                  caption = wx.StaticText(self,-1, title,style = wx.ALIGN_CENTRE)              #static text control for the caption
     82                  caption.SetForegroundColour(wx.WHITE)                                      #white foreground text colour
     83                  #SetCaptionForegroundColor()                                              #set caption text colour to rgb
     84                  caption.SetFont(wx.Font(13,wx.SWISS,wx.NORMAL, wx.BOLD,False,''))         #TODO implement font size parameter
     85                  sizer.Add(caption,1,wx.EXPAND)                                      #add caption to the sizer
     86                  self.SetSizer(sizer)                                               #set the sizer
     87                  sizer.Fit(self)                                                    #set to minimum size as calculated by sizer
     88                  self.SetAutoLayout(True)                                           #tell frame to use the sizer
     89                  #self.Show(True)                                                    #show the panel
     90
     91 -        def SetCaptionBackgroundColor(self, bg_red, bg_blue, bg_green):
     92                  self.SetBackgroundColour(wx.Colour(bg_red,bg_blue,bg_green))
     93
     94 -        def SetCaptionForegroundColor(self, fg_red, fg_blue, fg_green):
     95                  self.caption.SetForegroundColour(wx.Colour(fg_red,fg_blue,fg_green))
     96                  return
     97
     98  #===========================================================================
     99 -class cHeadingCaption(wx.Panel):
    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
    118 -    def OnPaint (self, event):
    119          self.redraw (wxPaintDC (self))
    120
    121 -    def OnSize (self, event):
    122          self.w, self.h = self.GetClientSizeTuple ()
    123
    124 -    def redraw (self, dc):
    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 # buffer to left of text
    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  # $Log: gmTerryGuiParts.py,v $
    158  # Revision 1.6  2005-09-28 21:27:30  ncq
    159  # - a lot of wx2.6-ification
    160  #
    161  # Revision 1.5  2005/09/28 19:47:01  ncq
    162  # - runs until login dialog
    163  #
    164  # Revision 1.4  2005/09/28 15:57:48  ncq
    165  # - a whole bunch of wx.Foo -> wx.Foo
    166  #
    167  # Revision 1.3  2005/09/26 18:01:51  ncq
    168  # - use proper way to import wx26 vs wx2.4
    169  # - note: THIS WILL BREAK RUNNING THE CLIENT IN SOME PLACES
    170  # - time for fixup
    171  #
    172  # Revision 1.2  2004/07/18 19:55:29  ncq
    173  # - true/false -> True/False
    174  # - indentation fix
    175  #
    176  # Revision 1.1  2004/07/17 20:48:19  ncq
    177  # - aggregate Richard space GUI parts
    178  #
    179  #
    180  #
    181  # old change log:
    182  #       10.06.2002 rterry initial implementation, untested
    183