def setupGrid(self, grid, states, stateTypes):
     nStates = len(states)
     
     grid.SetDefaultColSize(70)
     grid.CreateGrid(nStates, nStates)
     
     for i in range(nStates):
         grid.SetRowLabelValue(i, states[i])
         grid.SetColLabelValue(i, states[i])
         grid.SetReadOnly(i, i)
         grid.SetCellBackgroundColour(i, i, wx.LIGHT_GREY)
         grid.SetCellTextColour(i, i, wx.LIGHT_GREY)
         
         if (stateTypes[i] == fluor.TO_ONLY):
             for j in range(nStates):
                 grid.SetReadOnly(i, j)
                 grid.SetCellBackgroundColour(i, j, wx.LIGHT_GREY)
                 grid.SetCellTextColour(i, j, wx.LIGHT_GREY)
         
         if (stateTypes[i] == fluor.FROM_ONLY):
             for j in range(nStates):
                 grid.SetReadOnly(j, i)
                 grid.SetCellBackgroundColour(j, i, wx.LIGHT_GREY)
                 grid.SetCellTextColour(j, i, wx.LIGHT_GREY)
                 
     grid.SetMinSize(grid.BestSize)
Example #2
0
    def _updateColAttrs(self, grid):
        """
        wx.grid.Grid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """

        for row in range(self.GetNumberRows()):
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                colname = self.GetColLabelValue(col, False)
                if col != 0:
                    grid.SetReadOnly(row, col, False)
                    if colname == "Name":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                    elif colname == "Initial Value":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                    elif colname == "Type":
                        editor = wx.grid.GridCellTextEditor()
                else:
                    grid.SetReadOnly(row, col, True)

                grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)

                highlight_colours = row_highlights.get(
                    colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)
Example #3
0
    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)
Example #4
0
    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
Example #5
0
    def _updateColAttrs(self, grid, row=None):
        """
        wxGrid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """

        for row in range(self.GetNumberRows()):
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                colname = self.GetColLabelValue(col, False)

                editortype = self.columnTypes.get(colname, None)
                if editortype is not None:
                    editor = editortype(self, row, col)

                grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)

                highlight_colours = row_highlights.get(
                    colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)
Example #6
0
    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
Example #7
0
    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
Example #8
0
    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()
Example #9
0
        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 _updateColAttrs(self, grid):
        """
        wx.grid.Grid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """

        for col in range(self.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            grid.SetColAttr(col, attr)
            grid.SetColSize(col, self.ColSizes[col])

        for row in range(self.GetNumberRows()):
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                colname = self.GetColLabelValue(col, False)
                grid.SetReadOnly(row, col, False)
                if colname == "Name":
                    editor = wx.grid.GridCellTextEditor()
                    renderer = wx.grid.GridCellStringRenderer()
                elif colname == "Interval":
                    editor = DurationCellEditor(self)
                    renderer = wx.grid.GridCellStringRenderer()
                    if self.GetValueByName(row, "Triggering") != "Cyclic":
                        grid.SetReadOnly(row, col, True)
                elif colname == "Single":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.VariableList)
                    if self.GetValueByName(row, "Triggering") != "Interrupt":
                        grid.SetReadOnly(row, col, True)
                elif colname == "Triggering":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(
                        ",".join([""] + map(_, GetTaskTriggeringOptions())))
                elif colname == "Type":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.TypeList)
                elif colname == "Priority":
                    editor = wx.grid.GridCellNumberEditor()
                    editor.SetParameters("0,65535")
                elif colname == "Task":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.TaskList)

                grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)

                highlight_colours = row_highlights.get(
                    colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)
Example #11
0
    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
