Пример #1
0
    def _updateColAttrs(self, grid):
        """
        wx.Grid -> update the column attributes to add the
        appropriate renderer given the column name.  (renderers
        are stored in the self.plugins dictionary)

        Otherwise default to the default renderer.
        """
        col = 0

        for colname in self.colnames:
            attr = gridlib.GridCellAttr()
            if colname in self.plugins:
                renderer = self.plugins[colname](self)

                if renderer.colSize:
                    grid.SetColSize(col, renderer.colSize)

                if renderer.rowSize:
                    grid.SetDefaultRowSize(renderer.rowSize)

                attr.SetReadOnly(True)
                attr.SetRenderer(renderer)

            grid.SetColAttr(col, attr)
            col += 1
    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)
Пример #3
0
    def _updateColAttrs(self, grid):
        """
        wx.Grid -> update the column attributes to add the
        appropriate renderer given the column name.  (renderers
        are stored in the self.plugins dictionary)

        Otherwise default to the default renderer.
        """
        col = 0

        for colname in self.table.columns:
            attr = wx.grid.GridCellAttr()
            renderer = MegaFontRenderer(self.table)
            attr.SetRenderer(renderer)
            grid.SetColAttr(col, attr)
            col += 1
Пример #4
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]
            if wx.Platform == '__WXMSW__':
                grid.SetRowMinimalHeight(row, 20)
            else:
                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 == "dcf":
                    editor = wx.grid.GridCellTextEditor()
                    renderer = wx.grid.GridCellStringRenderer()
                elif 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.GridCellBoolEditor()
                        # editor.SetParameters(BoolList)
                    elif editortype == "access":
                        editor = wx.grid.GridCellChoiceEditor(AccessList, False)
                        # editor.SetParameters(AccessList)
                    elif editortype == "raccess":
                        editor = wx.grid.GridCellChoiceEditor(RAccessList, False)
                        # editor.SetParameters(RAccessList)
                    elif editortype == "option":
                        editor = wx.grid.GridCellChoiceEditor(OptionList, False)
                        # editor.SetParameters(OptionList)
                    elif editortype == "type":
                        if typelist == None:
                            typelist = self.Parent.Manager.GetCurrentTypeList()
                        editor = wx.grid.GridCellChoiceEditor(typelist.split(","))
                        # editor.SetParameters(typelist)
                    elif editortype == "map":
                        if maplist == None:
                            maplist = self.Parent.Manager.GetCurrentMapList()
                        editor = wx.grid.GridCellChoiceEditor(maplist.split(","))    
                        # 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()
                else:
                    grid.SetReadOnly(row, col, True)
                    
                grid.SetCellEditor(row, col, editor)
                grid.SetCellRenderer(row, col, renderer)
                
                grid.SetCellBackgroundColour(row, col, wx.WHITE)
Пример #5
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)
Пример #6
0
if __name__ == '__main__':
    import sys
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, size=(700, 500), title="wx.Grid example")

    grid = wx.grid.Grid(frame)
    grid.CreateGrid(20, 6)

    # To add capability, mix it in, then set key handler, or add call to grid.Key() in your own handler
    wx.grid.Grid.__bases__ += (PyWXGridEditMixin, )
    grid.__init_mixin__()

    grid.SetDefaultColSize(70, 1)
    grid.EnableDragGridSize(False)

    grid.SetCellValue(0, 0, "Col is")
    grid.SetCellValue(1, 0, "Read Only")
    grid.SetCellValue(1, 1, "hello")
    grid.SetCellValue(2, 1, "23")
    grid.SetCellValue(4, 3, "greren")
    grid.SetCellValue(5, 3, "geeges")

    # make column 1 multiline, autowrap
    cattr = wx.grid.GridCellAttr()
    cattr.SetEditor(wx.grid.GridCellAutoWrapStringEditor())
    #cattr.SetRenderer(wx.grid.GridCellAutoWrapStringRenderer())
    grid.SetColAttr(1, cattr)

    frame.Show(True)
    app.MainLoop()
Пример #7
0
def hook_grid_button_column(grid,
                            col,
                            bitmap_dictionary,
                            bevel_width=2,
                            hook_events=True):
    """Attach hooks to a grid to make a column display grid buttons
    
    grid - the grid in question
    col  - the index of the column to modify
    bitmap_dictionary - a dictionary of bitmaps suitable for GridButtonRenderer
    """
    renderer = GridButtonRenderer(bitmap_dictionary, bevel_width)
    ui_dictionary = {"selected_row": None}
    event_handler = wx.EvtHandler()
    width = 0
    for bitmap in bitmap_dictionary.values():
        width = max(bitmap.Width, width)
    width += bevel_width * 2
    grid.SetColSize(col, width)

    def on_left_down(event):
        x = event.GetX()
        y = event.GetY()
        coords = grid.XYToCell(x, y)
        if coords and coords.Col == col:
            row = coords.Row
            if renderer.get_state(grid, row, col) == BU_NORMAL:
                ui_dictionary["selected_row"] = row
                renderer.set_cell_state(grid, row, col, BU_PRESSED)
                grid.GridWindow.CaptureMouse()
                event.Skip()
        else:
            if event_handler.NextHandler:
                event_handler.NextHandler.ProcessEvent(event)

    def on_mouse_move(event):
        if (ui_dictionary["selected_row"] is not None
                and grid.GridWindow.HasCapture()):
            x = event.GetX()
            y = event.GetY()
            coords = grid.XYToCell(x, y)
            row = ui_dictionary["selected_row"]
            selection_state = BU_NORMAL
            if coords and coords.Col == col and coords.Row == row:
                selection_state = BU_PRESSED
            if renderer.get_state(grid, row, col) != selection_state:
                renderer.set_cell_state(grid, row, col, selection_state)
        if event_handler.NextHandler:
            event_handler.NextHandler.ProcessEvent(event)

    def on_capture_lost(event):
        if ui_dictionary["selected_row"] is not None:
            renderer.set_cell_state(grid, ui_dictionary["selected_row"], col,
                                    BU_NORMAL)
            ui_dictionary["selected_row"] = None
        else:
            if event_handler.NextHandler:
                event_handler.NextHandler.ProcessEvent(event)

    def on_left_up(event):
        if (ui_dictionary["selected_row"] is not None
                and grid.GridWindow.HasCapture()):
            row = ui_dictionary["selected_row"]
            if renderer.get_state(grid, row, col) == BU_PRESSED:
                renderer.set_cell_state(grid, row, col, BU_NORMAL)
                grid.AddPendingEvent(GridButtonClickedEvent(grid, row, col))
            ui_dictionary["selected_row"] = None
            grid.GridWindow.ReleaseMouse()
            event.Skip()
        else:
            if event_handler.NextHandler:
                event_handler.NextHandler.ProcessEvent(event)

    col_attr = wx.grid.GridCellAttr()
    col_attr.SetReadOnly(True)
    col_attr.SetRenderer(renderer)
    grid.SetColAttr(col, col_attr)
    if hook_events:
        grid.GridWindow.PushEventHandler(event_handler)
        event_handler.Bind(wx.EVT_LEFT_DOWN, on_left_down, grid.GridWindow)
        event_handler.Bind(wx.EVT_LEFT_UP, on_left_up, grid.GridWindow)
        event_handler.Bind(wx.EVT_MOTION, on_mouse_move, grid.GridWindow)
        event_handler.Bind(wx.EVT_MOUSE_CAPTURE_LOST, on_capture_lost,
                           grid.GridWindow)
    return renderer, width