示例#1
0
    def SetRowColours(self, colors=ALTERNATE_COLORS):
        """Define the base attribute for odd and even rows:

        * background color
        * text color
        * selected color

        The selected color is based on the system (gtk, windows or
        mac os x).
        """
        #odd rows
        self.odd_attr = gridlib.GridCellAttr()
        self.odd_attr.SetBackgroundColour(colors[1])
        #even rows
        self.even_attr = gridlib.GridCellAttr()
        self.even_attr.SetBackgroundColour(colors[0])
        #missing_rows
        self.missing_attr = gridlib.GridCellAttr()
        self.missing_attr.SetBackgroundColour(RED)
        #selected rows
        self.selected_attr = gridlib.GridCellAttr()
        self.selected_attr.SetBackgroundColour(
            wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
        self.selected_attr.SetTextColour(
            wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
示例#2
0
    def __init__(self, parent, data):
        gridlib.PyGridTableBase.__init__(self)
        self.parent = parent
        self.data = data
        self.colorInactive = wx.SystemSettings.GetColour(
            wx.SYS_COLOUR_GRAYTEXT)

        self.editor = gridlib.GridCellChoiceEditor([
            'default', 'read-only', 'read-write', 'write-only', 'writeOnce',
            'read-writeOnce'
        ])

        self.attr_dd = gridlib.GridCellAttr()
        self.attr_dd.SetEditor(self.editor)

        self.attr_dg = gridlib.GridCellAttr()
        self.attr_dg.SetEditor(self.editor)
        self.attr_dg.SetTextColour(self.colorInactive)

        self.attr_ro = gridlib.GridCellAttr()
        self.attr_ro.SetReadOnly(True)
        self.attr_ro.SetTextColour(self.colorInactive)

        self.attr_g = gridlib.GridCellAttr()
        self.attr_g.SetTextColour(self.colorInactive)
示例#3
0
    def __init__(self, datasource, rowLabels=None, colLabels=None):
        '''
        [
            [value1,value2,value3,...],
            [value1,value2,value3,...],
            [value1,value2,value3,...],
            ...
        ]
        '''
        grd.PyGridTableBase.__init__(self)
        self.data = {}
        self.colLabels = colLabels
        self.rowLabels = rowLabels
        self.rows = len(datasource)  #行数
        self.cols = len(self.colLabels)  #行数

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

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

        self.imagecell = grd.GridCellAttr()
        self.imagecell.SetEditor(grd.GridCellTextEditor())
        self.imagecell.SetRenderer(BitmapRenderer())
        self.imagecell.SetReadOnly()
示例#4
0
    def __init__(self, log):
        gridlib.PyGridTableBase.__init__(self)
        self.log = log

        self.odd = gridlib.GridCellAttr()
        self.odd.SetBackgroundColour("sky blue")
        self.even = gridlib.GridCellAttr()
        self.even.SetBackgroundColour("sea green")
    def __init__(self, parent):
        gridlib.Grid.__init__(self, parent, -1)

        table = PDFTable()  # initialize table

        #==============================================================================
        # announce table to Grid
        # 'True' = enable Grid to manage the table (destroy, etc.)
        #==============================================================================
        self.SetTable(table, True)
        #==============================================================================
        # set font, width, alignment in the grid
        #==============================================================================
        self.SetDefaultCellFont(
            wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False,
                    "DejaVu Sans Mono"))

        # center columns (indent level, delete check box)
        ct_al1 = gridlib.GridCellAttr()
        ct_al1.SetAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
        self.SetColAttr(0, ct_al1)
        self.SetColAttr(3, ct_al1)
        # page number right aligned
        re_al1 = gridlib.GridCellAttr()
        re_al1.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
        self.SetColAttr(2, re_al1)

        #==============================================================================
        # Enable Row moving
        #==============================================================================
        gridmovers.GridRowMover(self)

        #==============================================================================
        # Bind: move row
        #==============================================================================
        self.Bind(gridmovers.EVT_GRID_ROW_MOVE, self.OnRowMove, self)

        #==============================================================================
        # Bind: duplicate a row
        #==============================================================================
        self.Bind(gridlib.EVT_GRID_LABEL_LEFT_DCLICK, self.OnRowDup, self)

        #==============================================================================
        # Bind: delete a row
        #==============================================================================
        self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnRowDel, self)

        #==============================================================================
        # Bind: (double) click a cell
        #==============================================================================
        self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnCellClick, self)
        self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellDClick, self)

        #==============================================================================
        # Bind: cell is changing
        #==============================================================================
        self.Bind(gridlib.EVT_GRID_CELL_CHANGING, self.OnCellChanging, self)
