wx.TextCtrl maximal line length

Hello list,

I seem to have hit a limit in the wx.TextCtrl, created with
wx.TE_MULTILINE and wx.HSCROLL, when displaying a long line of text.
(long in my case meaning > 12000 characters)
The output is corrupted, as if two lines of text were printed on top of each
other. The control works perfectly for short lines of text.

In fact I want to display two such lines, neatly aligned under each other,
and with differences between them being colored.

Is this a python specific limitation, or a general wxwidgets limitation?
Any other widgets I could use to accomplish my goal?

I am using python 2.3 and wxpython 2.6.3.2.1.2 as packaged on debian unstable.
(This uses the gtk2-unicode version of wxwidgets)

Thanks in advance,
Stefaan.

Hello list,

I seem to have hit a limit in the wx.TextCtrl, created with
wx.TE_MULTILINE and wx.HSCROLL, when displaying a long line of text.
(long in my case meaning > 12000 characters)
The output is corrupted, as if two lines of text were printed on top of each
other. The control works perfectly for short lines of text.

In fact I want to display two such lines, neatly aligned under each other,
and with differences between them being colored.

Are you sure you are going to need to handle lines of >12000 characters?
Seems a bit overkill for line diffs.

Is this a python specific limitation, or a general wxwidgets limitation?
Any other widgets I could use to accomplish my goal?

You may or may not have better luck using a wx.ScrolledPanel and
wx.lib.fancytext .

- Josiah

···

stefaan <stefaan.himpe@gmail.com> wrote:

Hello list,

Are you sure you are going to need to handle lines of >12000 characters?
Seems a bit overkill for line diffs.

Yes I am sure. I'd never try something like that for fun :wink:

You may or may not have better luck using a wx.ScrolledPanel and
wx.lib.fancytext .

No luck going there. (In fact X.org reported a BadAlloc error)
Also StyledTextCtrl shows the same behaviour.

I am now thinking of using a grid, and
putting each character in its own cell.

For the interested people: here's a code fragment
showing the fancytext alloc error.

···

--
import wx
import wx.lib
import wx.lib.scrolledpanel
import wx.lib.fancytext
app = wx.PySimpleApp()
f = wx.Frame(None, -1)
sp = wx.lib.scrolledpanel.ScrolledPanel(f,-1)
s = wx.BoxSizer(wx.VERTICAL)
ft = wx.lib.fancytext.StaticFancyText(sp,-1,"abcd"*2000)
s.Add(ft,flag=wx.ALL|wx.EXPAND,border=10)
sp.SetSizer(s)
sp.SetupScrolling(f)
app.SetTopWindow(f)
f.Show()
app.MainLoop()

--
And here is a code fragment showing weird wx.TextCtrl behavior
(try pressing "end" or scroll past the initially visible characters)

import wx
import wx.lib
app = wx.PySimpleApp()
f = wx.Frame(None, -1)
p = wx.Panel(f,-1)
s = wx.BoxSizer(wx.VERTICAL)
ft = wx.TextCtrl(p,-1,"abcd"*2000)
s.Add(ft,flag=wx.ALL|wx.EXPAND,border=10)
p.SetSizer(s)
app.SetTopWindow(f)
f.Show()
app.MainLoop()

--

Hello Stefaan,

    well, I have tried your latest sample and I don't see how you want
to make 2 lines of the text while you are simply using "abcd"*2000.
Moreover, have you tried wx.TE_RICH2 as a style for the wx.TextCtrl?
Maybe I am completely missing the point here.

Andrea.

···

On 8/12/06, stefaan <stefaan.himpe@gmail.com> wrote:

Hello list,

> Are you sure you are going to need to handle lines of >12000 characters?
> Seems a bit overkill for line diffs.

Yes I am sure. I'd never try something like that for fun :wink:

> You may or may not have better luck using a wx.ScrolledPanel and
> wx.lib.fancytext .

No luck going there. (In fact X.org reported a BadAlloc error)
Also StyledTextCtrl shows the same behaviour.

I am now thinking of using a grid, and
putting each character in its own cell.

For the interested people: here's a code fragment
showing the fancytext alloc error.
--
import wx
import wx.lib
import wx.lib.scrolledpanel
import wx.lib.fancytext
app = wx.PySimpleApp()
f = wx.Frame(None, -1)
sp = wx.lib.scrolledpanel.ScrolledPanel(f,-1)
s = wx.BoxSizer(wx.VERTICAL)
ft = wx.lib.fancytext.StaticFancyText(sp,-1,"abcd"*2000)
s.Add(ft,flag=wx.ALL|wx.EXPAND,border=10)
sp.SetSizer(s)
sp.SetupScrolling(f)
app.SetTopWindow(f)
f.Show()
app.MainLoop()

--
And here is a code fragment showing weird wx.TextCtrl behavior
(try pressing "end" or scroll past the initially visible characters)

import wx
import wx.lib
app = wx.PySimpleApp()
f = wx.Frame(None, -1)
p = wx.Panel(f,-1)
s = wx.BoxSizer(wx.VERTICAL)
ft = wx.TextCtrl(p,-1,"abcd"*2000)
s.Add(ft,flag=wx.ALL|wx.EXPAND,border=10)
p.SetSizer(s)
app.SetTopWindow(f)
f.Show()
app.MainLoop()

