zoukankan      html  css  js  c++  java
  • TopicSpace: PyQt4, QThread example

    TopicSpace: PyQt4, QThread example

    Title: PyQt4, QThread example

    Last Modified: 10.16.2008

    This is about the most simple example I could think of how to make a thread

    #!/usr/bin/env python
    """This is a short program to have an external program grab data for me and get displayed without blocking the whole program"""
    from PyQt4 import QtGui,QtCore
    import sys
    class TerminalViewer(QtGui.QWidget):
    	def __init__(self,parent=None):
    		QtGui.QWidget.__init__(self,parent)
    		self.Label = QtGui.QLabel("Waiting for Something",self)
    		self.DataCollector = TerminalX(self)
    		self.connect(self.DataCollector,QtCore.SIGNAL("Activated ( QString ) "), self.Activated)
    		self.DataCollector.start()
    	def Activated(self,newtext):
    		self.Label.setText(newtext)
    	def closeEvent(self,e):
    		e.accept()
    		app.exit()
    
    class TerminalX(QtCore.QThread):
    	def __init__(self,parent=None):
    		QtCore.QThread.__init__(self,parent)
    		self.test = ''
    	def run(self):
    		while self.test != 'q':
    			self.test = raw_input('enter data: ')
    			self.emit(QtCore.SIGNAL("Activated( QString )"),self.test)
    
    app = QtGui.QApplication(sys.argv)
    qb = TerminalViewer()
    qb.show()
    sys.exit(app.exec_())
    

    This starts a QLabel with some text, if you type in the terminal where you started the program then you can change the text on the widget. The "start()" method executes the "run()" method in addition to starting the thread in a separate process.

  • 相关阅读:
    linux mysql添加用户名并实现远程访问
    bootstrap-datetimepicker时间控件的使用
    jquery图片左右来回循环飘动
    jquery 全选获取值
    设置linux编码utf-8
    nginx 自签名https
    Laravel 邮件配置
    memcachq队列安装
    开发与运维使用常用工具
    composer配置和安装php框架
  • 原文地址:https://www.cnblogs.com/lexus/p/2820151.html
Copyright © 2011-2022 走看看