class MainWindow(QMainWindow):
Launches the terminal
def __init__(self, command: str, substring: str):
super(MainWindow, self).__init__()
widget = QWidget()
layout = QGridLayout(widget)
self.setCentralWidget(widget)
win = latchToWindow(command, substring)
hwnd = win._hWnd
self.window = QtGui.QWindow.fromWinId(hwnd)
self.windowcontainer = self.createWindowContainer(self.window, widget)
layout.addWidget(self.windowcontainer, 0, 0)
def latchToWindow(winLaunchCommand: str, gettitle: str):
Used when there are additional dialogs and you need to grab a specific one
:param winLaunchCommand:
:param title:
:return:
makeNewWindow(winLaunchCommand)
while True:
windows = pygetwindow.getAllWindows()
for win in windows:
tempTitle = win.title
if gettitle in tempTitle:
return win
time.sleep(0.1)
def makeNewWindow(winLaunchCommand: str):
Makes a new window with that command, and returns that window
:param winLaunchCommand:
:return:
windows = pygetwindow.getAllWindows()
os.popen(winLaunchCommand)
while True:
newWindow = pygetwindow.getAllWindows()
if len(newWindow) != len(windows):
for win in newWindow:
if win.title != "":
if win not in windows:
time.sleep(0.05)
return win
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle("fusion")
# This doesn't work with keyboard and mouse
form = MainWindow("start cmd.exe", "cmd.exe")
# This does work with keyboard and mouse
// form = MainWindow("putty.exe", "PuTTY")
form.setWindowTitle('Embedded Python Terminal')
form.show()
app.exec()
class MainWindow(QMainWindow):
Launches the terminal
def __init__(self, command: str, substring: str):
super(MainWindow, self).__init__()
win = latchToWindow(command, substring)
self.hwnd = win._hWnd
widget = widgetMouseTracking(self.hwnd)
widget.setMouseTracking(True)
layout = QGridLayout(widget)
self.setCentralWidget(widget)
self.window = QtGui.QWindow.fromWinId(self.hwnd)
self.windowcontainer = self.createWindowContainer(self.window, widget)
layout.addWidget(self.windowcontainer, 0, 0)
class widgetMouseTracking(QWidget):
def __init__(self, windowsID):
super().__init__()
self.id = windowsID
def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
win32gui.BringWindowToTop(self.id)
win32gui.SetFocus(self.id)
def latchToWindow(winLaunchCommand: str, gettitle: str):
Used when there are additional dialogs and you need to grab a specific one
:param winLaunchCommand:
:param title:
:return:
makeNewWindow(winLaunchCommand)
while True:
windows = pygetwindow.getAllWindows()
for win in windows:
tempTitle = win.title
if gettitle in tempTitle:
return win
time.sleep(0.1)
def makeNewWindow(winLaunchCommand: str):
Makes a new window with that command, and returns that window
:param winLaunchCommand:
:return:
windows = pygetwindow.getAllWindows()
os.popen(winLaunchCommand)
while True:
newWindow = pygetwindow.getAllWindows()
if len(newWindow) != len(windows):
for win in newWindow:
if win.title != "":
if win not in windows:
time.sleep(0.05)
return win
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle("fusion")
# This doesn't work with keyboard and mouse
form = MainWindow("start cmd.exe", "cmd.exe")