[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnumed-devel] Using queues to store parameters for parameterized fu
From: |
catmat |
Subject: |
Re: [Gnumed-devel] Using queues to store parameters for parameterized functions put on wxCallAfter queue. |
Date: |
Fri, 10 Dec 2004 22:18:54 +1100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 |
Karsten Hilbert wrote:
I think the bug was in using wxCallAfter. I used wxCallAfter because I
found changing the tree from within an event handler caused core dumps.
Strange. That *should* work, one would suspect ...
But the functions that have to be called from wxCallAfter need
parameters, so the solution
seemed to be to queue the parameters as well.
Nope. CallAfter takes arguments which it then passes to the
first argument as arguments to that function call ... No need
for queuing.
You're right,
wxCallAfter does take arguments.
I tried not using wxCallAfter , and the error does occur.
def start_edit_root_node(self, start_edit_text ):
"""
this handles the problem of no event fired if label unchanged.
By detecting for the return key on the edit control, the start
text
can be compared, and if no change, the node is deleted
in the __key_down handler
"""
root_node = self.get_emr_tree().GetRootItem()
#self.q_edit.put( (root_node, start_edit_text) )
self.start_edit_node(root_node, start_edit_text)
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/wx/_core.py", line 10588, in
<lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "wxpython/gmEMRBrowser.py", line 391, in start_edit_node
wx.EVT_KEY_DOWN( self.edit_control, self.__key_down)
File "/usr/lib/python2.3/site-packages/wx/_core.py", line 2753, in
__call__
self.Bind(target, id1, id2, func)
File "/usr/lib/python2.3/site-packages/wx/_core.py", line 2719, in Bind
target.Connect(id1, id2, et, function)
AttributeError: 'NoneType' object has no attribute 'Connect'
Previously , the node was created outside of wxCallAfter, and the event
handlers to delete it if it wasn't used during edit mode , was
added from within wxCallAfter. So rapid clicking could move the node
from edit mode, to saved mode, before
the event handlers could be added later in wxCallAfter, and adding the
event handlers when the node was already saved
with the default label was too late.
Isn't that an interesting bug ? :-)
Nice catch. But the solution should be far easier than
explicitely using the Queue module (see above).
Karsten
It should, but it doesn't. The ghost edit control on rapid clicking still
occurs.
It's a bit fortuituous I didn't know about the arguments for wxCallAfter().
def start_edit_root_node(self, start_edit_text ):
"""
this handles the problem of no event fired if label unchanged.
By detecting for the return key on the edit control, the start
text
can be compared, and if no change, the node is deleted
in the __key_down handler
"""
root_node = self.get_emr_tree().GetRootItem()
#self.q_edit.put( (root_node, start_edit_text) )
wx.wxCallAfter(self.start_edit_node, root_node, start_edit_text)
def start_edit_node( self, node, start_edit_text):
#node = None
#while True:
# try:
# print "removed edit request"
# old_node = node
# (node, start_edit_text) =
self.q_edit.get_nowait()
# if not old_node is None:
# print "request on old
root_node discarded : ", old_node, start_edit_text
# except Queue.Empty:
# break
if not node is None:
root_node = node
node=
self.get_emr_tree().AppendItem(root_node, start_edit_text)
self.get_emr_tree().EnsureVisible(node)
self.get_emr_tree().EditLabel(node)
self.edit_control =
self.get_emr_tree().GetEditControl()
print self.edit_control
self.start_edit_text = start_edit_text
self.edit_node = node
wx.EVT_KEY_DOWN( self.edit_control,
self.__key_down)
wx.EVT_KILL_FOCUS(self.edit_control,
self.__kill_focus)
else:
print "No node was found"
![PNG image](pngrP2es1GPaJ.png)