Exemplo n.º 1
0
    def refresh(self, grid):
        font = GetFont()

        Utils.AdjustGridSize(self.grid,
                             rowsRequired=grid.GetNumberRows(),
                             colsRequired=grid.GetNumberCols() + 1)
        self.grid.SetColLabelValue(0, 'Pos')
        attr = gridlib.GridCellAttr()
        attr.SetFont(font)
        attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_TOP)
        attr.SetReadOnly(True)
        self.grid.SetColAttr(0, attr)

        iColStatus = None
        for col in six.moves.range(grid.GetNumberCols()):
            headerName = grid.GetColLabelValue(col)
            self.grid.SetColLabelValue(col + 1, headerName)
            attr = gridlib.GridCellAttr()
            attr.SetFont(font)
            if headerName == 'Bib':
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_TOP)
            elif headerName.startswith('Time'):
                attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
            elif headerName.startswith('Status'):
                iColStatus = col
            elif headerName.startswith('Warn'):
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                attr.SetRenderer(gridlib.GridCellBoolRenderer())
            elif headerName.startswith('Rel'):
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                attr.SetRenderer(gridlib.GridCellBoolRenderer())
            attr.SetReadOnly(True)
            self.grid.SetColAttr(col + 1, attr)

        results = [[
            grid.GetCellValue(row, col)
            for col in six.moves.range(grid.GetNumberCols())
        ] for row in six.moves.range(grid.GetNumberRows())]
        results.sort(key=lambda x: x[iColStatus])

        for row in six.moves.range(grid.GetNumberRows()):
            self.grid.SetCellValue(row, 0, u'{}'.format(row + 1))
            for col in six.moves.range(grid.GetNumberCols()):
                v = results[row][col]
                self.grid.SetCellValue(row, col + 1, v if v != '0.000' else '')

        self.grid.AutoSizeColumns(False)
        self.grid.AutoSizeRows(False)

        self.GetSizer().Layout()
        self.GetSizer().Fit(self)

        self.CentreOnParent(wx.BOTH)
        self.SetFocus()
Exemplo n.º 2
0
    def __init__(self,
                 datasource,
                 rowLabels=None,
                 colLabels=None,
                 selectedcolour="green"):
        '''
        [
            [value1,value2,value3,...],
            [value1,value2,value3,...],
            [value1,value2,value3,...],
            ...
        ]
        '''
        grd.PyGridTableBase.__init__(self)
        self.selectedcolour = selectedcolour
        self.data = {}
        self.colLabels = ('√', )
        if colLabels:
            self.colLabels += colLabels
        self.rowLabels = rowLabels
        self.rows = len(datasource)  #行数
        self.cols = len(self.colLabels)  #行数

        self.attr = attr = grd.GridCellAttr()
        attr.SetEditor(grd.GridCellBoolEditor())
        attr.SetRenderer(grd.GridCellBoolRenderer())

        self.boolattr = grd.GridCellAttr()
        self.boolattr.SetReadOnly()
        self.boolattr.SetEditor(grd.GridCellBoolEditor())
        self.boolattr.SetRenderer(grd.GridCellBoolRenderer())
        self.sid_cell = grd.GridCellAttr()
        self.sid_cell.SetReadOnly(1)

        i = 0
        for row in datasource:
            self.data[(i, 0)] = ''
            j = 1
            for v in row:
                self.data[(i, j)] = v  #给每一个单元格赋值的方法
                j += 1
            i += 1

        self.cell = grd.GridCellAttr()
        #self.cell.SetReadOnly()
        self.cell.SetOverflow(False)

        self.sid_attr = grd.GridCellAttr()
        self.sid_attr.SetOverflow(True)
