Exemple #1
0
    def OnClose(self, event):
        """ Event handler activated when this dialog is closed"""

        if event.GetId() == wx.ID_OK:
            type_wizard = cdml.iif('Cost' in self.cb_type.GetValue(), 0, 1)
            ival = self.ed_ival.GetValue()

            coef, val = [], []
            item_num = self.lc_vector.GetItemCount()
            for i in range(item_num):
                coef.append(str(self.lc_vector.GetItem(i, 0).GetText()))
                val.append(str(self.lc_vector.GetItem(i, 1).GetText()))

            wizard_output = [type_wizard, ival, coef, val]
            try:
                CostWizardOutput = DB.ConstructCostWizardString(wizard_output)
                cdml.SetRefreshInfo(self, '', CostWizardOutput)

            except:
                CostWizardOutput = None
                ans = cdml.dlgErrorMsg(0, True, Parent=self)
                if ans == wx.ID_YES: return
            cdml.CloseForm(self, True, '', CostWizardOutput)

        else:
            cdml.CloseForm(self, False)
Exemple #2
0
    def OnMenuSelected(self, event):
        """ Do something when action buttons are clicked.
            Action buttons are Save, Run Simulation, View Result and Close"""
        menuId = event.GetId()
        evtType = event.GetEventType()

        if evtType==wx.wxEVT_COMMAND_MENU_SELECTED:
            if menuId not in [cdml.ID_MENU_REPORT_ALL]:
                # Use the default handler first and if no more processing needed return
                if cdml.OnMenuSelected(self, event):
                    return

        try:
            # In any case, if a button - Save, Run, View Result - is clicked, data will be save
            save_ok = self.CheckData()

            if evtType == wx.wxEVT_CLOSE_WINDOW:    # Close Window Event
                #cdml.CloseForm(self, True, self.Collection, self.idPrj)
                cdml.CloseForm(self, True)
                return

            elif menuId == cdml.ID_MENU_COPY_RECORD:
                copy_ok = self.CopyProject()
                if not copy_ok: return
                cdml.dlgSimpleMsg('INFO', 'The project has been successfully copied - you are now working on the new copy', wx.OK, wx.ICON_INFORMATION, Parent = self)
            elif menuId == wx.ID_SAVE :
                if not save_ok: return
                cdml.dlgSimpleMsg('INFO', 'The project data has been saved successfully', wx.OK, wx.ICON_INFORMATION, Parent = self)

            elif menuId == wx.ID_APPLY:             # Run Simulation
                self.RunSimulation()

            elif menuId == wx.ID_VIEW_DETAILS:  # View Results / Extract PopulationSets
                self.ShowSimResult()

            elif menuId == wx.ID_CLEAR:

                result_ids = [ result.ID for result in DB.SimulationResults.values()
                                if result.ProjectID == self.idPrj ]

                if result_ids == [] :
                    cdml.dlgSimpleMsg('ERROR', "There are no simulation results for this project", Parent = self)
                else:
                    ans = cdml.dlgSimpleMsg('WARNING', 'Simulation results will be deleted permanently.\nDo you want to continue with deletion?', wx.YES_NO, wx.ICON_WARNING, Parent = self)
                    if ans == wx.ID_NO: return

                    for id in result_ids:
                        DB.SimulationResults.Delete(id, ProjectBypassID = self.idPrj)

                    cdml.dlgSimpleMsg('INFO', 'All simulation results were deleted', wx.OK, wx.ICON_INFORMATION, Parent = self)

        except:
            (ExceptType, ExceptValue, ExceptTraceback) = sys.exc_info()
            need_ans = cdml.iif(evtType == wx.wxEVT_CLOSE_WINDOW, True, False)
            if cdml.dlgErrorMsg(yesno=need_ans, Parent = self) == wx.ID_NO:
                cdml.CloseForm(self, False)
Exemple #3
0
    def FrameEventHandler(self, evt):
        """ Frame Event Handler """

        evtType = evt.GetEventType()
        # if current event is close window, call CloseForm function
        if evtType == wx.wxEVT_CLOSE_WINDOW:
            cdml.CloseForm(self)
            return
