I am calling wx.TheClipboard.GetData() in an UpdateUI handler and this
works fine in Windows, but it will not work properly in GTK. The GTK
implementation of GetData() calls gtk_main_iteration() while waiting
for the clipboard data. Unfortunately this causes the UpdateUI handler
to be called again, recursively. When it tries to reopen the already
opened clipboard, it fails. If I only reopen the clipboard if it's
closed, the second call to GetData() segfaults. The only way this can
work is to manually guard against recursion.
Luke McCarthy wrote:
I am calling wx.TheClipboard.GetData() in an UpdateUI handler and this
works fine in Windows, but it will not work properly in GTK. The GTK
implementation of GetData() calls gtk_main_iteration() while waiting
for the clipboard data. Unfortunately this causes the UpdateUI handler
to be called again, recursively. When it tries to reopen the already
opened clipboard, it fails. If I only reopen the clipboard if it's
closed, the second call to GetData() segfaults. The only way this can
work is to manually guard against recursion.
>
I found this too, I had to adjust the frequency of my UI handler so that
it wouldn't call it too often, but was slowing down my handlers for the
other menu items
What I do is this.
if _id == wx.ID_PASTE: # check this less frequently
self.count += 1
if self.count == 5:
self.can_paste = False
if self.util.get_clipboard():
self.can_paste = True
self.count = 0
try:
event.Enable(self.can_paste)
self.menu.Enable(ID_PASTE_NEW, self.can_paste)
self.menu.Enable(wx.ID_PASTE, self.can_paste)
except wx.PyDeadObjectError:
pass
return
my update interval is 65ms, and it only checks the clipboard once every
5 iterations, so every 325ms the clipboard is checked; giving the other
menu items more time to check themselves. The menu seems pretty
responsive to update when I do copy something into the clipboard so it
seems to be a decent workaround.
···
--
Steven Sproat, BSc
http://www.basicrpg.com/
Do you really need to get the data object in the UPdateUI handler, or is just checking the type of the available data object with IsSupported enough?
···
On 11/2/09 8:16 AM, Luke McCarthy wrote:
I am calling wx.TheClipboard.GetData() in an UpdateUI handler and this
works fine in Windows, but it will not work properly in GTK. The GTK
implementation of GetData() calls gtk_main_iteration() while waiting
for the clipboard data. Unfortunately this causes the UpdateUI handler
to be called again, recursively. When it tries to reopen the already
opened clipboard, it fails. If I only reopen the clipboard if it's
closed, the second call to GetData() segfaults. The only way this can
work is to manually guard against recursion.
--
Robin Dunn
Software Craftsman
Calling IsSupported() causes the same problem as GetData().
···
On Nov 3, 7:14 am, Robin Dunn <ro...@alldunn.com> wrote:
Do you really need to get the data object in the UPdateUI handler, or is
just checking the type of the available data object with IsSupported enough?--
Robin Dunn
Software Craftsmanhttp://wxPython.org