Windows 10, wxPython 4.0.6, Python 3.7.4
I create several sub wx.Frame with style: wx.MINIMIZE_BOX | wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT. When sub frames are showing, after minimize->restore the main frame by clicking the icon on taskbar, the sub frames’ showing order are changed.
Sample code:
Thom,
Thank you for the attachment. But how can I restore the showing order of frames same as the order before minimized. For example, if I set focus to frame2, changing the showing order to be frame1->frame3->frame2. After minimize->restore, how to restore to be the same order?
One could create a list that keeps track of the desired focus order for your subframes. Update the list at every EVT_SET_FOCUS event, i.e. the clicked (focused) subframe should be moved 1st in list.
Operations:
list = [1,2,3], in __init__
click frame2 -> update: list = [2,1,3]
walk the list (reversed) on restore and show the corresponding subframe
be creative
Good luck filling in the rest of the missing blanks yourself.
Thom,
Sorry for late. I used EVT_SET_FOCUS event to count the orders of subframes, but still has problem. When it is restored, all frames are restored in order as my specified list, but after that, frame 2 is set focus unexpectedly. For example, if the list is [1, 2, 3] before minimized, after restore, it changed to be [1, 3, 2].
Please help to check what’s wrong in code?minimized-error.py (2.7 KB)
After a quick code scan it generally seems ok. Have to look into it later this afternoon…
For now - if you haven’t done this yet - I suggest you first debug/watch the relevant events with WIT aka Widget Inspection Tool. I suspect that EVT_SET_FOCUS itself triggers an unhandled EVT_CHILD_FOCUS (sub)event which might disrupt things.
Thom,
I have used inspection tool, but it seems there is a little difference. When using the inspection tool, after restore, list is changed from [1,2,3] to [2,3,1]. In the last, subframe1’s EVT_CHILD_FOCUS event is triggered.
I have changed the code. When main window is minimized, adding the process for hiding sub windows. Then show sub window when main window is restored. It seems work, but I’m not sure whether there is any other problem. minimized-error-ok.py (2.9 KB)
Found 1 error: after subframe delete and minimize:
Traceback (most recent call last):
File "minimized-error-ok.py", line 33, in OnMinimize
frame.Hide()
RuntimeError: wrapped C/C++ object of type MyFrame has been deleted
I’ve further tested and refactored your code:
add OnClose method to cater for orderList error when subframe deleted (and minimize main)
add OnSetFocus method: aggregate from 3 OnSetFocus[123] methods
__init__: remove local funcList, combine subframes attribute binds
use of f-strings (does not work with python < 3.6)
add name parameter in MyFrame for use in close/focus methods
Thom,
Thank you very much! I have added OnClose on my program, but forgot to add it on the sample code. The use of f-strings is new to me. Thank you for the reduced code. I have learned a lot.
Linda