示例#6
0
    def __init__(self, log, num_rows, num_cols):
        gridlib.GridTableBase.__init__(self)
        self.log = log

        self.odd = gridlib.GridCellAttr()
        #self.odd.SetBackgroundColour("sky blue")
        self.even = gridlib.GridCellAttr()
        #self.even.SetBackgroundColour("sea green")
        self.num_rows = num_rows
        self.num_cols = num_cols
        self.dataframe = []
示例#7
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()
示例#8
0
 def __init__(self, parent):
     self.parent = parent
     self.parent.GetPlayed()
     gridlib.PyGridTableBase.__init__(self)
     #self.SetDefaultCellBackgroundColour("sea green")
     self.more = gridlib.GridCellAttr()
     self.more.SetBackgroundColour("#1b6f0d")
     self.less = gridlib.GridCellAttr()
     self.less.SetBackgroundColour("#51b741")
     self.empty = gridlib.GridCellAttr()
     self.empty.SetBackgroundColour("black")
示例#9
0
文件: views.py 项目: Evansbee/synacor
 def __init__(self, vm):
     gridlib.GridTableBase.__init__(self)
     self.vm = vm
     self.changed = gridlib.GridCellAttr()
     self.changed.SetBackgroundColour(wx.RED)
     self.rw = gridlib.GridCellAttr()
     self.rw.SetBackgroundColour(wx.GREEN)
     self.pc = gridlib.GridCellAttr()
     self.pc.SetBackgroundColour(wx.BLUE)
     self.normal = gridlib.GridCellAttr()
     self.normal.SetBackgroundColour(wx.WHITE)
