[wxpython-users] How to make frame apear in foreground temporarily ?

516 views
Skip to first unread message

Barak, Ron

unread,
Jan 28, 2009, 4:47:40 AM1/28/09
to wxpytho...@lists.wxwidgets.org

Hi,

I'm trying to find a combination of wx.Frame styles that can give me the following behaviour:

  1. when the frame is created, it would appear on top of its parent.
  2. clicking on the parent will bring the parent to the foreground.
Best I could do, after consulting http://docs.wxwidgets.org/stable/wx_wxframe.html, is using style=wx.DEFAULT_FRAME_STYLE|wx.STAY_ON_TOP or style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT. These would answer requirement 1.
 
I cannot find the right combination of frame styles that would fulfil requirement 1 and 2.
Also, I cannot find a method that would allow me to change frame's styles after the frame is created.
 
Does anyone have an idea for requirement 2 ?
 
Thanks,
Ron.


Mike Driscoll

unread,
Jan 28, 2009, 9:16:26 AM1/28/09
to wxpytho...@lists.wxwidgets.org
Barak, Ron wrote:
>
> Hi,
>
> I'm trying to find a combination of wx.Frame styles that can give me
> the following behaviour:
>
> 1. when the frame is created, it would appear /on top/ of its parent.
> 2. clicking on the parent will bring /the parent/ to the foreground.

>
> Best I could do, after consulting
> http://docs.wxwidgets.org/stable/wx_wxframe.html, is
> using style=wx.DEFAULT_FRAME_STYLE|wx.STAY_ON_TOP or
> style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT. These would
> answer requirement 1.
>
> I cannot find the right combination of frame styles that would fulfil
> requirement 1 /and/ 2.

> Also, I cannot find a method that would allow me to change frame's
> styles /after/ the frame is created.

>
> Does anyone have an idea for requirement 2 ?
>
> Thanks,
> Ron.
>
>

You should be able to call Raise() on the 2nd frame which should put it
in front of the first frame, although not necessarily centered on top of
it. Then you'll be able to click the 1st frame and bring it to the front.

This use case sounds kind of weird though. Most of the time when I have
my application open a secondary frame, I make the secondary frame into a
modal dialog.

I'm not aware of a way to change a frame's style after it is created.
Why do you want to do that?

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Barak, Ron

unread,
Jan 28, 2009, 11:03:55 AM1/28/09
to mi...@pythonlibrary.org, wxpytho...@lists.wxwidgets.org

Hi Mike,

Implementing what you suggest (I think) does not give me the expected results.
Namely, when OnItemSelected is activated and creates a new instance of ListControl, the parent is on top, even though there's a Raise() on the child.

#!/usr/bin/env python
 
import sys
import wx
 
class ListControl(wx.Frame):
    def __init__(self, parent, id, title, list, max_list_width):
        wx.Frame.__init__(self,parent,id,title,size=(-1,-1), style=wx.DEFAULT_FRAME_STYLE)
        #wx.Frame.__init__(self,parent,id,title,size=(-1,-1), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)

        self.list = list
        self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT| wx.LC_NO_HEADER)
        self.list_ctrl.InsertColumn(0, title)
        for i,line_ in enumerate(list):
            self.list_ctrl.InsertStringItem(i, line_)
        self.list_ctrl.SetColumnWidth(0, max_list_width)
 
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list_ctrl)
 
        self.Raise()
        self.Show(True)
 
    def OnItemSelected(self, evt):
        item = evt.GetText()
        max_list_width = 10 * len(item)
        ListControl(self, -1, item, item, max_list_width)
 
if __name__ == "__main__":
    list = [   "First Line", "Second Line", "Third Line"]
    app = wx.App(redirect=False)
    max_list_width = 6 * max([len(x) for x in list])
    ListControl(None, -1, "Parent Window", list, max_list_width)
    app.MainLoop()
 
 
If I change the style to style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT, then the child is always on top, and clicking on the parent does not bring the parent to the foreground.
 
Could you point what I'm doing wrong ?

Thanks,
Ron.

Mike Driscoll

unread,
Jan 28, 2009, 11:23:11 AM1/28/09
to wxpytho...@lists.wxwidgets.org
Cody Precord wrote:
> Hello,

>
>
> On Wed, Jan 28, 2009 at 10:03 AM, Barak, Ron <Ron....@lsi.com
> <mailto:Ron....@lsi.com>> wrote:
>
> Hi Mike,
>
> Implementing what you suggest (I think) does not give me the
> expected results.
> Namely, when OnItemSelected is activated and creates a new
> instance of ListControl, _the parent is on top_, even though

> there's a Raise() on the child.
>
>
>
> <snip>
> </snip>

>
> Could you point what I'm doing wrong ?
>
>
> The click event for the listctrl will generate a focus event which is
> what is raising that frame to the top after the other one is shown.
> You need to delay your Raise call till after the click event has
> finished processing.
>
> i.e) wx.CallLater(100, self.Raise)
>
> Cody
>

Also, don't shadow the builtin "list" function. That will probably bite
you later...

<code>

list = [1,2,3]
>>> x =list(4,5,6)

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
x =list(4,5,6)
TypeError: 'list' object is not callable

</code>

Cody Precord

unread,
Jan 28, 2009, 11:19:42 AM1/28/09
to wxpytho...@lists.wxwidgets.org
Hello,
 
 
On Wed, Jan 28, 2009 at 10:03 AM, Barak, Ron <Ron....@lsi.com> wrote:

Hi Mike,

Implementing what you suggest (I think) does not give me the expected results.
Namely, when OnItemSelected is activated and creates a new instance of ListControl, the parent is on top, even though there's a Raise() on the child.

 
<snip>
</snip>
Could you point what I'm doing wrong ?
 
Reply all
Reply to author
Forward
0 new messages