473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forcing the position of scroll bars on a wxTextCtrl

Hello, this is my first post here so apologies if it's in the wrong
place, inappropriate or embarrassingly stupid - please let me know :)

My problem seems quite simple - I've redirected stdout to a wxTextCtrl,
so that any trace messages appear in a log window at the bottom of my
app. The problem is that whenever I update the text, the scrollbar
resets to the top - i.e. to the earliest log message. What I really
want it to do is reset to the bottom, so that the most recent log
messages are on screen.

Calling SetScrollPos( GetScrollRange( ) ) sets the scrollbar slider to
the correct position, but *doesn't update the text in the window* :(

Is there a call to tell it to update the visible text based on the new
slider position? Or is there a better way to update the slider
position, e.g. by sending the control an event?

I'm new to wxWindows and new to Python, so any help (and as much
detail!) as possible would be appreciated! Here's the class I'm using
to capture stdout:

class LogControl:
""" Simple helper to redirect stdout to a panel in the GUI """
def __init__( self, textCtrl ):
self._ctrl = textCtrl
self._log = ""
self.write( "Applicatio n Started...\n" )

def write( self, Message ):
self._log = self._log + Message
self._ctrl.SetV alue( self._log )
# Force scroll bars to end of window - does not update text in
control!
self._ctrl.SetS crollPos( wx.VERTICAL,
self._ctrl.GetS crollRange( wx.VERTICAL) )

Thanks!

Nov 2 '05 #1
4 8711
Someone who's probably not really called Clans Of Intrigue wrote:
Hello, this is my first post here so apologies if it's in the wrong
place, inappropriate or embarrassingly stupid - please let me know :)
No, that's ok. The wxpython mailing list might give better answers though.
My problem seems quite simple - I've redirected stdout to a wxTextCtrl,
so that any trace messages appear in a log window at the bottom of my
app. The problem is that whenever I update the text, the scrollbar
resets to the top - i.e. to the earliest log message. What I really
want it to do is reset to the bottom, so that the most recent log
messages are on screen.


It's a few years since I coded wx, but I guess you should do
something along the lines of:

self._ctrl.Show Position(self._ ctrl.GetLastPos ition())

Don't mess manually with the scroll bars (I think).

(I know I've gone through this once...)
Nov 2 '05 #2
Thanks, that did the trick perfectly :)

also got rid of the self._log member so the class is now just:

class LogControl:
""" Simple helper to redirect stdout to a panel in the GUI """
def __init__( self, textCtrl ):
self._ctrl = textCtrl
self.write( "Applicatio n Started..." )

def write( self, Message ):
# Add message to log and force scroll bars to end of window
self._ctrl.SetV alue( self._ctrl.GetV alue() + Message )
self._ctrl.Show Position(self._ ctrl.GetLastPos ition())

Lovely :)

Nov 2 '05 #3
Hello Clans,

as a first suggestion, it is usually recommended that you post a small
*working* sample, in order to help others in understanding the problem and
also to give others the possibility to test your code. Noting that I am not
able to run your code as it is, I can just speculate one suggestion:
Calling SetScrollPos( GetScrollRange( ) ) sets the scrollbar slider to
the correct position, but *doesn't update the text in the window* :(


This is because SetScrollPos only affects scrollbars, not the wx.TextCtrl
itself. What happens if you add a self._ctrl.Refr esh() after the
SetScrollPos() call? Something like:

class LogControl:
""" Simple helper to redirect stdout to a panel in the GUI """
def __init__( self, textCtrl ):
self._ctrl = textCtrl
self._log = ""
self.write( "Applicatio n Started...\n" )

def write( self, Message ):
self._log = self._log + Message
self._ctrl.SetV alue( self._log )
# Force scroll bars to end of window - does not update text in
control!
self._ctrl.SetS crollPos(wx.VER TICAL, self._ctrl.GetS crollRange(
wx.VERTICAL))
self._ctrl.Refr esh()
I also suggest that you use AppendText() instead of the bunch of calls to
write(). Something along the lines (untested code!!!):

class LogControl:
""" Simple helper to redirect stdout to a panel in the GUI """
def __init__( self, textCtrl ):
self._ctrl = textCtrl
self._log = ""
self.write( "Applicatio n Started...\n" )