示例#10
0
 def SetRowColours(self,
                   odd=wx.Colour(250, 250, 250),
                   even=wx.Colour(254, 255, 255)):
     self.odd_attr = gridlib.GridCellAttr()
     self.odd_attr.SetBackgroundColour(odd)
     self.even_attr = gridlib.GridCellAttr()
     self.even_attr.SetBackgroundColour(even)
     self.selected_attr = gridlib.GridCellAttr()
     self.selected_attr.SetBackgroundColour(
         wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
     self.selected_attr.SetTextColour(
         wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
示例#11
0
    def __init__(self, datas):
        grid.GridTableBase.__init__(self)

        self.datas = datas
        self.colLabels = [u'姓名', u'性别', u'学校', u'专业', u'年级']
        self.isModified = False

        self.odd = grid.GridCellAttr()
        self.odd.SetReadOnly(False)
        self.odd.SetBackgroundColour('yellow')
        self.even = grid.GridCellAttr()
        self.even.SetReadOnly(False)
示例#12
0
 def SetColor(self, num):
     if self.firstLoop is 0:
         for row in range(num):
             if row & 1:
                 attr = Grid.GridCellAttr()
                 attr.SetBackgroundColour(wx.Colour(255, 255, 204))
                 self.SetRowAttr(row, attr)
                 for col in coll:
                     attr = self.GetOrCreateCellAttr(row, col)
                     attr = attr.Clone()
                     attr.SetAlignment(wx.RIGHT, -1)
                     self.SetColAttr(col, attr)
         self.firstLoop = 1
         return
     if self.gridRowSize is num:
         for row in range(num):
             if row & 1:
                 attr = self.GetOrCreateCellAttr(row, 0)
                 attr = attr.Clone()
                 attr.SetBackgroundColour(wx.Colour(255, 255, 204))
                 self.SetRowAttr(row, attr)
                 for col in coll:
                     attr = self.GetOrCreateCellAttr(row, col)
                     attr = attr.Clone()
                     attr.SetAlignment(wx.RIGHT, -1)
                     self.SetColAttr(col, attr)
     else:
         for row in range(num):
             if row < self.gridRowSize:
                 if row & 1:
                     attr = self.GetOrCreateCellAttr(row, 0)
                     attr = attr.Clone()
                     attr.SetBackgroundColour(wx.Colour(255, 255, 204))
                     self.SetRowAttr(row, attr)
                     for col in coll:
                         attr = self.GetOrCreateCellAttr(row, col)
                         attr = attr.Clone()
                         attr.SetAlignment(wx.RIGHT, -1)
                         self.SetColAttr(col, attr)
             else:
                 if row & 1:
                     attr = Grid.GridCellAttr()
                     attr.SetBackgroundColour(wx.Colour(255, 255, 204))
                     self.SetRowAttr(row, attr)
                     for col in coll:
                         attr = self.GetOrCreateCellAttr(row, col)
                         attr = attr.Clone()
                         attr.SetAlignment(wx.RIGHT, -1)
                         self.SetColAttr(col, attr)
         self.gridRowSize = num
     self.ForceRefresh()
     self.Refresh()
示例#13
0
    def __init__(self, header=None, log=None):
        gridlib.PyGridTableBase.__init__(self)
        self.log = log
        self.header = header
        self.defattr = gridlib.GridCellAttr()
        self.defattr.SetReadOnly()
        self.defattr.SetBackgroundColour(wx.WHITE)

        self.cod_attr = gridlib.GridCellAttr()
        self.cod_attr.SetReadOnly()
        self.cod_attr.SetBackgroundColour(wx.WHITE)

        self.dataset = None
示例#14
0
    def __init__(self, log, DBQuery):
        gridlib.PyGridTableBase.__init__(self)
        self.log = log
        self.DBQuery = DBQuery

        self.colnames = [
            'Transaction ID', 'Item Bought', 'Amount Spent', 'Who spent?',
            'Expenditure Shared among?', 'Expense Date', 'Comments'
        ]

        self.odd = gridlib.GridCellAttr()
        #self.odd.SetBackgroundColour('sky blue')
        self.even = gridlib.GridCellAttr()
示例#15
0
    def __init__(self, datas):
        grid.PyGridTableBase.__init__(self)

        self.datas = datas
        self.colLabels = [
            u'试卷名', u'制卷人', u'制卷人账号', u'考试成绩', u'测试开始时间', u'测试结束时间', u'测试时长'
        ]

        self.odd = grid.GridCellAttr()
        self.odd.SetReadOnly(True)
        self.odd.SetBackgroundColour('yellow')
        self.even = grid.GridCellAttr()
        self.even.SetReadOnly(True)
        pass
示例#16
0
    def __init__(self, parent, sheet, rowInfo, colInfo, cellInfo, flag):
        grid.Grid.__init__(self, parent, -1, size=(450, 200))
        self.table = DiffTable(sheet, rowInfo, colInfo, cellInfo, flag)
        self.SetTable(self.table, True)
        self.SetRowLabelSize(0)
        self.SetMargins(0, 0)
        self.AutoSizeColumns(False)
        self.mapping = self.table.GetMapping()
        self.initData = self.table.initData
        self.flag = flag

        # 逐个设置单元格只读
        # 没找到其他便捷方法
        for row in range(self.table.GetRowsCount()):
            for col in range(self.table.GetColsCount()):
                self.SetReadOnly(row, col)

        for row in range(len(rowInfo)):
            diffType = rowInfo[row][0:1]
            if diffType == 'd':
                # attr不能复用,每行都需要独自的attr
                attrDel = grid.GridCellAttr()
                attrDel.SetBackgroundColour("#CD2990")
                self.SetRowAttr(row, attrDel)
            elif diffType == 'a':
                attrAdd = grid.GridCellAttr()
                attrAdd.SetBackgroundColour("#B0E2FF")
                self.SetRowAttr(row, attrAdd)
        for row in range(len(colInfo)):
            diffType = colInfo[row][0:1]
            if diffType == 'd':
                # attr不能复用,每行都需要独自的attr
                attrDel = grid.GridCellAttr()
                attrDel.SetBackgroundColour("#CD2990")
                self.SetColAttr(row + 1, attrDel)
            elif diffType == 'a':
                attrAdd = grid.GridCellAttr()
                attrAdd.SetBackgroundColour("#B0E2FF")
                self.SetColAttr(row + 1, attrAdd)

        cellMapping = self.table.mapping['cell']
        for info in cellInfo:
            if flag == 'B':
                row, col = cellMapping[info[0][0]][info[0][1]]
            elif flag == 'A':
                row, col = cellMapping[info[1][0]][info[1][1]]
            self.SetCellBackgroundColour(row, col, wx.YELLOW)

        self.Bind(grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)
        self.SetSelectionBackground(wx.BLUE)
示例#17
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)
示例#18
0
    def __init__(self, datas):
        grid.GridTableBase.__init__(self)

        self.datas = datas

        self.colLabels = [u'File Name', u'File Path', u'Page Num']

        self.odd = grid.GridCellAttr()
        self.odd.SetReadOnly(True)
        self.odd.SetBackgroundColour('white')

        self.even = grid.GridCellAttr()
        self.even.SetReadOnly(True)

        pass
示例#19
0
    def __init__(self, header=None, log=None):
        gridlib.PyGridTableBase.__init__(self)
        self.log = log
        self.header = header
        self.defattr = gridlib.GridCellAttr()
        self.defattr.SetReadOnly()
        self.defattr.SetBackgroundColour(wx.WHITE)

        self.cod_attr = gridlib.GridCellAttr()
        self.cod_attr.SetReadOnly()
        self.cod_attr.SetBackgroundColour(wx.WHITE)

        self.dataset = None
        #        from ic.imglib import newstyle_img
        img_rndr = xpr.stateImageRenderer(newstyle_img.folder)
        self.cod_attr.SetRenderer(img_rndr)
示例#20
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()
示例#21
0
 def attribut(self, ref='paire'):
     attr = grid.GridCellAttr()
     if ref == 'paire':
         attr.SetBackgroundColour(images.couleur('grille_paire'))
         attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
         attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
         attr.SetReadOnly(True)
     elif ref == 'impaire':
         attr.SetBackgroundColour(images.couleur('grille_impaire'))
         attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
         attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
         attr.SetReadOnly(True)
     elif ref == 'selection':
         attr.SetBackgroundColour(images.couleur('selection'))
         attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
         attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
         attr.SetReadOnly(True)
     elif ref == 'entete1':
         attr.SetBackgroundColour(images.couleur('gradient1'))
         attr.SetTextColour(images.couleur('texte'))
         attr.SetFont(wx.Font(14, wx.ROMAN, wx.ITALIC, wx.BOLD))
         attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
         attr.SetReadOnly(True)
     elif ref == 'entete2':
         attr.SetBackgroundColour(images.couleur('gradient1'))
         attr.SetTextColour(images.couleur('texte'))
         attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
         attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
         attr.SetReadOnly(True)
     return attr
示例#22
0
 def OnFontPickerChanged(self, event):
     """Change the Font."""
     font = self.font_picker.GetSelectedFont()
     attr = gridlib.GridCellAttr()
     attr.SetFont(font)
     self.grid.SetGridCellAttr(attr)
     self.main_sizer.Fit(self.panel)
示例#23
0
    def GetAttr(self, row, col, someExtraParameter):
        hCellAlign = None
        if col in self.leftAlignCols:
            hCellAlign = wx.ALIGN_LEFT
        elif self.rightAlign:
            hCellAlign = wx.ALIGN_RIGHT

        rc = (row, col)
        key = (self.textColour.get(rc, None),
               self.backgroundColour.get(rc, None), col, hCellAlign)
        try:
            attr = self.attrs[key]
        except KeyError:
            # Create an attribute for the cache.
            attr = Grid.GridCellAttr()
            attr.SetReadOnly(1)  # All cells read-only.
            if rc in self.textColour:
                attr.SetTextColour(self.textColour[rc])
            if rc in self.backgroundColour:
                attr.SetBackgroundColour(self.backgroundColour[rc])
            if hCellAlign is not None:
                attr.SetAlignment(hAlign=hCellAlign, vAlign=wx.ALIGN_CENTRE)

            renderer = self.colRenderer.get(col, None)
            if renderer:
                attr.SetRenderer(renderer.Clone())
            self.attrs[key] = attr

        attr.IncRef()
        return attr
示例#24
0
 def Align_Col ( self, col,
                 align_hor = wx.ALIGN_LEFT,
                 align_ver = wx.ALIGN_CENTER ) :
   attr1 = gridlib.GridCellAttr()
   attr1.SetAlignment ( align_hor, align_ver )
   attr1.IncRef()       # Robin Dunn !!
   self.SetColAttr ( col, attr1 )
示例#25
0
    def __init__(self):  # , editor_context):
        grid.PyGridTableBase.__init__(self)
        # self._ctx = editor_context
        self._objects = []

        self._cell_attr = ca = grid.GridCellAttr()
        ca.SetReadOnly(True)
    def __init__(self, parent, nRows, fnSortEvent):
        gridlib.Grid.__init__(self, parent, -1, size=wx.Size(550, 200))
        self.fnSortEvent = fnSortEvent
        self.CreateGrid(nRows, len(COLFIELDS))  # e.g. (40 rows, 5 cols)

        self.SetRowLabelSize(22)
        self.SetColLabelValue(COL_FILENAME, "Filename")
        self.SetColLabelValue(COL_NEWNAME, "New name")
        self.SetColLabelValue(COL_SIZE, "Size")

        # set size
        self.SetColSize(0, 175)
        self.SetColSize(1, 175)

        # note: create a new GridCellAttr for each c.
        # if you reuse a GridCellAttr you get "C++ assertion "m_count > 0" failed" on app exit
        for c in (COL_FILENAME, COL_SIZE):
            attrReadonly = gridlib.GridCellAttr()
            attrReadonly.SetReadOnly()
            self.SetColAttr(c, attrReadonly)

        self.EnableDragRowSize(False)

        # events
        self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick)
        self.GetGridWindow().Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
