Non-modal dialog

Hi, ALL,
I'm trying to display a non-modal dialog as a custom logger.
Here's what I do:

class Redirect(object):
        def __init__(self, textctrl):
                self.out = textctrl

        def write(self, string):
                wx.CallAfter(self.out.WriteText, string )

class LoggingRedirectHandler(logging.StreamHandler):
        def __init__(self,textctrl):
                logging.StreamHandler.__init__( self )
                self.textctrl = textctrl

        def emit(self, record):
                msg = self.format( record )
                stream = self.stream
                self.textctrl.WriteText( msg + "\n" )
                self.flush

class Executor(wx.Dialog):
        def __init__(self, parent, ID, title, options, path_spec,
size=wx.DefaultSize, pos=wx.DefaultPosition,
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME ):
                self.options = options
                self.path_spec = path_spec
                wx.Dialog.__init__( self, parent, ID, title, pos, size, style )
                sizer1 = wx.BoxSizer( wx.VERTICAL )
                self.log = wx.TextCtrl( self, -1, "",
wx.DefaultPosition, ( 300, 300 ), wx.TE_MULTILINE )
                sizer1.Add( self.log, 1, wx.EXPAND, 0 )
                sizer2 = wx.BoxSizer( wx.HORIZONTAL )
                self.done = wx.Button( self, -1, "Close Window" )
                self.done.Enable( False )
                sizer2.Add( self.done, 1, wx.EXPAND |
wx.ALIGN_CENTER_HORIZONTAL, 0 )
                sizer1.Add( sizer2, 0, wx.EXPAND, 0 )
                self.SetSizer( sizer1 )
                sizer1.Fit( self )

        def OnShowExecutor(self):
                format_str = "[%(levelname)s] %(message)s"
                logging.basicConfig( level=logging.INFO, format=format_str )
                self.logger = logging.getLogger()
                redir = Redirect( self.log )
                sys.stdout = redir
                sys.stderr = redir
                logger_stream_handler = LoggingRedirectHandler( self.log )
                self.logger.addHandler( logger_stream_handler )
                try:
                    self.Show()
                    logging.info("Logging check")
               except Exception as e:
                    print e

Unfortunately the dialog is not displayed properly and hence there is
nothing in the text control.
What am I doing wrong?

Thank you.

Almost forgot. :wink:
I'm on WinXP SP3 with python 2.7 and wxPython 3.0 (classic).

Thank you.

···

On Sun, Jun 8, 2014 at 3:08 AM, Igor Korot <ikorot01@gmail.com> wrote:

Hi, ALL,
I'm trying to display a non-modal dialog as a custom logger.
Here's what I do:

class Redirect(object):
        def __init__(self, textctrl):
                self.out = textctrl

        def write(self, string):
                wx.CallAfter(self.out.WriteText, string )

class LoggingRedirectHandler(logging.StreamHandler):
        def __init__(self,textctrl):
                logging.StreamHandler.__init__( self )
                self.textctrl = textctrl

        def emit(self, record):
                msg = self.format( record )
                stream = self.stream
                self.textctrl.WriteText( msg + "\n" )
                self.flush

class Executor(wx.Dialog):
        def __init__(self, parent, ID, title, options, path_spec,
size=wx.DefaultSize, pos=wx.DefaultPosition,
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME ):
                self.options = options
                self.path_spec = path_spec
                wx.Dialog.__init__( self, parent, ID, title, pos, size, style )
                sizer1 = wx.BoxSizer( wx.VERTICAL )
                self.log = wx.TextCtrl( self, -1, "",
wx.DefaultPosition, ( 300, 300 ), wx.TE_MULTILINE )
                sizer1.Add( self.log, 1, wx.EXPAND, 0 )
                sizer2 = wx.BoxSizer( wx.HORIZONTAL )
                self.done = wx.Button( self, -1, "Close Window" )
                self.done.Enable( False )
                sizer2.Add( self.done, 1, wx.EXPAND |
wx.ALIGN_CENTER_HORIZONTAL, 0 )
                sizer1.Add( sizer2, 0, wx.EXPAND, 0 )
                self.SetSizer( sizer1 )
                sizer1.Fit( self )

        def OnShowExecutor(self):
                format_str = "[%(levelname)s] %(message)s"
                logging.basicConfig( level=logging.INFO, format=format_str )
                self.logger = logging.getLogger()
                redir = Redirect( self.log )
                sys.stdout = redir
                sys.stderr = redir
                logger_stream_handler = LoggingRedirectHandler( self.log )
                self.logger.addHandler( logger_stream_handler )
                try:
                    self.Show()
                    logging.info("Logging check")
               except Exception as e:
                    print e

Unfortunately the dialog is not displayed properly and hence there is
nothing in the text control.
What am I doing wrong?

Thank you.

Morning,

While trying to test your code I needed to create a “main app” that would allow launching the dialog window. After I was able to open the dialog window I did not see any issues with the dialog window itself. When you have the opportunity could you attach a small example application that recreates the issue you are experiencing?

Thanks,

  • Mike S
···

On Sunday, June 8, 2014 6:09:01 AM UTC-4, Igor Korot wrote:

Hi, ALL,

I’m trying to display a non-modal dialog as a custom logger.

Here’s what I do:

class Redirect(object):

    def __init__(self, textctrl):

            self.out = textctrl



    def write(self, string):

            wx.CallAfter(self.out.WriteText, string )

class LoggingRedirectHandler(logging.StreamHandler):

    def __init__(self,textctrl):

            logging.StreamHandler.__init__( self )

            self.textctrl = textctrl



    def emit(self, record):

            msg = self.format( record )

            stream = self.stream

            self.textctrl.WriteText( msg + "\n" )

            self.flush

class Executor(wx.Dialog):

    def __init__(self, parent, ID, title, options, path_spec,

size=wx.DefaultSize, pos=wx.DefaultPosition,

style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME ):

            self.options = options

            self.path_spec = path_spec

            wx.Dialog.__init__( self, parent, ID, title, pos, size, style )

            sizer1 = wx.BoxSizer( wx.VERTICAL )

            self.log = wx.TextCtrl( self, -1, "",

wx.DefaultPosition, ( 300, 300 ), wx.TE_MULTILINE )

            sizer1.Add( self.log, 1, wx.EXPAND, 0 )

            sizer2 = wx.BoxSizer( wx.HORIZONTAL )

            self.done = wx.Button( self, -1, "Close Window" )

            self.done.Enable( False )

            sizer2.Add( self.done, 1, wx.EXPAND |

wx.ALIGN_CENTER_HORIZONTAL, 0 )

            sizer1.Add( sizer2, 0, wx.EXPAND, 0 )

            self.SetSizer( sizer1 )

            sizer1.Fit( self )



    def OnShowExecutor(self):

            format_str = "[%(levelname)s] %(message)s"

            logging.basicConfig( level=logging.INFO, format=format_str )

            self.logger = logging.getLogger()

            redir = Redirect( self.log )

            sys.stdout = redir

            sys.stderr = redir

            logger_stream_handler = LoggingRedirectHandler( self.log )

            self.logger.addHandler( logger_stream_handler )

            try:

                self.Show()

                [logging.info](http://logging.info)("Logging check")

           except Exception as e:

                print e

Unfortunately the dialog is not displayed properly and hence there is

nothing in the text control.

What am I doing wrong?

Thank you.