problem with displaying multi-line text in wx.TextCtrl - lines wrap although I don't want that!

Hi everybody,

I have a strange little problem with displaying text in a wx.TextCtrl. I have some data that I would like to display in a table-like format in an info window, see first screen shot below. The code for the info window is:

class InfoWindow(wx.MiniFrame):
“”“window to display all kinds of information to the user”""

def __init__(self, parent, ID, title, size=(500, 200)):
    wx.MiniFrame.__init__(self, parent, ID, title, style=wx.CLOSE_BOX | wx.RESIZE_BORDER)
    self.panel = wx.Panel(self)
    self.panel.SetBackgroundColour("white")
    self.textfield = wx.TextCtrl(self.panel, -1, size=size, style=wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_RICH)
    self.sizer = wx.BoxSizer(wx.VERTICAL)
    self.sizer.Add(self.textfield, 1, border=5, flag=wx.EXPAND | wx.ALL)
    self.panel.SetSizerAndFit(self.sizer)
    self.Fit()

and it is called in the program via

def displayInInfoWindow(title, text, size=(500, 200)):
“”“display text in an info window of a given size, with a given title”""
infowindow = InfoWindow(None, -1, title, size)
infowindow.textfield.SetValue(text)
infowindow.Show()

displayInInfoWindow(“Data table looks fine”, durtext, size=(700, 550)) ## looks good
displayInInfoWindow(“Data table looks horrible”, durtext2, size=(700, 550))

At first everything was fine. Then I decided to move the last column a bit further to the right by adding another tab before “(N = …” - and whoa! Suddenly the whole layout was changed. I really don’t understand what the problem is, since the text field is wide enough to accommodate the lines. What’s going wrong here? Any input would be greatly appreciated.

Thanks in advance,

Ingrid

PS: Sample code is attached.

infowindow_problem.py (2.93 KB)

Hi Ingrid,

···

On Friday, September 13, 2013 4:09:23 PM UTC-5, Ingrid wrote:

Hi everybody,

I have a strange little problem with displaying text in a wx.TextCtrl. I have some data that I would like to display in a table-like format in an info window, see first screen shot below. The code for the info window is:

I think for displaying data like that, it would be better to use a different widget, such as a ListCtrl or ObjectListView. I have a couple of tutorials that might help you:

HTH
Mike

Hi Mike,
thanks for your response, and the links to your blog! It’s a great resource; I’ve read a few other posts of yours, and they have been really helpful. Thanks for putting all that information out there! :slight_smile:
I’ll keep the possibility of using ListCtrl or ObjectListView in mind if I ever have to display more complex data. For my info window, however, unfortunately it’s not really a feasible solution, because I need/want a general window to display all kinds of feedback to the users of my program, not just the data table in my example that was causing the problem. Yes, I could use a different form of display for this, but frankly, designing a different window (depending on the type of data) every time I have something to display is too much work for something that is only a tiny part of the functionality of my program.
For now, I’ve removed the offending tab and I’m sticking with my current solution. However, this weird line wrapping business is making me uneasy. I would really like to understand what’s going on here. If anybody can offer some explanation of why this is happening, I would greatly appreciate it!

Again, many thanks!

Ingrid

···

Am Freitag, 13. September 2013 14:19:54 UTC-7 schrieb Mike Driscoll:

Hi Ingrid,

On Friday, September 13, 2013 4:09:23 PM UTC-5, Ingrid wrote:

Hi everybody,

I have a strange little problem with displaying text in a wx.TextCtrl. I have some data that I would like to display in a table-like format in an info window, see first screen shot below. The code for the info window is:

I think for displaying data like that, it would be better to use a different widget, such as a ListCtrl or ObjectListView. I have a couple of tutorials that might help you:

HTH
Mike

Ingrid wrote:

At first everything was fine. Then I decided to move the last column a
bit further to the right by adding another tab before "(N = ..." - and
whoa! Suddenly the whole layout was changed. I really don't understand
what the problem is, since the text field is wide enough to accommodate
the lines. What's going wrong here? Any input would be greatly appreciated.

I'm not sure why it is happening, but it appears to be Mac-specific. It may be just a quirk of the native widget.

···

--
Robin Dunn
Software Craftsman

Hi Robin,

thanks for your answer! I guess there’s not much I can do about it then, other than steer clear of too many tabs… Thanks for the feedback! At least now I know it’s not some stupid mistake on my part.

Ingrid

···

Am Samstag, 14. September 2013 11:35:51 UTC-7 schrieb Robin Dunn:

Ingrid wrote:

At first everything was fine. Then I decided to move the last column a

bit further to the right by adding another tab before “(N = …” - and

whoa! Suddenly the whole layout was changed. I really don’t understand

what the problem is, since the text field is wide enough to accommodate

the lines. What’s going wrong here? Any input would be greatly appreciated.

I’m not sure why it is happening, but it appears to be Mac-specific. It
may be just a quirk of the native widget.


Robin Dunn

Software Craftsman

http://wxPython.org

I’m surprised Robin didn’t mention this, but you could try a different text control widget, such as StyledTextCtrl or maybe try the TextCtrl in Rich Text mode.

  • Mike
···

On Saturday, September 14, 2013 3:14:31 PM UTC-5, Ingrid wrote:

Hi Robin,

thanks for your answer! I guess there’s not much I can do about it then, other than steer clear of too many tabs… Thanks for the feedback! At least now I know it’s not some stupid mistake on my part.

Ingrid