示例#27
0
    def __init__(self, parent, log):
        gridlib.Grid.__init__(self, parent, -1)
        self.log = log

        self.CreateGrid(10, 3)

        # Somebody changed the grid so the type registry takes precedence
        # over the default attribute set for editors and renderers, so we
        # have to set null handlers for the type registry before the
        # default editor will get used otherwise...
        #self.RegisterDataType(wxGRID_VALUE_STRING, None, None)
        #self.SetDefaultEditor(MyCellEditor(self.log))

        # Or we could just do it like this:
        #self.RegisterDataType(wx.GRID_VALUE_STRING,
        #                      wx.GridCellStringRenderer(),
        #                      MyCellEditor(self.log))
        #                       )

        # but for this example, we'll just set the custom editor on one cell
        self.SetCellEditor(1, 0, MyCellEditor(self.log))
        self.SetCellValue(1, 0, "Try to edit this box")

        # and on a column
        attr = gridlib.GridCellAttr()
        attr.SetEditor(MyCellEditor(self.log))
        self.SetColAttr(2, attr)
        self.SetCellValue(1, 2, "or any in this column")

        self.SetColSize(0, 150)
        self.SetColSize(1, 150)
        self.SetColSize(2, 150)
示例#28
0
    def GetAttr(self, row, col, kind):
        """
		"""

        attr = gridlib.GridCellAttr()
        val = self.GetValue(row, col)

        ### format font of attr
        if col == 0:
            attr.SetReadOnly(True)
            attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
            #attr.SetBackgroundColour("light blue")
        elif col == 2:
            attr.SetReadOnly(True)
            attr.SetFont(wx.Font(10, wx.SWISS, wx.ITALIC, wx.NORMAL))
        else:
            ### load color in cell for pen and fill
            if isinstance(val, list):
                ### if elem in list begin by #. It is color.
                for s in filter(lambda a: a.startswith('#'), map(str, val)):
                    attr.SetBackgroundColour(s)
                    break

        ### TODO : a ameliorer car bad_filename_path_flag ne prend pas en compte python_path. relechir sur comment faire en sorte de ne pas donner la main a la simlation
        ### en fonction de la validite des deux criteres plus bas

        ### if the path dont exists, background color is red
        try:

            ### if the type of cell is string
            if isinstance(val, (str, unicode)):

                if col == 1:

                    v = self.GetValue(row, 0)

                    ### if bad filemane (for instance generator)
                    m = re.match('[a-zA-Z]*(ile)[n|N](ame)[_-a-zA-Z0-9]*', v,
                                 re.IGNORECASE)

                    ### if filename is match and not exist (ensuring that the filename are extention)
                    if m is not None and not os.path.exists(
                            self.GetValue(row, 1)) and os.path.splitext(
                                self.GetValue(row, 1))[-1] != '':
                        self.bad_flag.update({v: False})
                        attr.SetBackgroundColour("pink")

                    ### if the python path is not found
                    if v == "python_path":
                        ### si un le modèle est un fichier python et que le path n'existe pas ou si c'est un amd ou cmd et que le fichier modèle n'existe pas
                        if (not os.path.exists(self.model.python_path) and not zipfile.is_zipfile(self.model.model_path)) or\
                         (not os.path.exists(self.model.model_path) and zipfile.is_zipfile(self.model.model_path)):
                            self.bad_flag.update({v: False})
                            attr.SetBackgroundColour("pink")

            return attr

        except Exception, info:
            sys.stderr.write(_('Error in GetAttr : %s' % info))
            return
示例#29
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 = Grid.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
示例#30
0
    def _updateColAttrs(self, grid):
        """
        Update the column attributes for the given Grid and add the
        appropriate renderer.

        Argument
        grid: The grid view to update.
        """
        colNum = 0

        for colName in self.colNames:
            attr = Grid.GridCellAttr()
            if colName in self.renderers:
                renderer = self.renderers[colName](self)

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

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

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

            grid.SetColAttr(colNum, attr)
            colNum += 1