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

# Source Code for Module Gnumed.wxpython.gmGP_HabitsRiskFactors

     1  try:
     2          import wxversion
     3          import wx
     4  except ImportError:
     5          from wxPython import wx
     6
     7 -class HabitsRiskFactors(wx.Panel):
     8 -    def __init__(self, parent,id):
     9          wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, 0 )
    10          sizer = wx.BoxSizer(wx.VERTICAL)
    11
    12          #captions for the two columns
    13          #habit_caption = gmTerryGuiParts..cDividerCaption(self,-1,"Habits")
    14          #risk_caption = gmTerryGuiParts.cDividerCaption(self,-1,"Risk Factors")
    15
    16          #text controls for each column
    17          txt_habits = wx.TextCtrl(self, 30,
    18                          "Smoker - 30/day.\n"
    19                          "Alcohol - 30gm/day (Previously very heavy.\n",
    20                                wx.DefaultPosition,wx.DefaultSize, style=wxTE_MULTILINE|wx.NO_3D|wx.SIMPLE_BORDER)
    21          txt_habits.SetInsertionPoint(0)
    22
    23          txt_riskfactors = wx.TextCtrl(self,30,
    24                               "Hypercholesterolaemia \n"
    25                               "Current Smoker \n"
    26                               "NIDDM \n"
    27                               "No exercise data recorded\n",
    28                                wx.DefaultPosition,wx.DefaultSize, style = wx.TE_MULTILINE)
    29          txt_riskfactors.SetInsertionPoint(0)
    30          #heading sizer- add headings
    31          #heading_sizer = wx.BoxSizer(wxHORIZONTAL)
    32          #heading_sizer.Add(habit_caption,1,wxEXPAND)
    33          #heading_sizer.Add(risk_caption,1,wxEXPAND)
    34          #self.SetSizer(heading_sizer)  #set the sizer
    35          #heading_sizer.Fit(self)             #set
    36          ##text sizer - add text
    37          text_sizer = wx.BoxSizer(wx.HORIZONTAL)
    38          text_sizer.Add(txt_habits,1,wx.EXPAND)
    39          text_sizer.Add(txt_riskfactors,1,wx.EXPAND)
    40          self.SetSizer(text_sizer)  #set the sizer
    41          text_sizer.Fit(self)             #set
    42          self.SetAutoLayout(True)                 #tell frame to use the sizer
    43          #self.Show(True)
    44
    45          self.lists = { 'habit': txt_habits, 'risk': txt_riskfactors }
    46
    47          print self.GetData()
    48
    49          self.SetData( { 'habit': ['smoker', 'drinks 20/day'] , 'risk': [ 'cholesterol', 'diabetes'] } )
    50
    51 -    def getTextCtrl(self, which):
    52                  return self.lists.get(which, "risk")
    53
    54 -    def SetData(self, map):
    55                  for which, data in map.items():
    56                          if type(data) == type(""):
    57                                  self.lists.get(which, 'risk').SetValue(data)
    58
    59                          if type(data) in [ type([]), type ( () ) ]:
    60                                  self.lists.get(which, 'risk').SetValue("\n".join(data))
    61
    62 -    def GetData(self):
    63                  map = {}
    64                  for k in self.lists.keys():
    65                          map[k] = self.lists[k].GetValue().split('\n')
    66                  return map
    67
    68
    69  if __name__ == "__main__":
    70          app = wxPyWidgetTester(size = (400, 200))
    71          app.SetWidget(HabitsRiskFactors, -1)
    72          app.MainLoop()
    73