Example #1
0
    def CreationLigne(self):
        """ Création d'une ligne """
        numLigne = self.GetNumberRows()-1
##        if numLigne > 24 :
##            dlg = wx.MessageDialog(self, _(u"Vous ne pouvez saisir qu'un maximum de 26 lignes !"), "Erreur", wx.OK | wx.ICON_EXCLAMATION)
##            dlg.ShowModal()
##            dlg.Destroy()
##            return
        # Création de la ligne
        self.AppendRows(1)
        numLigne += 1
        self.SetRowLabelValue(numLigne, str(numLigne+1)) #self.SetRowLabelValue(numLigne, ALPHABET[numLigne])
        self.SetRowSize(numLigne, 20)
        # Mémorisation de la ligne
        if self.dictDonnees.has_key(self.code) == False : 
            self.dictDonnees[self.code] = {}
        if self.dictDonnees[self.code].has_key(numLigne) == False : 
            self.dictDonnees[self.code][numLigne] = {}
        # Configuration des cases
        numColonne = 0
        for indexColonne in self.listeColonnes :
            codeEditeur = LISTE_COLONNES[indexColonne]["editeur"]
            if codeEditeur == "decimal" :
                renderer = gridlib.GridCellFloatRenderer(6, 2)
                editor = gridlib.GridCellFloatEditor(6, 2)
            elif codeEditeur == "decimal3" :
                renderer = gridlib.GridCellFloatRenderer(6, 3)
                editor = gridlib.GridCellFloatEditor(6, 3)
            elif codeEditeur == "decimal4" :
                renderer = gridlib.GridCellFloatRenderer(6, 4)
                editor = gridlib.GridCellFloatEditor(6, 4)
            elif codeEditeur == "decimal6" :
                renderer = gridlib.GridCellFloatRenderer(6, 6)
                editor = gridlib.GridCellFloatEditor(6, 6)
            elif codeEditeur == "entier" :
                renderer = gridlib.GridCellNumberRenderer()
                editor = gridlib.GridCellNumberEditor(0, 100)
            elif codeEditeur == "heure" :
                renderer = None
                editor = EditeurHeure()
            elif codeEditeur == "date" :
                renderer = None
                editor = EditeurDate()
            elif codeEditeur == "questionnaire" :
                listeChoix = [(0, ""),]
                for dictQuestion in self.listeQuestions :
                    if dictQuestion["controle"] in ("montant", "decimal") :
                        label = dictQuestion["label"] + " (%s)" % dictQuestion["type"].capitalize()
                        listeChoix.append((dictQuestion["IDquestion"], label))
                renderer = RendererChoix(listeChoix)
                editor = EditeurChoix(listeChoix)
            else:
                renderer = None
                editor = None
            if renderer != None : self.SetCellRenderer(numLigne, numColonne, renderer)
            if editor != None : self.SetCellEditor(numLigne, numColonne, editor)
            
            self.SetCellBackgroundColour(numLigne, numColonne, COULEUR_FOND_CASE)
            
            numColonne += 1
Example #2
0
	def updateGrid( self ):
		race = Model.race
		riderInfo = race.riderInfo if race else []
		
		Utils.AdjustGridSize( self.grid, len(riderInfo), len(self.headerNames) )
		
		# Set specialized editors for appropriate columns.
		for col, name in enumerate(self.headerNames):
			self.grid.SetColLabelValue( col, name )
			attr = gridlib.GridCellAttr()
			if col == 0:
				attr.SetRenderer( gridlib.GridCellNumberRenderer() )
			elif col == 1:
				attr.SetRenderer( gridlib.GridCellFloatRenderer(precision=1) )
			if name == 'Bib':
				attr.SetBackgroundColour( wx.Colour(178, 236, 255) )
			attr.SetFont( Utils.BigFont() )
			self.grid.SetColAttr( col, attr )
		
		missingBib = 5000
		for row, ri in enumerate(riderInfo):
			for col, field in enumerate(self.fieldNames):
				v = getattr(ri, field, None)
				if v is None:
					if field == 'bib':
						v = ri.bib = missingBib
						missingBib += 1
				self.grid.SetCellValue( row, col, u'{}'.format(v) )
		self.grid.AutoSize()
		self.Layout()
