Ejemplo n.º 1
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()
Ejemplo n.º 2
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
Ejemplo n.º 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)
Ejemplo n.º 4
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        font = GetFont()
        self.title = wx.StaticText(
            self, wx.ID_ANY,
            "Enter each rider's qualifying time in hh:mm:ss.ddd format.  Use a colon ':' a space, or a dash '-' to separate hour, minute and seconds."
        )
        self.title.SetFont(font)

        self.renumberButton = wx.Button(self, wx.ID_ANY,
                                        'Renumber Bibs by Time')
        self.renumberButton.SetFont(font)
        self.renumberButton.Bind(wx.EVT_BUTTON, self.doRenumber)

        hs = wx.BoxSizer(wx.HORIZONTAL)
        hs.Add(self.title, 0, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=6)
        hs.AddStretchSpacer()
        hs.Add(self.renumberButton, 0, flag=wx.ALL, border=6)

        self.headerNames = ['Bib', 'Name', 'Team', 'Time', 'Status']
        self.iTime = next(i for i, n in enumerate(self.headerNames)
                          if n.startswith('Time'))
        self.iStatus = next(i for i, n in enumerate(self.headerNames)
                            if n.startswith('Status'))

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

        # Set specialized editors for appropriate columns.
        self.grid.SetLabelFont(font)
        for col in six.moves.range(self.grid.GetNumberCols()):
            attr = gridlib.GridCellAttr()
            attr.SetFont(font)
            if col == self.iTime:
                attr.SetEditor(HighPrecisionTimeEditor())
                attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
            elif col == self.iStatus:
                attr.SetEditor(
                    gridlib.GridCellChoiceEditor(choices=['', 'DNQ']))
                attr.SetReadOnly(False)
                attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
            else:
                if col == 0:
                    attr.SetRenderer(gridlib.GridCellNumberRenderer())
                attr.SetReadOnly(True)
            self.grid.SetColAttr(col, attr)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(hs, 0, flag=wx.ALL | wx.EXPAND, border=6)
        sizer.Add(self.grid, 1, flag=wx.EXPAND | wx.ALL, border=6)
        self.SetSizer(sizer)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
	def __init__(self, parent):
		wx.Panel.__init__(self, parent)
 
		font = wx.Font( (0,FontSize), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL )
		
		self.title = wx.StaticText(self, wx.ID_ANY, u"Seeding" + u':')
		self.title.SetFont( font )
		
		self.communiqueLabel = wx.StaticText( self, label=u'Communiqu\u00E9:' )
		self.communiqueLabel.SetFont( font )
		self.communiqueNumber = wx.TextCtrl( self, size=(64,-1) )
		self.communiqueNumber.SetFont( font )
		
		self.randomizeButton = wx.Button( self, wx.ID_ANY, 'Randomize...' )
		self.randomizeButton.Bind( wx.EVT_BUTTON, self.doRandomize )
		self.randomizeButton.SetFont( font )
 
		self.importButton = wx.Button( self, wx.ID_ANY, 'Import From Excel' )
		self.importButton.Bind( wx.EVT_BUTTON, self.doImportFromExcel )
		self.importButton.SetFont( font )
 
		self.headerNames = ['Bib', 'First Name', 'Last Name', 'Team', 'Team Code', 'License']
		
		self.grid = ReorderableGrid( self, style = wx.BORDER_SUNKEN )
		self.grid.DisableDragRowSize()
		self.grid.SetRowLabelSize( 64 )
		self.grid.CreateGrid( 200, len(self.headerNames) )
		self.setColNames()

		# Set specialized editors for appropriate columns.
		self.grid.SetLabelFont( font )
		for col in six.moves.range(self.grid.GetNumberCols()):
			attr = gridlib.GridCellAttr()
			attr.SetFont( font )
			if col == 0:
				attr.SetRenderer( gridlib.GridCellNumberRenderer() )
				attr.SetEditor( gridlib.GridCellNumberEditor() )
			self.grid.SetColAttr( col, attr )
		
		hs = wx.BoxSizer( wx.HORIZONTAL )
		hs.Add( self.title, 0, flag=wx.ALIGN_CENTRE_VERTICAL|wx.RIGHT, border = 8 )
		hs.Add( self.communiqueLabel, 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=4 )
		hs.Add( self.communiqueNumber, 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, border=4 )
		hs.AddStretchSpacer()
		hs.Add( self.randomizeButton, 0, flag=wx.ALL, border=4 )
		hs.Add( self.importButton, 0, flag=wx.ALL, border=4 )
		
		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.Add( hs, 0, flag=wx.ALL|wx.EXPAND, border=6 )
		sizer.Add( wx.StaticText(self, label=u'Set Bib to 0 to Delete row.  Drag-and-drop row numbers to Change Sequence.'), flag=wx.LEFT, border = 8 )
		sizer.Add(self.grid, 1, flag=wx.EXPAND|wx.ALL, border=6)
		self.SetSizer(sizer)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def renderer(self):
     return gridlib.GridCellNumberRenderer()
