[PyQt] Mac OS X Problem: PyQT applications not focusing on launch
Holger Rapp
Rapp at mrt.uka.de
Fri Sep 25 15:16:32 BST 2009
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 -------------------
More information about the PyQt
mailing list