validator blues ... UltimateListCtrl and validating a TextCtrl element in a cell

Ok,

so I do have difficulties understanding the validator, i.e. transfering
data.
Short: I want to be able to fill a ListCtrl with data and allow the user
to enter some values which i later transfer back to my dict
I am now on UltimateListCtrl that allows for a textCtrl to be placed in
a cell.
I want to transfer data to it and from it but it does not work - i
basically did what I've been doing w/ textVtrl validators all along
which worked.
MAYBE IT'S JUST THE LACK OF SLEEP BUT I AM STUCK ...

Attached a sample ulc.py based on Andrea's ReportStyle demo

What am I doing wrong?

ThanX

ulc.py (4.17 KB)

UltimateListCtrl.py (268 KB)

Hi,

···

On 25 October 2011 10:26, Tobias Weber wrote:

Ok,

so I do have difficulties understanding the validator, i.e. transfering

data.

Short: I want to be able to fill a ListCtrl with data and allow the user

to enter some values which i later transfer back to my dict

I am now on UltimateListCtrl that allows for a textCtrl to be placed in

a cell.

I want to transfer data to it and from it but it does not work - i

basically did what I’ve been doing w/ textVtrl validators all along

which worked.

MAYBE IT’S JUST THE LACK OF SLEEP BUT I AM STUCK …

Attached a sample ulc.py based on Andrea’s ReportStyle demo

What am I doing wrong?

I am no expert of validators, as I normally prefer another approach to check the validity of the user’s inputs. Anyway, what is it that is not working?

Andrea.

Hi,

Ok,

      so I do have difficulties understanding the validator, i.e.

transfering

      data.

      Short: I want to be able to fill a ListCtrl with data and

allow the user

      to enter some values which i later transfer back to my dict

      I am now on UltimateListCtrl that allows for a textCtrl to be

placed in

      a cell.

      I want to transfer data to it and from it but it does not work
  • i

        basically did what I've been doing w/ textVtrl validators all
    

along

      which worked.

      MAYBE IT'S JUST THE LACK OF SLEEP BUT I AM STUCK ...



      Attached a sample ulc.py based on Andrea's ReportStyle demo





      What am I doing wrong?
      I am no expert of validators, as I normally prefer another

approach to check the validity of the user’s inputs. Anyway,
what is it that is not working?

  Andrea.
1. I am open to whatever works (how would you do it?- I am far from

fluent in wx.Python yet but the validator concept gives me the
creeps) to let me a: insert values in a multiline list with some
cells that accept user input b: lets me read these values back

:-)

2: In my attached sample you see that I have a dict (w/ one

key/value pair) data{}

I created a Ulc and put a textCtrl into the 1st cell- Now I want to

1st transfer the data of that dict to the TextCtrl and later
transfer it back.

But the TextCrtl would not be filled w/ the data, i.e. the

validator’s self.list.TransferDataToWindow() doesn’t do anything …

(The data is read from a SQlite DB into a dictionary. it is a list

of products and I need the user to tell me how many items are
required )

Tobi
···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

Hi,

Ok,

        so I do have difficulties understanding the validator, i.e.

transfering

        data.

        Short: I want to be able to fill a ListCtrl with data and

allow the user

        to enter some values which i later transfer back to my dict

        I am now on UltimateListCtrl that allows for a textCtrl to

be placed in

        a cell.

        I want to transfer data to it and from it but it does not

work - i

        basically did what I've been doing w/ textVtrl validators

all along

        which worked.

        MAYBE IT'S JUST THE LACK OF SLEEP BUT I AM STUCK ...



        Attached a sample ulc.py based on Andrea's ReportStyle demo





        What am I doing wrong?
        I am no expert of validators, as I normally prefer

another approach to check the validity of the user’s inputs.
Anyway, what is it that is not working?

    Andrea.
  1. I am open to whatever works (how would you do it?- I am far

from fluent in wx.Python yet but the validator concept gives me
the creeps) to let me a: insert values in a multiline list with
some cells that accept user input b: lets me read these values
back

  :-)

  2: In my attached sample you see that I have a dict (w/ one

key/value pair) data{}

  I created a Ulc and put a textCtrl into the 1st cell- Now I want

to 1st transfer the data of that dict to the TextCtrl and later
transfer it back.

  But the TextCrtl would not be filled w/ the data, i.e. the

validator’s self.list.TransferDataToWindow() doesn’t do anything

  (The data is read from a SQlite DB into a dictionary. it is a list

of products and I need the user to tell me how many items are
required )

  Tobi

Attached the sample in case it was stripped before

ulc.py (4.17 KB)

UltimateListCtrl.py (268 KB)

···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=enwxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