Exemplo n.º 3
0
    def Draw(self, numLigne=0, ligneRegroupement=None):
        """ Dessine la ligne dans la grid """
        self.numLigne = numLigne
        self.ligneRegroupement = ligneRegroupement

        # Init ligne
        hauteurLigne = 25
        self.grid.SetRowSize(numLigne, hauteurLigne)

        # Case à cocher
        numColonne = 0
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  gridlib.GridCellBoolRenderer())
        self.grid.SetReadOnly(self.numLigne, numColonne, True)

        # Date
        numColonne = 1
        self.grid.SetReadOnly(self.numLigne, numColonne, True)
        self.grid.SetCellAlignment(self.numLigne, numColonne, wx.ALIGN_LEFT,
                                   wx.ALIGN_CENTRE)

        # Individu
        numColonne = 2
        self.grid.SetReadOnly(self.numLigne, numColonne, True)
        self.grid.SetCellAlignment(self.numLigne, numColonne, wx.ALIGN_LEFT,
                                   wx.ALIGN_CENTRE)

        # Label prestation
        numColonne = 3
        self.grid.SetReadOnly(self.numLigne, numColonne, True)
        self.grid.SetCellAlignment(self.numLigne, numColonne, wx.ALIGN_LEFT,
                                   wx.ALIGN_CENTRE)

        # Facture
        numColonne = 4
        self.grid.SetCellAlignment(self.numLigne, numColonne, wx.ALIGN_CENTER,
                                   wx.ALIGN_CENTRE)
        self.grid.SetReadOnly(self.numLigne, numColonne, True)

        # Montant prestation
        numColonne = 5
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        self.grid.SetReadOnly(self.numLigne, numColonne, True)

        # Montant déjà ventilé
        numColonne = 6
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        self.grid.SetReadOnly(self.numLigne, numColonne, True)

        # Ventilation actuelle
        numColonne = 7
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        self.grid.SetCellEditor(self.numLigne, numColonne,
                                EditeurMontant(ligne=self))
Exemplo n.º 4
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.alphaSort = wx.Button(self, label=u'Sort Alphabetically')
        self.alphaSort.Bind(wx.EVT_BUTTON, self.onSort)

        self.explanation = wx.StaticText(
            self,
            label=u'\n'.join([
                _("Change the Category order by dragging-and-dropping the first grey column in the table."
                  ),
                _("If 'Use Nth Result Only' is True, 'Team N' specifies the top Nth rider's time to use for the team's time (eg. Team TT, scored on 3rd rider's result)"
                  ),
                _("If 'Use Nth Result Only' if False, 'Team N' specifies the top riders' times to be totaled for the team result (eg. Team Stage Finish, scored on sum of top 3 results for each team)."
                  ),
            ]))

        self.headerNames = [
            'Category', 'Ind. Publish', 'Team N', 'Use Nth Result Only',
            'Team Publish'
        ]

        self.grid = ReorderableGrid(self, style=wx.BORDER_SUNKEN)
        self.grid.DisableDragRowSize()
        self.grid.SetRowLabelSize(64)
        self.grid.CreateGrid(0, len(self.headerNames))
        for col in range(self.grid.GetNumberCols()):
            self.grid.SetColLabelValue(col, self.headerNames[col])

        for col in range(self.grid.GetNumberCols()):
            attr = gridlib.GridCellAttr()
            if col == self.CategoryCol:
                attr.SetReadOnly(True)
            elif col in (self.PublishCol, self.UseNthScoreCol,
                         self.TeamPublishCol):
                editor = gridlib.GridCellBoolEditor()
                editor.UseStringValues('1', '0')
                attr.SetEditor(editor)
                attr.SetRenderer(gridlib.GridCellBoolRenderer())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
            elif col == self.TeamNCol:
                editor = gridlib.GridCellNumberEditor()
                attr.SetEditor(editor)
                attr.SetRenderer(gridlib.GridCellNumberRenderer())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

            self.grid.SetColAttr(col, attr)

        self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.onGridLeftClick)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.alphaSort, 0, flag=wx.ALL | wx.ALIGN_RIGHT, border=4)
        sizer.Add(self.explanation, 0, flag=wx.ALL, border=4)
        sizer.Add(self.grid, 1, flag=wx.EXPAND | wx.ALL, border=6)
        self.SetSizer(sizer)