Ejemplo n.º 10
0
	def __init__( self, parent, controller, id = wx.ID_ANY ):
		wx.Panel.__init__(self, parent, id)
		self.SetBackgroundColour( wx.WHITE )

		self.controller = controller

		self.headerNames = [_('Time'), _('Bib')]
		
		self.maxRows = 10
		
		fontSize = 18
		self.font = wx.FontFromPixelSize( wx.Size(0,fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL )
		self.bigFont = wx.FontFromPixelSize( wx.Size(0,int(fontSize*1.3)), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL )
		self.vbs = wx.BoxSizer(wx.VERTICAL)
		
		tapForTimeLabel = _('Tap for Time')
		if 'WXMAC' in wx.Platform:
			self.recordTimeButton = wx.lib.buttons.ThemedGenButton( self, label=tapForTimeLabel )
			self.recordTimeButton.Bind( wx.EVT_BUTTON, self.doRecordTime )
		else:
			self.recordTimeButton = wx.Button( self, label=tapForTimeLabel )
			self.recordTimeButton.Bind( wx.EVT_LEFT_DOWN, self.doRecordTime )
		
		self.recordTimeButton.SetFont( self.bigFont )
		self.recordTimeButton.SetToolTip(wx.ToolTip(u'\n'.join(
			[_('Tap to Record Times (or press the "t" key).'), _('Then enter the Bib numbers and Save as soon as possible.')]) ))
		
		hbs = wx.BoxSizer( wx.HORIZONTAL )
		hbs.Add( self.recordTimeButton, 0 )
		
		self.grid = ReorderableGrid( self, style = wx.BORDER_SUNKEN )
		self.grid.SetFont( self.font )
		self.grid.EnableReorderRows( False )
		
		dc = wx.WindowDC( self.grid )
		dc.SetFont( self.font )
		width, height = dc.GetTextExtent(" 999 ")
		self.rowLabelSize = width
		self.grid.SetRowLabelSize( self.rowLabelSize )
		
		self.grid.CreateGrid( self.maxRows, len(self.headerNames) )
		self.grid.Bind( gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.doClickLabel )
		for col, name in enumerate(self.headerNames):
			self.grid.SetColLabelValue( col, name )
		self.grid.SetLabelFont( self.font )
		for col in xrange(self.grid.GetNumberCols()):
			attr = gridlib.GridCellAttr()
			attr.SetFont( self.font )
			if col == 0:
				attr.SetEditor( HighPrecisionTimeEditor() )
			elif col == 1:
				attr.SetRenderer( gridlib.GridCellNumberRenderer() )
				attr.SetEditor( gridlib.GridCellNumberEditor() )
			self.grid.SetColAttr( col, attr )
		
		saveLabel = _('Save')
		if 'WXMAC' in wx.Platform:
			self.commitButton = wx.lib.buttons.ThemedGenButton( self, label=saveLabel )
		else:
			self.commitButton = wx.Button( self, label=saveLabel )
		self.commitButton.Bind( wx.EVT_BUTTON, self.doCommit )
		self.commitButton.SetFont( self.bigFont )
		self.commitButton.SetToolTip(wx.ToolTip(_('Save Entries (or press the "s" key)')))
		
		self.vbs.Add( hbs, 0, flag=wx.ALL|wx.EXPAND, border = 4 )
		self.vbs.Add( self.grid, 1, flag=wx.ALL|wx.EXPAND, border = 4 )
		self.vbs.Add( self.commitButton, flag=wx.ALL|wx.ALIGN_RIGHT, border = 4 )
		
		idRecordAcceleratorId, idCommitAccelleratorId = wx.NewId(), wx.NewId()
		self.Bind(wx.EVT_MENU, self.doRecordTime, id=idRecordAcceleratorId)
		self.Bind(wx.EVT_MENU, self.doCommit, id=idCommitAccelleratorId)
		accel_tbl = wx.AcceleratorTable([
			(wx.ACCEL_NORMAL,  ord('T'), idRecordAcceleratorId),
			(wx.ACCEL_NORMAL,  ord('S'), idCommitAccelleratorId),
		])
		self.SetAcceleratorTable(accel_tbl)
		
		self.SetSizer(self.vbs)
		self.Fit()
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
    def addData(self, data=None):
        self.data = data
#         logger.info(self.GetRowSizes())
#         logger.info(self.GetColSizes())
        self.ClearGrid()
        try:
            if data and len(data) > 0:
                dataTypeRow = data.get(-1)
#                 logger.info('rows:', self.GetNumberRows())
#                 logger.info('cols:', self.GetNumberCols())
        #         self.DeleteRows()
                currentRows, currentCols = (self.GetNumberRows(), self.GetNumberCols())
                newRows = len(data) - 1
                if dataTypeRow:
                    newRows = newRows - 1
                newCols = len(data[0])
        #         self.AppendRows(numRows=len(data)-1, updateLabels=True)
        #         if len(data) > 0 :
        #             self.AppendCols(numCols=len(data[0]), updateLabels=True)
                if newRows < currentRows:
                    # - Delete rows:
                    self.DeleteRows(0, currentRows - newRows, True)

                if newRows > currentRows:
                    # - append currentRows:
                    self.AppendRows(newRows - currentRows)

                if newCols < currentCols:
                    # - Delete rows:
                    self.DeleteCols(pos=0, numCols=currentCols - newCols, updateLabels=True)

                if newCols > currentCols:
                    # - append currentRows:
                    self.AppendCols(newCols - currentCols)

                for dataKey, dataValue in data.items():
#                     logger.info(dataKey, dataValue)
                    for idx, colValue in enumerate(dataValue):
        #                 logger.info(idx, dataValue)

                        if dataKey == 0:
                            self.SetColLabelValue(idx, str(colValue))
                        elif dataKey > 0:
                            row = dataKey - 1
                            col = idx
                            try:
#                                 if col==3:
#                                     size=self.GetCellSize(row, col)
#                                     data='3.jpg'
#                                     self.SetCellRenderer(row, col, MegaImageRenderer(self.GetTable(), data))
#                                 elif str(colValue).startswith('-______-'):
                                    
                                if str(colValue).startswith('-______-'):
                                    newStringValue = str(colValue).replace('-______-', '')
                                    self.SetCellFont(row, col, wx.Font(10, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
                                    self.SetCellTextColour(row, col, wx.LIGHT_GREY)
                                    self.SetCellValue(row, col, newStringValue)
                                else:
                                    if dataTypeRow and dataTypeRow[col].lower() == 'blob':
#                                         data='3.jpg'
                                        if str(colValue).startswith('-______-'):
                                            newStringValue = str(colValue).replace('-______-', '')
                                            self.SetCellFont(row, col, wx.Font(10, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
                                            self.SetCellTextColour(row, col, wx.LIGHT_GREY)
                                            self.SetCellValue(row, col, newStringValue)
                                        else:
                                            self.SetCellRenderer(row, col, MegaImageRenderer(self.GetTable(), colValue))
                                    elif dataTypeRow and dataTypeRow[col].lower() == 'integer':
                                        self.SetCellRenderer(row, col, gridlib.GridCellNumberRenderer())
                                        self.SetCellValue(row, col, str(colValue))
                                    elif dataTypeRow and dataTypeRow[col].lower() == 'datetime':
                                        self.SetCellRenderer(row, col, gridlib.GridCellDateTimeRenderer())
                                        self.SetCellValue(row, col, colValue)
                                    elif dataTypeRow and dataTypeRow[col].lower() == 'boolean':
                                        self.SetCellEditor(row, col, gridlib.GridCellBoolEditor())
                                        self.SetCellRenderer(row, col, CheckBoxCellRenderer(self))
                                        self.SetCellValue(row, col, str(colValue))
                                        self.SetCellAlignment(row, col, wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
#                                     elif dataTypeRow and dataTypeRow[col] in ['varchar', 'int']:
                                    else:                               
#                                     self.SetCellFont(dataKey - 1, idx,  wx.Font(10, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL))
#                                     self.SetCellTextColour(dataKey - 1, idx,wx.LIGHT_GREY)
                                        self.SetCellValue(row, col, str(colValue))
#                                 self.SetCellAlignment(dataKey - 1,idx, wx.ALIGN_RIGHT)
                            except Exception as e:
                                logger.error(e, exc_info=True)
            else:
                numCols = self.GetNumberCols()
                numRows = self.GetNumberRows()
                logger.debug("numRows:%s, numCol: %s", numRows, numCols)
                if numRows > 0 and numCols > 0:
                    self.DeleteCols(pos=0, numCols=numCols, updateLabels=True)
                    self.DeleteRows(pos=0, numRows=numRows, updateLabels=True)
        except Exception as e:
            logger.error(e, exc_info=True)
        self.Refresh()