def write( self, Message ):
self._log = self._log + Message
self._ctrl.Appe ndText( self._log )
# Force scroll bars to end of window - does not update text in control!
# self._ctrl.SetS crollPos(wx.VER TICAL, self._ctrl.GetS crollRange(
wx.VERTICAL))
# self._ctrl.Refr esh()
HTH.

Andrea.

"Imaginatio n Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77
Nov 2 '05 #4
Clans Of Intrigue wrote:
Thanks, that did the trick perfectly :)

also got rid of the self._log member so the class is now just:

class LogControl:
""" Simple helper to redirect stdout to a panel in the GUI """
def __init__( self, textCtrl ):
self._ctrl = textCtrl
self.write( "Applicatio n Started..." )

def write( self, Message ):
# Add message to log and force scroll bars to end of window
self._ctrl.SetV alue( self._ctrl.GetV alue() + Message )
self._ctrl.Show Position(self._ ctrl.GetLastPos ition())


But if you have 100kB text in the control, and add another 1kB log
message, it certainly seems suboptimal to use:
self._ctrl.SetV alue( self._ctrl.GetV alue() + Message )
Here, you first copy all the text in the control to a Python
string, build a new string with old+new text, and replace the old
text with the context of this bigger string. You should simply use
self._ctrl.Appe ndText( Message ). I'm not sure exactly what happens
under he hood, but I suspect that's more efficient, besides being
prettier in the source...

Thou shalt study thy libraries and strive not to reinvent them
without cause, that thy code may be short and readable and thy
days pleasant and productive.

E.g. http://www.wxpython.org/docs/api/wx.TextCtrl-class.html
Nov 3 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
12744
by: Arlie Rahn | last post by:
I would like to ad a custom scroll bar control to my app that has a customizable and "flat" look to it (not the normal VB look). Does anyone have any ideas on where to find a good one?
5
8783
by: Analysis&Solutions | last post by:
Hey Folks: I'm probably dreaming here, but perhaps there's a way... I just gave a presentation. It's in XHTML and uses CSS for making things look nice. Right now there's a small navigation system on top and the main text area. The presentation is about to be put on the web, so I'd like to add a footer on each page with the presentation name and a link back to the main site.
2
1810
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB code provided on the website. Once I have this example running correctly, I will need to use the concept in a more complex project. The code I am using involves an webform and an htc file. The code for ScrollPos.htc (which is located in a folder...
2
8517
by: Leonid Shirmanov | last post by:
Hi, I have a form with control placed on it. Control has the image painted on its graphics. Size of the contol is greater than size of the form and scroll bars appear in the form. I scroll the image to the end (i.e. bottom-right edge). After this, I open other form as modal dialog and after closing this modal form control with image scrolled to
2
2227
by: usenet | last post by:
When I open a form design window in Access 2003 it *always* has scroll bars, this is even when the form itself is tiny. It's as if the 'page' on which the form is being designed is very large. Is this normal? If so it's very annoying and confusing. If not then how do I get it so my form design window doesn't have scroll bars. -- Chris Green
3
6062
by: zazu | last post by:
We have a database that can be accessed by a small number of users on a small network. The database is on the server. One form has a combo box with a large number of selections. Usually there is a scroll bar on the right hand side when the combo box is selected. One user comments that he doesn't always get the scroll bar. The problem is variable - excuse the pun - sometimes the scroll bar is never there, sometimes it disappears after a...
1
2413
by: David_from_Chicago | last post by:
I am developing an application in Access 2000 (A2K) which has multiple forms and subforms. Until now, all subforms displayed scroll bars properly (according to the subform's property setting). However, a new subform control will not display horizontal scroll bars despite it's form's property setting. I have tried deleting and recreating both the subform control and the subform itself thinking this would address the issue. I also tried...
5
10116
by: Lord Zoltar | last post by:
Hello, I'm trying to force a listView to scroll to some location when a certain button is clicked on. I've found that the SendMessage function seems to be the choice way of doing it. Here's what I've put in my button handler: //somewhere else in my code: private const int WM_VSCROLL = 277; // Vertical scroll .. ..
6
4615
by: bgold12 | last post by:
I was using quirks mode (without a doctype) and set the overflow CSS property to :auto for the body tag like so: <body style="overflow:auto"> And it worked; it got rid of IE's default scroll bars. However, when I tried to add any doctype at all (HTML strict, HTML loose, XHTML transitional, XHTML strict, etc.), it stopped working. Do I have any control over IE's scroll bars when using doctypes?
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.