wxDataViewFloatSpingCustomRender

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

wxDataViewFloatSpingCustomRender

Juvenal Claros
hi every one.
i'm  doing at desktop app i would like use into DataViewListCtrl a FloatSpin control then i was making my custom DataViewFloatSpinRender who extends from DataViewCustomRender(see code below), then i was making my model who is DetalleVentaVirtualListModel who extend from DataViewVirtualListModel.

My question is next when exceute my app dont show the  FloatSpin control class? thank to all for read it


==============other class who addColumn into DataViewListCtrl===============
ctrl.AppendIconTextColumn('Producto', dv.DATAVIEW_CELL_EDITABLE, width=400)
#ctrl.AppendTextColumn('Producto', dv.DATAVIEW_CELL_EDITABLE, width=400)
render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Cantidad', render, 1, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Precio', render, 2, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Descuento(Bs)', render, 3, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Descuento(%)', render, 4, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Monto', render, 5, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

ctrl.AssociateModel(DetalleVentaVirtualListModel(self.model.detalleCompras, sys.stdout))



class DetalleVentaVirtualListModel(dv.DataViewVirtualListModel, dv.DataViewItemObjectMapper):
def __init__(self, data, log=sys.stdout):
dv.DataViewVirtualListModel.__init__(self, len(data))
dv.DataViewItemObjectMapper.__init__(self)
self.data = data
self.log = log
self.UseWeakRefs(True)

def GetItem(self, row):
return self.ObjectToItem(self.data[row])

# Report how many columns this model provides data for.
def GetColumnCount(self):
return 6

# Map the data column numbers to the data type
def GetColumnType(self, col):
mapper = { 0 : 'wxDataViewIconText',
1 : 'float',
2 : 'float',
3.: 'float', # the real value is an int, but the renderer should convert it okay
4 : 'float',
5 : 'float',
}
return mapper[col]

# This method is called to provide the data object for a
# particular row,col
def GetValueByRow(self, row, col):
#self.log.write('GetValueByRow:row<{0}>col<{1}>'.format(row, col))
model = self.data[row]
kwargs = dict()
kwargs['text'] = model.producto.nombre
if model.producto.imagen:
kwargs['icon'] = wx.Icon(os.path.abspath(model.producto.imagen), wx.BITMAP_TYPE_ANY, 10, 10)
mapper = {
0: dv.DataViewIconText(**kwargs),
1: model.cantidad,
2: model.precio,
3: model.descuentoMoneda if model.descuentoMoneda else 0.0,
4: model.descuentoPorcentaje if model.descuentoPorcentaje else 0.0,
5: model.monto
}
return mapper[col]

# This method is called when the user edits a data item in the view.
def SetValueByRow(self, value, row, col):
#self.log.write("SetValueByRow: (%d,%d) %s\n" % (row, col, value))
model = self.data[row]
mapper = {
1: 'cantidad',
2: 'precio',
3: 'descuentoMoneda',
4: 'descuentoPorcentaje',
5: 'monto'
}
if hasattr(model, mapper[col]):
model.__setattr__(mapper[col], value)
return True

# Report the number of rows in the model
def GetCount(self):
# self.log.write('GetCount')
return len(self.data)

# Called to check if non-standard attributes should be used in the
# cell at (row, col)
def GetAttrByRow(self, row, col, attr):
##self.log.write('GetAttrByRow: (%d, %d)' % (row, col))
if col == 3:
attr.SetColour('blue')
attr.SetBold(True)
return True
return False

def DeleteRows(self, rows):
# make a copy since we'll be sorting(mutating) the list
rows = list(rows)
# use reverse order so the indexes don't change as we remove items
rows.sort(reverse=True)

for row in rows:
# remove it from our data structure
del self.data[row]
# notify the view(s) using this model that it has been removed
self.RowDeleted(row)


'''
def AddRow(self, value):
# update data structure
self.data.append(value)
print(len(self.data))
# notify views
self.RowAppended()
print(len(self.data))
'''

class DataViewFloatRender(dv.DataViewCustomRenderer):
def __init__(self, log, value=0.0, min=None, max=None, digits=2, *args, **kw):
dv.DataViewCustomRenderer.__init__(self, *args, **kw)
self.min=min
self.max=max
self.digits=digits
self.log = log
self.value = value

def SetValue(self, value):
#self.log.write('FloatRender.SetValue: {0}\n'.format(value))
self.value = value
return True

def GetValue(self):
#self.log.write('FloatRenderer.GetValue:{0}\n'.fomat(self.value))
return self.value

def GetSize(self):
# Return the size needed to display the value. The renderer
# has a helper function we can use for measuring text that is
# aware of any custom attributes that may have been set for
# this item.

size = self.GetTextExtent(str(self.value))
return wx.Size(size.GetWidth()+50, size.GetHeight())

