[PyQt] Mac OS X Problem: PyQT applications not focusing on launch

Hans-Peter Jansen hpj at urpla.net
Fri Sep 25 18:23:13 BST 2009


Am Freitag 25 September 2009 schrieb Alexei Puzikov:
> hello = HelloWorld()
> hello.show()
> hello.raise_() # this will raise the window on Mac OS X
> sys.exit(app.exec_())
>
>
> Given it's a Mac-only problem, which wasn't reproducible with Qt, only
> PyQt, for me it looks like a PyQt bug. But the fix is quite easy.

No, it's not a PyQt issue, it's about Qt being compliant with Apple design 
guidelines.. (red that in some Qt developer blog, but didn't remember the 
address..)

I bet, wxpython does ignore these guides and implicitely raises the window. 
Now imagine, you try to respect them with wx.. Calling raise_() is a small 
price to pay, doesn't it?

Pete

> A.
>
> On Fri, Sep 25, 2009 at 5:16 PM, Holger Rapp <Rapp at mrt.uka.de> wrote:
> > Hi,
> >
> > Every pyqt example I start under Mac OS X (PyQt 4.5.4, Python 2.6 from
> > Python.org, Mac OS X 10.5.8), no matter which (I tried the delivered
> > examples
> > in the source distribution and also the examples from the python book
> > [1], I also tried the eric IDE and spyder) fail to receive the focus
> > when launched. A click is needed to raise the application. Sometimes
> > the newly opened window
> > is hidden under others.
> >
> > I am aware that I have to use pythonw (instead of python) for GUI
> > scripts, but
> > this doesn't change anything. After googling I read that I just have to
> > bundle
> > my scripts in .app packages because the issues is all Apples fault. I
> > feel this is
> > unelegant and most importantly: all wxpython applications RECEIVE the
> > focus when launched (no matter if with python or pythonw), therefore
> > there IS a way
> > to make scripts open up GUI applications with focus. I give code
> > examples for
> > pyqt (no focus) and WXPython (receives focus) below my message.
> >
> > Maybe someone with more insight can shed some light on this problem.
> >
> > [1] http://www.qtrac.eu/pyqtbook.tar.gz
> >
> > Greetings,
> > Holger
> >
> > ------------------- SNIP -------------------
> > # encoding: utf-8
> > # wxPython example. This receives focus on launch.
> > # Launch with
> > # $ python hello_world_wx.py
> > # File: hello_world_wx.py
> >
> > import wx
> > app = wx.PySimpleApp()
> > frame = wx.Frame(None, wx.ID_ANY, "Hello World")
> > frame.Show(True)
> > app.MainLoop()
> > ------------------- SNAP -------------------
> >
> > ------------------- SNIP -------------------
> > # encoding: utf-8
> > # pyqt example. This DOES NOT receives focus on launch.
> > # Launch with
> > # $ python hello_world_qt.py
> > # or
> > # $ pythonw hello_world_qt.py
> > # Doesn't make a difference on my computer.
> > # File: hello_world_qt.py
> >
> > from PyQt4 import QtCore, QtGui
> > import sys
> >
> > class HelloWorld(QtGui.QWidget):
> >    def __init__(self, parent=None):
> >        super(HelloWorld, self).__init__(parent)
> >
> >        self.setWindowTitle("Hello World")
> >
> > app = QtGui.QApplication(sys.argv)
> > hello = HelloWorld()
> > hello.show()
> > sys.exit(app.exec_())
> > ------------------- SNAP -------------------
> >
> >
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt




More information about the PyQt mailing list