Пример #1
0
 def SetComboItem(self):
     """
     Set items of ComboCtrl in RowPanel class when focus is moved in current RowPanel instance
     The items are removed when lost focus --> Implemented in CDMFrame class
     RowPanel class that have combo controls must implement this method.
     """
     parm_type = [(str(Type), -1) for Type in DB.ParameterTypes
                  if (cdml.GetAdminMode()
                      or Type not in ['State Indicator', 'System Reserved'])
                  ]
     self.cc_type.SetItems(parm_type)
Пример #2
0
 def SimulationStartMiniScript():
     "Compile and execute the simulation"
     SimulationTraceBack = ExtractTraceBack()
     prj = DB.Projects[self.idPrj]
     # if an override population is defined, this means it was
     # generated from distributions and therefore repetitions should
     # be 1 as the number of repetitions defined the population size
     if self.TempOverridePopulationSet == None:
         OverrideRepetitionCount = None
     else:
         OverrideRepetitionCount = 1
     ScriptFileName = prj.CompileSimulation(OverrideRepetitionCount = OverrideRepetitionCount, OverridePopulationSet = self.TempOverridePopulationSet, RecreateFromTraceBack = SimulationTraceBack)
     # run the simulation once without collecting results
     # also do nto delete the compiled script file if in Admin mode
     DeleteScriptFileAfterRun = not cdml.GetAdminMode()
     (ProcessList, PipeList) = prj.RunSimulation(ScriptFileName, NumberOfProcessesToRun = -1, DeleteScriptFileAfterRun = DeleteScriptFileAfterRun)
     return (ProcessList, PipeList)
Пример #3
0
 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)
Пример #4
0
 def GenerationStartMiniScript():
     "Compile and execute the generation"
     prj = DB.Projects[self.idPrj]
     PopID = prj.PrimaryPopulationSetID
     NumberOfRepetitions = prj.NumberOfRepetitions
     Pop = DB.PopulationSets[PopID]
     
     if Pop.IsDistributionBased():
         SimulationTraceBack = ExtractTraceBack()
         if SimulationTraceBack == None:
             PopulationTraceBack = None
         else:
             PopulationTraceBack = SimulationTraceBack[-1]
         # if the population is distribution based, then 
         # Compile the generation script with default options
         ScriptFileNameFullPath = Pop.CompilePopulationGeneration(GeneratedPopulationSize = NumberOfRepetitions, 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)
     else:
         # otherwise don't run anything                    
         (ProcessList, PipeList) = (None,None)
     return (ProcessList, PipeList)