def Render(self, cell, dc, state):

if state != 0:
self.log.write('Render: %s, %d\n' % (cell, state))

if not state & dv.DATAVIEW_CELL_SELECTED:
# we'll draw a shaded background to see if the rect correctly
# fills the cell
print('selected')
dc.SetBrush(wx.Brush('light grey'))
dc.SetPen(wx.TRANSPARENT_PEN)
cell.Deflate(1, 1)
dc.DrawRoundedRectangle(cell, 2)

# And then finish up with this helper function that draws the
# text for us, dealing with alignment, font and color
# attributes, etc
self.RenderText(str(self.value),
4, # x-offset, to compensate for the rounded rectangles
cell,
dc,
state # wxDataViewCellRenderState flags
)
return True

# The HasEditorCtrl, CreateEditorCtrl and GetValueFromEditorCtrl
# methods need to be implemented if this renderer is going to
# support in-place editing of the cell value, otherwise they can
# be omitted.

def HasEditorCtrl(self):
self.log.write('HasEditorCtrl')
return True

def CreateEditorCtrl(self, parent, labelRect, value):
#self.log.write('CreateEditorCtrl: {0}'.format(value))
kwargs=dict()
if hasattr(self, 'min'):
kwargs['min_val']=self.min
if hasattr(self, 'max'):
kwargs['max_val']=self.max
if hasattr(self, 'digits'):
kwargs['digits']=self.digits

ctrl = floatspin.FloatSpin(parent,
id=wx.ID_ANY,
value=value,
pos=labelRect.Position,
size=labelRect.Size,
**kwargs )
print(ctrl)
return ctrl

def GetValueFromEditorCtrl(self, editor):
#self.log.write('GetValueFromEditorCtrl: %s'%(editor))
return editor.GetValue()

# The LeftClick and Activate methods serve as notifications
# letting you know that the user has either clicked or
# double-clicked on an item. Implementing them in your renderer
# is optional.

def LeftClick(self, pos, cellRect, model, item, col):
self.log.write('LeftClick')
return False

def ActivateCell(self, cellRect, model, item, col, mouseEvent):
self.log.write('ActivateCell')
return False

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wxDataViewFloatSpingCustomRender

Juvenal Claros
i load imagen of the app gui when i click on float value in it dont show floatspin control class


El sábado, 23 de septiembre de 2017, 18:49:36 (UTC-7), Juvenal Claros escribió:
hi every one.
i'm  doing at desktop app i would like use into DataViewListCtrl a FloatSpin control then i was making my custom DataViewFloatSpinRender who extends from DataViewCustomRender(see code below), then i was making my model who is DetalleVentaVirtualListModel who extend from DataViewVirtualListModel.

My question is next when exceute my app dont show the  FloatSpin control class? thank to all for read it


==============other class who addColumn into DataViewListCtrl===============
ctrl.AppendIconTextColumn('Producto', dv.DATAVIEW_CELL_EDITABLE, width=400)
#ctrl.AppendTextColumn('Producto', dv.DATAVIEW_CELL_EDITABLE, width=400)
render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Cantidad', render, 1, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Precio', render, 2, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Descuento(Bs)', render, 3, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Descuento(%)', render, 4, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

render = DataViewFloatRender(sys.stdout, mode=dv.DATAVIEW_CELL_EDITABLE)
column = dv.DataViewColumn('Monto', render, 5, width=100)
#column.Alignment = wx.ALIGN_LEFT
ctrl.AppendColumn(column, 'float')

ctrl.AssociateModel(DetalleVentaVirtualListModel(self.model.detalleCompras, sys.stdout))



class DetalleVentaVirtualListModel(dv.DataViewVirtualListModel, dv.DataViewItemObjectMapper):
def __init__(self, data, log=sys.stdout):
dv.DataViewVirtualListModel.__init__(self, len(data))
dv.DataViewItemObjectMapper.__init__(self)
self.data = data
self.log = log
self.UseWeakRefs(True)

def GetItem(self, row):
return self.ObjectToItem(self.data[row])

# Report how many columns this model provides data for.
def GetColumnCount(self):
return 6

# Map the data column numbers to the data type
def GetColumnType(self, col):
mapper = { 0 : 'wxDataViewIconText',
1 : 'float',
2 : 'float',
3.: 'float', # the real value is an int, but the renderer should convert it okay
4 : 'float',
5 : 'float',
}
return mapper[col]

