Using StaticText with style = ST_ELLIPSIZE_MIDDLE doesn't seem to work

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
MrSurly
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 26, 2020 6:52 pm

Using StaticText with style = ST_ELLIPSIZE_MIDDLE doesn't seem to work

Post by MrSurly »

I have a StaticText box that may be very long (it's a full file path) inside a FlexGridSizer.

When using SetSizer on the window, the FGS simply expands past the edge of the windows and is cut off. The text is never ellipsized.

When using SetSizerAndFit, the window resizes to accommodate the long text. The text is never ellipsized.

Doing any combination of SetMinSize or SetMaxSize on the parent window with SetSizerAndFit results in

Code: Select all

DoSetSizeHints(): min width/height must be less than max width/height!
even if the minsize is lower than the maxsize.

I can use SetMaxSize on the StaticText itself, but I have no idea how to find out the max allowable size is for the particular FlexGridSize cell that it's in.

Additionally, when the StaticText is not in a FGS, and placed directly in the StaticBoxSizer that contains it, it "sorta" works in that it's ellipsized, but only after pushing the StaticBox border all the way out to the window border.

Put Simply: I want a StaticText that will grow to use the available space, and if it's too big for that, then it will be ellipsized.

WRT to this being an XY problem: I'm trying to add extra controls to a FileDialog. Seems that that's impossible in WxPython, so I'm making a separate Dialog with the extra controls that will open a FileDialog when a button is pressed. The StaticText in question is for displaying the selected filename.

Entire class is below:

Code: Select all

class LogDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):
        self.filename = kwargs.pop('defaultFilename', 'log')
        super().__init__(*args, **kwargs)

        self.filename = 'abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyzzabcdefghijklmnopqrstuvwxyz'
        self.SetMaxSize(self.GetSize())
        sizer = wx.BoxSizer()
        #self.SetSizer(sizer)
        self.layout(self, sizer)
        self.SetSizerAndFit(sizer)


    def layout(self, parent, sizer):
        self.panel = panel = wx.Panel(parent)
        sizer.Add(panel, 1, *defaultBorder)
        sb = wx.StaticBox(panel, label='Logging')
        sbs = wx.StaticBoxSizer(sb, wx.VERTICAL)
        panel.SetSizer(sbs)

        fgs = wx.FlexGridSizer(3)
        sbs.Add(fgs, 0, *defaultBorder)
        sbs.FitInside(self)

        t = wx.StaticText(sb, label = 'Format:')
        f = EnumChoice(sb, choices = LogFormatEnum)
        ttt = 'Logfile format.  "Default" matches the original JBD app format.  "Numeric" uses better field names and numeric data fields.'
        t.SetToolTip(ttt)
        f.SetToolTip(ttt)
        fgs.Add(t, 1, rflags)
        fgs.AddSpacer(5)
        fgs.Add(f, 1, lflags)

        t = wx.StaticText(sb, label = 'File:')
        #t2 = wx.StaticText(sb, label = self.filename, style = wx.ST_ELLIPSIZE_MIDDLE)
        t2 = wx.StaticText(sb, style = wx.ST_ELLIPSIZE_END)
        t2.SetLabelText(self.filename)
        #t2.SetMaxSize(self.GetClientSize())

        b = wx.Button(sb, label = 'Choose')
        bs = wx.BoxSizer()
        bs.Add(t2, 1, wx.ALIGN_CENTER_VERTICAL)
        bs.AddSpacer(5)
        bs.Add(b, 0, wx.ALIGN_CENTER_VERTICAL)

        fgs.Add(t, 1, rflags)
        fgs.AddSpacer(5)
        fgs.Add(bs, 0, lflags)

    def openFileDialog(self, evt):
        pass
Post Reply