def setSessionDetail(self, grid, session, begin_row, begin_col): """ Sets session detail in GUI Arguments: grid -- wx.grid.Grid The grid to add session details t session -- model_runner_db.CalibrationSession begin_row -- int The row to begin adding values to begin_col -- int The column to begin adding values to """ #self.sessionDetail.Clear() #self.sessionDetail.WriteText("id: %s\nobs_filename: %s" % # (session.id, session.obs_filename)) grid.ClearGrid() grid.SetCellValue(begin_row, begin_col, str(session.starttime)) if session.endtime: grid.SetCellValue(begin_row+1, begin_col, str(session.endtime)) grid.SetCellValue(begin_row+2, begin_col, session.user) grid.SetCellValue(begin_row+3, begin_col, session.project) grid.SetCellValue(begin_row+4, begin_col, str(session.iterations)) grid.SetCellValue(begin_row+5, begin_col, str(session.processes)) grid.SetCellValue(begin_row+6, begin_col, session.status) if session.obs_filename: grid.SetCellValue(begin_row+7, begin_col, session.obs_filename) if session.notes: grid.SetCellValue(begin_row+8, begin_col, session.notes) grid.AutoSizeColumns() grid.AutoSizeRows()
def addSessionsToGrid(self, grid, begin_row, begin_col): """ Add session.id to each row of the grid Arguments: grid -- wx.grid.Grid The grid to add session IDs to begin_row -- int The row to begin adding values to begin_col -- int The column to begin adding values to """ if None == self.sessions: self.sessions = self.calibratorDB.getSessions() grid.ClearGrid() # Add rows to the grid if necessary numSessions = len(self.sessions) rowsNeeded = numSessions - grid.NumberRows if rowsNeeded > 0: grid.AppendRows(rowsNeeded) myRow = begin_row for session in self.sessions: grid.SetCellValue(myRow, begin_col, str(session.id)) myRow += 1 grid.AutoSizeColumns() grid.AutoSizeRows()
def excel_to_grid(self, source, sheet, grid): """ Opens the Excel file in source and loads the sheet into the grid nx is the number of extra columns required. """ wb = xlrd.open_workbook(source) names = wb.sheet_names() if sheet in names: grid.ClearGrid() if grid.GetNumberRows() > 0: grid.DeleteRows(0, grid.GetNumberRows(), True) if grid.GetNumberCols() > 0: grid.DeleteCols(0, grid.GetNumberCols(), True) sh = wb.sheet_by_name(sheet) num_rows = sh.nrows num_cols = sh.ncols self.SetGridRows(grid, num_rows) self.SetGridCols(grid, num_cols) #extra columns for results #print 'number of rows = ', num_rows #print 'number of columns = ', num_cols curr_row = -1 while curr_row < num_rows - 1: curr_row += 1 for i in range(num_cols): grid.SetCellValue(curr_row, i, self.style(sh, curr_row, i)) return True else: return False
def OnSetView(usrData,value,msg): gridFrm =usrData.slider.Parent.Parent grid=gridFrm.grid tbl=grid.GetTable() data=tbl.data sl=ut.GetSlice(tbl.idxXY,data.shape,gridFrm.wxAxCtrlLst) #tbl.view = tbl.data[value,...] tbl.view = tbl.data[sl] grid.ClearGrid() pass
def __init__(self, task): super(GridData, self).__init__() dts = task['payload'] oldColumns = task['columns'] showColumns = [] rows = dts['rows'] for k, v in enumerate(dts['columns']): item = list_firstOrDefault(lambda x: v == x['name'], oldColumns) if (item is None) == False: showColumns.append(item['text']) else: showColumns.append('● [ 未知 ]') global grid grid.ClearGrid() for j, p in enumerate(showColumns): grid.SetColLabelValue(j, p) # 表格数据 for k, v in enumerate(rows): # 表格列 for j, p in enumerate(showColumns): text = str(v[j]) if p == '创建者' or p == '指派给': text = text.split('<')[0] elif p == '完成日期' or p == '开始日期' or p == '截止日期': text = is_valid_date(v[j]) elif p == '初始估计' or p == '已完成工作': if text == 'None': text = ' ' else: if text == 'None': text = ' ' grid.SetCellValue(k, j, text) self._cols = showColumns self._data = rows
def reCreateGrid(self, grid=None, row_count=5, col_count=5): """ Re create grid object with new rows and columns :param grid: wx.Grid control object. :param row_count: Number of row. :param col_count: Number of columns. :return: True/False. """ if grid is None: grid = self._spreadsheet_grid if not isinstance(grid, wx.grid.Grid): log_func.warning(u'Error grid control type <%s>' % grid.__class__.__name__) return False try: prev_row_count = grid.GetNumberRows() prev_col_count = grid.GetNumberCols() delta_row_count = row_count - prev_row_count delta_col_count = col_count - prev_col_count # Clear all data grid.ClearGrid() if delta_col_count > 0: grid.AppendCols(delta_col_count) else: grid.DeleteCols(prev_col_count + delta_col_count - 1, -delta_col_count) if delta_row_count > 0: grid.AppendRows(delta_row_count) else: grid.DeleteRows(prev_row_count + delta_row_count - 1, -delta_row_count) # self.Layout() return True except: log_func.fatal(u'Error recreate grid object') return False
def addRunDetailsToGrid(self, grid, run, begin_row, begin_col): """ Sets run detail in GUI Arguments: grid -- wx.grid.Grid The grid to add run details to run -- model_runner_db.CalibrationRun begin_row -- int The row to begin adding values to begin_col -- int The column to begin adding values to """ grid.ClearGrid() grid.SetCellValue(begin_row, begin_col, run.worldfile) grid.SetCellValue(begin_row+1, begin_col, run.output_path) grid.SetCellValue(begin_row+2, begin_col, run.cmd_raw) if run.param_s1: grid.SetCellValue(begin_row+3, begin_col, "%.4f" % run.param_s1) if run.param_s2: grid.SetCellValue(begin_row+4, begin_col, "%.4f" % run.param_s2) if run.param_s3: grid.SetCellValue(begin_row+5, begin_col, "%.4f" % run.param_s3) if run.param_sv1: grid.SetCellValue(begin_row+6, begin_col, "%.4f" % run.param_sv1) if run.param_sv2: grid.SetCellValue(begin_row+7, begin_col, "%.4f" % run.param_sv2) if run.param_gw1: grid.SetCellValue(begin_row+8, begin_col, "%.4f" % run.param_gw1) if run.param_gw2: grid.SetCellValue(begin_row+9, begin_col, "%.4f" % run.param_gw2) if run.param_vgsen1: grid.SetCellValue(begin_row+10, begin_col, "%.4f" % run.param_vgsen1) if run.param_vgsen2: grid.SetCellValue(begin_row+11, begin_col, "%.4f" % run.param_vgsen2) if run.param_vgsen3: grid.SetCellValue(begin_row+12, begin_col, "%.4f" % run.param_vgsen3) grid.AutoSizeColumns() grid.AutoSizeRows()
def addRunsToGrid(self, grid, runs, begin_row, begin_col): """ Add run summary information for self.runGrid Arguments: grid -- wx.grid.Grid Grid to add run information to runs -- list<model_runner_db.CalibrationRun> begin_row -- int Row at which to begin writing information begin_col -- int Column at which to begin writing information """ grid.ClearGrid() # Add rows to the grid if necessary numRuns = len(runs) rowsNeeded = numRuns - grid.NumberRows if rowsNeeded > 0: grid.AppendRows(rowsNeeded) myRow = begin_row myCol = begin_col for run in runs: grid.SetCellValue(myRow, myCol, str(run.id)) if run.nse: grid.SetCellValue(myRow, myCol+1, "%.2f" % run.nse) if run.nse_log: grid.SetCellValue(myRow, myCol+2, "%.2f" % run.nse_log) if run.pbias: grid.SetCellValue(myRow, myCol+3, "%.2f" % run.pbias) if run.rsr: grid.SetCellValue(myRow, myCol+4, "%.2f" % run.rsr) if run.user1: grid.SetCellValue(myRow, myCol+5, "%.2f" % run.user1) if run.user2: grid.SetCellValue(myRow, myCol+6, "%.2f" % run.user2) if run.user3: grid.SetCellValue(myRow, myCol+7, "%.2f" % run.user3) myRow += 1