# This method is called to provide the data object for a
# particular row,col
def GetValueByRow(self, row, col):
#self.log.write('GetValueByRow:row<{0}>col<{1}>'.format(row, col))
model = self.data[row]
kwargs = dict()
kwargs['text'] = model.producto.nombre
if model.producto.imagen:
kwargs['icon'] = wx.Icon(os.path.abspath(model.producto.imagen), wx.BITMAP_TYPE_ANY, 10, 10)
mapper = {
0: dv.DataViewIconText(**kwargs),
1: model.cantidad,
2: model.precio,
3: model.descuentoMoneda if model.descuentoMoneda else 0.0,
4: model.descuentoPorcentaje if model.descuentoPorcentaje else 0.0,
5: model.monto
}
return mapper[col]

# This method is called when the user edits a data item in the view.
def SetValueByRow(self, value, row, col):
#self.log.write("SetValueByRow: (%d,%d) %s\n" % (row, col, value))
model = self.data[row]
mapper = {
1: 'cantidad',
2: 'precio',
3: 'descuentoMoneda',
4: 'descuentoPorcentaje',
5: 'monto'
}
if hasattr(model, mapper[col]):
model.__setattr__(mapper[col], value)
return True

# Report the number of rows in the model
def GetCount(self):
# self.log.write('GetCount')
return len(self.data)

# Called to check if non-standard attributes should be used in the
# cell at (row, col)
def GetAttrByRow(self, row, col, attr):
##self.log.write('GetAttrByRow: (%d, %d)' % (row, col))
if col == 3:
attr.SetColour('blue')
attr.SetBold(True)
return True
return False

def DeleteRows(self, rows):
# make a copy since we'll be sorting(mutating) the list
rows = list(rows)
# use reverse order so the indexes don't change as we remove items
rows.sort(reverse=True)

for row in rows:
# remove it from our data structure
del self.data[row]
# notify the view(s) using this model that it has been removed
self.RowDeleted(row)


'''
def AddRow(self, value):
# update data structure
self.data.append(value)
print(len(self.data))
# notify views
self.RowAppended()
print(len(self.data))
'''

class DataViewFloatRender(dv.DataViewCustomRenderer):
def __init__(self, log, value=0.0, min=None, max=None, digits=2, *args, **kw):
dv.DataViewCustomRenderer.__init__(self, *args, **kw)
self.min=min
self.max=max
self.digits=digits
self.log = log
self.value = value

def SetValue(self, value):
#self.log.write('FloatRender.SetValue: {0}\n'.format(value))
self.value = value
return True

def GetValue(self):
#self.log.write('FloatRenderer.GetValue:{0}\n'.fomat(self.value))
return self.value

def GetSize(self):
# Return the size needed to display the value. The renderer
# has a helper function we can use for measuring text that is
# aware of any custom attributes that may have been set for
# this item.

size = self.GetTextExtent(str(self.value))
return wx.Size(size.GetWidth()+50, size.GetHeight())

def Render(self, cell, dc, state):

if state != 0:
self.log.write('Render: %s, %d\n' % (cell, state))

if not state & dv.DATAVIEW_CELL_SELECTED:
# we'll draw a shaded background to see if the rect correctly
# fills the cell
print('selected')
dc.SetBrush(wx.Brush('light grey'))
dc.SetPen(wx.TRANSPARENT_PEN)
cell.Deflate(1, 1)
dc.DrawRoundedRectangle(cell, 2)

# And then finish up with this helper function that draws the
# text for us, dealing with alignment, font and color
# attributes, etc
self.RenderText(str(self.value),
4, # x-offset, to compensate for the rounded rectangles
cell,
dc,
state # wxDataViewCellRenderState flags
)
return True

# The HasEditorCtrl, CreateEditorCtrl and GetValueFromEditorCtrl
# methods need to be implemented if this renderer is going to
# support in-place editing of the cell value, otherwise they can
# be omitted.

def HasEditorCtrl(self):
self.log.write('HasEditorCtrl')
return True

def CreateEditorCtrl(self, parent, labelRect, value):
#self.log.write('CreateEditorCtrl: {0}'.format(value))
kwargs=dict()
if hasattr(self, 'min'):
kwargs['min_val']=self.min
if hasattr(self, 'max'):
kwargs['max_val']=self.max
if hasattr(self, 'digits'):
kwargs['digits']=self.digits

ctrl = floatspin.FloatSpin(parent,
id=wx.ID_ANY,
value=value,
pos=labelRect.Position,
size=labelRect.Size,
**kwargs )
print(ctrl)
return ctrl

def GetValueFromEditorCtrl(self, editor):
#self.log.write('GetValueFromEditorCtrl: %s'%(editor))
return editor.GetValue()

# The LeftClick and Activate methods serve as notifications
# letting you know that the user has either clicked or
# double-clicked on an item. Implementing them in your renderer
# is optional.

def LeftClick(self, pos, cellRect, model, item, col):
self.log.write('LeftClick')
return False

def ActivateCell(self, cellRect, model, item, col, mouseEvent):
self.log.write('ActivateCell')
return False

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

dont show.png (258K) Download Attachment
ok.png (258K) Download Attachment