def OnLeftDblClick(self, event): """ Event handler to open child form""" ctrl = event.GetEventObject() type = '' if ctrl.Id == cdml.IDF_BUTTON3: # Population Set cc = self.cc_pset id_obj = cc.GetValue() form = 'PopulationSets' elif ctrl.Id == cdml.IDF_BUTTON4 : # Primary Model cc = self.cc_model id_obj = cc.GetValue() form = 'StudyModels' elif ctrl.Id == cdml.IDP_BUTTON4: # The notes rule text cc = ctrl TheTextControl = cc id_obj = cc.GetValue() DefaultText = id_obj form = '' else: cc = ctrl.GetParent() TheTextControl = cc.GetTextCtrl() if cc.Id == cdml.IDF_BUTTON1: id_obj = cc.GetValue() form = 'PopulationSets' elif cc.Id == cdml.IDF_BUTTON2: id_obj = cc.GetValue() form = 'StudyModels' else: id_obj = str(cc.GetValueString()) DefaultText = id_obj if cc.Id == cdml.IDP_BUTTON1: form = 'Parameters' type = ['System Option']*(self.curPage==0) + ['Number','Integer','State Indicator'] elif cc.Id == cdml.IDP_BUTTON2: form = '' type = 'Expression' elif cc.Id == cdml.IDP_BUTTON3: form = '' type = 'Expression' if ('CostWizard' in DefaultText): form = 'WIZARD' self.curCtrl = cc if form == 'WIZARD': try: Sequence = DB.CostWizardParserForGUI(DefaultText, True) dlg_wizard = Wizard.WizardDialog(data=Sequence, parent=self) dlg_wizard.CenterOnScreen() dlg_wizard.Show() dlg_wizard.MyMakeModal() except: cdml.dlgErrorMsg(Parent = self) elif form == '': TheText = cdml.dlgTextEntry(Message = 'Modify Text and Press OK, or Press Cancel to ignore changes', Caption = type, DefaultValue = DefaultText, Parent = self) TheTextControl.SetValue(str(TheText)) # make sure focus returne properly to this form self.MyMakeModal() self.Raise() else: if id_obj == 0 or id_obj == '' : id_obj = -1 cdml.OpenForm(form, self, cdml.ID_MODE_SINGL, id_obj, type, self.idPrj)
def SpecialRecordAdd(self, ClickedPanel): """ Add a special record - In this case this means a new population set Generated from a distribution population set """ if ClickedPanel != None: RecordID = ClickedPanel.Key if (RecordID == 0 or RecordID == None) or not DB.PopulationSets.has_key(RecordID): ReturnRecord = None else: if not DB.PopulationSets[RecordID].IsDistributionBased(): # This is a data population set cdml.dlgSimpleMsg( "ERROR", "This population set is not based on distribution and therefore cannot be used to generate new population data", Parent=self, ) ReturnRecord = None else: # This means this population set is defined by distributions dlg = wx.NumberEntryDialog( self, "Define population size", "Please enter the size of the population to generate ", "Population Size", 1000, 0, 100000, ) dlg.CenterOnScreen() if dlg.ShowModal() != wx.ID_OK: # If 'Cancel' button is clicked ReturnRecord = None else: NumberOfIndividuals = dlg.GetValue() # Get selection index dlg.Destroy() PopulationTraceBack = None # When in admin mode, also ask for traceback info AskForTraceBack = cdml.GetAdminMode() if AskForTraceBack: TraceBackText = cdml.dlgTextEntry( Message="Please enter the Pickled TraceBack information as appear in the hidden report of the population you are trying to reconstruct ", Caption="Enter Pickled TraceBack Info", DefaultValue="", Parent=self, ) if TraceBackText == "": PopulationTraceBack = None else: try: PopulationTraceBack = DB.pickle.loads(TraceBackText) except: raise ValueError, "TraceBack Error: Could not properly extract TraceBack - please make sure a proper TraceBack was entered" PopulationTraceBack = None TheProgressDialog = None try: # version 2.5 does not support canceling simulation TheProgressDialog = cdml.ProgressDialogTimeElapsed( Parent=self, StartTimerUponCreation=False, AllowCancel=DB.SystemSupportsProcesses ) # Define the Function to run on a thread/process def GenerationStartMiniScript(): "Compile and execute the generation" Pop = DB.PopulationSets[RecordID] # Compile the generation script with default options ScriptFileNameFullPath = Pop.CompilePopulationGeneration( GeneratedPopulationSize=NumberOfIndividuals, GenerationFileNamePrefix=None, OutputFileNamePrefix=None, RandomStateFileNamePrefix=None, GenerationOptions=None, RecreateFromTraceBack=PopulationTraceBack, ) # run the generation script DeleteScriptFileAfterRun = not cdml.GetAdminMode() (ProcessList, PipeList) = Pop.RunPopulationGeneration( GenerationFileName=ScriptFileNameFullPath, NumberOfProcessesToRun=-1, DeleteScriptFileAfterRun=DeleteScriptFileAfterRun, ) return (ProcessList, PipeList) def GenerationEndMiniScript(ProcessList, PipeList): "Complete Generation by collecting results" Pop = DB.PopulationSets[RecordID] # Collect the results RetVal = Pop.CollectResults(ProcessList, PipeList) return RetVal ThreadObject = cdml.WorkerThread(GenerationStartMiniScript, GenerationEndMiniScript) # Tell the dialog box what to do when cancel is pressed TheProgressDialog.FunctionToRunUponCancel = ThreadObject.StopProcess # Now start the timer for the progress dialog box TheProgressDialog.StartTimer() # wait until thread/process exits Info = ThreadObject.WaitForJob() # Cancel through the dialog box is no longer possible TheProgressDialog.FunctionToRunUponCancel = None # Properly destroy the dialog WasCanceled = TheProgressDialog.WasCanceled TheProgressDialog.Destroy() TheProgressDialog = None if WasCanceled: cdml.dlgSimpleMsg( "INFO", "The Population generation was canceled by request!", wx.OK, wx.ICON_INFORMATION, Parent=self, ) ReturnRecord = None else: cdml.dlgSimpleMsg( "INFO", "The Population generation has finished successfully! After you press OK your cursor will be focused on the new population set.", wx.OK, wx.ICON_INFORMATION, Parent=self, ) ReturnRecord = Info except: cdml.dlgErrorMsg() ReturnRecord = None # Properly destroy the progress dialog box if not done before if TheProgressDialog != None: TheProgressDialog.Destroy() return ReturnRecord
def SpecialRecordAdd(self, ClickedPanel): """ Add a special record - In this case this means a new population set Generated from a distribution population set """ if ClickedPanel != None: RecordID = ClickedPanel.Key if (RecordID == 0 or RecordID == None) or not DB.PopulationSets.has_key(RecordID): ReturnRecord = None else: if not DB.PopulationSets[RecordID].IsDistributionBased(): # This is a data population set cdml.dlgSimpleMsg( 'ERROR', 'This population set is not based on distribution and therefore cannot be used to generate new population data', Parent=self) ReturnRecord = None else: # This means this population set is defined by distributions dlg = wx.NumberEntryDialog( self, 'Define population size', 'Please enter the size of the population to generate ', 'Population Size', 1000, 0, 100000) dlg.CenterOnScreen() if dlg.ShowModal() != wx.ID_OK: # If 'Cancel' button is clicked ReturnRecord = None else: NumberOfIndividuals = dlg.GetValue( ) # Get selection index dlg.Destroy() PopulationTraceBack = None # When in admin mode, also ask for traceback info AskForTraceBack = cdml.GetAdminMode() if AskForTraceBack: TraceBackText = cdml.dlgTextEntry( Message= 'Please enter the Pickled TraceBack information as appear in the hidden report of the population you are trying to reconstruct ', Caption='Enter Pickled TraceBack Info', DefaultValue='', Parent=self) if TraceBackText == '': PopulationTraceBack = None else: try: PopulationTraceBack = DB.pickle.loads( TraceBackText) except: raise ValueError, 'TraceBack Error: Could not properly extract TraceBack - please make sure a proper TraceBack was entered' PopulationTraceBack = None TheProgressDialog = None try: # version 2.5 does not support canceling simulation TheProgressDialog = cdml.ProgressDialogTimeElapsed( Parent=self, StartTimerUponCreation=False, AllowCancel=DB.SystemSupportsProcesses) # Define the Function to run on a thread/process def GenerationStartMiniScript(): "Compile and execute the generation" Pop = DB.PopulationSets[RecordID] # Compile the generation script with default options ScriptFileNameFullPath = Pop.CompilePopulationGeneration( GeneratedPopulationSize=NumberOfIndividuals, GenerationFileNamePrefix=None, OutputFileNamePrefix=None, RandomStateFileNamePrefix=None, GenerationOptions=None, RecreateFromTraceBack=PopulationTraceBack) # run the generation script DeleteScriptFileAfterRun = not cdml.GetAdminMode( ) (ProcessList, PipeList) = Pop.RunPopulationGeneration( GenerationFileName=ScriptFileNameFullPath, NumberOfProcessesToRun=-1, DeleteScriptFileAfterRun= DeleteScriptFileAfterRun) return (ProcessList, PipeList) def GenerationEndMiniScript(ProcessList, PipeList): "Complete Generation by collecting results" Pop = DB.PopulationSets[RecordID] # Collect the results RetVal = Pop.CollectResults( ProcessList, PipeList) return RetVal ThreadObject = cdml.WorkerThread( GenerationStartMiniScript, GenerationEndMiniScript) # Tell the dialog box what to do when cancel is pressed TheProgressDialog.FunctionToRunUponCancel = ThreadObject.StopProcess # Now start the timer for the progress dialog box TheProgressDialog.StartTimer() # wait until thread/process exits Info = ThreadObject.WaitForJob() # Cancel through the dialog box is no longer possible TheProgressDialog.FunctionToRunUponCancel = None # Properly destroy the dialog WasCanceled = TheProgressDialog.WasCanceled TheProgressDialog.Destroy() TheProgressDialog = None if WasCanceled: cdml.dlgSimpleMsg( 'INFO', 'The Population generation was canceled by request!', wx.OK, wx.ICON_INFORMATION, Parent=self) ReturnRecord = None else: cdml.dlgSimpleMsg( 'INFO', 'The Population generation has finished successfully! After you press OK your cursor will be focused on the new population set.', wx.OK, wx.ICON_INFORMATION, Parent=self) ReturnRecord = Info except: cdml.dlgErrorMsg() ReturnRecord = None # Properly destroy the progress dialog box if not done before if TheProgressDialog != None: TheProgressDialog.Destroy() return ReturnRecord