Exemple #4
0
    def OnButtonClick(self, event):
        """ Event handler for buttons """

        btn_id = event.GetId()

        try:
            if btn_id == cdml.IDF_BUTTON2:  # Import
                self.ImportCSV()

            if btn_id == cdml.IDF_BUTTON3:  # Export
                try:
                    self.SaveData()
                    self.ShowData(self.DataColumns, self.Data, self.Objectives)
                except:
                    cdml.dlgErrorMsg(Parent=self)
                else:
                    if self.Data == []:
                        cdml.dlgSimpleMsg(
                            'INFO',
                            'No data has been defined so exporting makes no sense',
                            wx.OK,
                            wx.ICON_INFORMATION,
                            Parent=self)
                    else:
                        self.ExportCSV(self.DataColumns, self.Data)

            elif btn_id == cdml.IDF_BUTTON4:  # Undo
                self.Undo()

            elif btn_id == cdml.IDF_BUTTON5 or \
                event.GetEventType() == wx.wxEVT_CLOSE_WINDOW : # Ok or Close
                try:
                    self.SaveData()

                except:
                    cdml.dlgErrorMsg(Parent=self)

                else:
                    cdml.CloseForm(self, False)

            elif btn_id == wx.ID_ADD:  # Up Arrow : Add new State/Distribution
                self.AddColumn()

            elif btn_id == wx.ID_DELETE:  # Down Arrow : Delete State/Distribution
                self.DeleteColumn()

            elif btn_id == cdml.IDF_BUTTON7:  # Down Arrow in objective pane
                self.DeleteObjective()

            elif btn_id == cdml.IDF_BUTTON8:  # Up Arrow in objective pane
                self.AddObjective()

        except:
            cdml.dlgErrorMsg(Parent=self)
Exemple #5
0
 def LoadReportOptions(self):
     """ Load report options from file"""
     path = self.GetReportOptionsFileName(wx.FD_OPEN)
     if path != None:
         try:
             BackupFormatOptions = copy.deepcopy(self.FormatOptions)
             FormatOptions = DB.LoadOptionList(path)
             KeyFilterOptionValue = DB.HandleOption('KeyFilter',
                                                    self.FormatOptions,
                                                    Value=None,
                                                    UseNewValue=False,
                                                    DeleteThisOption=False)
             if KeyFilterOptionValue != None:
                 DB.HandleOption('KeyFilter',
                                 FormatOptions,
                                 Value=KeyFilterOptionValue,
                                 UseNewValue=True,
                                 DeleteThisOption=False)
             # now load the data to the controls to reflect the newly loaded data
             # note that not validity checks are made, so if the file loaded
             # properly and had bad data this may be reflected as bad text in
             # the control or even raise an error that can be caught. Since this
             # is not disruptive to data stored in the system no additional
             # checks are made beyond what the system will allow in the controls
             self.PopulateOptionsOnScreen(FormatOptions)
             # now after data was updated update self with the new options
             self.FormatOptions = FormatOptions
             # Everything went fine - no need for backup anymore
             BackupFormatOptions = None
         except:
             cdml.dlgErrorMsg(Parent=self)
         if BackupFormatOptions != None:
             try:
                 # in case of a bad file or an error, restore blank values
                 self.PopulateOptionsOnScreen(BackupFormatOptions)
             except:
                 answer = cdml.dlgErrorMsg(
                     msg_prefix=
                     'ASSERTION ERROR: Unable to recover from Error. Here are additional details: ',
                     yesno=True,
                     Parent=self)
                 if answer == wx.ID_YES:
                     return
                 else:
                     cdml.CloseForm(self, False)
     return
Exemple #6
0
 def FrameEventHandler(self, evt):
     "The frame handling routine"
     # if current event is close window, call CloseForm function
     evtType = evt.GetEventType()
     evtId = evt.GetId()
     if evtType == wx.wxEVT_CLOSE_WINDOW:
         cdml.CloseForm(self, False)
         return
     elif evtType == wx.wxEVT_COMMAND_BUTTON_CLICKED:
         if evtId == wx.ID_ADD:
             self.AddColumnHandler()
         if evtId == wx.ID_DELETE:
             self.DelColumnHandler()
         if evtId == wx.ID_APPLY:
             self.RegenerateHandler()
         if evtId == cdml.IDP_BUTTON1:
             self.LoadReportOptions()
         if evtId == cdml.IDP_BUTTON2:
             self.SaveReportOptions()
     return