0

I'm working on an application that runs visualization using 3rd party software, and sending commands and doing other things through the PyQt5 GUI. At this point, both the PyQt5 window and the visualization run on separate windows, but I'd like to at some point merge them so that it looks like one window. To do that, I'm trying to make a simple example work. Here is code that spawns the calculator app on Mac and a simple window that has some text labels in it:

import os
import sys
import subprocess
import atexit
from PyQt5 import QtWidgets


class CalcWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(CalcWindow, self).__init__()
        self.setWindowTitle("Embedded Calc")
        lines_widget = LinesWidget()
        self.setCentralWidget(lines_widget)
        calc_path = "/Applications/Calculator.app/Contents/MacOS/Calculator"
        print("Path = " + calc_path)
        print("Exists: " + str(os.path.exists(calc_path)))
        p = subprocess.Popen(calc_path)
        atexit.register(self.kill_proc, p)

    @staticmethod
    def kill_proc(proc):
        try:
            proc.terminate()
        except Exception:
            pass


class LinesWidget(QtWidgets.QWidget):

    def __init__(self):
        super().__init__()
        self.vLayout = QtWidgets.QVBoxLayout()
        self.line1 = QtWidgets.QHBoxLayout()
        self.line1.addWidget(QtWidgets.QLabel("HELLO"))
        self.line1.addWidget(QtWidgets.QLabel("WORLD"))
        self.line2 = QtWidgets.QHBoxLayout()
        self.line2.addWidget(QtWidgets.QLabel("SUP"))
        self.line2.addWidget(QtWidgets.QLabel("DAWG"))
        self.vLayout.addLayout(self.line1)
        self.vLayout.addLayout(self.line2)
        self.setLayout(self.vLayout)


def main():
    app = QtWidgets.QApplication(sys.argv)
    calc = CalcWindow()
    calc.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()

I'd like the calculator to be apart of the same window as the Text Labels which are in the main window. I've seen it done on the Windows using hwnd , but I don't know how to directly translate that to OSX or if it's even possible. Maybe there's some PyQt magic of throwing the executable in a widget and adding it to the main window that would work. Not sure. Any help would be appreciated. Thanks.

three_pineapples
  • 11,579
  • 5
  • 38
  • 75
Ned U
  • 401
  • 2
  • 7
  • 15

0 Answers0