is there a way to hide a wx.frame without destroying it?

1,156 views
Skip to first unread message

t gillespie

unread,
Mar 12, 2015, 7:02:47 AM3/12/15
to wxpytho...@googlegroups.com
i would like to hide the frame without it losing all of its data and continuing to update the controls, is there a method to do that?

currently using :

 def Back_Button(self, event):
    print "Indicator From Diagnostic"
    frame = DiagnosticIndicators()
    frame.Show()
    self.Hide()

Tim Roberts

unread,
Mar 12, 2015, 12:45:22 PM3/12/15
to wxpytho...@googlegroups.com
The "Hide" method does exactly that. This code isn't right, however.
Is this just pseudo-code typed from memory? You aren't passing any
parameters here. If DiagnosticIndicators is supposed to be a subwindow,
then you'd need to pass "self" to it as a parent. And if you want to
show and hide the DiagnosticIndicators, then you want frame.Hide, not
self.Hide. Also, if you're going to make it visible at a later time,
you'll need to save frame in a member variable so you can refer to it.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

t gillespie

unread,
Mar 12, 2015, 1:56:55 PM3/12/15
to wxpytho...@googlegroups.com
no that is the actual code i am using, only been using python for a week or less. got about 1000 lines of code going right now, most of it cobbled together from the very limited information i can find on the web. I have past code experiance though so i am good at reading between the lines, but wxpython seems to be one of those languages that you hate at first then grows on you, and the little caveats to this seem to be where the magic happens.

the code i typed above is actually dealing with two frames, the current one (self) and the one to be displayed, the target device screen is so small that basically i stack the frames ontop of one another and it looks like i changed the screen. so the code above displays the new frame and hides the one it was called from ...

the parent window, is not the (self) window. the hierchy goes like this

MainWindow -> SubMenu -> Mp3 Player
                                      -> GPS
                                      -> GPS Telemetry
                                      -> Graphs
                                      -> Settings
                                      -> Diagnostics
                                      -> Retuen to main
                                      -> power off

is how the windows are layed out then each sub window has a button similar in function to the back button on android where it takes you back one level in the hierarchy

can you give me an example of the modification that should be made to my code sample?
Message has been deleted

Rufus

unread,
Mar 12, 2015, 4:43:30 PM3/12/15
to wxpytho...@googlegroups.com
if DiagnosticIndicators is your wx.Frame subclass, you are completely
recreating your frame every time you push the button.