...

2: In my attached sample

Nothing attached here;-)

Werner

···

On 10/25/2011 10:42 AM, Tobias Weber wrote:

...

2: In my attached sample

Nothing attached here;-)

Werner

pastebin:

Andrea's UltimateListCtrl:

#here as text- have UltimateListCtrl from the demo or Andrea in the same
path

import sys
import os
import wx
import random
import datetime
import math

import wx.lib.mixins.listctrl as listmix
import wx.lib.colourdb as cdb
import wx.lib.colourselect as csel

import UltimateListCtrl as ULC

data = {'CONTRACT_TERM':'TEST'}

class DataXfervalidator(wx.PyValidator):
    def __init__(self, data, key):
        wx.PyValidator.__init__(self)
        self.data = data
        self.key = key
        #self.TransferFromWindow()
        #print "validating"
        print data
        print "VALIDATOR CLASS TRIGGRED"
        print key
       
    def Clone (self):
        print "VAL CLONE TRIGGERED"
        return DataXfervalidator(self.data, self.key)
   
    def Validate(self):
        print 'here we go'
   
    def TransferToWindow(self):
        print "TransferTO"
        print data
        textCtrl = self.GetWindow()
        textCtrl.SetValue(self.data.get(self.key, ""))
        return True

    def TransferFromWindow(self):
        textCtrl = self.GetWindow()
        print "TransferFROM"
        #print textCtrl
        self.data[self.key] = textCtrl.GetValue()
        print data
        return True

class TestUltimateListCtrl(ULC.UltimateListCtrl):
   
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0, extraStyle=0):
       
        ULC.UltimateListCtrl.__init__(self, parent, id, pos, size,
style, extraStyle)
   
class UltimateListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
   
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,
style=wx.WANTS_CHARS|wx.SUNKEN_BORDER)
       
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.list = TestUltimateListCtrl(self, -1,
                                         style=wx.LC_REPORT
                                         #| wx.BORDER_SUNKEN
                                         > wx.BORDER_NONE
                                         > wx.LC_EDIT_LABELS
                                         #| wx.LC_SORT_ASCENDING
                                         #| wx.LC_NO_HEADER
                                         > wx.LC_VRULES
                                         > wx.LC_HRULES,
                                         #| wx.LC_SINGLE_SEL
                                        
extraStyle=ULC.ULC_HAS_VARIABLE_ROW_HEIGHT
                                         )
        sizer.Add(self.list, 1, wx.EXPAND)
       
        self.PopulateList()
        #self.TransferDataFromWindow()
       
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
   
    def PopulateList(self):

        self.list.Freeze()
       
        info = ULC.UltimateListItem()
        info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE |
wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
        info._image =
        info._format = 0
        #info._kind = 1
        info._text = "CONTRACT"
       
        self.list.TransferDataToWindow()
        self.list.InsertColumnInfo(0, info)
        index = self.list.InsertStringItem(sys.maxint,'')
        item = self.list.GetItem(0, 0)
        textctrl = wx.TextCtrl(self.list, -1, "",
validator=DataXfervalidator(data,'CONTRACT_TERM'))
        ##textctrl = wx.TextCtrl(self.list, -1, "", style=wx.TE_MULTILINE)
        item.SetWindow(textctrl)
        self.list.SetItem(item)
        self.list.TransferDataToWindow()
        #self.list.TransferDataFromWindow()
        #textctrl.TransferDataToWindow()
       
        self.list.SetColumnWidth(0, 100)

        self.list.Thaw()
        self.list.Update()
   
class MiniFrame(wx.MiniFrame):
    def __init__(self):
        wx.MiniFrame.__init__(self, None, -1, 'Mini Frame', size=(800,
600),style=wx.DEFAULT_FRAME_STYLE)
        self.ulc = UltimateListCtrlPanel(self)
       
        #button = wx.Button(self.ulc, -1, "Close Me", pos=(15, 15))
        #self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
        #self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
   
    def OnCloseMe(self, event):
        self.Close(True)

    def OnCloseWindow(self, event):
        self.Destroy()

app = wx.PySimpleApp()
MiniFrame().Show()
app.MainLoop()

···

Am 25.10.11 12:35, schrieb werner:

On 10/25/2011 10:42 AM, Tobias Weber wrote:
       
--
--------------------------------------------------
Tobias Weber
CEO

The ROG Corporation GmbH
Donaustaufer Str. 200
93059 Regensburg
Tel: +49 941 4610 57 55
Fax: +49 941 4610 57 56

www.roglink.com

Gesch�ftsf�hrer: Tobias Weber
Registergericht: Amtsgericht Regensburg - HRB 8954
UStID DE225905250 - Steuer-Nr.184/59359
--------------------------------------------------

