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
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: