Beispiel #1
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 col in range(self.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(ColAlignements[col], wx.ALIGN_CENTRE)
            grid.SetColAttr(col, attr)
            grid.SetColMinimalWidth(col, ColSizes[col])
            grid.AutoSizeColumn(col, False)

        typelist = None
        maplist = None
        for row in range(self.GetNumberRows()):
            editors = self.editors[row]
            grid.SetRowMinimalHeight(row, 28)
            grid.AutoSizeRow(row, False)
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None

                colname = self.GetColLabelValue(col, False)
                editortype = editors[colname]
                if editortype and self.Editable:
                    grid.SetReadOnly(row, col, False)
                    if editortype == "string":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                        if colname == "value" and "length" in editors:
                            editor.SetParameters(editors["length"])
                    elif editortype == "number":
                        editor = wx.grid.GridCellNumberEditor()
                        renderer = wx.grid.GridCellNumberRenderer()
                        if colname == "value" and "min" in editors and "max" in editors:
                            editor.SetParameters(
                                "%s,%s" % (editors["min"], editors["max"]))
                    elif editortype == "float":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                    elif editortype == "bool":
                        editor = wx.grid.GridCellChoiceEditor()
                        editor.SetParameters(BoolList)
                    elif editortype == "access":
                        editor = wx.grid.GridCellChoiceEditor()
                        editor.SetParameters(AccessList)
                    elif editortype == "raccess":
                        editor = wx.grid.GridCellChoiceEditor()
                        editor.SetParameters(RAccessList)
                    elif editortype == "option":
                        editor = wx.grid.GridCellChoiceEditor()
                        editor.SetParameters(OptionList)
                    elif editortype == "type":
                        editor = wx.grid.GridCellChoiceEditor()
                        if typelist == None:
                            typelist = self.Parent.Manager.GetCurrentTypeList()
                        editor.SetParameters(typelist)
                    elif editortype == "map":
                        editor = wx.grid.GridCellChoiceEditor()
                        if maplist == None:
                            maplist = self.Parent.Manager.GetCurrentMapList()
                        editor.SetParameters(maplist)
                    elif editortype == "time":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                    elif editortype == "domain":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                    elif editortype == "dcf":
                        editor = wx.grid.GridCellTextEditor()
                        renderer = wx.grid.GridCellStringRenderer()
                else:
                    grid.SetReadOnly(row, col, True)

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

                grid.SetCellBackgroundColour(row, col, wx.WHITE)
Beispiel #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 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()
                    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)

                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)
Beispiel #3
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._GetRowEdit(row):
                        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 InitUI(self): 
     vbox = wx.BoxSizer(wx.VERTICAL)
     (server, group, item) = self.rulePath
     labelText = u"地址:{}.{}.{}".format(server, group, item)
     addressLabel = wx.StaticText(self, -1, label=labelText)
     font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
     addressLabel.SetFont(font)
     vbox.Add(addressLabel, flag=(wx.ALL | wx.ALIGN_CENTER | wx.BOTTOM), border=5) 
     
     grid = wx.grid.Grid(self)
     grid.CreateGrid(6, 2)
     grid.SetDefaultRowSize(25)
     grid.SetColLabelValue(0, u"值")
     grid.SetColLabelValue(1, u"报警信息")
     
     grid.SetRowLabelValue(0, u'低低')
     grid.SetRowLabelValue(1, u'低')
     grid.SetRowLabelValue(2, u'高')
     grid.SetRowLabelValue(3, u'高高')
     grid.SetRowLabelValue(4, u'当')
     grid.SetRowLabelValue(5, u'间隔时间(分)')
     grid.SetRowLabelSize(70)
     
     # attr = wx.grid.GridCellAttr()
     # attr.SetEditor(wx.grid.GridCellChoiceEditor())
     # attr.SetRenderer(wx.grid.GridCellChoiceEditor(['5', '15', '30', '60'], True))
     grid.SetCellEditor(4, 0, wx.grid.GridCellChoiceEditor([u'真', u'假'], True))
     grid.SetCellValue(4, 0, u'假')
     
     grid.SetCellEditor(5, 0, wx.grid.GridCellChoiceEditor(['5', '15', '30', '60'], True))
     grid.SetCellValue(5, 0, '5')
     
     grid.SetColSize(0, 50)
     grid.SetColSize(1, 300)
     
     grid.SetDefaultCellAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
     grid.SetCellValue(5, 1, u"当前温度:{}".format(self.itemValue[0]))
     grid.SetReadOnly(5, 1, True)
     
     vbox.Add(grid, proportion=1, flag=(wx.ALL | wx.ALIGN_CENTER))
     
     btn = wx.Button(self, -1, label=u"确定")
     btn.Bind(wx.EVT_BUTTON, lambda event, grid=grid: self.btnClick(event, grid))
     vbox.Add(btn, proportion=1, flag=(wx.TOP | wx.CENTRE), border=5)
     self.SetSizer(vbox)  
 
     if self.rule.isBool:
         (dang1, dang2) = self.rule.dang
         interal = self.rule.interal
         grid.SetCellValue(4, 0, u'真' if dang1 else u'假')
         grid.SetCellValue(4, 1, dang2)
         grid.SetCellValue(5, 0, interal)
     else:
         (lower1, lower2) = self.rule.lower
         (low1, low2) = self.rule.low
         (high1, high2) = self.rule.high
         (higher1, higher2) = self.rule.higher
         interal = self.rule.interal
             
         grid.SetCellValue(0, 0, lower1)
         grid.SetCellValue(0, 1, lower2)
         grid.SetCellValue(1, 0, low1)
         grid.SetCellValue(1, 1, low2)
         grid.SetCellValue(2, 0, high1)
         grid.SetCellValue(2, 1, high2)
         grid.SetCellValue(3, 0, higher1)
         grid.SetCellValue(3, 1, higher2)
             
         grid.SetCellValue(5, 0, interal)      
