TextCtrl does not scroll?

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

It might be that you need to add style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER to the TextCtrl.

···

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

That didn’t seem to do anything either -

self.txt = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH|wx.TE_PROCESS_ENTER, pos=(150,350), size=(680,200))

···

On Saturday, March 16, 2013 10:19:26 PM UTC, Yoriz wrote:

It might be that you need to add style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER to the TextCtrl.

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

I’ve also tried to put SetInsertionPoint too, but it doesn’t seem to make the text scrollable either.

···

On Saturday, March 16, 2013 10:19:26 PM UTC, Yoriz wrote:

It might be that you need to add style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER to the TextCtrl.

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

I put your TextCtrl line into some wx code so it could be run and the box scrolls as it should do

import wx

text = ‘’’
import wx

class MainFrame(wx.Frame):
def init(self, *args, **kwargs):
super(MainFrame, self).init(*args, **kwargs)
self.panel = MainPanel(self)
fsizer = wx.BoxSizer(wx.VERTICAL)
fsizer.Add(self.panel, 1, wx.EXPAND)
self.SetSizer(fsizer)

    self.Layout()
    self.Fit()

class MainPanel(wx.Panel):
def init(self, *args, **kwargs):
super(MainPanel, self).init(*args, **kwargs)
self.txt = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE |
wx.TE_RICH | wx.TE_PROCESS_ENTER,
size=(680, 200))
‘’’

class MainFrame(wx.Frame):
def init(self, *args, **kwargs):
super(MainFrame, self).init(*args, **kwargs)
self.panel = MainPanel(self)
fsizer = wx.BoxSizer(wx.VERTICAL)
fsizer.Add(self.panel, 1, wx.EXPAND)
self.SetSizer(fsizer)

    self.Layout()
    self.Fit()

class MainPanel(wx.Panel):
def init(self, *args, **kwargs):
super(MainPanel, self).init(*args, **kwargs)
self.txt = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE |
wx.TE_RICH | wx.TE_PROCESS_ENTER,
size=(680, 200))

    self.txt.SetValue(text)

if name == ‘main’:
wxapp = wx.App(False)
mainFrame = MainFrame(None)
mainFrame.Show()
wxapp.MainLoop()

···

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

Odd, yours works fine. But it still doesn’t work for my application.

self.txt = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH|wx.TE_PROCESS_ENTER, pos=(150,350), size=(680,200))

self.txt.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u’Consolas’))

panel.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)

self.textFiles = glob.glob(r’.\Basic*.txt’)

That’s the whole code for the textCtrl.

I also use this, as you suggested to load the text file

self.txt.LoadFile(os.path.join(TEXT_DIR, self.text.next()))

···

On 16 March 2013 22:37, Yoriz oldknackers@googlemail.com wrote:

I put your TextCtrl line into some wx code so it could be run and the box scrolls as it should do

import wx

text = ‘’’
import wx

class MainFrame(wx.Frame):
def init(self, *args, **kwargs):
super(MainFrame, self).init(*args, **kwargs)
self.panel = MainPanel(self)

    fsizer = wx.BoxSizer(wx.VERTICAL)
    fsizer.Add(self.panel, 1, wx.EXPAND)
    self.SetSizer(fsizer)

    self.Layout()
    self.Fit()

class MainPanel(wx.Panel):
def init(self, *args, **kwargs):

    super(MainPanel, self).__init__(*args, **kwargs)

    self.txt = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE |
                           wx.TE_RICH | wx.TE_PROCESS_ENTER,

size=(680, 200))
‘’’

class MainFrame(wx.Frame):
def init(self, *args, **kwargs):
super(MainFrame, self).init(*args, **kwargs)
self.panel = MainPanel(self)

    fsizer = wx.BoxSizer(wx.VERTICAL)
    fsizer.Add(self.panel, 1, wx.EXPAND)
    self.SetSizer(fsizer)

    self.Layout()
    self.Fit()

class MainPanel(wx.Panel):
def init(self, *args, **kwargs):

    super(MainPanel, self).__init__(*args, **kwargs)

    self.txt = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE |
                           wx.TE_RICH | wx.TE_PROCESS_ENTER,

size=(680, 200))

    self.txt.SetValue(text)

if name == ‘main’:
wxapp = wx.App(False)
mainFrame = MainFrame(None)
mainFrame.Show()

wxapp.MainLoop()

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/UzBSMfhJctE/unsubscribe?hl=en-US.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Sion Jones wrote:

Odd, yours works fine. But it still doesn't work for my application.

     self.txt = wx.TextCtrl(self,
style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH|wx.TE_PROCESS_ENTER,
  pos=(150,350), size=(680,200))
     self.txt.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0,
u'Consolas'))
     panel.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
     self.textFiles = glob.glob(r'.\Basic\*.txt')

That's the whole code for the textCtrl.

I also use this, as you suggested to load the text file
self.txt.LoadFile(os.path.join(TEXT_DIR, self.text.next()))

Please make a runnable, small as possible, sample application that
demonstrates the problem, and let us know the platform and wx version.
http://wiki.wxpython.org/MakingSampleApps

···

--
Robin Dunn
Software Craftsman

Does your text file have all the text on one line?

···

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

No, I have separated some lines.

···

On Saturday, March 16, 2013 10:50:26 PM UTC, Yoriz wrote:

Does your text file have all the text on one line?

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

I have made a little test to see if it would work, and it does!

import wxversion

wxversion.select(“2.8”)

import wx

import os

import glob

TEXT_DIR = os.path.expanduser(‘./Basic’)

class DIter:

#“Iterable with next and previous”

def init(self, ItemList):

#“Creator”

self.ItemList = ItemList