Example #12
0
    def RemoveHighlight(self, grid, infos, highlight_type):
        row = infos[0]
        for col in range(self.GetNumberCols()):
            # grid.SetReadOnly(row, col, True)
            # grid.SetCellEditor(row, col, None)
            # grid.SetCellRenderer(row, col, None)

            highlight_colours = (wx.WHITE, wx.BLACK)
            grid.SetCellBackgroundColour(row, col, highlight_colours[0])
            grid.SetCellTextColour(row, col, highlight_colours[1])
        grid.ForceRefresh()
        row_highlights = self.Highlights.get(infos[0])
        if row_highlights is not None:
            col_highlights = row_highlights.get(infos[1])
            if col_highlights is not None and highlight_type in col_highlights:
                col_highlights.remove(highlight_type)
            if col_highlights is not None and len(col_highlights) == 0:
                row_highlights.pop(infos[1])
Example #13
0
    def AddHighlight(self, grid, infos, highlight_type):
        row_highlights = self.Highlights.setdefault(infos[0], {})
        col_highlights = row_highlights.setdefault(infos[1], [])
        col_highlights.append(highlight_type)
        for row in self.Highlights.keys():
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                colname = self.GetColLabelValue(col, False)

                # grid.SetReadOnly(row, col, True)
                # grid.SetCellEditor(row, col, None)
                # grid.SetCellRenderer(row, col, None)

                highlight_colours = row_highlights.get(
                    colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)
        grid.ForceRefresh()
Example #14
0
	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
Example #15
0
    def __init__(self):
        wx.Frame.__init__(self, None, title="Grid Attributes", size=(600, 300))
        grid = wx.grid.Grid(self)
        grid.CreateGrid(10, 6)
        for row in range(10):
            for col in range(6):
                grid.SetCellValue(row, col, "(%s,%s)" % (row, col))

        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(4, 0, attr)
        grid.SetAttr(5, 1, attr)
        grid.SetRowAttr(8, attr)
Example #16
0
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        self.create_widgets()
        # Create a wxGrid object
        grid = wx.grid.Grid(self, -1)
        gridPanel = wx.Panel(self, 43, wx.DefaultPosition, wx.Size(300, 200))
        vbox = wx.BoxSizer()
        vbox.Add(grid, 0, wx.ALIGN_CENTER)
        vbox.Add(self.einlese_Button, 0, wx.BOTTOM)
        gridPanel.SetSizer(vbox)
        # Then we call CreateGrid to set the dimensions of the grid
        # (100 rows and 10 columns in this example)
        grid.CreateGrid(20, 10)

        # We can set the sizes of individual rows and columns
        # in pixels
        grid.SetRowSize(0, 60)
        grid.SetColSize(0, 120)

        # 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()
Example #17
0
    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
Example #18
0
    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()
Example #19
0
    def _updateColAttrs(self, grid):
        """
        wx.grid.Grid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """
        for row in range(self.GetNumberRows()):
            var_class = self.GetValueByName(row, "Class")
            var_type = self.GetValueByName(row, "Type")
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                colname = self.GetColLabelValue(col, False)
                if self.Parent.Debug:
                    grid.SetReadOnly(row, col, True)
                else:
                    if colname == "Option":
                        options = GetOptions(
                            constant=var_class
                            in ["Local", "External", "Global"],
                            retain=self.Parent.ElementType != "function"
                            and var_class
                            in ["Local", "Input", "Output", "Global"],
                            non_retain=self.Parent.ElementType != "function"
                            and var_class in ["Local", "Input", "Output"])
                        if len(options) > 1:
                            editor = wx.grid.GridCellChoiceEditor()
                            editor.SetParameters(",".join(map(_, options)))
                        else:
                            grid.SetReadOnly(row, col, True)
                    elif col != 0 and self.GetValueByName(row, "Edit"):
                        grid.SetReadOnly(row, col, False)
                        if colname == "Name":
                            editor = wx.grid.GridCellTextEditor()
                            renderer = wx.grid.GridCellStringRenderer()
                        elif colname == "Initial Value":
                            if var_class not in ["External", "InOut"]:
                                if self.Parent.Controler.IsEnumeratedType(
                                        var_type):
                                    editor = wx.grid.GridCellChoiceEditor()
                                    editor.SetParameters(",".join(
                                        self.Parent.Controler.
                                        GetEnumeratedDataValues(var_type)))
                                else:
                                    editor = wx.grid.GridCellTextEditor()
                                renderer = wx.grid.GridCellStringRenderer()
                            else:
                                grid.SetReadOnly(row, col, True)
                        elif colname == "Location":
                            if var_class in [
                                    "Local", "Global"
                            ] and self.Parent.Controler.IsLocatableType(
                                    var_type):
                                editor = LocationCellEditor(
                                    self, self.Parent.Controler)
                                renderer = wx.grid.GridCellStringRenderer()
                            else:
                                grid.SetReadOnly(row, col, True)
                        elif colname == "Class":
                            if len(self.Parent.ClassList) == 1:
                                grid.SetReadOnly(row, col, True)
                            else:
                                editor = wx.grid.GridCellChoiceEditor()
                                excluded = []
                                if self.Parent.IsFunctionBlockType(var_type):
                                    excluded.extend(["Local", "Temp"])
                                editor.SetParameters(",".join([
                                    _(choice)
                                    for choice in self.Parent.ClassList
                                    if choice not in excluded
                                ]))
                    elif colname != "Documentation":
                        grid.SetReadOnly(row, col, True)

                grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)

                if colname == "Location" and LOCATION_MODEL.match(
                        self.GetValueByName(row, colname)) is None:
                    highlight_colours = ERROR_HIGHLIGHT
                else:
                    highlight_colours = row_highlights.get(
                        colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)
    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