Exemplo n.º 5
0
    def __init__(self, grid=None, numLigne=0, dictRegroupement={}):
        self.grid = grid
        self.type_ligne = "regroupement"
        self.numLigne = numLigne
        self.dictRegroupement = dictRegroupement
        self.listeLignesPrestations = []

        # Init ligne
        hauteurLigne = 20
        grid.SetRowSize(numLigne, hauteurLigne)

        # Attributs communes à toutes les colonnes
        for numColonne in range(0, 8):
            self.grid.SetCellBackgroundColour(self.numLigne, numColonne,
                                              COULEUR_FOND_REGROUPEMENT)
            self.grid.SetReadOnly(self.numLigne, numColonne, True)

        # Case à cocher
        numColonne = 0
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  gridlib.GridCellBoolRenderer())

        # Label du groupe
        self.grid.SetCellValue(self.numLigne, 1,
                               self.dictRegroupement["label"])

        font = self.grid.GetFont()
        font.SetWeight(wx.BOLD)
        self.grid.SetCellFont(self.numLigne, 1, font)

        # Montant prestation
        numColonne = 5
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        font = self.grid.GetFont()
        font.SetPointSize(8)
        self.grid.SetCellFont(self.numLigne, numColonne, font)

        # Montant déjà ventilé
        numColonne = 6
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        font = self.grid.GetFont()
        font.SetPointSize(8)
        self.grid.SetCellFont(self.numLigne, numColonne, font)

        # Ventilation actuelle
        numColonne = 7
        self.grid.SetCellRenderer(self.numLigne, numColonne,
                                  RendererCaseMontant())
        font = self.grid.GetFont()
        font.SetPointSize(8)
        self.grid.SetCellFont(self.numLigne, numColonne, font)
Exemplo n.º 6
0
    def __init__(self, parent):
        grd.Grid.__init__(self, parent, -1, pos=(10, 40), size=(420, 95))

        self.CreateGrid(3, 3)
        self.RowLabelSize = 0
        self.ColLabelSize = 20

        attr = grd.GridCellAttr()
        attr.SetEditor(grd.GridCellBoolEditor())
        attr.SetRenderer(grd.GridCellBoolRenderer())
        self.SetColAttr(1, attr)
        self.SetColSize(1, 20)

        self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse)
        self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected)
        self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
Exemplo n.º 7
0
    def __init__(self,gui,parent,dic,**kwargs):
        wgrid.Grid.__init__(self,parent,-1,**kwargs)
        self.rowString,self.colString,data=dic['rows'],dic['cols'],dic['data']
        if dic['rows']=='': self.rowString=['']*len(dic['data'])
        nrow, ncol = len(self.rowString),len(self.colString)
        self.chk = zeros((nrow,ncol))
        ln=[len(x) for x in self.rowString]
        self.SetRowLabelSize(min(max(ln)*8,170))
        lent = sum([len(x.replace(' ','')) for x in self.colString])
        if lent==0 : self.SetColLabelSize(0) # if all '', remove col headers
        self.CreateGrid(nrow,ncol);#print data
        for j,col in enumerate(self.colString):
            self.SetColLabelValue(j,col);
        for i,row in enumerate(self.rowString):
            self.SetRowLabelValue(i,row)
            ln = len(data[i])
            for j,col in enumerate(self.colString[:ln]):
                d = data[i][j]
                if type(d)==type([5,6]):
                    choice_editor = wgrid.GridCellChoiceEditor(d,False)
                    #choice_editor.SetCellAttr()
                    self.SetCellEditor(i,j, choice_editor)  
                    #self.SetCellValue(i, j, 1)
                elif type(d)==type(True):
                    e_boo = wgrid.GridCellBoolEditor()                       
                    self.SetCellEditor(i,j, e_boo)    
                    r_boo = wgrid.GridCellBoolRenderer()                       
                    self.SetCellRenderer(i,j, r_boo) 
                    self.chk[i,j] = 1
                    self.SetCellValue(i, j, str(d*1))
                else : 
                    # limit size cell if float
                    try : 
                        float(d)
                        #if 'e' not in d: d1 = d[:6]
                        d1 = str(d)[:9] #a real
                    except ValueError: 
                        d1 = str(d)
                    self.SetCellValue(i, j, d1)
                #self.SetCellSize(i,j,8,len(col)*4)

        self.AutoSizeColumns(True)
        self.AutoSizeRows(True)
        wx.EVT_KEY_DOWN(self, self.OnKey)
