Hi Josiah,
Here is a sample of code that illustrates the problem I have encountered. If you click the "Increment Avar" button, the global value is incremented, however, whenever the ListCtrl is scrolled, the value "Avar = 1" is always printed. Now I can get around this as you mentioned by putting Avar in a global .py file and then importing this .py file in the OnGetItemText callback, and using globModule.Avar everywhere, but this I think people would not generally guess to do!
Thanks for considering all this,
Lee
=== lc.xrc ===
<?xml version="1.0" encoding="iso8859-1"?>
<title></title>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxListCtrl" name="LIST_CTRL" subclass="lc.TraceListCtrl">
<style>wxLC_REPORT|wxLC_VIRTUAL|wxLC_HRULES|wxLC_VRULES</style>
</object>
<option>1</option>
<flag>wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxButton" name="INC_AVAR">
<label>Increment Avar</label>
</object>
<flag>wxALL</flag>
<border>10</border>
</object>
</object>
=== lc.py ===
#!/usr/bin/python
import os, platform, sys import wx, wx.xrc Avar = 1
def getCtrl(ctrlName, parent=None): if not parent: parent = Root
return wx.xrc.XRCCTRL(parent, ctrlName)
class TraceListCtrl(wx.ListCtrl):
def __init__(self): self.PostCreate(wx.PreListCtrl()) self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate) def OnCreate(self, evt): self.attr = wx.ListItemAttr() self.InsertColumn(0, "Col 1")
self.InsertColumn(1, "Col 2")
self.InsertColumn(2, "Col 3")
self.InsertColumn(3, "Col 4")
for col in xrange(4):
self.SetColumnWidth(col, wx.LIST_AUTOSIZE)
self.Unbind(wx.EVT_WINDOW_CREATE)
def OnGetItemText(self, row, col):
if col == 0:
return str(row+1)
print "In OnGetItemText: Avar is %d" % Avar
return "(%d - %d)" % (row+1, col+1)
def OnGetItemAttr(self, row):
return self.attr
class App(wx.App):
def __init__(self, redirect=True, fileName=None):
wx.App.__init__(self, redirect, fileName)
def OnInit(self):
global Root
self.xrc = wx.xrc.XmlResource("lc.xrc")
Root = self.frame = self.xrc.LoadFrame(None, "MAIN_FRAME")
szr = Root.GetSizer()
szr.Fit(Root)
Root.Bind(wx.EVT_BUTTON, self.onButton)
return True
def onButton(self, evt):
global Avar
Avar += 1
print "In onButton: Avar is %d" % Avar
def main():
myApp = App(False)
lc = getCtrl("LIST_CTRL")
lc.SetItemCount(100)
Root.SetSize( (400, 300) )
Root.Show()
Avar = 2
myApp.MainLoop()
if name == “main”:
sys.exit(main())
···
On Fri, 2006-11-10 at 08:10 -0800, Josiah Carlson wrote:
I don't understand what you are trying to say. Show some code with some
context (example names of modules with short example content), and I
will do my best to explain why you are getting the results you are, and
how you can get what you want.
“There is nothing remarkable about it. All one has to do is press the right keys at the right time and the computer programs itself.” (ala J.S. Bach)
Unless otherwise stated, any views presented in this e-mail are solely those of the author and do not necessarily represent those of the company.