dialogs/IDManager.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 05 Oct 2022 16:10:17 +0200
branchwxPython4
changeset 3617 c3aae4c95bc1
parent 2492 7dd551ac2fa0
child 3750 f62625418bff
permissions -rw-r--r--
Runtime: work around 1s delay added when using twisted reactor's callLater.

Since wxPython4, using wxReactor from non-main thread was producing
exceptions in wxWidget's C++ code. Then reactor.run() was called from
main thread, and runtime's worker was delegating calls to reactor
with callLater(0, callable).

While this worked perfectly with wxReactor, it did introduce an unexplained
1 second delay to each worker call when using nomal linux reactors
(i.e. without wxPython). As a workaround reactor runs in a thread when using
twisted without wxPython
from __future__ import absolute_import

import wx
from controls.IDBrowser import IDBrowser


class IDManager(wx.Dialog):
    def __init__(self, parent, ctr):
        self.ctr = ctr
        wx.Dialog.__init__(self,
                           name='IDManager', parent=parent,
                           title=_('URI Editor'),
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           size=(800, 600))
        # start IDBrowser in manager mode
        self.browser = IDBrowser(self, ctr)
        self.Bind(wx.EVT_CHAR_HOOK, self.OnEscapeKey)

    def OnEscapeKey(self, event):
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_ESCAPE:
            self.EndModal(wx.ID_CANCEL)
        else:
            event.Skip()