Пример #5
0
    def __init__(self,
                 mode=None,
                 data=None,
                 type=None,
                 id_prj=0,
                 *args,
                 **kwds):
        """ Constructor of the MainFrame class """
        self.idPrj = id_prj
        # Note that key stands for the text to display rather than a record key
        # The name has not been changed to conform with the existing terminology
        # of the system.
        kwdsnew = copy.copy(kwds)
        kwdsnew["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwdsnew)
        # Default path is the report
        t = datetime.datetime.now().isoformat()
        time_stamp = t.replace(':',
                               '').replace('.',
                                           '').replace('T',
                                                       '').replace('-', '')
        self.Path = os.path.join(os.getcwd(),
                                 'Report' + '_' + time_stamp + '.txt')

        self.ReportObject, self.FormatOptions = data

        # Create the tabs
        self.NoteBook = wx.Notebook(self, -1, style=0)
        self.ReportPane = wx.Panel(self.NoteBook, 0)
        self.OptionsPane = wx.Panel(self.NoteBook, 1)

        self.tc_ReportDisplay = stc.StyledTextCtrl(self.ReportPane, wx.ID_ANY)
        self.tc_ReportDisplay.StyleSetFaceName(stc.STC_STYLE_DEFAULT,
                                               'Courier')
        self.tc_ReportDisplay.StyleClearAll()
        self.DisplayText()
        # Now add the filter controls:
        self.st_DetailLevel = wx.StaticText(self.OptionsPane, -1,
                                            'Detail Level:')
        self.cc_DetailLevel = cdml.Combo(self.OptionsPane, cdml.IDF_BUTTON1)
        self.st_ShowDependency = wx.StaticText(self.OptionsPane, -1,
                                               'Show Dependency:')
        self.cc_ShowDependency = cdml.Combo(self.OptionsPane,
                                            cdml.IDF_BUTTON2,
                                            validator=cdml.KeyValidator(
                                                cdml.NO_EDIT))
        self.st_SummaryIntevals = wx.StaticText(self.OptionsPane, -1,
                                                'Summary Intervals:')
        self.tc_SummaryIntevals = cdml.Text(self.OptionsPane, -1, "")
        self.st_ColumnNumberFormatFloat = wx.StaticText(
            self.OptionsPane, -1, 'Float Column Number Format:')
        self.tc_ColumnNumberFormatFloat = cdml.Text(self.OptionsPane, -1, "")
        self.st_ColumnNumberFormatInteger = wx.StaticText(
            self.OptionsPane, -1, 'Integer Column Number Format:')
        self.tc_ColumnNumberFormatInteger = cdml.Text(self.OptionsPane, -1, "")
        self.st_ColumnSeparator = wx.StaticText(self.OptionsPane, -1,
                                                'Column Separator:')
        self.tc_ColumnSeparator = cdml.Text(self.OptionsPane, -1, "")
        self.st_ShowHidden = wx.StaticText(self.OptionsPane, -1,
                                           'Show Hidden:')
        self.cc_ShowHidden = cdml.Combo(self.OptionsPane,
                                        cdml.IDF_BUTTON2,
                                        validator=cdml.KeyValidator(
                                            cdml.NO_EDIT))

        # allow showing Hidden parameters only in Admin mode
        IsVisible = cdml.GetAdminMode()
        self.st_ShowHidden.Show(IsVisible)
        self.cc_ShowHidden.Show(IsVisible)

        self.st_CandidateColumns = wx.StaticText(self.OptionsPane, -1,
                                                 'Candidate Columns:')
        self.lc_CandidateColumns = cdml.List(
            self.OptionsPane,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)
        self.st_ColumnTitle = wx.StaticText(self.OptionsPane, -1,
                                            'Column Title:')
        self.tc_ColumnTitle = cdml.Text(self.OptionsPane, -1, "")
        self.st_CalculationMethod = wx.StaticText(self.OptionsPane, -1,
                                                  'Calculation Method:')
        self.cc_CalculationMethod = cdml.Combo(self.OptionsPane,
                                               cdml.IDF_BUTTON3,
                                               validator=cdml.KeyValidator(
                                                   cdml.NO_EDIT))

        self.st_StratificationTable = wx.StaticText(self.OptionsPane, -1,
                                                    'Stratification Table:')
        self.tc_StratificationTable = cdml.Text(self.OptionsPane,
                                                -1,
                                                "",
                                                style=wx.TE_MULTILINE)

        self.btn_LoadReportOptions = wx.Button(self.OptionsPane,
                                               cdml.IDP_BUTTON1,
                                               "Load Report Options")
        self.btn_SaveReportOptions = wx.Button(self.OptionsPane,
                                               cdml.IDP_BUTTON2,
                                               "Save Report Options")

        self.btn_Add = wx.Button(self.OptionsPane, wx.ID_ADD, ">")
        self.btn_Del = wx.Button(self.OptionsPane, wx.ID_DELETE, "X")
        self.st_SelectedColumns = wx.StaticText(self.OptionsPane, -1,
                                                'Selected Columns:')
        self.lc_SelectedColumns = cdml.List(
            self.OptionsPane,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)
        self.btn_Regenerate = wx.Button(self.OptionsPane, wx.ID_APPLY,
                                        "Regenerate Report")

        # Add Standard menu while skipping a few options
        cdml.GenerateStandardMenu(
            self,
            SkipItems=[cdml.ID_MENU_REPORT_THIS, cdml.ID_MENU_REPORT_ALL])
        # Add a SaveAs option to the menu
        self.MenuItemSave = wx.MenuItem(self.MenuBarFile, wx.ID_SAVE, "&Save",
                                        "", wx.ITEM_NORMAL)
        self.MenuBarFile.AppendItem(self.MenuItemSave)
        self.MenuItemSaveAs = wx.MenuItem(self.MenuBarFile, wx.ID_SAVEAS,
                                          "Save &As", "", wx.ITEM_NORMAL)
        self.MenuBarFile.AppendItem(self.MenuItemSaveAs)
        #
        self.Bind(wx.EVT_MENU, self.OnMenuSelected, self.MenuItemSave)
        self.Bind(wx.EVT_MENU, self.OnMenuSelected, self.MenuItemSaveAs)
        self.Bind(wx.EVT_BUTTON, self.FrameEventHandler)
        self.Bind(wx.EVT_CLOSE, self.FrameEventHandler)

        self.__set_properties()
        self.__do_layout()
Пример #6
0
    def __init__(self, mode=None, data=None, type=None, id_prj=0, *args, **kwds):

        kwdsnew = copy.copy(kwds)
        kwdsnew["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwdsnew)

        self.Collection = 'Projects'

        self.idPrj = data     # Current project id.
        self.typePrj = type # Current project type.

        self.HelpContext = self.typePrj

        # List to save simulation rules at each stage
        # stage 2 doesn't have rule, but added here for indexing
        # This list is used to maintain temporary rule data before saving
        self.SimRule = [[], [], [], []]

        # Create empty class to save initial value(s) of project variables
        self.record = cdml.GetInstanceAttr(DB.Project)

        self.curCtrl = None # Current control which is selected for opening of a form
        self.curPage = 0     # Variable to save current page(i.e. tab) number
        self.openMode = mode

        # reset the override population
        self.TempOverridePopulationSet = None

        # Deine Popup menu items
        # Format : tuple of list --> ([Label, Event handler, Id] , [], [], ... )
        #           Label : label of an item
        #           Evet handler : name of event handler
        #           Id : Id of current menu item
        # Special label : '-'--> seperator, '+' --> submenu items
        #           First item after last '+' marked items is the title of the submenu
        # If an item doesn't have event handler, the second parameter should be 'None'
        # If an item doesn't have Id, the third item should be -1
        # In Project form dedicated event handler(OnMenuSelected) is being used
        # to deal with the button press event and focus change.
        self.pup_menus = (  ["Undo", self.OnUndo, wx.ID_UNDO ],
                            ["Copy Record" , self.OnMenuSelected, cdml.ID_MENU_COPY_RECORD],
                            ["Save" , self.OnMenuSelected, wx.ID_SAVE],
                            ["-" , None, -1],
                            ["Run Simulation" , self.OnMenuSelected, wx.ID_APPLY],
                            ["View Result" , self.OnMenuSelected, wx.ID_VIEW_DETAILS])

        # Define the window menus 
        cdml.GenerateStandardMenu(self, SkipItems = [cdml.ID_MENU_REPORT_ALL])

        self.panel_main = wx.Panel(self, -1)
        self.panel_common = wx.Panel(self.panel_main, -1)
        self.notebook = wx.Notebook(self.panel_main, -1, style=0)

        # title
        self.st_title = wx.StaticText(self.panel_main, -1, "Project Definition")

        # Common simulation information
        self.st_name = wx.StaticText(self.panel_common, -1, "Name : ")
        self.tc_name = cdml.Text(self.panel_common, -1, "")
        self.st_from = wx.StaticText(self.panel_common, -1, "Derived From : ")
        self.tc_from = cdml.Text(self.panel_common, -1, "", validator=cdml.KeyValidator(cdml.NO_EDIT))

        self.st_created = wx.StaticText(self.panel_common, -1, "Created On : ")
        self.tc_created = cdml.Text(self.panel_common, -1, "", validator=cdml.KeyValidator(cdml.NO_EDIT))
        self.st_modified = wx.StaticText(self.panel_common, -1, "Last Modified : ")
        self.tc_modified = cdml.Text(self.panel_common, -1, "", validator=cdml.KeyValidator(cdml.NO_EDIT))
        self.st_notes = wx.StaticText(self.panel_common, -1, "Notes : ")
        self.tc_notes = cdml.Text(self.panel_common, -1, "", style = wx.TE_MULTILINE)

        # reserved for future extension

        arrow_up = cdml.getSmallUpArrowBitmap() # arrow bitmap for buttons
        arrow_dn = cdml.getSmallDnArrowBitmap()

        self.btn_save = wx.Button(self.panel_main, wx.ID_SAVE)
        self.btn_copy = wx.Button(self.panel_main, cdml.ID_MENU_COPY_RECORD, "Copy")
        self.btn_undo = wx.Button(self.panel_main, wx.ID_UNDO)

        # simulation conditions
        self.panel_sim = wx.Panel(self.panel_main, -1)
        self.st_pset = wx.StaticText(self.panel_sim, -1, "Population Set : ")
        self.cc_pset = cdml.Combo(self.panel_sim, cdml.IDF_BUTTON1, validator=cdml.KeyValidator(cdml.NO_EDIT))
        self.st_simsteps = wx.StaticText(self.panel_sim, -1, "No. of Simulation Steps : ")
        self.tc_simsteps = cdml.Text(self.panel_sim, -1, "")
        self.st_model = wx.StaticText(self.panel_sim, -1, "Primary Model : ")
        self.cc_model = cdml.Combo(self.panel_sim, cdml.IDF_BUTTON2, validator=cdml.KeyValidator(cdml.NO_EDIT))
        self.st_repet = wx.StaticText(self.panel_sim, -1, "No. of Repetitions : ")
        self.tc_repet = cdml.Text(self.panel_sim, -1, "")

        self.btn_ed_pset = wx.Button(self.panel_sim, cdml.IDF_BUTTON3, "...")
        self.btn_ed_model = wx.Button(self.panel_sim, cdml.IDF_BUTTON4, "...")

        self.btn_run = wx.Button(self.panel_sim, wx.ID_APPLY, "Run Simulation")
        self.btn_result = wx.Button(self.panel_sim, wx.ID_VIEW_DETAILS, "View Result")
        self.btn_delete = wx.Button(self.panel_sim, wx.ID_CLEAR, "Delete Results")


        # create tabs for simulation stage
        self.nb_pane_0 = wx.Panel(self.notebook, 0)
        self.nb_pane_1 = wx.Panel(self.notebook, 1)
        self.nb_pane_2 = wx.Panel(self.notebook, 2)
        self.nb_pane_3 = wx.Panel(self.notebook, 3)

        
        # simulation stage 0 : initialization
        self.tab0_label = wx.StaticText(self.nb_pane_0, -1, "Initialize the simulation")
        self.tab0_list = cdml.List(self.nb_pane_0, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        # simulation stage 1 - Pre state transition
        self.tab1_label = wx.StaticText(self.nb_pane_1, -1, "Pre-State Transition Rules")
        self.tab1_list = cdml.List(self.nb_pane_1, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        # simulation stage 2
        self.tab2_label = wx.StaticText(self.nb_pane_2, -1, "Execute state transitions according to the primary model:", style=wx.ALIGN_CENTRE)
        self.tab2_st_model = wx.StaticText(self.nb_pane_2, -1, "")
        self.tab2_st_TraceBack = wx.StaticText(self.nb_pane_2, -1, "Pickled TraceBack Information for Reproducing simulation")
        self.tab2_tc_TraceBack = cdml.Text(self.nb_pane_2, -1, "", style = wx.TE_MULTILINE)
     
        # show the TraceBack fields only in Admin mode
        TraceBackIsVisible = cdml.GetAdminMode()
        self.tab2_st_TraceBack.Show(TraceBackIsVisible)
        self.tab2_tc_TraceBack.Show(TraceBackIsVisible)


        # simulation stage 3 - Post state transition
        self.tab3_label = wx.StaticText(self.nb_pane_3, -1, "Post-State Transition Rules")
        self.tab3_list = cdml.List(self.nb_pane_3, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)


        # combo boxes
        self.panel_combo = wx.Panel(self.panel_main, -1)
        self.label_1 = wx.StaticText(self.panel_combo, -1, "Parameter")
        self.label_2 = wx.StaticText(self.panel_combo, -1, "Occurrence Probability")
        self.label_3 = wx.StaticText(self.panel_combo, -1, "Function")
        self.label_4 = wx.StaticText(self.panel_combo, -1, "Notes")

        self.combo_box_1 = cdml.Combo(self.panel_combo, cdml.IDP_BUTTON1)
        self.combo_box_2 = cdml.Combo(self.panel_combo, cdml.IDP_BUTTON2)
        self.combo_box_2.AllowInput = True
        self.combo_box_3 = cdml.Combo(self.panel_combo, cdml.IDP_BUTTON3)
        self.combo_box_3.AllowInput = True
        self.tc_notes_rule = cdml.Text(self.panel_combo, cdml.IDP_BUTTON4)


        # Up/Down arrow button, Cost and QoL Wizard button
        self.btn_up = wx.BitmapButton(self.panel_combo, wx.ID_ADD, arrow_up)
        self.btn_dn = wx.BitmapButton(self.panel_combo, wx.ID_DELETE, arrow_dn)


        # Bind common event handler for Project form
        self.Bind(wx.EVT_CONTEXT_MENU, self.OnPopupMenu) # Dedicated event handler for popup menu
        self.Bind(wx.EVT_CLOSE, self.OnMenuSelected)
        self.Bind(wx.EVT_END_PROCESS, self.OnRefresh)

        self.btn_save.Bind(wx.EVT_BUTTON, self.OnMenuSelected)
        self.btn_copy.Bind(wx.EVT_BUTTON, self.OnMenuSelected)
        self.btn_undo.Bind(wx.EVT_BUTTON, self.OnUndo)

        self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)

        self.btn_up.Bind(wx.EVT_BUTTON, self.ChangeSimulaionRules)
        self.btn_dn.Bind(wx.EVT_BUTTON, self.ChangeSimulaionRules)

        self.btn_run.Bind(wx.EVT_BUTTON, self.OnMenuSelected)
        self.btn_result.Bind(wx.EVT_BUTTON, self.OnMenuSelected)
        self.btn_delete.Bind(wx.EVT_BUTTON, self.OnMenuSelected)

        self.btn_ed_pset.Bind(wx.EVT_BUTTON, self.OnLeftDblClick)
        self.btn_ed_model.Bind(wx.EVT_BUTTON, self.OnLeftDblClick)

        self.cc_pset.GetTextCtrl().Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
        self.cc_model.GetTextCtrl().Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)

        self.combo_box_1.GetTextCtrl().Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
        self.combo_box_2.GetTextCtrl().Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
        self.combo_box_3.GetTextCtrl().Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
        self.tc_notes_rule.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)

        self.__set_properties()
        self.__do_layout()

        # This method is different from the Initialize method of CDMFrame class
        # It is implemented in this module
        self.Initialize()
Пример #7
0
    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
Пример #8
0
    def GetParameterList(self):
        """ Open a dialog and get parameter list to display """

        types = ['ALL User Accessible']
        types.extend(DB.ParameterTypes)
        # Decide if to include system reserve parameters according to if
        # admin mode was set
        if not cdml.GetAdminMode():
            types.remove('State Indicator')
            types.remove('System Reserved')
        else:
            types.append('ALL')

        if self.openData == None:
            # if no specific parameter was requested show a dialog box
            dlg = wx.MultiChoiceDialog(
                self,
                'Please select parameter type you want to see.\n Some parameter types may take long time to display.',
                'Select Parameter', types, wx.CHOICEDLG_STYLE)

            dlg.SetSelections([0])  # set default selection
            dlg.CenterOnScreen()

            if dlg.ShowModal() != wx.ID_OK:
                return []  # If 'Cancel' button is clicked

            indexes = dlg.GetSelections()  # Get selection index
            dlg.Destroy()

            selections = [types[i]
                          for i in indexes]  # extract selected parameter types
            if selections == []:
                params = []
            elif selections[0] == 'ALL User Accessible':
                # Sort the entries according to key and filter
                params = [
                    Entry for (Key, Entry) in sorted(DB.Params.iteritems())
                    if Entry.ParameterType not in
                    ['State Indicator', 'System Reserved']
                ]

            elif selections[-1] == 'ALL':
                # Sort the entries according to key
                params = [
                    Entry for (Key, Entry) in sorted(DB.Params.iteritems())
                ]

            else:
                # Sort the entries according to key and filter
                params = [
                    Entry for (Key, Entry) in sorted(DB.Params.iteritems())
                    if Entry.ParameterType in selections
                ]
        else:
            # The form was called with a particular parameter in mind
            parm = cdml.GetRecordByKey(getattr(DB, self.Collection),
                                       self.openData)
            if parm == None or parm.ParameterType not in types:
                params = []
            else:
                params = [parm]
        return params