...

2: In my attached sample

Nothing attached here;-)

Werner

pastebin:

Andrea's UltimateListCtrl:

#here as text- have UltimateListCtrl from the demo or Andrea in the same
path

import sys
import os
import wx
import random
import datetime
import math

import wx.lib.mixins.listctrl as listmix
import wx.lib.colourdb as cdb
import wx.lib.colourselect as csel

import UltimateListCtrl as ULC

data = {'CONTRACT_TERM':'TEST'}

class DataXfervalidator(wx.PyValidator):
    def __init__(self, data, key):
        wx.PyValidator.__init__(self)
        self.data = data
        self.key = key
        #self.TransferFromWindow()
        #print "validating"
        print data
        print "VALIDATOR CLASS TRIGGRED"
        print key
       
    def Clone (self):
        print "VAL CLONE TRIGGERED"
        return DataXfervalidator(self.data, self.key)
   
    def Validate(self):
        print 'here we go'
   
    def TransferToWindow(self):
        print "TransferTO"
        print data
        textCtrl = self.GetWindow()
        textCtrl.SetValue(self.data.get(self.key, ""))
        return True

    def TransferFromWindow(self):
        textCtrl = self.GetWindow()
        print "TransferFROM"
        #print textCtrl
        self.data[self.key] = textCtrl.GetValue()
        print data
        return True

class TestUltimateListCtrl(ULC.UltimateListCtrl):
   
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0, extraStyle=0):
       
        ULC.UltimateListCtrl.__init__(self, parent, id, pos, size,
style, extraStyle)
   
class UltimateListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
   
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,
style=wx.WANTS_CHARS|wx.SUNKEN_BORDER)
       
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.list = TestUltimateListCtrl(self, -1,
                                         style=wx.LC_REPORT
                                         #| wx.BORDER_SUNKEN
                                         > wx.BORDER_NONE
                                         > wx.LC_EDIT_LABELS
                                         #| wx.LC_SORT_ASCENDING
                                         #| wx.LC_NO_HEADER
                                         > wx.LC_VRULES
                                         > wx.LC_HRULES,
                                         #| wx.LC_SINGLE_SEL
                                        
extraStyle=ULC.ULC_HAS_VARIABLE_ROW_HEIGHT
                                         )
        sizer.Add(self.list, 1, wx.EXPAND)
       
        self.PopulateList()
        #self.TransferDataFromWindow()
       
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
   
    def PopulateList(self):

        self.list.Freeze()
       
        info = ULC.UltimateListItem()
        info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE |
wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
        info._image =
        info._format = 0
        #info._kind = 1
        info._text = "CONTRACT"
       
        self.list.TransferDataToWindow()
        self.list.InsertColumnInfo(0, info)
        index = self.list.InsertStringItem(sys.maxint,'')
        item = self.list.GetItem(0, 0)
        textctrl = wx.TextCtrl(self.list, -1, "",
validator=DataXfervalidator(data,'CONTRACT_TERM'))
        ##textctrl = wx.TextCtrl(self.list, -1, "", style=wx.TE_MULTILINE)
        item.SetWindow(textctrl)
        self.list.SetItem(item)
        self.list.TransferDataToWindow()
        #self.list.TransferDataFromWindow()
        #textctrl.TransferDataToWindow()
       
        self.list.SetColumnWidth(0, 100)

        self.list.Thaw()
        self.list.Update()
   
class MiniFrame(wx.MiniFrame):
    def __init__(self):
        wx.MiniFrame.__init__(self, None, -1, 'Mini Frame', size=(800,
600),style=wx.DEFAULT_FRAME_STYLE)
        self.ulc = UltimateListCtrlPanel(self)
       
        #button = wx.Button(self.ulc, -1, "Close Me", pos=(15, 15))
        #self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
        #self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
   
    def OnCloseMe(self, event):
        self.Close(True)

    def OnCloseWindow(self, event):
        self.Destroy()

app = wx.PySimpleApp()
MiniFrame().Show()
app.MainLoop()

···

Am 25.10.11 12:35, schrieb werner:

On 10/25/2011 10:42 AM, Tobias Weber wrote:

I think I would just load the data and save it with a button instead of using validators in this case, see attached.

In case you have lots of items in "data" then you might want to come up with a way of just doing the SaveData bit for the items which have changed.

Werner

listval.py (4.3 KB)

···

On 10/25/2011 12:51 PM, Tobias Weber wrote:

Am 25.10.11 12:35, schrieb werner:

On 10/25/2011 10:42 AM, Tobias Weber wrote:
...

2: In my attached sample

Nothing attached here;-)

Werner