def OnOpenRecordClicked(self, event): self.callDataBase(2) grid = wx.grid.Grid(self, pos=(320, 0), size=(600, 500)) grid.CreateGrid(100, 4) for i in range(100): for j in range(4): grid.SetCellAlignment(i, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetColLabelValue(0, "学号") grid.SetColLabelValue(1, "姓名") grid.SetColLabelValue(2, "签到时间") grid.SetColLabelValue(3, "是否迟到") grid.SetColSize(0, 100) grid.SetColSize(1, 100) grid.SetColSize(2, 150) grid.SetColSize(3, 150) grid.SetCellTextColour("NAVY") for i, id in enumerate(self.Sign_Info_id): grid.SetCellValue(i, 0, str(id)) grid.SetCellValue(i, 1, self.Sign_Info_name[i]) grid.SetCellValue(i, 2, self.Sign_Info_time_info[i]) grid.SetCellValue(i, 3, self.Sign_Info_if_late[i]) pass
def __init__(self, parent): wx.Frame.__init__(self, parent, title='Statistics') wtl = CsvTimeLogger() statistics = wtl.get_statistics() panel = wx.Panel(self) top_sizer = wx.BoxSizer(wx.VERTICAL) grid = wx.grid.Grid(self, -1) grid.CreateGrid(len(statistics), 2) # + 1 due to summary row at end grid.SetColLabelValue(0, "Day") grid.SetColLabelValue(1, "Worked") grid.SetRowLabelSize(0) for i, (k, v) in enumerate(statistics.items()): grid.SetCellValue(i, 1, format_timedelta(v)) grid.SetCellAlignment(i, 1, wx.ALIGN_RIGHT, wx.ALIGN_CENTER) if isinstance(k, dt.date): grid.SetCellValue(i, 0, k.strftime('%a %Y-%m-%d')) grid.SetCellAlignment(i, 0, wx.ALIGN_RIGHT, wx.ALIGN_CENTER) rel_extra_time = v.total_seconds() / dt.timedelta(hours=4).seconds grid.SetCellBackgroundColour(i, 1, get_color_red_white_blue(rel_extra_time)) else: grid.SetCellValue(i, 0, k) grid.AutoSize() top_sizer.Add(grid, 0, wx.CENTER) panel.SetSizer(top_sizer) top_sizer.Fit(self) self.Show()
def __init__(self, parent): wx.Frame.__init__(self, parent) # Create a wxGrid object grid = wx.grid.Grid(self, -1) # Then we call CreateGrid to set the dimensions of the grid # (100 rows and 10 columns in this example) grid.CreateGrid(100, 10) # We can set the sizes of individual rows and columns # in pixels grid.SetColSize(5, 200) # And set grid cell contents as strings grid.SetCellValue(0, 0, 'wxGrid is good') # We can specify that some cells are read.only grid.SetCellValue(0, 3, 'This is read.only') grid.SetReadOnly(0, 3) # Colours can be specified for grid cell contents grid.SetCellValue(3, 3, 'green on grey') grid.SetCellTextColour(3, 3, wx.GREEN) grid.SetCellBackgroundColour(3, 3, wx.LIGHT_GREY) # We can specify the some cells will store numeric # values rather than strings. Here we set grid column 5 # to hold floating point values displayed with width of 6 # and precision of 2 grid.SetColFormatFloat(5, 6, 2) grid.SetCellValue(0, 6, '3.1415') self.Show()
def __init__(self, parent): wx.Frame.__init__(self, parent) # create a wxGrid object grid = wx.grid.Grid(self, -1) grid.CreateGrid(100, 10) #setting sizes of individual rows and colums in pixels grid.SetRowSize(0, 60) grid.SetColSize(0, 120) #set grid contents as strings grid.SetCellValue(0,0,'wxgrid is good') #can specify cells as read-only grid.SetReadOnly(0,0) #colors for cell contents grid.SetCellValue(0,1,'color!') grid.SetCellTextColour(0,1,wx.LIGHT_GREY) #define the default cell text color grid.SetDefaultCellTextColour(wx.BLACK) self.Show()
def OnOpenLogcatClicked(self, event): if user_now == ID_WORKER_UNAVIABLE: wx.MessageBox(message="未检测到用户,请进行识别", caption="警告") else: self.loadDataBase(2) # 必须要变宽才能显示 scroll self.SetSize(980, 560) grid = wx.grid.Grid(self, pos=(320, 0), size=(640, 500)) grid.CreateGrid(100, 4) for i in range(100): for j in range(4): grid.SetCellAlignment(i, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetColLabelValue(0, "序号") # 第一列标签 grid.SetColLabelValue(1, "姓名") grid.SetColLabelValue(2, "识别时间") grid.SetColLabelValue(3, "操作") grid.SetColSize(0, 120) grid.SetColSize(1, 120) grid.SetColSize(2, 150) grid.SetColSize(3, 150) grid.SetCellTextColour(1, 1, 'red') for i, id in enumerate(self.logcat_id): grid.SetCellValue(i, 0, str(id)) grid.SetCellValue(i, 1, self.logcat_name[i]) grid.SetCellValue(i, 2, self.logcat_datetime[i]) grid.SetCellValue(i, 3, self.logcat_late[i]) pass
def OnSearch(self, event): # Scan libraries looking for parts that match search string. progress = wx.ProgressDialog("Searching Part Libraries", "Loading parts from libraries.") self.lib_parts = set() search_text = self.search_text.GetLineText(0) for lib_part in search_libraries(search_text): if lib_part[0] == "LIB": lib_name, lib_idx, num_libs = lib_part[1:4] progress.SetRange(num_libs) progress.Update(lib_idx, "Reading library {}...".format(lib_name)) elif lib_part[0] == "PART": self.lib_parts.add(LibPart(*lib_part[1:])) # Sort parts by libraries and part names. self.lib_parts = sorted( list(self.lib_parts), key=lambda x: "/".join([x.lib_name, x.part_name]), ) # place libraries and parts into a table. grid = self.found_parts # Clear any existing grid cells and add/sub rows to hold search results. grid.Resize(len(self.lib_parts)) # Places libs and part names into table. for row, lib_part in enumerate(self.lib_parts): grid.SetCellValue(row, 0, lib_part.lib_name) grid.SetCellValue(row, 1, lib_part.part_name) # Size the columns for their new contents. grid.AutoSizeColumns()
def OnOpenLogcatClicked(self, event): self.loadDataBase(2) self.SetSize(980, 560) grid = wx.grid.Grid(self, pos=(320, 0), size=(640, 500)) grid.CreateGrid(100, 4) for i in range(100): for j in range(4): grid.SetCellAlignment(i, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetColLabelValue(0, "工号") #第一列标签 grid.SetColLabelValue(1, "姓名") grid.SetColLabelValue(2, "打卡时间") grid.SetColLabelValue(3, "是否迟到") grid.SetColSize(0, 120) grid.SetColSize(1, 120) grid.SetColSize(2, 150) grid.SetColSize(3, 150) grid.SetCellTextColour("NAVY") for i, id in enumerate(self.logcat_id): grid.SetCellValue(i, 0, str(id)) grid.SetCellValue(i, 1, self.logcat_name[i]) grid.SetCellValue(i, 2, self.logcat_datetime[i]) grid.SetCellValue(i, 3, self.logcat_late[i]) pass
def __init__(self): wx.Frame.__init__(self, None, title="Grid demo", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE) sizer = wx.BoxSizer() self.SetSizer(sizer) bmp_rabbit, bmp_carrot = [ wx.BitmapFromImage(wx.ImageFromStream(StringIO.StringIO(x))) for x in (IMG_RABBIT, IMG_CARROT) ] d = {"rabbit": bmp_rabbit, "carrot": bmp_carrot} grid = wx.grid.Grid(self) sizer.Add(grid, 1, wx.EXPAND) grid.CreateGrid(4, 5) grid.SetGridLineColour(wx.BLACK) self.grid = grid for i in range(4): hook_grid_button_column(grid, i, d) for j in range(4): grid.SetCellValue( i, j, (((i + j) % 2 == 0 and "rabbit:") or "carrot:") + BU_NORMAL) grid.SetCellValue(i, 4, "Row %d" % (i + 1)) grid.SetReadOnly(i, 4) grid.SetColLabelSize(0) grid.SetRowLabelSize(0) self.Bind(EVT_GRID_BUTTON, self.on_grid_button, grid) self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_left_click, grid)
def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, data=[], head=[], info=[]): wx.Frame.__init__(self, parent, id, title, pos, size, style) grid = wx.grid.Grid(self, -1) col = len(data[0]) row = len(data) colnum = len(head) inforownum = len(info) collen = [] for c in range(colnum): lmax = 0 for item in data: l = len(str(item[c])) if lmax < l: lmax = l l = len(str(head[c])) if lmax < l: lmax = l collen.append(lmax) grid.CreateGrid(row + inforownum, col) grid.SetRowSize(0, 30) for i, value in enumerate(collen): grid.SetColSize(i, value * 8 + 20) for i, item in enumerate(head): grid.SetColLabelValue(i, item) for irow, x in enumerate(data): for icol, item in enumerate(x): grid.SetCellValue(irow + inforownum, icol, str(item)) grid.SetReadOnly(irow + inforownum, icol) #设置头信息格 headstr = '' for item in info: headstr += item grid.SetCellSize(0, 0, inforownum, colnum) grid.SetCellValue(0, 0, headstr) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
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 OnSelectCell(self, event): # When a row of the lib/part table is selected, display the data for that part. def natural_sort_key(s, _nsre=re.compile("([0-9]+)")): return [ int(text) if text.isdigit() else text.lower() for text in _nsre.split(s) ] # Get any selected rows in the lib/part table plus wherever the cell cursor is. selection = self.found_parts.GetSelectedRows() selection.append(self.found_parts.GetGridCursorRow()) # Only process the part in the first selected row and ignore the rest. for row in selection: # Fully instantiate the selected part. part = self.lib_parts[row].part part.parse() # Instantiate pins. # Show the part description. self.part_desc.Remove(0, self.part_desc.GetLastPosition()) desc = part.description # if part.aliases: # desc += "\nAliases: " + ", ".join(list(part.aliases)) if part.keywords: desc += "\nKeywords: " + part.keywords self.part_desc.WriteText(desc) # Display the link to the part datasheet. self.datasheet_link.SetURL(part.datasheet) # Place pin data into a table. grid = self.pin_info # Clear any existing pin data and add/sub rows to hold results. grid.Resize(len(part)) # Sort pins by pin number. pins = sorted(part, key=lambda p: natural_sort_key(p.get_pin_info()[0])) # Place pin data into the table. for row, pin in enumerate(pins): num, names, func = pin.get_pin_info() grid.SetCellValue(row, 0, num) grid.SetCellValue(row, 1, names) grid.SetCellValue(row, 2, func) # Size the columns for their new contents. grid.AutoSizeColumns() # Return after processing only one part. return
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 __init__(self): wx.Frame.__init__(self, None, title="Simple Grid", size=(640, 480)) grid = wx.grid.Grid(self) grid.CreateGrid(50, 50) for row in range(20): for col in range(6): grid.SetCellValue(row, col, "cell (%d,%d)" % (row, col))
def __init__(self, parent, vlist=[], ntitle="Values"): wx.Frame.__init__(self, parent, -1, ntitle, wx.DefaultPosition, wx.Size(400, 500)) global dir_path self.SetMenu() icon_path = os.path.join(dir_path, "Icon") self.icon = wx.Icon(os.path.join(icon_path, "Text.ico"), wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) wx.BeginBusyCursor() self.grid = grid = wx.Grid(self, -1) rtotal = len(vlist) try: ctotal = len(vlist[0]) except: ctotal = 1 grid.CreateGrid(rtotal, ctotal) grid.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM) row = 0 for val in vlist: col = 0 for set in val: grid.SetCellValue(row, col, str(set)) col += 1 row += 1 grid.AutoSizeRows() grid.Refresh() wx.EndBusyCursor()
def populate_registerGrid(self, grid, registers): column_labels = ["name", "type", "isPointer", "read", "write"] for i, label in enumerate(column_labels): grid.SetColLabelValue(i,label) for i, reg in enumerate(registers.iteritems()): print reg grid.SetCellValue(i,0,reg[1].name)
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 __init__(self, parent, title, size=(400, 600)): wx.Frame.__init__(self, parent, title=title, size=size) grid = wx.grid.Grid(self) grid.CreateGrid(50, 50) for row in range(20): for col in range(6): grid.SetCellValue(row, col, "Cell (%d,%d)" % (row, col))
def __init__(self, filename): wx.Frame.__init__(self, None, title="Grid Attributes", size=(600, 300)) data = xlrd.open_workbook(filename, formatting_info=True) table = data.sheets()[0] nrow = table.nrows ncol = table.ncols grid = wx.grid.Grid(self) grid.CreateGrid(nrow, ncol) for col in range(ncol): for row in range(nrow): cell = table.cell(row, col) if cell.ctype == 1: content = cell.value.encode("UTF-8") elif cell.ctype == 2: content = str(cell.value) grid.SetCellValue(row, col, content) grid.SetCellTextColour(1, 1, "red") grid.SetCellFont(1, 1, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) grid.SetCellBackgroundColour(2, 2, "light blue") attr = wx.grid.GridCellAttr() attr.SetTextColour("navyblue") attr.SetBackgroundColour("pink") attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) grid.SetAttr(2, 0, attr) grid.SetRowAttr(0, attr)
def update_grid(self, *args): """Fill the grid rows with data, and set the right editors.""" # @type grid wx.grid.Grid grid = self.panel.gridExp #Adjust number of rows num_rows = len(model.instrument.inst.positions) if grid.GetNumberRows() > num_rows: grid.DeleteRows(0, grid.GetNumberRows() - num_rows) else: old_num_rows = grid.GetNumberRows() grid.AppendRows(num_rows - grid.GetNumberRows()) #Set the editors for the new rows choices = model.experiment.get_stopping_criteria_names() for row in xrange(old_num_rows, num_rows): grid.SetCellEditor(row, self.criterion_col, wx.grid.GridCellChoiceEditor(choices)) #Font for angles angle_font = wx.Font(10, 76, wx.NORMAL, wx.NORMAL, False, u'Monospace') for (i, poscov) in enumerate(model.instrument.inst.positions): row = i #The checkbox grid.SetCellAlignment(row, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) grid.SetReadOnly(row, 0, True) #Do set it read-only #The angles for (j, angleinfo) in enumerate(model.instrument.inst.angles): x = poscov.angles[j] col = j + 1 grid.SetCellValue(row, col, u"%8.2f" % angleinfo.internal_to_friendly(x)) grid.SetReadOnly(row, col, True) #Do set it read-only grid.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) grid.SetCellFont(row, col, angle_font) #The criterion grid.SetCellValue( row, self.criterion_col, model.experiment.get_stopping_criterion_friendly_name( poscov.criterion)) grid.SetCellValue(row, self.criterion_col + 1, str(poscov.criterion_value)) #Comment string grid.SetCellValue(row, self.criterion_col + 2, str(poscov.comment)) self.update_selection()
def EndEdit(self, row, column, grid, old_val=None, new_val=None): if self.__event_handler: self.__chooser.PushEventHandler(self.__event_handler) new_val = self.__chooser.GetValue() if new_val != self.__init_val: grid.SetCellValue(row, column, new_val) return True return False
def __init__(self, td): wx.Frame.__init__(self, None, title="Grid Headers", size=(500, 200)) grid = wx.grid.Grid(self) grid.CreateGrid(5, 5) for row in range(5): grid.SetRowLabelValue(row, self.rowLabels[row]) grid.SetColLabelValue(row, self.colLabels[row]) for col in range(5): grid.SetCellValue( row, col, "(%s,%s)" % (self.rowLabels[row], self.colLabels[col])) grid.SetCellValue(0, 0, "shendi") grid.SetCellValue(0, 1, "12345.0") grid.SetCellValue(0, 2, "1") self.__grid = grid self.__td = td self.__td.RegTradeCallback(self.__OnTd)
def formulaEntryIsDeleted(variableObj,grid,gridIndex,row,col): cellAddress=addressWxpythonToExcelFormat(row,col) if(variableObj.formulas[gridIndex].get(cellAddress) != None): #checking if the formula exists in the variableObj.formulas grid.SetCellBackgroundColour(row,col,variableObj.constantObj.COLOR_FILLED_CELL) #reset cell color to white grid.SetCellValue(row,col,"") #reset cell value to null del variableObj.formulas[gridIndex][cellAddress] #delete the formula from the formulas variable variableObj.formulaEntry.SetBackgroundColour(variableObj.constantObj.COLOR_FILLED_CELL) # formula entry color to white grid.SetReadOnly(row, col, False)
def setupSplitterGrid(self): grid = self.gSplitter #grid.SetDefaultColSize(70) grid.CreateGrid(2, 4) grid.SetRowLabelValue(0, 'Spectral chan') grid.SetRowLabelValue(1, 'Z offset [nm]') #hard code some initial values z_offset, spec = self.sim_controller.z_offsets, self.sim_controller.spec_chans for i in range(4): grid.SetColLabelValue(i, 'Chan %d' % i) grid.SetCellValue(0, i, '%d' % spec[i]) grid.SetCellValue(1, i, '%3.2f' % z_offset[i])
def __init__(self, parent, content): wx.Frame.__init__(self, parent, title="单词表 关闭即可保存修改", size=(300, 200)) # Create a wxGrid object grid = wx.grid.Grid(self, -1) # 数据库操作 db = sql.DBControl() data = db.findWord(content) # 渲染表格 grid.CreateGrid(len(data), 3) # id号不可编辑 for i in range(len(data)): grid.SetReadOnly(i, 0, isReadOnly=True) for i in range(len(data)): grid.SetCellValue(i, 0, str(data[i][0])) grid.SetCellValue(i, 1, data[i][1]) grid.SetCellValue(i, 2, data[i][2]) that = self def OnClose(self): r = wx.MessageBox("保存修改?", "确认", wx.CANCEL | wx.OK | wx.ICON_QUESTION) if r == wx.OK: reviseData = [] for i in range(len(data)): reviseData.append( (int(grid.GetCellValue(i, 0)), grid.GetCellValue(i, 1), grid.GetCellValue(i, 2))) # 与原数据比较是否有更改 subData = [] for x in reviseData: flag = 1 for y in data: if x[1] == y[1] and x[2] == y[2]: flag = 0 break if (flag == 1): subData.append(x) db.updateWord(subData) that.Show(False) else: that.Show(False) self.Bind(wx.EVT_CLOSE, OnClose) self.Show()
def setupSplitterGrid(self): grid = self.gSplitter #grid.SetDefaultColSize(70) grid.CreateGrid(2, 4) grid.SetRowLabelValue(0, 'Spectral chan') grid.SetRowLabelValue(1, 'Z offset [nm]') #hard code some initial values spec = [0, 1, 1, 0] z_offset = [0, -200, 300., 500.] for i in range(4): grid.SetColLabelValue(i, 'Chan %d' % i) grid.SetCellValue(0, i, '%d' % spec[i]) grid.SetCellValue(1, i, '%3.2f' % z_offset[i])
def CreateGrid(self, parent): grid = wx.grid.Grid(parent) grid.CreateGrid(len(data), len(data[0])) for r in range(len(data)): for c in range(len(data[r])): grid.SetColLabelValue(c, column_names[c]) grid.SetCellValue(r, c, data[r][c]) grid.AutoSize() return grid
def set_scores(self, players_list, grid): # set best scores in the right table counter = 0 num = len(players_list)/2 for i in range(int(num)): for j in range(2): grid.SetReadOnly(i, j, True) grid.SetCellFont(i, j, wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD)) grid.SetCellBackgroundColour(i, j,(206, 126, 206)) grid.SetCellValue(i, j, players_list[counter]) counter = counter + 1
def CreateGrid(self, parent): grid = wx.grid.Grid(parent) grid.CreateGrid(len(list_jsj), len(list_jsj[0])) for row in range(len(list_jsj)): for col in range(len(list_jsj[row])): grid.SetColLabelValue(col, column_names[col]) grid.SetCellValue(row, col, list_jsj[row][col]) # 设置行和列自动调整 grid.AutoSize() return grid
def createTable(self): grid = wx.grid.Grid(self, -1) grid.createGrid(100, 10) grid.SetRowSize(0, 60) grid.SetColSize(0, 120) grid.SetCellValue(0, 0, 'wxGrid is good')
def __init__(self): wx.Frame.__init__(self, None, title="Grid Sizes", size=(600, 300)) grid = wx.grid.Grid(self) grid.CreateGrid(5, 5) for row in range(5): for col in range(5): grid.SetCellValue(row, col, "(%s,%s)" % (row, col)) grid.SetCellSize(2, 2, 2, 3) grid.SetColSize(1, 125) grid.SetRowSize(1, 100)