ATR
ATR

Reputation: 36

Unexpected square appear in pure python, but occasionally when pyinstaller-packed

My simple wx app has only one wx.lib.FileBrowseButton & a wx.TextCtrl. It functions normal, but always with a unexpected square appear in the left-top corner, which covers the 'HEX' label, see below screen-shot.

unexpected-square

And if I pack my app with pyinstaller, this square will not always appear. See pic below (nothing over the 'HEX' label). no-square

Here is the app code:

import logging
import os
import time
import sys

import wx
import wx.lib.filebrowsebutton as filebrowse

class FWScripterPanel(wx.Panel):
    def __init__(self, parent, ID):
        wx.Panel.__init__(self, parent, ID)

        self.fbb = filebrowse.FileBrowseButton(self, wx.ID_ANY, size=(450, -1), changeCallback = self.fbbCallback, labelText='HEX', buttonText='Select HEX', fileMask='*.hex', toolTip='Select & transfer a HEX file to script')

        style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL
        self.log = wx.TextCtrl(self, wx.ID_ANY, '', size=(-1, -1), style=style)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.fbb, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)

    def fbbCallback(self, evt):
        path = evt.GetString()
        logging.info(path)
        self.make_script(path)

    def make_script(self, hex_path):
        pass

class FWScripterFrame(wx.Frame):
    """
    """

    def __init__(
            self, parent, ID, title, pos=wx.DefaultPosition,
            size=(800,600), style=wx.DEFAULT_FRAME_STYLE
            ):

        wx.Frame.__init__(self, parent, ID, title, pos, size, style)
        panel = FWScripterPanel(self, -1)


class App(wx.App): 
    def OnInit(self): 
        frame = FWScripterFrame(parent=None, ID=-1, title='20220208') 
        frame.Show() 
        return True 

def main():
    app = App() 
    app.MainLoop()

if __name__ == '__main__':
    main()

And if I remove the wx.TextCtrl, leaving only the filebrowsebutton, then this strage little square will not appeared at all. Same issue when I add a new filebrowsebutton before the first filebrowsebutton (the 2nd filebrowsebutton will be covered by a little square)

Upvotes: 0

Views: 32

Answers (1)

ATR
ATR

Reputation: 36

Finally I solved the problem by adding one line 'self.Layout()' in the FWScripterPanel.init(), see below.

class FWScripterPanel(wx.Panel):
    def __init__(self, parent, ID):
        wx.Panel.__init__(self, parent, ID)

        self.fbb = filebrowse.FileBrowseButton(self, wx.ID_ANY, size=(450, -1), changeCallback = self.fbbCallback, labelText='HEX', buttonText='Select HEX', fileMask='*.hex', toolTip='Select & transfer a HEX file to script')

        style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL
        self.log = wx.TextCtrl(self, wx.ID_ANY, '', size=(-1, -1), style=style)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.fbb, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)
        self.Layout()  # Add this line to solve the 'square' issue

WhenAndHowToCallLayout The above link provides quite a lot helpful information. Hope it helps.

Upvotes: 1

Related Questions