-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (46 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
import time
import win32gui
from PySide2.QtCore import Qt, QProcess
from PySide2.QtGui import QWindow
from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
vl = QVBoxLayout()
self.setWindowTitle("Project UI")
widget = QWidget()
widget.setLayout(vl)
self.setCentralWidget(widget)
def winEnumHandler(hwnd, ctx):
if win32gui.IsWindowVisible(hwnd):
print(hex(hwnd), win32gui.GetWindowText(hwnd))
if __name__ == '__main__':
# Create unique QApplication instance
app = QApplication(sys.argv)
# Create a QMainWindow
# I have also tested it with a QWidget instead of QMainWindow and it works as well
main_window = MainWindow()
# Create QProcess that runs the unity .exe
unity = QProcess()
unity.setProgram("C:\\Users\\UJA\\Documents\\Unity\\Ejecutable Proyecto GJ (bandera)\\Proyecto GJ.exe")
unity.start()
unity.waitForStarted()
# I used this method to print the active windows and see unity's window name.
# win32gui.EnumWindows(winEnumHandler, 0)
hwnd = 0
while hwnd == 0:
hwnd = win32gui.FindWindow(0, "Proyecto GJ")
# Get the unity window from the hwnd
UnitySceneWindow = QWindow.fromWinId(hwnd)
# Create the Unity widget that contains the Unity window
unityWidget = QWidget.createWindowContainer(UnitySceneWindow)
unityWidget.setFocusPolicy(Qt.TabFocus)
# Set the the unity widget to the QMainWindow central widget
main_window.setCentralWidget(unityWidget)
# Show the window
main_window.show()
# Start the event loop.
app.exec_()
# Your application won't reach here until you exit and the event
# loop has stopped.