Example #3
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.headerNames = ['Pos', 'Bib', 'Name', 'Team', 'Time']

        self.grid = ReorderableGrid(self, style=wx.BORDER_SUNKEN)
        self.grid.DisableDragRowSize()
        self.grid.SetRowLabelSize(0)
        self.grid.CreateGrid(0, len(self.headerNames))
        self.setColNames()
        self.grid.EnableReorderRows(False)

        # Set a larger font for the table.
        # Set specialized editors for appropriate columns.
        font = GetFont()
        self.grid.SetLabelFont(font)
        for col in six.moves.range(self.grid.GetNumberCols()):
            attr = gridlib.GridCellAttr()
            attr.SetFont(font)
            if col == self.grid.GetNumberCols() - 1:
                attr.SetRenderer(gridlib.GridCellFloatRenderer(-1, 3))
                attr.SetEditor(gridlib.GridCellFloatEditor(-1, 3))
            else:
                if col in (0, 1):
                    attr.SetRenderer(gridlib.GridCellNumberRenderer())
                attr.SetReadOnly(True)
            self.grid.SetColAttr(col, attr)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.grid, 1, flag=wx.EXPAND | wx.ALL, border=6)
        self.SetSizer(sizer)
Example #4
0
    def columnas(self):
    """
    Define los atributos de las columnas
    Etiqueta, Tamaño, Tipo lectura, Presentador
    """
    return [
            ('Codigo experto', 65, True, wxgrid.GridCellNumberRenderer()),
            ('Nombre', 65, False, wxgrid.GridCellStringRenderer()),
            ('Descripcion',300, False, wxgrid.GridCellStringRenderer()),
            ('Cantidad',70, False, wxgrid.GridCellFloatRenderer(10,2))
            ('Stock',70, False, wxgrid.GridCellFloatRenderer(10,2))
           ]
 
    def crearColumnas(self):
    """ Establece atributos de las columnas de la rejilla """
        for ind, col in enumerate(self.columnas()):
            self.SetColLabelValue(ind, col[0])
            self.SetColSize(ind, col[1])
            atrib = wxgrid.GridCellAttr()
            atrib.SetReadOnly(col[2])
            atrib.SetRenderer(col[3])
            self.SetColAttr(ind, atrib)
Example #5
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)
Example #6
0
    def addRow(self, index=None):
        if index == None:
            self.AppendRows(1, True)
            row = len(self.objects)
        else:
            self.InsertRows(index, 1, True)
            row = index

        # Filename
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_FILENAME, attr)
        renderer = gridlib.GridCellAutoWrapStringRenderer()
        self.SetCellRenderer(row, ID_COL_FILENAME, renderer)
        self.SetCellValue(row, ID_COL_FILENAME, "Click to choose a sound")
        self.SetCellTextColour(row, ID_COL_FILENAME, "#888888")
        # Loop Mode
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_LOOPMODE, attr)
        # Transpo
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_TRANSPO, attr)
        rd = gridlib.GridCellFloatRenderer()
        rd.SetPrecision(4)
        self.SetCellRenderer(row, ID_COL_TRANSPO, rd)
        # Gain
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_GAIN, attr)
        rd = gridlib.GridCellFloatRenderer()
        rd.SetPrecision(4)
        self.SetCellRenderer(row, ID_COL_GAIN, rd)
        # Playing
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_PLAYING, attr)
        # Direct Out
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_DIRECTOUT, attr)
        # Start Point
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_STARTPOINT, attr)
        rd = gridlib.GridCellFloatRenderer()
        rd.SetPrecision(4)
        self.SetCellRenderer(row, ID_COL_STARTPOINT, rd)
        # End Point
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_ENDPOINT, attr)
        rd = gridlib.GridCellFloatRenderer()
        rd.SetPrecision(4)
        self.SetCellRenderer(row, ID_COL_ENDPOINT, rd)
        # Crossfade
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_CROSSFADE, attr)
        rd = gridlib.GridCellFloatRenderer()
        rd.SetPrecision(1)
        self.SetCellRenderer(row, ID_COL_CROSSFADE, rd)
        # Channel
        attr = gridlib.GridCellAttr()
        attr.SetReadOnly(True)
        self.SetAttr(row, ID_COL_CHANNEL, attr)
        rd = gridlib.GridCellNumberRenderer()
        self.SetCellRenderer(row, ID_COL_CHANNEL, rd)

        self.SetCellAlignment(row, 0, wx.ALIGN_LEFT, wx.ALIGN_CENTER)
        for i in range(1, len(LABELS)):
            self.SetCellAlignment(row, i, wx.ALIGN_CENTER, wx.ALIGN_CENTER)