--

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/

Hello Andrea,

    well, I have tried your latest sample and I don't see how you want
to make 2 lines of the text while you are simply using "abcd"*2000.
Moreover, have you tried wx.TE_RICH2 as a style for the wx.TextCtrl?
Maybe I am completely missing the point here.

Andrea.

This example is simplified from the original code to highlight
a problem. There's no point in pasting a few hundred of lines of code
here just to show that a long line makes wx.TextCtrl unhappy :wink:

Thanks for trying though!
Best regards,
Stefaan.

Hello list,

> Are you sure you are going to need to handle lines of >12000 characters?
> Seems a bit overkill for line diffs.

Yes I am sure. I'd never try something like that for fun :wink:

Ahh, DNA comparisons of some kind. That's the only place where 12k
characters in one 'line' makes any amount of sense.

> You may or may not have better luck using a wx.ScrolledPanel and
> wx.lib.fancytext .

No luck going there. (In fact X.org reported a BadAlloc error)
Also StyledTextCtrl shows the same behaviour.

Scintilla (the C implementation of the StyledTextCtrl) has a line length
limit of 1024 characters, if I remember correctly.

I am now thinking of using a grid, and
putting each character in its own cell.

You may have trouble making that work. Some platforms have issues with
large numbers of controls being created at one time. But it does
introduce a method that should be fairly extensible; chunk your data.
In my attempts to chunk and add to a sizer on a ScrolledWindow, I
noticed that some wasn't displayed. However, there is another option.

Create a text control without a horizontal scrollbar. Get the Window's
size, and determine the maximum number of characters that can fit in the
window. Use tctrl.SetMaxLength().

Create your own scrollbar with wx.ScrollBar(), and set proper scrolling
information with .SetScrollbar(...). Use the wx.EVT_SCROLL method to
get scrolling events.

When you get a scroll event, get the scrollbar's position, slice into
your two strings, and display only that portion that is usable.

- Josiah

import wx

text1 = 16384*'abcd' #64k of text
text2 = text1[2:]+text1[:2] #offset it by 2 characters for variety

tl = 64 #this will need to be tweaked

class F(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, size=(640, 100))
        
        s = wx.BoxSizer(wx.VERTICAL)
        self.tc1 = wx.TextCtrl(self, style=wx.TE_READONLY)
        self.tc1.SetMaxLength(tl)
        
        s.Add(self.tc1, 0, wx.ALL|wx.EXPAND, 2)
        
        self.tc2 = wx.TextCtrl(self, style=wx.TE_READONLY)
        self.tc2.SetMaxLength(tl)
        
        s.Add(self.tc2, 0, wx.ALL|wx.EXPAND, 2)
        
        self.sc = wx.ScrollBar(self)
        self.sc.SetScrollbar(0, tl, len(text1)-tl, tl, 1)
        
        s.Add(self.sc, 0, wx.ALL|wx.EXPAND, 2)
        
        self.SetSizer(s)
        
        self.Bind(wx.EVT_SCROLL, self.OnScroll)
        wx.CallAfter(self.OnScroll, None)
    
    def OnScroll(self, evt):
        p = self.sc.GetThumbPosition()
        self.tc1.SetValue(text1[p:p+tl])
        self.tc2.SetValue(text2[p:p+tl])

app = wx.App(0)
f = F()
f.Show()
app.MainLoop()

···

stefaan <stefaan.himpe@gmail.com> wrote:

stefaan wrote:

Hello list,

I seem to have hit a limit in the wx.TextCtrl, created with
wx.TE_MULTILINE and wx.HSCROLL, when displaying a long line of text.
(long in my case meaning > 12000 characters)
The output is corrupted, as if two lines of text were printed on top of each
other. The control works perfectly for short lines of text.

In fact I want to display two such lines, neatly aligned under each other, and with differences between them being colored.

Is this a python specific limitation, or a general wxwidgets limitation?

I expect that it is a limitation of the gtk widget being used for the textctrl. It may be that some internal value dealing with the horizontal pixel position is overflowing and so it is wrapping around to a smaller value for the subsequent characters.

Any other widgets I could use to accomplish my goal?

If you don't need to edit the text then I'd suggest using a ScrolledWindow and drawing the text segments yourself, although the ScrolledWindow might have the same problem if the virtual size gets too big. (Some platforms have limits on how big of a coordinate space can be for DC's or windows. In that case I would use an unscrolled window with an added scrollbar and then virtualize the drawing of the visible space of the lines yourself based on the position of the scrollbar.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn <robin <at> alldunn.com> writes:

In that case I would use an unscrolled window
with an added scrollbar and then virtualize the drawing of the visible
space of the lines yourself based on the position of the scrollbar.

Thank you Robin, as far as I can see,
this is the way to go.

Best regards,
Stefaan.

stefaan wrote:

Robin Dunn <robin <at> alldunn.com> writes:

In that case I would use an unscrolled window with an added scrollbar and then virtualize the drawing of the visible space of the lines yourself based on the position of the scrollbar.

Thank you Robin, as far as I can see, this is the way to go.

And probably faster too.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!