Discussion:
convert windows app to PyQt Widget
(too old to reply)
M Chauhan
2010-11-29 15:31:17 UTC
Permalink
Hello all,

I have been trying to convert an app launched by windows (for ex. calc) into
a QT Widget. In docs, I found a "find()" command which should do that. (
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#find
)

But "find" returns a None.

Below you will find an example code for calculator app. May be I am not
doing something right.
Any pointers please? (I am using : PyQT 4.7.1, Windows XP, Python 2.6.4)

Ex code:

import os , time, win32gui
from subprocess import Popen
from PyQt4 import QtGui
root_dir = os.environ.get("SystemRoot",r"C:\WINDOWS")
calc = r'%s\System32\calc.exe' % root_dir
Popen(calc)
time.sleep(1)
#Get window handle of calc window
calc_hwnd = win32gui.FindWindow(None, "Calculator")
#Creat QT Application
a = QtGui.QApplication([])
mainwin = QtGui.QMainWindow()
#Set QT mainwindow as parent of calc window
win32gui.SetParent(calc_hwnd, int(mainwin.winId()))
mainwin.showMaximized()
mainwin.show()
#Convert calc into QT widget
wgt = mainwin.find(calc_hwnd)
#XXX: following print gives "None"
*print type(wgt)*
a.exec_()

Thanks and wishes,
Mru
Hans-Peter Jansen
2010-11-29 17:38:23 UTC
Permalink
Post by M Chauhan
Hello all,
I have been trying to convert an app launched by windows (for ex.
calc) into a QT Widget. In docs, I found a "find()" command which
should do that. (
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.ht
ml#find )
But "find" returns a None.
Below you will find an example code for calculator app. May be I am
not doing something right.
Any pointers please? (I am using : PyQT 4.7.1, Windows XP, Python 2.6.4)
import os , time, win32gui
from subprocess import Popen
from PyQt4 import QtGui
root_dir = os.environ.get("SystemRoot",r"C:\WINDOWS")
calc = r'%s\System32\calc.exe' % root_dir
Popen(calc)
time.sleep(1)
#Get window handle of calc window
calc_hwnd = win32gui.FindWindow(None, "Calculator")
#Creat QT Application
a = QtGui.QApplication([])
mainwin = QtGui.QMainWindow()
#Set QT mainwindow as parent of calc window
win32gui.SetParent(calc_hwnd, int(mainwin.winId()))
mainwin.showMaximized()
mainwin.show()
#Convert calc into QT widget
wgt = mainwin.find(calc_hwnd)
#XXX: following print gives "None"
*print type(wgt)*
a.exec_()
I wouldn't expect something like this to have a _chance_ to work
properly. You might get away with some Active X controls, but embedding
arbitrary windows is possible with X11 only (AFAIK).

Pete
M Chauhan
2010-12-01 10:26:52 UTC
Permalink
Thanks Pete,

I guess, like you said, I should avoid this on windows. However I will try
it on X11 to see if it works fine.

Regards,
Mrugesh.
Post by Hans-Peter Jansen
Post by M Chauhan
Hello all,
I have been trying to convert an app launched by windows (for ex.
calc) into a QT Widget. In docs, I found a "find()" command which
should do that. (
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.ht
ml#find )
But "find" returns a None.
Below you will find an example code for calculator app. May be I am
not doing something right.
Any pointers please? (I am using : PyQT 4.7.1, Windows XP, Python 2.6.4)
import os , time, win32gui
from subprocess import Popen
from PyQt4 import QtGui
root_dir = os.environ.get("SystemRoot",r"C:\WINDOWS")
calc = r'%s\System32\calc.exe' % root_dir
Popen(calc)
time.sleep(1)
#Get window handle of calc window
calc_hwnd = win32gui.FindWindow(None, "Calculator")
#Creat QT Application
a = QtGui.QApplication([])
mainwin = QtGui.QMainWindow()
#Set QT mainwindow as parent of calc window
win32gui.SetParent(calc_hwnd, int(mainwin.winId()))
mainwin.showMaximized()
mainwin.show()
#Convert calc into QT widget
wgt = mainwin.find(calc_hwnd)
#XXX: following print gives "None"
*print type(wgt)*
a.exec_()
I wouldn't expect something like this to have a _chance_ to work
properly. You might get away with some Active X controls, but embedding
arbitrary windows is possible with X11 only (AFAIK).
Pete
_______________________________________________
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Loading...