Example #7
0
 def renderer(self):
     return gridlib.GridCellFloatRenderer(*self.args)
Example #8
0
    def __init__(self, parent, table):
        self._tip_window = None
        self._find_data = wx.FindReplaceData()
        self._find_data.SetFlags(1)
        self._found_cell = None

        grid.Grid.__init__(self, parent, -1)
        self._ctx = table.editor_context
        self.SetTable(table)

        # read only
        if self._ctx.read_only:
            # self.SetSelectionMode( grid.Grid.wxGridSelectCells )
            # self.SetBackgroundColour( wx.YELLOW )
            self.SetCellHighlightColour(wx.RED)
            # self.SetCellHighlightPenWidth( 3 )

        # intercept key events from CellEditors
        self.Bind(wx.EVT_CHAR_HOOK, self.__OnCharHook)
        # self.Bind(wx.EVT_KEY_DOWN, self.__OnKeyDown)
        self.Bind(grid.EVT_GRID_SELECT_CELL, self.__OnCellSelected)
        self.Bind(grid.EVT_GRID_CELL_CHANGED, self.__OnCellChanged)

        # reset tip position if cell size/position changed
        self.Bind(wx.EVT_SET_FOCUS, self.__OnSetFocus)
        self.Bind(wx.EVT_KILL_FOCUS, self.__OnKillFocus)
        # self.Bind(grid.EVT_GRID_LABEL_LEFT_CLICK, self.__OnGirdLabelLeftClicked)
        self.Bind(grid.EVT_GRID_COL_SORT, self.__OnSortCol)

        self.Bind(wx.EVT_SIZE, self.__OnPositionTip)
        p = self
        while p.GetParent() and not p.IsTopLevel():
            p = p.GetParent()
        p.Bind(wx.EVT_SIZE, self.__OnSize)
        p.Bind(wx.EVT_MOVE, self.__OnPositionTip)

        self.Bind(grid.EVT_GRID_EDITOR_HIDDEN, self.__OnEditorHidden)
        self.UseNativeColHeader(True)

        # str_renderer = grid.GridCellAutoWrapStringRenderer
        str_renderer = grid.GridCellStringRenderer

        # todo can be customized by plugin?
        self.RegisterDataType(grid.GRID_VALUE_NUMBER,
                              grid.GridCellNumberRenderer(),
                              GridCellIntEditor())
        self.RegisterDataType(grid.GRID_VALUE_FLOAT,
                              grid.GridCellFloatRenderer(),
                              GridCellFloatEditor())
        self.RegisterDataType(grid.GRID_VALUE_STRING, str_renderer(),
                              GridCellStrEditor())

        self.RegisterDataType(MY_GRID_DATA_TYPE_MULTILINE_STR, str_renderer(),
                              GridCellDialogEditor(FilterEditorDialog))
        self.RegisterDataType(MY_GRID_DATA_TYPE_PYTHON_CODE, str_renderer(),
                              GridCellDialogEditor(FilterEditorDialog))
        self.RegisterDataType(MY_GRID_DATA_TYPE_LIST, str_renderer(),
                              GridCellDialogEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_DICT, str_renderer(),
                              DictEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_UNION, str_renderer(),
                              GridCellDialogEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_STRUCT, str_renderer(),
                              GridCellDialogEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_ENUM,
                              grid.GridCellStringRenderer(),
                              GridCellEnumEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_LIST_ENUM_UNIQUE,
                              str_renderer(), GridCellUniqueEnumListEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_REF,
                              grid.GridCellStringRenderer(),
                              GridCellDialogEditor(RefEditorDialog))
        self.RegisterDataType(MY_GRID_DATA_TYPE_FILE,
                              grid.GridCellStringRenderer(),
                              GridCellDialogEditor(FileDialog))
        self.RegisterDataType(MY_GRID_DATA_TYPE_FOLDER,
                              grid.GridCellStringRenderer(),
                              GridCellDialogEditor(FolderDialog))
        self.RegisterDataType(MY_GRID_DATA_TYPE_TIME, str_renderer(),
                              GridCellTimeEditor())
        self.RegisterDataType(MY_GRID_DATA_TYPE_DURATION, str_renderer(),
                              GridCellDurationEditor())

        self.auto_size()