Beispiel #5
0
    def __init__(self, parent, input_para):

        rect_parent = parent.GetRect()
        print rect_parent
        pos_target = rect_parent.GetTopRight()
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          "Resource Grid",
                          pos=pos_target,
                          size=(1000, 700))
        panel = wx.Panel(self, -1)

        sizer_grid = wx.GridBagSizer(0, 0)
        usr_style = wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL
        grid = wx.grid.Grid(self, -1)
        grid.CreateGrid(12 * 2, 14)
        cell_width = 20

        grid.DisableDragColSize()
        grid.DisableDragGridSize()
        grid.DisableDragRowSize()
        grid.SetRowLabelAlignment(wx.CENTER, wx.CENTER)

        clo_num = grid.GetNumberCols()
        row_num = grid.GetNumberRows()

        for i in range(0, row_num):
            grid.SetRowLabelValue(i, str(row_num - i - 1))
            grid.AutoSizeRowLabelSize(i)
        grid.SetRowLabelSize(cell_width)
        grid.SetDefaultRowSize(cell_width)
        for j in range(0, clo_num):
            grid.SetColLabelValue(j, str(j))
            grid.AutoSizeColLabelSize(j)
        grid.SetRowLabelSize(cell_width)
        grid.SetDefaultColSize(cell_width)
        grid.SetDefaultCellBackgroundColour(wx.Colour(192, 192, 192))

        #pdcch
        for i in range(0, row_num):
            for j in range(0, clo_num):
                grid.SetReadOnly(i, j)
                if (j < input_para['pdcch_symbol']):
                    grid.SetCellBackgroundColour(i, j, wx.GREEN)
                    if ((int(grid.GetRowLabelValue(i)) - 1) % 4 == 0):
                        grid.SetCellBackgroundColour(i, j,
                                                     wx.Colour(66, 66, 111))
        #pdsch
        for i in range(0, row_num):
            for j in range(input_para['start_symbol'], clo_num):
                if (j - input_para['start_symbol'] <
                        input_para['symbol_length']):
                    grid.SetCellBackgroundColour(i, j,
                                                 wx.Colour(255, 255, 255))
        #pdsch dmrs
        for j in range(0, len(input_para['dmrs_pos_list'])):
            for i in range(0, row_num):
                if input_para['dmrs_length'] == 0 and j == 0:
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(153, 204, 50))
                    continue
                if input_para['dmrs_length'] == 1 and (j == 1 or j == 0):
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(153, 204, 50))
                    continue
                else:
                    grid.SetCellBackgroundColour(
                        i, input_para['dmrs_pos_list'][j],
                        wx.Colour(234, 234, 173))

        sizer_grid.Add(grid,
                       pos=(0, 0),
                       span=(5, 5),
                       flag=wx.EXPAND | usr_style)

        lbl_pdcch = wx.StaticText(self, -1, u'  PDCCH  ', style=usr_style)
        lbl_pdcch.SetBackgroundColour(wx.GREEN)
        sizer_grid.Add(lbl_pdcch,
                       pos=(7, 0),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_pdcch_dmrs = wx.StaticText(
            self,
            -1,
            u'  PDCCH DMRS  ',
            style=usr_style,
        )
        lbl_pdcch_dmrs.SetBackgroundColour(wx.Colour(66, 66, 111))
        lbl_pdcch_dmrs.SetForegroundColour(wx.Colour(255, 255, 255))
        sizer_grid.Add(
            lbl_pdcch_dmrs,
            pos=(7, 1),
            span=(1, 1),
            flag=wx.EXPAND | usr_style,
        )

        lbl_pdsch = wx.StaticText(self, -1, u'  PDXCH  ', style=usr_style)
        lbl_pdsch.SetBackgroundColour(wx.Colour(255, 255, 255))
        lbl_pdsch.SetForegroundColour(wx.Colour(0, 0, 0))
        sizer_grid.Add(lbl_pdsch,
                       pos=(7, 2),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_fl_dmrs = wx.StaticText(self,
                                    -1,
                                    u'Front Loaded DMRS',
                                    style=usr_style)
        lbl_fl_dmrs.SetBackgroundColour(wx.Colour(153, 204, 50))
        lbl_fl_dmrs.SetForegroundColour(wx.Colour(255, 255, 255))
        sizer_grid.Add(lbl_fl_dmrs,
                       pos=(8, 0),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        lbl_add_dmrs = wx.StaticText(self, -1, u'Add DMRS', style=usr_style)
        lbl_add_dmrs.SetBackgroundColour(wx.Colour(234, 234, 173))
        lbl_add_dmrs.SetForegroundColour(wx.Colour(0, 0, 0))
        sizer_grid.Add(lbl_add_dmrs,
                       pos=(8, 1),
                       span=(1, 1),
                       flag=wx.EXPAND | usr_style)

        b_close = wx.Button(self, -1, "Close")
        self.Bind(wx.EVT_BUTTON, self.close_window, b_close)
        sizer_grid.Add(b_close,
                       pos=(10, 0),
                       span=(2, 5),
                       flag=wx.EXPAND | usr_style)
        self.equal = b_close

        self.SetSizer(sizer_grid)
        sizer_grid.Fit(self)

        self.Show()
Beispiel #6
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()