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)
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)
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)
def ShowData(self, Columns, Data, Objectives): """ Display DataColums/Data in the List Controls and Grid control if necessary""" self.lc_column.SetItems( Columns, do_sort=False) # Clear and add new Column names self.lc_objectives.SetItems( Objectives, do_sort=False) # Clear and add new Column names self.ShowTabData() # Create or delete 'Data' tab if Data == []: if self.HasDistribution: # if this is distribution based, make sure the grid is clear # do nothing return # Display Data on the grid control no_col = len(Columns) no_row = len(Data) no_grid_col = self.grid_1.GetNumberCols() no_grid_row = self.grid_1.GetNumberRows() # Adjust grid size according to the size of Data if no_col > no_grid_col: self.grid_1.AppendCols(no_col - no_grid_col) elif no_col < no_grid_col: self.grid_1.DeleteCols(no_col, no_grid_col - no_col) if no_row > no_grid_row: self.grid_1.AppendRows(no_row - no_grid_row) elif no_row < no_grid_row: self.grid_1.DeleteRows(no_row, no_grid_row - no_row) self.grid_1.ClearGrid() # Delete existing data in grid control # Set the column header of grid control for i, column in enumerate(Columns): self.grid_1.SetColLabelValue(i, column[0]) # Write Data in each cell for i, row in enumerate(Data): for j, col in enumerate(row): value = cdml.iif(row[j] == None, '', DB.SmartStr(row[j])) self.grid_1.SetCellValue(i, j, value) self.__do_layout()
def ShowData(self, Columns, Data, Objectives): """ Display DataColums/Data in the List Controls and Grid control if necessary""" self.lc_column.SetItems(Columns, do_sort=False) # Clear and add new Column names self.lc_objectives.SetItems(Objectives, do_sort=False) # Clear and add new Column names self.ShowTabData() # Create or delete 'Data' tab if Data == []: if self.HasDistribution: # if this is distribution based, make sure the grid is clear # do nothing return # Display Data on the grid control no_col = len(Columns) no_row = len(Data) no_grid_col = self.grid_1.GetNumberCols() no_grid_row = self.grid_1.GetNumberRows() # Adjust grid size according to the size of Data if no_col > no_grid_col: self.grid_1.AppendCols(no_col - no_grid_col) elif no_col < no_grid_col : self.grid_1.DeleteCols(no_col, no_grid_col - no_col) if no_row > no_grid_row: self.grid_1.AppendRows(no_row - no_grid_row) elif no_row < no_grid_row : self.grid_1.DeleteRows(no_row, no_grid_row - no_row) self.grid_1.ClearGrid() # Delete existing data in grid control # Set the column header of grid control for i, column in enumerate(Columns): self.grid_1.SetColLabelValue(i, column[0]) # Write Data in each cell for i, row in enumerate(Data): for j, col in enumerate(row): value = cdml.iif(row[j] == None, '', DB.SmartStr(row[j])) self.grid_1.SetCellValue(i,j, value) self.__do_layout()
def OnPopupMenu(self, event): """ Event handler to open Popup menu """ if not hasattr(self, 'pup_menus'): return menu = cdml.setupMenu(self, self.pup_menus, False) # crate popup menu and assign event handler page = self.nb.GetCurrentPage() menu_enable = cdml.iif( page.Id == 0, False, True ) item_add = menu.FindItemById(cdml.IDF_BUTTON1) item_del = menu.FindItemById(cdml.IDF_BUTTON2) item_add.Enable(menu_enable) item_del.Enable(menu_enable) self.PopupMenu(menu) # open popup menu menu.Destroy() # remove from memory to show just once when right button is clicked
def __set_properties(self): """ Set properties of frame and controls """ self.SetTitle("TRANSITIONS") self.SetSize((960, 600)) self.SetCollection('Transitions') # or self.Collection = 'Transitions' self.HelpContext = 'Transitions' self.st_title.SetFont( wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) self.cc_study_model.SetColumns((('Name', 150), ('Notes', 332))) self.cc_study_model.SetEvent( (None, cdml.ID_EVT_OWN, self.InitTransitions)) self.cc_study_model.typeData = cdml.ID_TYPE_COMBO self.pn_title.isRow = False self.pn_view.SetScrollRate(10, 10) StandardSize = (150, -1) # set sort id and event id for field titles for i in range(1, 5): btn = getattr(self, 'button_' + str(i)) btn.SetMinSize(StandardSize) btn.sortId = i - 1 btn.evtID = cdml.ID_EVT_SORT # Build and assign study/model list for the combo control in title section study_models = [(sm.Name, sm.Notes, sm.ID) for sm in DB.StudyModels.values()] self.cc_study_model.SetItems(study_models, allowBlank=False) # Set default study or model according to the opening mode init_id = cdml.iif(self.openData == None, DB.StudyModels.keys()[0], self.openData) self.cc_study_model.SetValue(init_id) # If specific Study/Model ID was given, disable the Combo control self.cc_study_model.Enable(self.openData == None)
def __set_properties(self): """ Set properties of frame and controls """ self.SetTitle("TRANSITIONS") self.SetSize((960, 600)) self.SetCollection('Transitions') # or self.Collection = 'Transitions' self.HelpContext = 'Transitions' self.st_title.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) self.cc_study_model.SetColumns( (('Name', 150), ('Notes', 332)) ) self.cc_study_model.SetEvent((None, cdml.ID_EVT_OWN, self.InitTransitions)) self.cc_study_model.typeData = cdml.ID_TYPE_COMBO self.pn_title.isRow = False self.pn_view.SetScrollRate(10, 10) StandardSize = (150, -1) # set sort id and event id for field titles for i in range(1,5): btn = getattr(self, 'button_' + str(i)) btn.SetMinSize(StandardSize) btn.sortId = i-1 btn.evtID = cdml.ID_EVT_SORT # Build and assign study/model list for the combo control in title section study_models = [(sm.Name, sm.Notes, sm.ID) for sm in DB.StudyModels.values() ] self.cc_study_model.SetItems(study_models, allowBlank = False) # Set default study or model according to the opening mode init_id = cdml.iif( self.openData == None, DB.StudyModels.keys()[0], self.openData) self.cc_study_model.SetValue(init_id) # If specific Study/Model ID was given, disable the Combo control self.cc_study_model.Enable(self.openData==None)
def ShowSimResult(self, event=None): """ Display simulation results in the grid control """ id = self.cc_id_sim.GetValue() # Retrieve simulation ID from combo box if id == "": return id = int(id) # Find simulation results object related to current project cur_result = None for result in DB.SimulationResults.values(): if result.ID == id and result.ProjectID == self.idPrj: cur_result = result break no_col = len(cur_result.DataColumns) no_row = len(cur_result.Data) no_grid_col = self.grid.GetNumberCols() no_grid_row = self.grid.GetNumberRows() # If there are too many records, allow the user to decide how many # to load to the system to reduce the load. It is impractical to show # very large simulation results. if no_col * no_row > 50000: dlg = wx.NumberEntryDialog( self, "Define number or records to show", "The result grid is very large (" + str(no_row) + " rows x " + str(no_col) + " columns) \nand it is probably not practical to show it on the screen. \nPlease decide how many rows you wish to view. \nNote that you can later export the results to view them in full in another application. \nPressing Cancel will show all rows and in some cases may overwhelm the system.", "Rows to show", 1000, 0, 100000, ) dlg.CenterOnScreen() if dlg.ShowModal() == wx.ID_OK: no_row = min(dlg.GetValue(), no_row) # adjust the number of rows and columns of the grid congtrol if no_col > no_grid_col: self.grid.AppendCols(no_col - no_grid_col) elif no_col < no_grid_col: self.grid.DeleteCols(no_col, no_grid_col - no_col) if no_row > no_grid_row: self.grid.AppendRows(no_row - no_grid_row) elif no_row < no_grid_row: self.grid.DeleteRows(no_row, no_grid_row - no_row) self.grid.ClearGrid() # Clear current values in grid control dlg = wx.GenericProgressDialog( "Load Data", "Loading Data. Please wait......", maximum=no_col + no_row, parent=self, style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME, ) dlg.CenterOnScreen() for i, column in enumerate(cur_result.DataColumns): # write column header on grid control self.grid.SetColLabelValue(i, column) dlg.Update(i) # update length of gauge in progress dialog for i, row in enumerate(cur_result.Data[0:no_row]): # write data in each cell in the range for j, col in enumerate(row): value = cdml.iif(row[j] == None, "", str(row[j])) self.grid.SetCellValue(i, j, value) dlg.Update(i + no_col) dlg.Destroy()
def ShowSimResult(self, event=None): """ Display simulation results in the grid control """ id = self.cc_id_sim.GetValue() # Retrieve simulation ID from combo box if id == '': return id = int(id) # Find simulation results object related to current project cur_result = None for result in DB.SimulationResults.values(): if result.ID == id and result.ProjectID == self.idPrj: cur_result = result break no_col = len(cur_result.DataColumns) no_row = len(cur_result.Data) no_grid_col = self.grid.GetNumberCols() no_grid_row = self.grid.GetNumberRows() # If there are too many records, allow the user to decide how many # to load to the system to reduce the load. It is impractical to show # very large simulation results. if no_col * no_row > 50000: dlg = wx.NumberEntryDialog( self, 'Define number or records to show', 'The result grid is very large (' + str(no_row) + ' rows x ' + str(no_col) + ' columns) \nand it is probably not practical to show it on the screen. \nPlease decide how many rows you wish to view. \nNote that you can later export the results to view them in full in another application. \nPressing Cancel will show all rows and in some cases may overwhelm the system.', 'Rows to show', 1000, 0, 100000) dlg.CenterOnScreen() if dlg.ShowModal() == wx.ID_OK: no_row = min(dlg.GetValue(), no_row) # adjust the number of rows and columns of the grid congtrol if no_col > no_grid_col: self.grid.AppendCols(no_col - no_grid_col) elif no_col < no_grid_col: self.grid.DeleteCols(no_col, no_grid_col - no_col) if no_row > no_grid_row: self.grid.AppendRows(no_row - no_grid_row) elif no_row < no_grid_row: self.grid.DeleteRows(no_row, no_grid_row - no_row) self.grid.ClearGrid() # Clear current values in grid control dlg = wx.GenericProgressDialog( "Load Data", "Loading Data. Please wait......", maximum=no_col + no_row, parent=self, style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME) dlg.CenterOnScreen() for i, column in enumerate( cur_result.DataColumns): # write column header on grid control self.grid.SetColLabelValue(i, column) dlg.Update(i) # update length of gauge in progress dialog for i, row in enumerate(cur_result.Data[0:no_row] ): # write data in each cell in the range for j, col in enumerate(row): value = cdml.iif(row[j] == None, '', str(row[j])) self.grid.SetCellValue(i, j, value) dlg.Update(i + no_col) dlg.Destroy()