wxPython dialogue won't STAY_ON_TOP

Post here if you need help with creating a Graphical User Interface in Python.

wxPython dialogue won't STAY_ON_TOP

Postby Mekire » Wed Apr 02, 2014 2:25 pm

I'm using wx.FileDialog in conjunction with a Pygame program for the save and load dialogues.
This works fine, but occasionally (not always) the dialogue will appear and then instantly shift underneath the Pygame window.
I can click over to it and use it perfectly, but it is definitely annoying. From what I have read, the style flag wx.STAY_ON_TOP should solve this problem, but it doesn't change the behavior for me.

My wx dialogue creation looks like this:
Code: Select all
wx_app = wx.App(False)
ask = wx.FileDialog(None, "Open", directory, "",
                   "Map files (*.map)|*.map",
                   wx.FD_OPEN|wx.FD_FILE_MUST_EXIST|wx.STAY_ON_TOP)
ask.ShowModal()

Using Python 2.7 on Windows 7
Any ideas?

-Mek
User avatar
Mekire
 
Posts: 1009
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: wxPython dialogue won't STAY_ON_TOP

Postby DrakeMagi » Wed Apr 02, 2014 6:16 pm

wx.STAY_ON_TOP is for wxWindow framework not sdl framework.

I don't know if there a lowlevel command to bring to front

but you could always try: (but they probably be only for wxWindow framework)
Raise()
SetFocus()

easiest solution is just create one in pygame.
Linux: won't find windows here.
Linux: the choice of a GNU generation.
https://github.com/DrakeMagi
DrakeMagi
 
Posts: 113
Joined: Sun May 12, 2013 8:36 pm

Re: wxPython dialogue won't STAY_ON_TOP

Postby metulburr » Thu Apr 03, 2014 11:31 pm

tkinter doesnt appear to have a problem with that (assuming you are OK with tkinter).

Code: Select all
import pygame as pg
import sys
if sys.version == '2':
    import Tkinter as tk
    from tkFileDialog import askopenfilename
else:
    import tkinter as tk
    from tkinter.filedialog import askopenfilename


screensize = (600,400)
screen = pg.display.set_mode(screensize)
done = False
pg.display.set_caption('press a button to load')


def openfile():
    root = tk.Tk()
    root.withdraw()
    f = askopenfilename()
    root.destroy()
    return f

while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
        elif event.type == pg.KEYDOWN:
            f = openfile()
            pg.display.set_caption(f)
    pg.display.update()
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1490
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: wxPython dialogue won't STAY_ON_TOP

Postby Mekire » Fri Apr 04, 2014 2:00 am

I have experienced identical behavior with tkinter (although I do prefer to use wx). Generally it doesn't seem to occur the first time the dialogue is created; but on subsequent creations sometimes it goes under (sometimes it doesn't). I have only been testing on Windows lately, I'll have to check it out in Linux to see if it has the same behavior.

-Mek
User avatar
Mekire
 
Posts: 1009
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: wxPython dialogue won't STAY_ON_TOP

Postby metulburr » Fri Apr 04, 2014 2:06 am

hmm i have not had it happen once in linux. WIth about 30 subsequent creations each time testing. Maybe wxpython might act the same in linux as well, not sure, i dont have it installed and not fluent in it.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1490
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: wxPython dialogue won't STAY_ON_TOP

Postby DrakeMagi » Fri Apr 04, 2014 2:51 pm

it might be wx.app doesn't have focus hidding the dialog.

maybe
Code: Select all
top = wx_app.GetTopWindow()
if not top.HasFocus():
    top.SetFocus()
else:
    print("wx window has focus")
Linux: won't find windows here.
Linux: the choice of a GNU generation.
https://github.com/DrakeMagi
DrakeMagi
 
Posts: 113
Joined: Sun May 12, 2013 8:36 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 1 guest