self.Index = -1

self.ListEnd = len(ItemList)

def next(self):

“”" Return the next item “”"

self.Index += 1

self.Index %= self.ListEnd # or to avoid wrapping self.Index = min([self.Index, self.ListEnd-1])

return self.ItemList[self.Index]

def prev(self):

#“”" Return the previous item “”"

self.Index -= 1

if self.Index < 0:

self.Index = self.Index = 0 #self.ListEnd-1 # or to avoid wrapping

return self.ItemList[self.Index]

class Frame(wx.Frame):

def init(self, parent, id):

wx.Frame.init(self,parent,id, size = (1000,800))

panel=wx.Panel(self, -1)

btn4 = wx.Button(self, label=“Next”, pos=(660, 250), size=(110, 40))

btn4.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u’Consolas’))

self.Bind(wx.EVT_BUTTON, self.loadImage, btn4)

self.text = DIter([filename for filename in os.listdir(TEXT_DIR) if any(filename.lower().endswith(ext) for ext in (‘.txt’))])

self.txt = wx.TextCtrl(self, style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH|wx.TE_PROCESS_ENTER, pos=(150,350), size=(680,200))

self.txt.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u’Consolas’))

def loadImage(self, event):

self.txt.LoadFile(os.path.join(TEXT_DIR, self.text.next()))

if name==‘main’:

wxapp = wx.App(False)

mainFrame = Frame(parent=None, id=-1)

mainFrame.Show()

wxapp.MainLoop()

So why doesn’t it work in my main application!

···

On Saturday, March 16, 2013 10:44:32 PM UTC, Robin Dunn wrote:

Sion Jones wrote:

Odd, yours works fine. But it still doesn’t work for my application.

 self.txt = wx.TextCtrl(self,

style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH|wx.TE_PROCESS_ENTER,

pos=(150,350), size=(680,200))

 self.txt.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0,

u’Consolas’))

 panel.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
 self.textFiles = glob.glob(r'.\Basic\*.txt')

That’s the whole code for the textCtrl.

I also use this, as you suggested to load the text file

self.txt.LoadFile(os.path.join(TEXT_DIR, self.text.next()))

Please make a runnable, small as possible, sample application that

demonstrates the problem, and let us know the platform and wx version.

http://wiki.wxpython.org/MakingSampleApps


Robin Dunn

Software Craftsman

http://wxPython.org

I see a pos attribute , have you got things set up in such a way that the scrollbar is there but pos and size is such that its outside of the viewable area?
As Robin said you need to make a runnable sample app.

···

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

Well if you look at the small runnable sample app i did it works.

And I basically use the same code from the main application.

The position and size is not outside the viewable area.

···

On Saturday, March 16, 2013 11:00:13 PM UTC, Yoriz wrote:

I see a pos attribute , have you got things set up in such a way that the scrollbar is there but pos and size is such that its outside of the viewable area?
As Robin said you need to make a runnable sample app.

On Saturday, March 16, 2013 9:44:25 PM UTC, Sion Jones wrote:

Hello,

I’ve recently used the Textctrl method, so that a text file is loaded into a text box using this.

I’ve notice though, when the text overlaps the box, you cannot scroll to see the rest of the text.

Anyway around this?

Thanks

Sion

Sion Jones wrote:

Well if you look at the small runnable sample app i did it works.
And I basically use the same code from the main application.
The position and size is not outside the viewable area.

Figure out what is different. Experiment with them one by one to eliminate things that are not problems. Whatever is left at the end is the cause of your problem.

···

--
Robin Dunn
Software Craftsman

Got it!

Changed -

self.txt = wx.TextCtrl(panel, style=wx.TE_MULTILINE, pos=(150,350), size=(680,200))

instead of the wx.TextCtrl(self… that was there I changed it to panel. Which is odd, how does this effect it really?

Anyway, glad it’s sorted! Cheers guys. As always, full of great insight.

···

On Sunday, March 17, 2013 1:38:49 AM UTC, Robin Dunn wrote:

Sion Jones wrote:

Well if you look at the small runnable sample app i did it works.

And I basically use the same code from the main application.

The position and size is not outside the viewable area.

Figure out what is different. Experiment with them one by one to
eliminate things that are not problems. Whatever is left at the end is
the cause of your problem.


Robin Dunn

Software Craftsman

http://wxPython.org

Sion Jones wrote:

Got it!

Changed -

self.txt = wx.TextCtrl(panel, style=wx.TE_MULTILINE, pos=(150,350),
size=(680,200))

instead of the wx.TextCtrl(self..... that was there I changed it to
panel. Which is odd, how does this effect it really?

The parent parameter specifies who owns the widget, and on whom it will be displayed, and other little tidbits. When you used self as the parent then that made the textctrl a sibling of the panel, (assuming self was the parent of panel) but you were probably trying to manage its layout as if it was a child of the panel.

···

--
Robin Dunn
Software Craftsman

Ah right. I usually look at examples of widgets and then copy some of the code, so usually I forget about this.

···

On Monday, March 18, 2013 4:40:59 PM UTC, Robin Dunn wrote:

Sion Jones wrote:

Got it!

Changed -

self.txt = wx.TextCtrl(panel, style=wx.TE_MULTILINE, pos=(150,350),

size=(680,200))

instead of the wx.TextCtrl(self… that was there I changed it to

panel. Which is odd, how does this effect it really?

The parent parameter specifies who owns the widget, and on whom it will
be displayed, and other little tidbits. When you used self as the
parent then that made the textctrl a sibling of the panel, (assuming
self was the parent of panel) but you were probably trying to manage its
layout as if it was a child of the panel.


Robin Dunn

Software Craftsman

http://wxPython.org