Robin Dunn wrote:
Please send a full sample that shows the problem, (and don't quote an entire
web page when replying.
(a) The sample is below. The problem is at line 87.
(b) Sorry about the web page with the last posting.
from wxPython.wx import *
class CheckBox(wxTextCtrl):
''' Effects of various keys:
Tab Move on to the next item
Space bar Setting toggled
Double Click Setting toggled
Del Set FALSE - Blank
Other Set TRUE - X (or other specified symbol)
'''
def __init__(self, parent, name= 'CheckBox', value= TRUE, pos= (-1, -1),
size= (-1, -1), symbol= 'X'):
self.value= value
self.symbol= symbol
wxTextCtrl.__init__(self, parent, -1, self.displayValue(), pos= pos,
## size= wxSize(17, 22), name= name)
size= wxSize(40, 22), name= name) # Temp for test
print '__init__:', self, self.value
self.SetBackgroundColour(wxLIGHT_GREY)
self.Refresh()
EVT_CHAR(self, self.OnChar)
EVT_KILL_FOCUS(self, self.OnKillFocus)
EVT_LEFT_DCLICK(self, self.OnLeftDoubleClick)
EVT_SET_FOCUS(self, self.OnFocus)
EVT_TEXT(self, self.GetId(), self.OnText)
def displayValue(self):
print 'display value:', self.value
if self.value:
vValue= self.symbol
else:
vValue= ''
return vValue
def OnLeftDoubleClick (self, event):
print 'OnLeftDoubleClick value:', self.value
self.value= not self.value
self.SetValue(self.displayValue())
self.Refresh()
def OnChar(self, event):
global alternate
print 'CheckBox: On Char', event.GetId(), event.GetKeyCode()
c= event.GetKeyCode()
if c in [WXK_TAB, WXK_RETURN]:
event.Skip()
else:
if c == WXK_SPACE:
if self.value:
self.value= FALSE
else:
self.value= TRUE
elif c == WXK_DELETE :
self.value= FALSE
else:
self.value= TRUE
v= self.displayValue()
'''
Robin Dunn wrote:
The only think I can think of is that the debugger has confused what self
is. What does it do if you don't run it from within PythonWin? What does
it do if you call
controlsc.wxTextCtrl_SetValue(self, "CCC")
?
CASE 1
self.SetValue(v)
before1 SetValue v= 'X' type(v)= <type 'string'>
Value: 1 X
TypeError: not enough arguments; expected 3, got 2
CASE 2
self.SetValue(1, v)
File "g:\program files\python20\wxPython\controls.py", line 513, in
SetValue
val = apply(controlsc.wxTextCtrl_SetValue,(self,) + _args, _kwargs)
TypeError: wxTextCtrl_SetValue requires exactly 2 arguments; 3 given
CASE 3
controlsc.wxTextCtrl_SetValue(self, "CCC")
before1 SetValue v= 'X' type(v)= <type 'string'>
TypeError: not enough arguments; expected 3, got 2
Value: 1 CCC
TypeError: not enough arguments; expected 3, got 2
'''
print 'before1 SetValue v=' , `v`, ' type(v)=', type(v)
controlsc.wxTextCtrl_SetValue(self, "CCC")
# self.SetValue(v)
print 'Value:', self.value, self.GetValue()
event.Skip()
def OnClose():
print 'CheckBox: OnClose'
event.skip()
def OnFocus(self, event):
print 'CheckBox: OnFocus', event.GetId()
self.SetBackgroundColour(wxColour(0, 255, 255))
self.Refresh()
def OnKillFocus(self, event):
print 'CheckBox: OnKillFocus', event.GetId()
# Restore the display - any non-null value treated as TRUE
self.value= self.GetValue() > ''
self.SetValue(self.displayValue())
self.SetBackgroundColour(wxLIGHT_GREY)
self.Refresh()
def OnText(self, id, event):
print 'CheckBox: OnTEXT id = ', id
if __name__ == '__main__':
# import sys
class MainFrame(wxFrame):
def __init__(self):
try:
wxFrame.__init__(self, NULL, -1, pos= (20, 20), size= (200, 200),
title= "Testing...", name= 'Main Frame')
self.SetBackgroundColour(wxWHITE)
self.CreateStatusBar()
mainmenu = wxMenuBar()
menu = wxMenu()
menu.Append(200, 'E&xit', 'We are finished!')
mainmenu.Append(menu, "&File")
self.SetMenuBar(mainmenu)
EVT_MENU(self, 200, self.OnExit)
EVT_CLOSE(self, self.OnCloseWindow)
rect= self.GetSize()
rect.x+=1
self.SetSize(rect)
print 'Main: End of __init__'
except:
import traceback
print 'TRAP FRAME'
traceback.print_exc() # and you still get your trace
self.Destroy() # causes main loop to exit
return 0
def __int__(self, *args):
print '__int__', args
return 99
def OnSetFocus(self):
print 'OnFocus:'
def OnSize(self):
print 'MainFrame: OnSize'
def OnCloseWindow(self, event):
print 'MainFrame: OnClose Veto=', event.GetVeto(), event.CanVeto()
self.Destroy()
def OnExit(self, event):
print 'Main: OnExit'
self.Close()
class MainPanel(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, -1, pos= (-1, -1), size= (-1, -1))
print 'MainPanel'
z= 1
class TestApp(wxApp):
def OnInit(self):
try:
frame = MainFrame()
p= wxPanel(frame, -1, style= wxTAB_TRAVERSAL)
win1= CheckBox(p, pos= (0, 0), size= (25, 25))
win2= CheckBox(p, pos= (0, 25), size= (25, 25))
win3= CheckBox(p, pos= (0, 50), size= (25, 25))
win4= CheckBox(p, pos= (0, 75), size= (25, 25))
win1.Show(TRUE)
frame.Show(true)
self.SetTopWindow(frame)
print 'End of TestApp.__init__'
return true
except:
import traceback
print 'TRAP FRAME'
traceback.print_exc() # and you still get your trace
self.ExitMainLoop() # causes main loop to exit
return false
app = TestApp(0)
app.MainLoop()
···
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users