Exemplo n.º 8
0
    def __init__(self, parent, callback):
        grd.Grid.__init__(self, parent, -1)

        self.callback = callback

        self.CreateGrid(1, 3)
        self.RowLabelSize = 0
        # self.ColLabelSize = 20

        self.SetColLabelValue(0, u"序号")
        self.SetColLabelValue(1, u"生效")
        self.SetColLabelValue(2, u"地址")

        self.SetCellValue(0, 0, "0")
        self.SetCellValue(0, 1, "1")
        self.SetCellValue(0, 2, u"OPCServer1.Group1.Item1")

        attr = grd.GridCellAttr()
        attr.SetEditor(grd.GridCellBoolEditor())
        attr.SetRenderer(grd.GridCellBoolRenderer())
        self.SetColAttr(1, attr)

        self.SetColSize(1, 50)
        self.SetColSize(2, 300)

        # self.SetRowLabelSize(0)
        self.SetMargins(0, 0)
        self.SetSelectionMode(self.wxGridSelectRows)
        # self.AutoSizeColumns(True)

        self.SetReadOnly(0, 0, True)
        # self.SetReadOnly(0,1,True)
        self.SetReadOnly(0, 2, True)

        self.SetDefaultCellBackgroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_FRAMEBK))

        self.SetDefaultCellAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
        self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse)
        self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected)
        self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
Exemplo n.º 9
0
 def __init__(self, parent):
     Grid.Grid.__init__(self, parent, -1)
     self.CreateGrid(25, 4)
     self._rows = 25
     self._cols = 4
     self.SetColLabelValue(0, _("Location"))
     self.SetColLabelValue(1, _("Intensity"))
     self.SetColLabelValue(2, _("Comment"))
     self.SetColLabelValue(3, _("Frozen"))
     attr = Grid.GridCellAttr()
     attrb = Grid.GridCellAttr()
     attr.SetEditor(Grid.GridCellFloatEditor())
     attrb.SetEditor(Grid.GridCellBoolEditor())
     attrb.SetRenderer(Grid.GridCellBoolRenderer())
     self.SetColAttr(0, attr)
     self.SetColAttr(1, attr)
     self.SetColSize(2, self.GetColSize(2) * 4)
     self.SetColAttr(3, attrb)
     self.Bind(Grid.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClicked)
     self.Bind(Grid.EVT_GRID_CELL_CHANGE, self.OnCellChange)
     wx.EVT_KEY_DOWN(self, self.on_key)
Exemplo n.º 10
0
    def __init__(self, Child):
        grd.Grid.__init__(self, Child, -1, size=(250, 460))
        self.EnableGridLines(enable=False)
        self.CreateGrid(len(output_list), len(output_list))
        self.RowLabelSize = 0
        self.ColLabelSize = 60

        attr = grd.GridCellAttr()  # type: GridCellAttr
        attr.SetEditor(grd.GridCellBoolEditor())
        attr.SetRenderer(grd.GridCellBoolRenderer())

        # digital

        for i in range(
                0, (len(output_list))
        ):  ###uses the number of grids depending on amount of items in colLabels
            self.SetColAttr(i, attr)
            self.SetRowSize(i, 40)
            self.SetColSize(i, 80)  ###sets column 0 size
            self.SetColLabelValue(i, "Machine " + str(i + 1))

        self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse)
        self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected)
        self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