Example #21
0
    def _updateColAttrs(self, grid, row=None):
        """
        wx.grid.Grid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """

        for col in range(self.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            grid.SetColAttr(col, attr)
            grid.SetColSize(col, self.ColSizes[col])

        for row in range(self.GetNumberRows()):
            row_highlights = self.Highlights.get(row, {})
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                error = False
                colname = self.GetColLabelValue(col, False)
                grid.SetReadOnly(row, col, False)
                if colname == "Name":
                    editor = wx.grid.GridCellTextEditor()
                    renderer = wx.grid.GridCellStringRenderer()
                elif colname == "Interval":
                    editor = DurationCellEditor(self, colname)
                    renderer = wx.grid.GridCellStringRenderer()
                    if self.GetValueByName(row, "Triggering") != "Cyclic":
                        grid.SetReadOnly(row, col, True)
                    interval = self.GetValueByName(row, colname)
                    if interval != "" and IEC_TIME_MODEL.match(
                            interval.upper()) is None:
                        error = True
                elif colname == "Single":
                    editor = SingleCellEditor(self, colname)
                    editor.SetParameters(self.Parent.VariableList)
                    if self.GetValueByName(row, "Triggering") != "Interrupt":
                        grid.SetReadOnly(row, col, True)
                    single = self.GetValueByName(row, colname)
                    if single != "" and not CheckSingle(
                            single, self.Parent.VariableList):
                        error = True
                elif colname == "Triggering":
                    editor = wx.grid.GridCellChoiceEditor(
                        GetTaskTriggeringOptions())
                    editor.SetParameters(",".join(
                        map(_, GetTaskTriggeringOptions())))
                elif colname == "Type":
                    editor = wx.grid.GridCellChoiceEditor(
                        self.Parent.TypeList.split(','))
                    # editor.SetParameters(self.Parent.TypeList)
                elif colname == "Priority":
                    editor = wx.grid.GridCellNumberEditor()
                    editor.SetParameters("0,65535")
                elif colname == "Task":
                    editor = wx.grid.GridCellChoiceEditor(
                        self.Parent.TaskList.split(','))
                    # editor.SetParameters(self.Parent.TaskList)

                if editor:
                    editor.IncRef()
                    grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)

                if error:
                    highlight_colours = ERROR_HIGHLIGHT
                else:
                    highlight_colours = row_highlights.get(
                        colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
                grid.SetCellTextColour(row, col, highlight_colours[1])
            self.ResizeRow(grid, row)