Python Forum
[PyQt] Execute the script in remote and get the output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Execute the script in remote and get the output
#1
Hi All,

I am working on one project (personal project), where I wanted to connect the remote system, execute my predefined script, get the result back and display it on the QPlainText widget.

Here is my code. There is a method named yamlExecute(self) -> where I want to write a code to connect the remote system, execute the my script present in the location and get the result of that script and print it back on the QPlainText widget.
#!/usr/bin/env python

'''
import Qt and system libraries
'''
from PyQt5 import QtGui, QtCore, QtWidgets
#from PyQt5.QtWidgets import QApplication, QPushButton, QVBoxLayout, QMainWindow, QWidget
import os, sys

'''
class YMLWidget(QtWidgets.QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle('YML Display Widget')
        self.setFixedWidth(500)
        mainLayout = QtWidgets.QVBoxLayout()
'''
        
class MyWidget(QtWidgets.QMainWindow):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.initWidget()
    
    def initWidget(self):
        self.setGeometry(600, 300, 450, 300)
        self.setWindowTitle('YAML Uploader Widget')
        self.tool_bar = self.addToolBar('File')
        
        upload_button = QtWidgets.QPushButton('upload the yaml', self)
        upload_button.resize(upload_button.sizeHint())
        upload_button.clicked.connect(self.yamlUpload)
        self.tool_bar.addWidget(upload_button)

        submit_button = QtWidgets.QPushButton('submit the yaml', self)
        submit_button.resize(submit_button.sizeHint())
        submit_button.clicked.connect(self.yamlExecute)
        self.tool_bar.addWidget(submit_button)

        close_button = QtWidgets.QPushButton('close the yaml', self)
        close_button.resize(close_button.sizeHint())
        close_button.clicked.connect(self.yamlClose)
        self.tool_bar.addWidget(close_button)

        self.editor = QtWidgets.QPlainTextEdit()
        #self.setCentralWidget(self.editor)
        #button.move(150, 150)
        #self.show()

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.tool_bar)
        layout.addWidget(self.editor)

        widget = QtWidgets.QWidget()
        widget.setLayout(layout)

        self.setCentralWidget(widget)
        self.show()
    
    def yamlUpload(self):
        filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Single File', r'C:\Users\maiyapr\Desktop\compare', '*.yml')
        with open(filePath, 'r', encoding='utf-8') as file_pointer:
            self.lines = file_pointer.readlines()
            self.editor.setPlainText(''.join(self.lines))

    def yamlExecute(self):
        '''
        1. connect the remote system
        2. execute the predefined script present in the /home/maiya/myscript.py
        3. get the output and display it back in the same self.editor.setPlainText screen.
        '''

    def yamlClose(self):
        self.close()

def main():
    app = QtWidgets.QApplication(sys.argv)
    widget = MyWidget()
    app.exec_()

if __name__ == '__main__':
    main()
Any help or suggestion would be very much appreciated. Thanks a lot
Regards,
maiya
Reply


Messages In This Thread
Execute the script in remote and get the output - by maiya - Jul-08-2022, 01:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to execute .py script when button is clicked D_frucht 1 6,243 Jun-22-2018, 04:23 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020