Exemplo n.º 11
0
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent = parent, size = (300,300))

        # ---------------- Grid section ---------------- #
        mock = data.mock_list
        
        # Get mock length
        rows = len(mock)
        print("Mock lenght = " + str(rows))
        # declare grid
        myGrid = grid.Grid(self, -1, size=(1,1))

        # Init grid
        myGrid.CreateGrid(rows, 4)
        # ---- pasted code ---- #
        
        attr = grid.GridCellAttr()
        attr.SetEditor(grid.GridCellBoolEditor())
        attr.SetRenderer(grid.GridCellBoolRenderer())
        for i in range(0, 4):
            myGrid.SetColAttr(i, attr)
            myGrid.SetColSize(i, 30)
        # ---- end pasted code ---- #

        # Set columns names
        for i in range(0, 4):
            myGrid.SetColLabelValue(i, ("Target set " + str(i+1)))
        
        # Set rows names
        for j in range(0, rows):
            myGrid.SetRowLabelValue(j, (mock[j][0]))

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(myGrid, 1, wx.EXPAND)
        self.SetSizer(sizer)
Exemplo n.º 12
0
    def __init__(self, parent, id=wx.ID_ANY):
        wx.Panel.__init__(self, parent, id)

        self.state = RaceInputState()

        vs = wx.BoxSizer(wx.VERTICAL)

        self.ignoreColour = wx.Colour(80, 80, 80)
        self.inactiveColour = wx.Colour(200, 200, 200)

        border = 4
        flag = wx.ALL

        hs = wx.BoxSizer(wx.HORIZONTAL)

        self.activateAllButton = wx.Button(self,
                                           label=_('Activate All'),
                                           style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onActivateAll, self.activateAllButton)
        hs.Add(self.activateAllButton, 0, border=border, flag=flag)

        hs.AddSpacer(6)

        self.newCategoryButton = wx.Button(self,
                                           label=_('New'),
                                           style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onNewCategory, self.newCategoryButton)
        hs.Add(self.newCategoryButton, 0, border=border, flag=flag)

        self.delCategoryButton = wx.Button(self,
                                           label=_('Delete'),
                                           style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onDelCategory, self.delCategoryButton)
        hs.Add(self.delCategoryButton,
               0,
               border=border,
               flag=(flag & ~wx.LEFT))

        hs.AddSpacer(6)

        self.upCategoryButton = wx.Button(self,
                                          label=u'\u2191',
                                          style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onUpCategory, self.upCategoryButton)
        hs.Add(self.upCategoryButton, 0, border=border, flag=flag)

        self.downCategoryButton = wx.Button(self,
                                            label=u'\u2193',
                                            style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onDownCategory, self.downCategoryButton)
        hs.Add(self.downCategoryButton,
               0,
               border=border,
               flag=(flag & ~wx.LEFT))

        hs.AddSpacer(6)

        self.setGpxDistanceButton = wx.Button(self,
                                              label=_('Set Gpx Distance'),
                                              style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onSetGpxDistance,
                  self.setGpxDistanceButton)
        hs.Add(self.setGpxDistanceButton, 0, border=border, flag=flag)

        hs.AddSpacer(6)

        self.addExceptionsButton = wx.Button(self,
                                             label=_('Bib Exceptions'),
                                             style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onAddExceptions,
                  self.addExceptionsButton)
        hs.Add(self.addExceptionsButton, 0, border=border, flag=flag)

        hs.AddSpacer(6)
        '''
		self.updateStartWaveNumbersButton = wx.Button(self, label=_('Update Start Wave Bibs'), style=wx.BU_EXACTFIT)
		self.Bind( wx.EVT_BUTTON, self.onUpdateStartWaveNumbers, self.updateStartWaveNumbersButton )
		hs.Add( self.updateStartWaveNumbersButton, 0, border = border, flag = flag )
		'''

        self.normalizeButton = wx.Button(self,
                                         label=_('Normalize'),
                                         style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onNormalize, self.normalizeButton)
        hs.Add(self.normalizeButton, 0, border=border, flag=flag)

        hs.AddStretchSpacer()

        self.printButton = wx.Button(self,
                                     label=u'{}...'.format(_('Print')),
                                     style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onPrint, self.printButton)
        hs.Add(self.printButton, 0, border=border, flag=flag)

        self.excelButton = wx.Button(self,
                                     label=u'{}...'.format(_('Excel')),
                                     style=wx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.onExcel, self.excelButton)
        hs.Add(self.excelButton, 0, border=border, flag=flag)

        self.grid = ReorderableGrid(self)
        self.colNameFields = [
            (u'', None),
            (_('Category Type'), 'catType'),
            (_('Active'), 'active'),
            (_('Name'), 'name'),
            (_('Gender'), 'gender'),
            (_('Numbers'), 'catStr'),
            (_('Start\nOffset'), 'startOffset'),
            (_('Race\nLaps'), 'numLaps'),
            (_('Race\nMinutes'), 'raceMinutes'),
            (_('Lapped\nRiders\nContinue'), 'lappedRidersMustContinue'),
            (_('Distance'), 'distance'),
            (_('Dist.\nBy'), 'distanceType'),
            (_('First\nLap\nDist.'), 'firstLapDistance'),
            (_('80%\nLap\nTime'), 'rule80Time'),
            (_('CrossMgr\nEstimated\nLaps'), 'suggestedLaps'),
            (_('Publish'), 'publishFlag'),
            (_('Upload'), 'uploadFlag'),
            (_('Series'), 'seriesFlag'),
        ]
        self.computedFields = {'rule80Time', 'suggestedLaps'}
        self.colnames = [
            colName if not colName.startswith('_') else _('Name Copy')
            for colName, fieldName in self.colNameFields
        ]
        self.iCol = {
            fieldName: i
            for i, (colName, fieldName) in enumerate(self.colNameFields)
            if fieldName and not colName.startswith('_')
        }

        self.activeColumn = self.iCol['active']
        self.genderColumn = self.iCol['gender']
        self.numbersColumn = self.iCol['catStr']
        self.grid.CreateGrid(0, len(self.colnames))
        self.grid.SetRowLabelSize(32)
        self.grid.SetMargins(0, 0)
        for col, name in enumerate(self.colnames):
            self.grid.SetColLabelValue(col, name)

        self.cb = None

        self.boolCols = set()
        self.choiceCols = set()
        self.readOnlyCols = set()
        self.dependentCols = set()

        # Set column attributes for the table.
        for col, (colName, fieldName) in enumerate(self.colNameFields):
            attr = gridlib.GridCellAttr()

            if fieldName is None:
                attr.SetRenderer(CategoryIconRenderer())
                attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
                attr.SetReadOnly(True)
                self.readOnlyCols.add(col)

            elif fieldName == 'catType':
                self.catTypeWidth = 64
                attr.SetEditor(
                    gridlib.GridCellChoiceEditor(self.CategoryTypeChoices,
                                                 False))
                attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
                self.choiceCols.add(col)

            elif fieldName in {
                    'active', 'lappedRidersMustContinue', 'publishFlag',
                    'uploadFlag', 'seriesFlag'
            }:
                boolEditor = gridlib.GridCellBoolEditor()
                boolEditor.UseStringValues('1', '0')
                attr.SetEditor(boolEditor)
                attr.SetRenderer(gridlib.GridCellBoolRenderer())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.boolCols.add(col)
                if fieldName == 'lappedRidersMustContinue':
                    self.dependentCols.add(col)

            elif fieldName == 'gender':
                attr.SetEditor(
                    gridlib.GridCellChoiceEditor(
                        [_('Open'), _('Men'), _('Women')], False))
                self.choiceCols.add(col)

            elif fieldName == 'startOffset':
                attr.SetEditor(TimeEditor())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.dependentCols.add(col)

            elif fieldName == 'numLaps':
                attr.SetEditor(wx.grid.GridCellNumberEditor())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.dependentCols.add(col)

            elif fieldName == 'raceMinutes':
                attr.SetEditor(wx.grid.GridCellNumberEditor())
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.dependentCols.add(col)

            elif fieldName in ['rule80Time', 'suggestedLaps']:
                attr.SetReadOnly(True)
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.readOnlyCols.add(col)
                self.dependentCols.add(col)

            elif fieldName in ['distance', 'firstLapDistance']:
                attr.SetEditor(gridlib.GridCellFloatEditor(7, 3))
                attr.SetRenderer(gridlib.GridCellFloatRenderer(7, 3))
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                self.dependentCols.add(col)

            elif fieldName == 'distanceType':
                attr.SetEditor(
                    gridlib.GridCellChoiceEditor(self.DistanceTypeChoices,
                                                 False))
                attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
                self.choiceCols.add(col)
                self.dependentCols.add(col)

            elif colName == '_name2':
                attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
                attr.SetBackgroundColour(wx.Colour(240, 240, 240))
                attr.SetReadOnly(True)

            self.grid.SetColAttr(col, attr)

        self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.onGridLeftClick)
        self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.onCellSelected)
        self.Bind(gridlib.EVT_GRID_CELL_CHANGED, self.onCellChanged)
        self.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)

        vs.Add(hs, 0, flag=wx.EXPAND | wx.ALL, border=4)
        vs.Add(self.grid, 1, flag=wx.GROW | wx.ALL | wx.EXPAND)

        self.rowCur = 0
        self.colCur = 0
        self.SetSizer(vs)
