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 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 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 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 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 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.SetCellAlignment(r, c, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False) grid.SetCellFont(r, c, font) if r % 2 == 0: grid.SetCellBackgroundColour(r, c, "SEA green") else: grid.SetCellBackgroundColour(r, c, "SLATE blue") grid.AutoSize() return grid
def __init__(self): wx.Frame.__init__(self,parent=None,title="成绩查询",size=(900,560)) grid = wx.grid.Grid(self,pos=(10,0),size=(750,500)) grid.CreateGrid(20,7) for i in range(20): for j in range(7): grid.SetCellAlignment(i,j,wx.ALIGN_CENTER,wx.ALIGN_CENTER) grid.SetColLabelValue(0, "星期一") #第一列标签 grid.SetColLabelValue(1, "星期二") grid.SetColLabelValue(2, "星期三") grid.SetColLabelValue(3, "星期四") grid.SetColLabelValue(4, "星期五") # 第一列标签 grid.SetColLabelValue(5, "星期六") grid.SetColLabelValue(6, "星期日") grid.SetColSize(0,100) grid.SetColSize(1,100) grid.SetColSize(2,100) grid.SetColSize(3,100) grid.SetColSize(4,100) grid.SetColSize(5,100) grid.SetColSize(6,100) grid.SetRowSize(0, 90) grid.SetRowSize(1, 90) grid.SetRowSize(2, 90) grid.SetRowSize(3, 90) grid.SetRowSize(4, 90) grid.SetCellTextColour("NAVY") data = test.search() for i in range(5): for j in range(7): file_handle = open('txt/%s.txt'%(i*7+j), mode='w', encoding='utf8') grid.SetCellValue(i, j, data[i*7+j]) file_handle.writelines(data[i*7+j]+"\n") file_handle.close() pass
def OnOpenLogcatClicked(self, event): self.open_logcat.Enable(False) self.close_logcat.Enable(True) # 加载数据库 self.loadDataBase( 2) # 用一个列表返回数据库 不要赋值给self (data = xx.loadDataBase() ) # 必须要变宽才能显示 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) # name of first row grid.SetColLabelValue(0, "工号") grid.SetColLabelValue(1, "姓名") grid.SetColLabelValue(2, "打卡时间") grid.SetColLabelValue(3, "是否迟到") # Size of each col grid.SetColSize(0, 120) grid.SetColSize(1, 120) grid.SetColSize(2, 150) grid.SetColSize(3, 150) grid.SetCellTextColour(wx.BLUE) 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]) grid.SetCellTextColour( i, 3, wx.RED ) if self.logcat_late[i] == '是' else grid.SetCellTextColour( i, 3, wx.GREEN) # Not allowed to edit grid.EnableEditing(False) pass
def update_selection(self, message=None): """Updates the GUI to reflect all the selected positions in the latest parameters. If message is set, this is the handler for an external change in selection. The message.data dictionary is used instead of latestparams. """ #Re-check the previously checked items. if message is None: pos_dict = display_thread.get_positions_dict() else: pos_dict = message.data grid = self.panel.gridExp all_selected = True for i in range(grid.GetNumberRows()): #Get the position from the instruments' list. if i < len(model.instrument.inst.positions): pos = model.instrument.inst.positions[i] #Default to False this_one_is_selected = pos_dict.get(id(pos), False) #Show a space for False. val = [" ", "X"][this_one_is_selected] #Count if all are selected all_selected = all_selected and this_one_is_selected else: val = "?" all_selected = False #Check it if you find it, and it's true. grid.SetCellValue(i, 0, val) grid.SetCellAlignment(i, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) #If the selection changes, the estimated time will change too self.update_estimated_time() #And the "use all" checkbox self.inside_set_checkUseAll = True self.panel.checkUseAll.SetValue(all_selected) self.inside_set_checkUseAll = False
def __init__(self): wx.Frame.__init__(self, parent=None, title="成绩查询", size=(1050, 560)) grid = wx.grid.Grid(self, pos=(10, 0), size=(1050, 500)) grid.CreateGrid(100, 9) for i in range(100): for j in range(9): grid.SetCellAlignment(i, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetColLabelValue(0, "序号") #第一列标签 grid.SetColLabelValue(1, "初修学期") grid.SetColLabelValue(2, "获得学期") grid.SetColLabelValue(3, "课程") grid.SetColLabelValue(4, "成绩") # 第一列标签 grid.SetColLabelValue(5, "学分") grid.SetColLabelValue(6, "课程属性") grid.SetColLabelValue(7, "课程性质") grid.SetColLabelValue(8, "获得方式") # 第一列标签 grid.SetColSize(0, 50) grid.SetColSize(1, 100) grid.SetColSize(2, 100) grid.SetColSize(3, 350) grid.SetColSize(4, 50) grid.SetColSize(5, 50) grid.SetColSize(6, 50) grid.SetColSize(7, 100) grid.SetColSize(8, 100) grid.SetCellTextColour("NAVY") data = csu.search() data.remove(data[0]) print(data) for i, item1 in enumerate(data): for j, item2 in enumerate(item1): grid.SetCellValue(i, j, data[i][j]) pass
def CreateGrid(self, parent): # pp = wx.Panel(parent) # grid = wx.grid.Grid(pp) grid = wx.grid.Grid(parent) grid.CreateGrid(len(data), len(data[0])) grid.SetColSize(0, 70) grid.SetColSize(1, 110) grid.SetColSize(2, 70) grid.SetColSize(3, 110) grid.SetColSize(4, 110) grid.SetColSize(5, 110) grid.SetColMinimalAcceptableWidth(80) grid.SetRowMinimalAcceptableHeight(50) for r in range(len(data)): grid.SetRowSize(r, 50) for c in range(len(data[r])): # grid.SetColLabelValue(c, column_names[c]) grid.SetCellValue(r, c, str(data[r][c])) grid.SetCellAlignment(r, c, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) font = wx.Font(15, wx.SWISS, wx.NORMAL, wx.BOLD, False) grid.SetCellFont(r, c, font) grid.AutoSize() # pp.SetSizer(grid) return grid
def OnOpenLogcatClicked(self, event): if (self.id == ID_WORKER_UNAVIABLE): wx.MessageBox('请先刷脸签到!', '温馨提示', wx.OK) return self.open_logcat.Enable(False) self.close_logcat.Enable(True) # 加载数据库 self.data.loadDataBase(2) # 用一个列表返回数据库 不要赋值给self (data = xx.loadDataBase() ) # 必须要变宽才能显示 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) # name of first row grid.SetColLabelValue(0, "工号") grid.SetColLabelValue(1, "姓名") grid.SetColLabelValue(2, "打卡时间") grid.SetColLabelValue(3, "是否迟到") # Size of each col grid.SetColSize(0, 120) grid.SetColSize(1, 120) grid.SetColSize(2, 150) grid.SetColSize(3, 150) grid.SetCellTextColour(wx.BLUE) # 建立请求连接 host_ip = "47.96.157.49" host_usr = "******" host_psw = "123lalala" host_db = "inspurer" conn = mysql.connect(host_ip, host_usr, host_psw, host_db) mycursor = conn.cursor() sqlQuery = 'Select id, name, datetime, late from logcat where id = %s' val = self.id print(val) print(type(self.id), type(val)) mycursor.execute(sqlQuery, val) origin = mycursor.fetchall() logcat_id = [] logcat_name = [] logcat_datetime = [] logcat_late = [] for row in origin: logcat_id.append(row[0]) logcat_name.append(row[1]) logcat_datetime.append(row[2]) logcat_late.append(row[3]) mycursor.close() conn.close() # for i, id in enumerate(self.data.logcat_id): for i, id in enumerate(logcat_id): grid.SetCellValue(i, 0, str(id)) grid.SetCellValue(i, 1, logcat_name[i]) grid.SetCellValue(i, 2, logcat_datetime[i]) grid.SetCellValue(i, 3, logcat_late[i]) grid.SetCellTextColour(i, 3, wx.RED) if logcat_late[i] == 'yes' else grid.SetCellTextColour(i, 3,wx.GREEN) # Not allowed to edit grid.EnableEditing(False) pass
def __init__(self, parent, square, size): self.size = size grid = wx.grid.Grid(parent, -1) grid.CreateGrid(self.size + 2, self.size + 2) # Set Sizer '''Sizer = wx.BoxSizer(wx.HORIZONTAL) Sizer.Add(grid, 0, wx.ALIGN_CENTER|wx.ALL, 5) parent.SetSizerAndFit(Sizer)''' # Set Labels not visible grid.SetRowLabelSize(0) grid.SetColLabelSize(0) # Set Row and Column size grid.SetDefaultRowSize(40) grid.SetDefaultColSize(40) # Print Square Values as string for j in range(2, self.size + 2): for i in range(2, self.size + 2): grid.SetCellAlignment(i-1, j-1, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellValue(i-1, j-1, str(square[(i-1,j-1)])) grid.SetReadOnly(i-1, j-1) # Evaluate Rows Sum for i in range(1, self.size + 1): mg_num = self.evaluateRowSum(square, i) grid.SetCellAlignment(i, self.size+1, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(i, self.size+1, wx.YELLOW) grid.SetCellValue(i, self.size+1, str(mg_num)) grid.SetCellAlignment(i, 0, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(i, 0, wx.YELLOW) grid.SetCellValue(i, 0, str(mg_num)) grid.SetReadOnly(i, 0) # Evaluate Columns Sum for j in range(1, self.size + 1): mg_num = self.evaluateColSum(square, j) grid.SetCellAlignment(self.size+1, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(self.size+1, j, wx.GREEN) grid.SetCellValue(self.size+1, j, str(mg_num)) grid.SetCellAlignment(0, j, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(0, j, wx.GREEN) grid.SetCellValue(0, j, str(mg_num)) grid.SetReadOnly(0, j) #Evaluate Diagonal 1 diag1 = self.evaluateDiag1(square) grid.SetCellAlignment(self.size+1, self.size+1, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(self.size+1, self.size+1, wx.BLUE) grid.SetCellTextColour(self.size+1, self.size+1, wx.WHITE) grid.SetCellValue(self.size+1, self.size+1, str(diag1)) grid.SetReadOnly(self.size+1, self.size+1) grid.SetCellAlignment(0, 0, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(0, 0, wx.BLUE) grid.SetCellTextColour(0, 0, wx.WHITE) grid.SetCellValue(0, 0, str(diag1)) grid.SetReadOnly(0, 0) #Evaluate Diagonal 2 diag2 = self.evaluateDiag2(square) grid.SetCellAlignment(0, self.size+1, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(0, self.size+1, wx.RED) grid.SetCellTextColour(0, self.size+1, wx.WHITE) grid.SetCellValue(0, self.size+1, str(diag2)) grid.SetReadOnly(0, self.size+1) grid.SetCellAlignment(self.size+1, 0, wx.ALIGN_CENTER, wx.ALIGN_CENTER) grid.SetCellBackgroundColour(self.size+1, 0, wx.RED) grid.SetCellTextColour(self.size+1, 0, wx.WHITE) grid.SetCellValue(self.size+1, 0, str(diag2)) grid.SetReadOnly(self.size+1, 0) parent.Show()