def __init__(self, controller, obj, db, row=None, title="Add", addRecord=True, algorithmId=None): """ Initializes the add/modify dialog. This consists of constructing an input form which has field names and a text field for entering field values. Arguments: controller - class performing the object creation, update, or deletion obj - object class to be processed row - row selected containing the object title - title to be displayed on form addRecord - flag indicating that a new record is to be created """ # set up controllers algorithmController = AlgorithmController(db, Algorithm, None, None) wx.Dialog.__init__(self, None, title="%s Experiment Record" % title) self.controller = controller if row: key = row.getKey() self.objInstance = controller.getRecordByKey(key) if addRecord: curAlgorithmtId = self.objInstance.algorithm_id self.objInstance = obj() self.objInstance.patient_id = curAlgorithmtId else: self.objInstance = obj() self.objInstance.algorithm_id = algorithmId self.addRecord = addRecord self.selectedRow = row size = (80, -1) font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD) # create the sizers mainSizer = wx.BoxSizer(wx.VERTICAL) btnSizer = wx.BoxSizer(wx.HORIZONTAL) # create some widgets lbl = wx.StaticText(self, label=self.objInstance.displayTableName) lbl.SetFont(font) mainSizer.Add(lbl, 0, wx.CENTER) font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD) self.ctls = [] lbl = wx.StaticText(self, size=size) lbl.SetLabel("Experiment Name:") lbl.SetFont(font) if row: self.experimentTextCtrl = wx.TextCtrl(self, value=row.experiment_name) else: self.experimentTextCtrl = wx.TextCtrl(self, value="") mainSizer.Add(self.rowBuilder([lbl, self.experimentTextCtrl]), 0, wx.EXPAND) lbl = wx.StaticText(self, size=size) lbl.SetLabel("Algorithm:") lbl.SetFont(font) self.algorithm_name = wx.ComboBox(self, wx.ID_ANY, choices=[], style=wx.CB_DROPDOWN | wx.CB_DROPDOWN) self.algorithm_name.SetFont(font) algorithms = algorithmController.getAll() for s in algorithms: self.algorithm_name.Append(s.algorithm_name, str(s.id)) if row: n = 0 for s in algorithms: if self.objInstance.algorithm_id == s.id: self.algorithm_name.Select(n) break n = n + 1 else: self.algorithm_name.Select(0) mainSizer.Add(self.rowBuilder([lbl, self.algorithm_name]), 0, wx.EXPAND) lbl = wx.StaticText(self, size=size) lbl.SetLabel("Default?:") lbl.SetFont(font) self.defCheckbox = wx.CheckBox(self) if row and not(self.addRecord) and self.objInstance.default_flag == 1: self.defCheckbox.SetValue(True) mainSizer.Add(self.rowBuilder([lbl, self.defCheckbox]), 0, wx.EXPAND) lbl = wx.StaticText(self, size=size) lbl.SetLabel("Description:") lbl.SetFont(font) if row and not(self.addRecord) and not(self.objInstance.experiment_description is None): self.descTextCtrl = wx.TextCtrl(self, value=self.objInstance.experiment_description) else: self.descTextCtrl = wx.TextCtrl(self, value="") mainSizer.Add(self.rowBuilder([lbl, self.descTextCtrl]), 0, wx.EXPAND) okBtn = wx.Button(self, label="%s" % title) okBtn.Bind(wx.EVT_BUTTON, self.onRecord) btnSizer.Add(okBtn, 0, wx.ALL, 5) cancelBtn = wx.Button(self, label="Close") cancelBtn.Bind(wx.EVT_BUTTON, self.onClose) btnSizer.Add(cancelBtn, 0, wx.ALL, 5) mainSizer.Add(btnSizer, 0, wx.CENTER) self.SetSizer(mainSizer) self.Refresh()