Exemplo n.º 13
0
    def __init__(self, parent):
        EnablePanel.__init__(self, parent)
        self.box = wx.StaticBox(
            self,
            label='Result (right-click to enter Bib numbers from keyboard)')
        boxSizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)

        self.event = None

        self.SetBackgroundColour(wx.WHITE)

        self.activeBar = EnableBar(self)
        self.activeBar.SetToolTip(
            wx.ToolTip('.\n'.join([
                'Record the Finish Order by dragging the row numbers in the table.',
                'Record DNF and DQ in the Status column.',
                'Then press OK or Cancel.'
            ])))

        vs = wx.BoxSizer(wx.VERTICAL)
        self.okButton = MakeRoundButton(self, 'OK')
        self.cancelButton = MakeRoundButton(self, 'Cancel', isCancel)
        vs.Add(self.okButton, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=4)
        vs.Add(self.cancelButton, flag=wx.ALL, border=4)

        self.headerNames = [
            'Bib', 'Name', 'Team', 'Status', 'Warn', 'Rel', 'Time    '
        ]
        self.iColStatus = self.headerNames.index('Status')
        self.iColWarning = self.headerNames.index('Warn')
        self.iColRelegation = self.headerNames.index('Rel')

        self.grid = ReorderableGrid(self, style=wx.BORDER_SUNKEN)
        self.grid.CreateGrid(4, len(self.headerNames))
        self.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnClick)
        self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick)

        font = GetFont()
        self.grid.SetLabelFont(font)
        for col in six.moves.range(self.grid.GetNumberCols()):
            self.grid.SetColLabelValue(col, self.headerNames[col])
            self.grid.SetCellValue(
                0, col, self.headerNames[col])  # Add the label as data.
            attr = gridlib.GridCellAttr()
            attr.SetFont(font)
            if self.headerNames[col] == 'Bib':
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_TOP)
                attr.SetReadOnly(True)
            elif self.headerNames[col].startswith('Time'):
                attr.SetEditor(HighPrecisionTimeEditor())
                attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
            elif col == 1 or col == 2:
                attr.SetReadOnly(True)
            elif col == self.iColStatus:
                attr.SetEditor(
                    gridlib.GridCellChoiceEditor(
                        choices=['DQ', 'DNF', 'DNS', '']))
            elif col == self.iColWarning or col == self.iColRelegation:
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
                attr.SetEditor(gridlib.GridCellBoolEditor())
                attr.SetRenderer(gridlib.GridCellBoolRenderer())
            self.grid.SetColAttr(col, attr)

        self.grid.AutoSizeColumns(False)  # Resize to fit the column name.
        self.grid.AutoSizeRows(False)
        for col in six.moves.range(self.grid.GetNumberCols()):
            self.grid.SetCellValue(0, col, '')  # Remove the labels.

        boxSizer.Add(self.activeBar, 0, flag=wx.ALL | wx.EXPAND, border=4)
        boxSizer.Add(vs, 0, flag=wx.ALL, border=4)
        boxSizer.Add(self.grid, 1, flag=wx.ALL | wx.EXPAND, border=4)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(boxSizer, 1, flag=wx.EXPAND)
        self.SetSizer(sizer)
Exemplo n.º 14
0
 def renderer(self):
     return gridlib.GridCellBoolRenderer()