(if it just returning a frame reference that had been created elsewhere, your code would
make sense, but I don't think that's what you're doing)


I think what you want is something more like:
 
def Back_Button(self, event):
   
print "Indicator From Diagnostic"

   
if self.indicators_frame is None:
         
self.indicators_frame = DiagnosticIndicators()
   
self.indicators_frame.Show()
   
self.Hide()



 
So the first time the button is pressed, the frame is created,
but subsequent presses returns the same frame.


Tim Roberts

unread,
Mar 13, 2015, 12:51:42 PM3/13/15
to wxpytho...@googlegroups.com
t gillespie wrote:
> no that is the actual code i am using, only been using python for a
> week or less. got about 1000 lines of code going right now, most of it
> cobbled together from the very limited information i can find on the
> web. I have past code experiance though so i am good at reading
> between the lines, but wxpython seems to be one of those languages
> that you hate at first then grows on you, and the little caveats to
> this seem to be where the magic happens.

wxPython is not a language. wxPython is just a user interface library
designed for the Python language.


> the code i typed above is actually dealing with two frames, the
> current one (self) and the one to be displayed, the target device
> screen is so small that basically i stack the frames ontop of one
> another and it looks like i changed the screen. so the code above
> displays the new frame and hides the one it was called from ...

If you truly want one window at a time, then it sounds like you need to
write a WindowManager class to ensure that. When one of the frames
wants to move to another frame, it could call into the WindowManager
object with the name or index value telling it which window to show
next. The window manager could then have the smarts to hide the current
window, create the new one if it did not already exist, and show it.
That way, you don't need to spread a bunch of identical code around
several places. Also, by caching the open windows, you don't have to
open multiple copies if you bring up a window several times.

t gillespie

unread,
Mar 20, 2015, 11:24:11 PM3/20/15
to wxpytho...@googlegroups.com
apparently my windows shuffling is not my as apparently something else broke and the script wont even run anymore. Howver i realize wxpython is a library, i meant that python is a language that you hate at first and eventually grows on you . the object i am trying to accomplish here is i have 10 frames, on which are various controls from graphs to gauges to simple indicators, the controls are always collecting data and updating themselves, the user has access to display the controls which just shows the frame they are on, i am doing it this way because the screen on the target application is only 320X240 px there for doing a MDI or even putting them in a notebook is out of the question becasue i dont have the display space. in one of the frames i have a notebook and it takes up almost 10% of the screen in tabs alone. If there was a way to just open all of the windows at runtime and then do something like MyFrame(),BringToFront() that would be perfect. I do not want the frames destroyed every time that they are hidden. and i do have a sort of window manager i suppose its more like a menue with a bunch of buttons on it , when a user uses the touch screen and presses a button the window is supposed to be moved to the front.

Torsten

unread,
Mar 21, 2015, 3:45:02 AM3/21/15
to wxpytho...@googlegroups.com
Hello t_gillespie,

did you take a look at the wizard class? Maybe this is what you want?

Dev Player

unread,
Mar 21, 2015, 4:32:19 AM3/21/15
to wxpython-users
Hiding a frame/widget and destroying a frame or widget are not the same actions. frame.Hide() allows the frame to continue to receive events and be manipulated by other widgets and objects, functions, methods, etc. When you hide a frame, whatever was behind it becomes visible.

For you application, you don't even need to hide a frame. You can also use frame.Raise() however there are minor differences. If a widget (like dialog box) is modal then Raise() will do little for you.

If your screen is so small it is likely that each TopLevelWindow (i.e. each frame) takes up the whole screen. Then Raise() is fine. However if there are frames that do not fill the entire screen then when those smaller frames are on top you will see full size frames behind it. This could cause visual confusion (especially on a small screen). Then Hide() might be better

if button1:
   frame1.Show()
   frame2.Hide()
   frame3.Hide()

if button2:
   frame1.Hide()
   frame2.Show()
   frame3.Hide()

if button3:
   frame1.Hide()
   frame2.Hide()
   frame3.Hide()

and frame1, frame2, and frame3 can continue to receive events and get updated. Personally updating frames that are hidden seem wasteful to me but it depends on your processing load of your app I suppose.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Werner

unread,
Mar 21, 2015, 4:33:33 AM3/21/15
to wxpytho...@googlegroups.com
On 3/21/2015 4:24, t gillespie wrote:
> apparently my windows shuffling is not my as apparently something else
> broke and the script wont even run anymore. Howver i realize wxpython
> is a library, i meant that python is a language that you hate at first
> and eventually grows on you . the object i am trying to accomplish
> here is i have 10 frames, on which are various controls from graphs to
> gauges to simple indicators, the controls are always collecting data
> and updating themselves, the user has access to display the controls
> which just shows the frame they are on, i am doing it this way because
> the screen on the target application is only 320X240 px there for
> doing a MDI or even putting them in a notebook is out of the question
> becasue i dont have the display space. in one of the frames i have a
> notebook and it takes up almost 10% of the screen in tabs alone. If
> there was a way to just open all of the windows at runtime and then do
> something like MyFrame(),BringToFront() that would be perfect. I do
> not want the frames destroyed every time that they are hidden. and i
> do have a sort of window manager i suppose its more like a menue with
> a bunch of buttons on it , when a user uses the touch screen and
> presses a button the window is supposed to be moved to the front.
>
http://wxpython.org/Phoenix/docs/html/Window.html?highlight=raise#Window.Raise

Werner

Vlastimil Brom

unread,
Mar 21, 2015, 12:00:13 PM3/21/15
to wxPython-users
2015-03-21 4:24 GMT+01:00 t gillespie <fatbo...@gmail.com>:
> apparently my windows shuffling is not my as apparently something else broke
> and the script wont even run anymore. Howver i realize wxpython is a
> library, i meant that python is a language that you hate at first and
> eventually grows on you . the object i am trying to accomplish here is i
> have 10 frames, on which are various controls from graphs to gauges to
> simple indicators, the controls are always collecting data and updating
> themselves, the user has access to display the controls which just shows the
> frame they are on, i am doing it this way because the screen on the target
> application is only 320X240 px there for doing a MDI or even putting them in
> a notebook is out of the question becasue i dont have the display space. in
> one of the frames i have a notebook and it takes up almost 10% of the screen
> in tabs alone. If there was a way to just open all of the windows at runtime
> and then do something like MyFrame(),BringToFront() that would be perfect. I
> do not want the frames destroyed every time that they are hidden. and i do
> have a sort of window manager i suppose its more like a menue with a bunch
> of buttons on it , when a user uses the touch screen and presses a button
> the window is supposed to be moved to the front.
>
Hi,
I am not sure, whether it fully fits your requirements, but you could
consider some UI manager like wx.aui or its mor comprehensive and more
recent version wx.lib.agw.aui
cf:
http://www.wxpython.org/docs/api/wx.aui-module.html
a newer docs format for the development version is probably more informative:
http://wxpython.org/Phoenix/docs/html/lib.agw.aui.framemanager.AuiManager.html

You canalso check the features of aui in the wxPython interactive demo
( http://www.wxpython.org/download.php )

While this panel manager is generally used to display and arrange a
larger number of panels at ones on the desktop, you can also hide most
of them and only show the needed ones on demand - e.g. via a menu
button with the respective entries.
I surely adds some complexity to the app, but some useful features for
arranging the panel are handled automatically (e.g. previously used
placement of temporarily hiden panes etc.).
I confess, I didn't use such apps on a touchscreen and I don't know,
how it works on such devices
hth,
vbr

t gillespie

unread,
Mar 21, 2015, 11:34:51 PM3/21/15
to wxpytho...@googlegroups.com
@ torsten : the wizard class seems to be to sequential, as in next and back control, my ap seems to be more random access, maybe they go from window one to window 3 and then back to window one to window 5, and so on from what i read the wizard class goes window one, window 2 window 3.

@DevPlayer : the raise() function i had not seen before but after reading that it may just blink the task bar icon i dont really know if that will work, my code is still broken but when i get it back running i will try this out. as for "Personally updating frames that are hidden seem wasteful to me but it depends on your processing load of your app I suppose." the other frames contain information that is collected in "real time" (haha) so when a user changes the frame from say the mp3 player to the vehicle gauges the gauges cant just say blank, or i suppose a more pertinent example would be the odometer, it cant just loose its count, and i know that the arguement will be that the display should just be updated from local variables that reliably represent the amount, of which i plan to code it this way, the thing that triggered my question in the first place was the mp3 player in which if you closed it and when back to the speedometer or the menu, then opened the mp3 player gain all of the displays were reset and even thought he song was still playing you could play another song at the same time. which is when i discovered that whatever i did to display the frame actually made a new one with a new mplayer control, allowinf two songs to messily play simultaneously.

@werner: thanks for the link

@vbr: wx.aui looks to be more like an MDI interface. which trust in the fact that if i had enough space on that tiny little screen i would probably go MDI but alas i do not, and from the examples i looked up it would appear that all of the sub windows can be tiled any which way in the parent. the best biug program example i can think of off the top of my head is wx.aui works like GIMP or Photoshop?

t gillespie

unread,
Mar 22, 2015, 1:01:51 AM3/22/15
to wxpytho...@googlegroups.com
if you call a frame like

MyFrame.show()

does it create a new instance or just show the class?

because im pretty sure

NewFrame = Myframe()
NewFrame. Show()

creates a new instance.

Werner

unread,
Mar 22, 2015, 3:14:11 AM3/22/15
to wxpytho...@googlegroups.com
On 3/22/2015 6:01, t gillespie wrote:
> if you call a frame like
>
> MyFrame.show()
>
> does it create a new instance or just show the class?
just shows it if you spell it correctly;-) , i.e. Show and not show.
>
> because im pretty sure
>
> NewFrame = Myframe()
that creates the instance
> NewFrame. Show()
this shows it, so at this point you can do:

NewFrame.Hide()
do some stuff
NewFrame.Show()
etc etc

Werner

Torsten

unread,
Mar 22, 2015, 3:38:18 AM3/22/15
to wxpytho...@googlegroups.com
Am Sonntag, 22. März 2015 04:34:51 UTC+1 schrieb t gillespie:
@ torsten : the wizard class seems to be to sequential, as in next and back control, my ap seems to be more random access, maybe they go from window one to window 3 and then back to window one to window 5, and so on from what i read the wizard class goes window one, window 2 window 3

You can always change the order of the pages.


 Am Samstag, 21. März 2015 09:32:19 UTC+1 schrieb DevPlayer:
If your screen is so small it is likely that each TopLevelWindow (i.e. each frame) takes up the whole screen. Then Raise() is fine. However if there are frames that do not fill the entire screen then when those smaller frames are on top you will see full size frames behind it. This could cause visual confusion (especially on a small screen). Then Hide() might be better

if button1:
   frame1.Show()
   frame2.Hide()
   frame3.Hide()

What about using one Frame and multiple Panels and showing/hiding them? See the attached example. 
multipanels.py

Dev Player

unread,
Mar 25, 2015, 12:57:37 PM3/25/15
to wxpython-users
Some various minor approaches or ideas for implementing multi-frames:
version d is unnecessarily comment heavy. 

multiframe_version_a.py
multiframe_version_b.py
multiframe_version_c.py
multiframe_version_d.py

Robin Dunn

unread,
Mar 26, 2015, 3:00:23 AM3/26/15
to wxpytho...@googlegroups.com
Torsten wrote:
> Am Sonntag, 22. März 2015 04:34:51 UTC+1 schrieb t gillespie:

> What about using one Frame and multiple Panels and showing/hiding them?

That is what I would suggest too, especially for a constrained display
size. It lets you easily swap views programatically in a single window
without needing any extra screen space.

--
Robin Dunn
Software Craftsman
http://wxPython.org

t gillespie

unread,
Mar 31, 2015, 3:07:00 AM3/31/15
to wxpytho...@googlegroups.com

sadly..  or maybe wisely I am beginning to see this as correct simple because the event handler can be all in one place neater shorter code.. arg.  recoding. lol.  and with the new job I got yesterday it's gonna be a minute.  maybe sometime this week.  I'll be sure to report back when I blow it up.

--
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/alidSRya9tI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages