python 2023. 2. 14. 14:03

 

초보자를 위한 PyQt 프로그래밍 

https://wikidocs.net/35495#qslider

 

emit () 및 pyqtSignal ()의 PyQt 적절한 사용

https://minorman.tistory.com/22

 

 

구글검색:  pyqt getvalue emit example

https://www.google.com/search?q=pyqt+getvalue+emit+example&oq=pyQt%2C+getvalue+emit+&aqs=chrome.1.69i57j33i10i160.16336j0j7&sourceid=chrome&ie=UTF-8

 

posted by cskimair
:
python 2022. 12. 19. 09:16

 

 

-

https://pythontic.com/modules/socket/udp-client-server-example

 

UDP - Client and Server example programs in Python | Pythontic.com

UDP Overview: UDP is the abbreviation of User Datagram Protocol. UDP makes use of Internet Protocol of the TCP/IP suit. In communications using UDP, a client program sends a message packet to a destination server wherein the destination server also runs on

pythontic.com

 

- UDPEchoClient.java

UDPEchoClient.java
0.00MB
UDPEchoServer.java
0.00MB
UDPSendClient.java
0.00MB

 

 

 

posted by cskimair
:
python 2022. 4. 15. 08:23
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *


class MyMainGUI(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.qtxt1 = QTextEdit(self)
        self.btn1 = QPushButton("Start", self)
        self.btn2 = QPushButton("Stop", self)
        self.btn3 = QPushButton("add 100", self)
        self.btn4 = QPushButton("send instance", self)

        vbox = QVBoxLayout()
        vbox.addWidget(self.qtxt1)
        vbox.addWidget(self.btn1)
        vbox.addWidget(self.btn2)
        vbox.addWidget(self.btn3)
        vbox.addWidget(self.btn4)
        self.setLayout(vbox)

        self.setGeometry(100, 50, 300, 300)

class Test:
    def __init__(self):
        name = ""


class MyMain(MyMainGUI):
    add_sec_signal = pyqtSignal()
    send_instance_singal = pyqtSignal("PyQt_PyObject")

    def __init__(self, parent=None):
        super().__init__(parent)

        self.btn1.clicked.connect(self.time_start)
        self.btn2.clicked.connect(self.time_stop)
        self.btn3.clicked.connect(self.add_sec)
        self.btn4.clicked.connect(self.send_instance)

        self.th = Worker(parent=self)
        self.th.sec_changed.connect(self.time_update)  # custom signal from worker thread to main thread

        self.add_sec_signal.connect(self.th.add_sec)   # custom signal from main thread to worker thread
        self.send_instance_singal.connect(self.th.recive_instance_singal)
        self.show()

    @pyqtSlot()
    def time_start(self):
        self.th.start()
        self.th.working = True

    @pyqtSlot()
    def time_stop(self):
        self.th.working = False

    @pyqtSlot()
    def add_sec(self):
        print(".... add singal emit....")
        self.add_sec_signal.emit()

    @pyqtSlot(str)
    def time_update(self, msg):
        self.qtxt1.append(msg)

    @pyqtSlot()
    def send_instance(self):
        t1 = Test()
        t1.name = "SuperPower!!!"
        self.send_instance_singal.emit(t1)


class Worker(QThread):
    sec_changed = pyqtSignal(str)

    def __init__(self, sec=0, parent=None):
        super().__init__()
        self.main = parent
        self.working = True
        self.sec = sec

        # self.main.add_sec_signal.connect(self.add_sec)   # 이것도 작동함. # custom signal from main thread to worker thread

    def __del__(self):
        print(".... end thread.....")
        self.wait()

    def run(self):
        while self.working:
            self.sec_changed.emit('time (secs):{}'.format(self.sec))
            self.sleep(1)
            self.sec += 1

    @pyqtSlot()
    def add_sec(self):
        print("add_sec....")
        self.sec += 100

    @pyqtSlot("PyQt_PyObject")
    def recive_instance_singal(self, inst):
        print(inst.name)



if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    form = MyMain()
    app.exec_()

 

PyQt5 -- QThread 사용하기 &  thread 간 통신하기

출처: https://freeprog.tistory.com/351 [취미로 하는 프로그래밍 !!!]
 
posted by cskimair
:
python 2021. 8. 9. 12:03

(NG, not good/not working)python subprocess kill on exit

SNMP Viewer / 종료해도 타스크매니저에서 프로세스가 보일때(종료안될때) ,

python subprocess kill on exit

관련 링크:

https://stackoverflow.com/questions/14128410/killing-child-process-when-parent-crashes-in-python/14128476#14128476

import atexit process = subprocess.Popen(args.server_file_path) atexit.register(process.terminate) pid = process.pid

- 실제

>subprocess.Popen 으로 호출후 종료시에 서브프로세스를 같이 종료하게 해줌.

 

> 변경전 소스: ED_SNMP_Setup.py

class LocalSetupDialog(QtWidgets.QDialog):
    def __init__(self):
        QtWidgets.QDialog.__init__(self)        
        self.ui = local_setup.Ui_Dialog()
        self.ui.setupUi(self)    
        self.setupData()
        self.ui.buttonBox.accepted.connect(self.popupConfirm)
        self.ui.pushButton.clicked.connect(self.snmpViewer)

......

    def snmpViewer(self):        
        self.accept()
        argList = ['ED_SNMP_Viewer.exe',
                   config['ipAddress'],
                   config['snmpCommunity_read'],
                   config['snmpCommunity_write'],
                   config['snmpPort'], config['trapPort']]

 

> 변경후 소스:

class LocalSetupDialog(QtWidgets.QDialog):
    def __init__(self):
        QtWidgets.QDialog.__init__(self)        
        self.ui = local_setup.Ui_Dialog()
        self.ui.setupUi(self)    
        self.setupData()
        self.ui.buttonBox.accepted.connect(self.popupConfirm)
        self.ui.pushButton.clicked.connect(self.snmpViewer)

......

    def snmpViewer(self):        
        self.accept()
        argList = ['ED_SNMP_Viewer.exe',
                   config['ipAddress'],
                   config['snmpCommunity_read'],
                   config['snmpCommunity_write'],
                   config['snmpPort'], config['trapPort']]
        m_process = subprocess.Popen(argList)
        import atexit
        atexit.register(m_process.terminate)

 



'python' 카테고리의 다른 글

Python UDP CLient / Server example  (0) 2022.12.19
PyQt - QThread 사용, thread 간 통신  (0) 2022.04.15
PyQt ProgressBar  (0) 2021.08.02
filename and line number of Python script  (0) 2021.08.02
python UDP socket timeout examples  (0) 2021.08.02
posted by cskimair
:
python 2021. 8. 2. 17:16

 

https://riptutorial.com/pyqt5/example/29500/basic-pyqt-progress-bar

 

pyqt5 Tutorial => Basic PyQt Progress Bar

Learn pyqt5 - Basic PyQt Progress Bar

riptutorial.com

 

posted by cskimair
:
python 2021. 8. 2. 17:15

 

https://stackoverflow.com/questions/3056048/filename-and-line-number-of-python-script

 

filename and line number of Python script

How can I get the file name and line number in a Python script? Exactly the file information we get from an exception traceback. In this case without raising an exception.

stackoverflow.com

 

'python' 카테고리의 다른 글

(NG, not good/not working)python subprocess kill on exit  (0) 2021.08.09
PyQt ProgressBar  (0) 2021.08.02
python UDP socket timeout examples  (0) 2021.08.02
PyQt5 -- QThread 사용하기 & thread 간 통신  (0) 2021.08.02
PyQt5 QTableWidget 자료  (0) 2021.08.02
posted by cskimair
: