Andres
Andres

Reputation: 5187

How can I get consistent behavior on my wxPython StyledTextControl?

I am having a problem with wxPython. I am attempting to have a scrollable window without a visible scroll bar. I still want to be able to use the mouse wheel to scroll as well as use the keyboard shortcuts that I have written.

I have the following simplified code:

import wx
import wx.stc

app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY, "Sample Scroll pane")

textViewer = wx.stc.StyledTextCtrl(frame, wx.ID_ANY)
textViewer.Text = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22"

textViewer.SetUseVerticalScrollBar(False)
textViewer.ScrollLines(1)

frame.Show()
app.MainLoop()

I am using the "ScrollLines" function to scroll my text programatically. On a windows machine this works as expected and scrolls down one line. However, on Ubuntu, the text does not scroll if the "SetUseVerticalScrollBar" is false.

How can I hide my scrollbar while maintaining it's functionality in a cross platform manner?

Upvotes: 0

Views: 259

Answers (1)

robots.jpg
robots.jpg

Reputation: 5161

ScrollToLine seems to work consistently on Windows and Linux, so you could replace the ScrollLines call with something like this:

first = textViewer.GetFirstVisibleLine()
textViewer.ScrollToLine(first + n)

where n is the number of lines to scroll down.

Upvotes: 1

Related Questions