wxwidgets / wxpython: how to erase a frame to avoid overpainting?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
wxwidgets / wxpython: how to erase a frame to avoid overpainting?
Hi
This is a really simple question, but so far I have not found a solution that works really.
I am not using dc contexts, but just a frame, a panel and a sizer. When I add text to a sizer, I need to clear that text away, because when I change the text on a new run, the old one is still there.
So far I tried to add an empty bitmap to the same position in the sizer, but that does not work.
How can I erase a sizer grid selectively?
I don't want to erase the whole frame with all widgets on it, since I need them still (menus and such).
Is there a way to erase a panel?
When I add text to a sizer, I need to clear that text away
?!? Why?
Quote:
Originally Posted by browny_amiga
[..] when I change the text on a new run, the old one is still there.
"on a new run"? What do you mean by "new run"?
Quote:
Originally Posted by browny_amiga
So far I tried to add an empty bitmap to the same position in the sizer, but that does not work.
Sounds like you're doing something wrong with the sier or something like that.
Quote:
Originally Posted by browny_amiga
How can I erase a sizer grid selectively?
Normally you would not need to do such things: just replace the string in the control: e.g. call SetText("new text") on your wx.StaticText object or whatever text-displaying-control you use. (what control do you use?)
Quote:
Originally Posted by browny_amiga
I don't want to erase the whole frame with all widgets on it, since I need them still (menus and such).
There should be no need to..
Could you post some code? Without it and without information how you try to display text, and change it, and how your using the sizer etc, its' hard to say what is wrong.
>Sounds like you're doing something wrong with the
>sier or something like that.
>Normally you would not need to do such things:
> just replace the string in the control: e.g. call
> SetText("new text") on your wx.StaticText object >or whatever text-displaying-control you use. (what
>control do you use?)
>There should be no need to..
Aha, so you mean that I do the chain:
add statictext to sizer
when I change the text in statictext, it will automatically change in the sizer?
So far I was trying to add a new statictext to the sizer. Did not know that you can do it the way you described.
I have the same problem over and over: I am writing basically a tutoring appl, in which the user gets shown a text or picture (bitmap) and then has to react to it. Then, it is repeated with a new, random picture or text. Obviously I have to erase the old one. So far I found no way to do it.
Can I also do the trick with the static text with bitmaps? Add the bitmap to a sizer and then reassign to bitmap object to a new picture to have it automatically display in the sizer?
Is there a good book out there for Wxpython?
I think there is hardly any, so far I have not found some. But what about WxWidgets? Because that is the source, ain't it? Everything true to wxwidgets should be true in Wxpython, right?
The thing I am most interested in is the structures and snags: Wxwidgets is old and there is lots of old trash and irregularities inside. I ended up trying to use functions that were depreciated and did not realize it. Or there are 4 functions that seem to do the same things and the names are confusing.
A book about WxWidgets should clean that up.
>Could you post some code? Without it and without
> information how you try to display text,
>and change it, and how your using the sizer etc,
>its' hard to say what is wrong.[/QUOTE]
I would gladly do that, it is just that it is 500 lines long and don't expect people here to wade through endless lines of my code.
Aha, so you mean that I do the chain:
add statictext to sizer
when I change the text in statictext, it will automatically change in the sizer?
So far I was trying to add a new statictext to the sizer. Did not know that you can do it the way you described.
Well. I'm not quite sure still what you mean by "change the sizer". But if I understand you correctly, then the answer is: yes, that is the only reason why sizers exist...
Quote:
Originally Posted by browny_amiga
Can I also do the trick with the static text with bitmaps? Add the bitmap to a sizer and then reassign to bitmap object to a new picture to have it automatically display in the sizer?
Again, I don't really understand what you mean by "display in the sizer".[/quote]
The bitmap, button, staticText, .. whatever wx-control displays in a window (which is: wx.Frame, wx.Panel etc), not in a sizer.
A sizer controls the size of the wx-controls within the window (or possibly the size of the window too).
Quote:
Originally Posted by browny_amiga
Is there a good book out there for Wxpython?
I think there is hardly any, so far I have not found some. But what about WxWidgets? Because that is the source, ain't it? Everything true to wxwidgets should be true in Wxpython, right?
The only book about wxWidgets is the book linked too from the wxWidgets website. But I suppose it is about the C++ library only. But usage of the library is basicaly the same for wxPython, since wx-python is a "just" a python module that maps all the classes and fucntions to the base C++ library below it.
All the documentation is written for C++, but it maps 1-to-1 to python 95% of the times. When there is an exception for python it there is a footnote.
Also deprecated functions are quite clearly documented AFAICS.
It is easier to read the docs if you know a bit about C++ though.
Now I get it, yes. I underestimated what OOP can do.
I before created a static text object, and added that to a sizer. Then, when the text changed, I created a new statictext and added that in the same position to the sizer.
Now, I can just reassign the old statictext object, that is already added to the sizer and through that the text is changed (displaywise).
Thanx for the pointer.
>The bitmap, button, staticText, .. whatever >wx-control displays in a window (which is: >wx.Frame, wx.Panel etc), not in a sizer.
I know that, but you set a sizer for a panel, so in a way it does display in a sizer (because the sizer defines the size and position it will get displayed)
>A sizer controls the size of the wx-controls
>within the window (or possibly the size of the
>window too).
Yeah, as you have said it already ;-)
>The only book about wxWidgets is the book linked
>too from the wxWidgets website. But I suppose it
Hmm, I know that one. But I am not so happy with that one, the way it is written. There must be commercial books, right? WXwidgets is ancient old, so there must be tons of them. I guess time to give amazon a spin.
>is about the C++ library only. But usage of the
>library is basicaly the same for wxPython, since
>wx-python is a "just" a python module that maps
>all the classes and fucntions to the base C++
>library below it.
Well, that is ok, I can deal with that.
>Also deprecated functions are quite clearly
>documented AFAICS.
Well, the documentation is not that accessible, at least not for me. I guess I am not really a programmer.
I before created a static text object, and added that to a sizer. Then, when the text changed, I created a new statictext and added that in the same position to the sizer.
Now, I can just reassign the old statictext object, that is already added to the sizer and through that the text is changed (displaywise).
Why not just do:
Code:
# Create text object
TextObject = wx.StaticText(parent, -1, "This is the text displayed first")
# Add to sizer and so on..
# Then when it is time to change the text, just do:
TextObject.SetLabel("This is the new text")
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.