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

Source Code for Module Gnumed.wxpython.gmDermTool

  1  #!/usr/bin/env python 
  2  # -*- coding: UTF-8 -*- 
  3  # generated by wxGlade 0.4 on Sat Oct 29 16:44:23 2005 
  4   
  5  # standard library 
  6  import os.path 
  7   
  8  # 3rd party 
  9  import wx 
 10  import wx.html 
 11   
 12  # GNUmed modules 
 13  from Gnumed.pycommon import gmI18N 
 14   
 15  #=================================================================== 
16 -class DermToolDialog(wx.Dialog):
17 - def __init__(self, *args, **kwds):
18 # begin wxGlade: DermToolDialog.__init__ 19 kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.THICK_FRAME 20 wx.Dialog.__init__(self, *args, **kwds) 21 self.population = wx.RadioBox(self, -1, _("Population"), choices=[_("Child"), _("Adult"), _("Elderly")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 22 self.distribution = wx.RadioBox(self, -1, _("Distribution"), choices=[_("Truncal"), _("Generalised"), _("Face"), _("Hands"), _("Flexural"), _("Sun-exposed")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 23 self.colouring = wx.RadioBox(self, -1, _("Colouring"), choices=[_("Normal"), _("Pigmented"), _("Depigmented"), _("Erythema"), _("Purpura")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 24 self.pattern = wx.RadioBox(self, -1, _("Pattern"), choices=[_("Confluent"), _("Macular"), _("Maculo-Papular"), _("Papular"), _("Bullous")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 25 self.surface = wx.RadioBox(self, -1, _("Surface"), choices=[_("Skin level"), _("Eroded"), _("Crust"), _("Scale"), _("Exudate")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 26 self.sensation = wx.RadioBox(self, -1, _("Sensation"), choices=[_("Normal"), _("Itchy"), _("Painful")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 27 self.time_course = wx.RadioBox(self, -1, _("Occurrence"), choices=[_("Evolving"), _("Sudden")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) 28 self.disease_name = wx.TextCtrl(self, -1, "") 29 self.disease_list = wx.ListBox(self, -1, choices=[]) 30 self.image = wx.Panel(self, -1) 31 self.image_credit = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY) 32 self.disease_text = wx.html.HtmlWindow(self, -1) 33 self.btn_save = wx.Button(self, -1, _("Save")) 34 self.btn_close = wx.Button(self, -1, _("Close")) 35 36 self.__set_properties() 37 self.__do_layout() 38 39 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.population) 40 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.distribution) 41 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.colouring) 42 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.pattern) 43 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.surface) 44 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.sensation) 45 self.Bind(wx.EVT_RADIOBOX, self.search_type, self.time_course) 46 self.Bind(wx.EVT_TEXT, self.search_text, self.disease_name) 47 self.Bind(wx.EVT_LISTBOX, self.open_disease, self.disease_list) 48 self.Bind(wx.EVT_BUTTON, self.save, self.btn_save) 49 self.Bind(wx.EVT_BUTTON, self.close, self.btn_close) 50 # end wxGlade 51 self.Bind(wx.EVT_CLOSE, self.close, self) 52 self.Bind(wx.EVT_SIZE, self.bind_image, self.image) 53 self.diseases = [] 54 self.path = os.path.join (self.gb['resource dir'], 'data', 'derm') 55 for l in open(os.path.join (self.path, 'INDEX')): 56 row = l.split () 57 d = {} 58 lang = gmI18N.system_locale_level['language'] 59 n = 0 60 for i in ['basename', 'code', 'population', 'distribution', 'colouring', 'pattern', 'surface', 'sensation','time_course']: 61 d[i] = row[n] 62 n += 1 63 try: 64 txt = open(os.path.join (self.gb['resource dir'], 'data', 'derm', '%s.%s.txt' % (row[0], lang))) 65 except IOError: 66 txt = open(os.path.join (self.gb['resource dir'], 'data', 'derm', '%s.en.txt' % row[0])) 67 # FIXME: should not this be done by Cheetah ? 68 d['title'] = txt.readline () 69 d['source'], d['text'] = tuple (txt.read ().split ('\n\n', 1)) 70 d['text'] = d['text'].replace ('&', '&amp;') 71 d['text'] = d['text'].replace ('<', '&lt;') 72 d['text'] = d['text'].replace ('>', '&gt;') 73 d['text'] = d['text'].replace ('\n\n', '<p>') 74 d['source'] = d['source'].split (',')[0] 75 self.diseases.append (d)
76 77
78 - def __set_properties(self):
79 # begin wxGlade: DermToolDialog.__set_properties 80 self.SetTitle("DermTool") 81 self.population.SetSelection(1) 82 self.distribution.SetSelection(0) 83 self.colouring.SetSelection(0) 84 self.pattern.SetSelection(0) 85 self.surface.SetSelection(0) 86 self.sensation.SetSelection(0) 87 self.time_course.SetSelection(0) 88 self.disease_name.SetToolTip(_("Type name of disease")) 89 self.btn_save.SetDefault()
90 # end wxGlade 91
92 - def __do_layout(self):
93 # begin wxGlade: DermToolDialog.__do_layout 94 sizer_1 = wx.BoxSizer(wx.VERTICAL) 95 sizer_3 = wx.BoxSizer(wx.HORIZONTAL) 96 sizer_6 = wx.BoxSizer(wx.HORIZONTAL) 97 sizer_7 = wx.BoxSizer(wx.VERTICAL) 98 sizer_8 = wx.BoxSizer(wx.HORIZONTAL) 99 sizer_5 = wx.BoxSizer(wx.VERTICAL) 100 sizer_4 = wx.BoxSizer(wx.VERTICAL) 101 sizer_2 = wx.BoxSizer(wx.HORIZONTAL) 102 sizer_2.Add(self.population, 1, 0, 0) 103 sizer_2.Add(self.distribution, 1, wx.ADJUST_MINSIZE, 0) 104 sizer_2.Add(self.colouring, 1, wx.ADJUST_MINSIZE, 0) 105 sizer_2.Add(self.pattern, 1, wx.ADJUST_MINSIZE, 0) 106 sizer_2.Add(self.surface, 1, wx.ADJUST_MINSIZE, 0) 107 sizer_2.Add(self.sensation, 1, wx.ADJUST_MINSIZE, 0) 108 sizer_2.Add(self.time_course, 1, wx.ADJUST_MINSIZE, 0) 109 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) 110 sizer_4.Add(self.disease_name, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 111 sizer_4.Add(self.disease_list, 1, wx.ALL|wx.EXPAND, 0) 112 sizer_3.Add(sizer_4, 1, wx.EXPAND, 0) 113 sizer_5.Add(self.image, 1, wx.EXPAND, 0) 114 sizer_5.Add(self.image_credit, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 115 sizer_3.Add(sizer_5, 3, wx.EXPAND, 0) 116 sizer_7.Add(self.disease_text, 1, wx.EXPAND, 0) 117 sizer_8.Add(self.btn_save, 0, wx.ADJUST_MINSIZE, 0) 118 sizer_8.Add(self.btn_close, 0, wx.ADJUST_MINSIZE, 0) 119 sizer_7.Add(sizer_8, 0, wx.EXPAND, 0) 120 sizer_6.Add(sizer_7, 2, wx.EXPAND, 0) 121 sizer_3.Add(sizer_6, 2, wx.EXPAND, 0) 122 sizer_1.Add(sizer_3, 2, wx.EXPAND, 0) 123 self.SetAutoLayout(True) 124 self.SetSizer(sizer_1) 125 sizer_1.Fit(self) 126 sizer_1.SetSizeHints(self) 127 self.Layout()
128 # end wxGlade 129
130 - def search_type(self, event): # wxGlade: DermToolDialog.<event_handler>
131 self.disease_name.Clear () 132 maps = [('population', ['P', 'A', 'E']), ('distribution', ['T', 'G', 'F', 'H', 'L', 'S']), ('colouring', ['N', 'P', 'D', 'E', 'P']), ('pattern', ['C', 'M', 'MP', 'P', 'B']), ('surface', ['F', 'E', 'C', 'S', 'X']), ('sensation', ['N', 'I', 'P']), ('time_course', ['E', 'S'])] 133 vals = dict ([(i,j[getattr (self, i).GetSelection ()]) for i, j in maps]) 134 for i in self.diseases: 135 n = 0 136 for j in vals: 137 if vals[j] == i[j]: 138 n += 1 139 i['matches'] = n 140 self.diseases.sort (lambda x,y: cmp (x['matches'], y['matches'])) 141 self.disease_list.Clear () 142 for i in self.diseases[:10]: 143 if i['matches'] > 4: 144 self.disease_list.Append (i['title'], i)
145 146
147 - def open_disease(self, event): # wxGlade: DermToolDialog.<event_handler>
148 data = self.disease_list.GetClientData (self.disease_list.GetSelection ()) 149 self.disease_text.SetPage (data['text']) 150 self.image_credit.SetValue (data['source']) 151 fname = os.path.join (self.path, data['basename'] + '.jpg') 152 if os.path.exists (fname): 153 self.jpeg = wx.Image (fname) 154 self.bind_image () 155 else: 156 print "No image available" 157
158 - def bind_image (self, event = None):
159 jpg_width = self.jpeg.GetWidth () 160 jpg_height = self.jpeg.GetHeight () 161 pnl_width,pnl_height = self.image.GetSize() 162 self.image.DestroyChildren () 163 jpg_aspect = jpg_width/float (jpg_height) 164 pnl_aspect = pnl_width/float (pnl_height) 165 if jpg_aspect > pnl_aspect: 166 desired_width = pnl_width 167 desired_height = int (pnl_width/jpg_aspect) 168 x = 0 169 y = (pnl_height-desired_height)/2 170 else: 171 desired_height = pnl_height 172 desired_width = int (pnl_height*jpg_aspect) 173 x = (pnl_width-desired_width)/2 174 y = 0 175 njpeg = self.jpeg.Scale (desired_width, desired_height) 176 bmp = wx.Bitmap(njpeg) 177 sbmp = wx.StaticBitmap (self.image, -1, bmp, pos=wx.Point (x, y)) 178 sbmp.Show ()
179
180 - def save(self, event): # wxGlade: DermToolDialog.<event_handler>
181 print "Event handler `save' not implemented" 182 event.Skip() 183
184 - def close(self, event): # wxGlade: DermToolDialog.<event_handler>
185 self.Destroy () 186
187 - def search_text(self, event): # wxGlade: DermToolDialog.<event_handler>
188 self.disease_list.Clear () 189 s = self.disease_name.GetValue ().upper () 190 if len (s) > 3: 191 for i in self.diseases: 192 if s in i['title'].upper (): 193 self.disease_list.Append (i['title'], i) 194 195 196 # end of class DermToolDialog 197 198 199 #== if run as standalone ======================================================= 200 if __name__ == '__main__': 201 # set up dummy app
202 - class TestApp (wx.App):
203 - def OnInit (self):
204 frame = DermToolDialog(None, -1) 205 frame.Show(True) 206 return True
207 #--------------------- 208 wx.InitAllImageHandlers() 209 app = TestApp() 210 app.MainLoop() 211