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

Holger Rapp Rapp at mrt.uka.de
Mon Sep 28 11:37:27 BST 2009


Am 25.09.2009 um 18:24 schrieb Alexei Puzikov:

> hello = HelloWorld()
> hello.show()
> hello.raise_() # this will raise the window on Mac OS X
> sys.exit(app.exec_())
This was a mighty useful advice. The internet doesn't seem to be aware  
of this
solution (as mentioned, I only found the clue to pack things together  
via
py2app). Is there a possibility to make this more prominent in the  
docs or add a
page with Mac OS X notes to some wiki?

Cheers,
Holger

>
> 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.
>
> 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
>>



More information about the PyQt mailing list