Converting c++ into Python
-
Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
unity thread
GitHub Code of C++ working exampleSo can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.
-
Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
unity thread
GitHub Code of C++ working exampleSo can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.
@Pythonic-person
I don't know what this unity thing is so I don't know what this is supposed to do. I converted over most of it but I left out the windows OS specific stuff because I didn't feel like messing with it at the moment (I don't know much c++ either). It's pyside6 instead of pyqt5 but hopefully this will be enough to get you started.import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import QApplication, QMainWindow, QSplitter, QWidget from PySide6.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsTextItem, QGraphicsItem from PySide6.QtGui import QPainter from PySide6.QtCore import QProcess class UnityWindow(QWidget): def __init__(self, unityExePath, parent=None): super().__init__(parent) self._m_unityHandle = 0 self._m_bIsValid = False self._m_pUnityProcess = None self._m_unityExecutablePath = unityExePath app.applicationStateChanged.connect(self.applicationStateChanged) def enumChildWindows(self, handle): # if windows do stuff pass def isValid(self): return self._m_bIsValid def applicationStateChanged(self, state): # if windows do stuff pass def resizeEvent(self, ev): super().resizeEvent(ev) # if windows do stuff def sEnumChildWindows(self, handle, params): # if windows do stuff pass def showEvent(self, ev): super().showEvent(ev) # if windows do stuff def hideEvent(self, ev): super().hideEvent(ev) # if windows do stuff def nativeEvent(self, eventType, message, result): # if windows do stuff return QWidget.nativeEvent(eventType, message, result) if __name__ == '__main__': app = QApplication(sys.argv) mainWindow = QMainWindow() splitter = QSplitter(mainWindow) splitter.setOrientation(Qt.Horizontal) unityWindow = UnityWindow("unity-game.exe", mainWindow) splitter.addWidget(unityWindow) view = QGraphicsView(mainWindow) scene = QGraphicsScene(mainWindow) item = QGraphicsTextItem("Test Item") item.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable) scene.addItem(item) view.setRenderHint(QPainter.Antialiasing, False) view.setDragMode(QGraphicsView.ScrollHandDrag) view.setInteractive(True) view.setOptimizationFlags(QGraphicsView.DontSavePainterState) view.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) view.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) view.setScene(scene) splitter.addWidget(view) mainWindow.setCentralWidget(splitter) mainWindow.show() sys.exit(app.exec())
-
Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
unity thread
GitHub Code of C++ working exampleSo can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.
Hello @Pythonic-person
In the Qt for Python repository, we have an internal tool that's for sure not ready for production, but it help us to transform some C++ code to Python:https://code.qt.io/cgit/pyside/pyside-setup.git/tree/tools/qtcpp2py.py
I hope it helps with future projects :)