English 中文(简体)
如何改变工人的read子进步
原标题:Howto change progress by worker thread

I m new to PyQt4 so maybe it is a letteratelle. 我试图在我的全球倡议中取得进展,这项工作将由一位工人阅读更新。 进展 律师在QTableWidget有其他记忆。

The worker thread starts in the init function of my GUI.

self.st = ServerThread()
    self.st.start()

Here is the thread class

_exportedMethods = {
     changes : signal_when_changes,
}  

class ServerThread(QtCore.QThread):

    def __init__(self):
        super(ServerThread,self).__init__()
        st = self
        #threading.Thread.__init__(self)
    def run(self):
        HOST =        # local host
        PORT = 50000
        SERVER_ADDRESS = HOST, PORT

    # set up server socket
        s = socket.socket()
        s.bind(SERVER_ADDRESS)
        s.listen(1)

        while True:
            conn, addr = s.accept()
            connFile = conn.makefile()
            name = cPickle.load(connFile)
            args = cPickle.load(connFile)
            kwargs = cPickle.load(connFile)
            res = _exportedMethods[name](*args,**kwargs)
            cPickle.dump(res,connFile) ; connFile.flush()
            conn.close()

如果我的服务器改变数据库中的数值,他将采用以下方法,在校边用边远传动电话。

def signal_when_changes():
    s = Subject()
    s.advise()

模式是一个简单的观察员,更新了我的全球倡议。 我的表是以下方法。

def refresh(self,table):
    clients = self.db.get_clients()
    if(self.ui.mainTable.rowCount() !=  len(clients)):
        self.search_add_client
    allRows = table.rowCount()
    for row in xrange(0,allRows):
        for c in clients:
            if table.item(row,0).text() == c.get_macaddr().text():
                self.refresh_line(table,row,c)

如果需要更新以下方法的话,这种方法会给人带来变化。

def refresh_line(self,table,rowNumber,client):
    table.item(rowNumber, 0).setText(client.get_macaddr().text())
    table.item(rowNumber, 1).setText(client.get_product().text())
    table.item(rowNumber, 2).setText(client.get_site().text())
    table.item(rowNumber, 3).setText(client.get_hostname().text())
    table.item(rowNumber, 4).setText(client.get_priv_data().text())
    table.cellWidget(rowNumber, 5).setValue(client.get_progress_value())
    table.item(rowNumber, 6).setText(client.get_stage().text())

其他记忆可以更新,但不是进展,在这里,我想更新进展情况。

self.ui.mainTable.setCellWidget(appendRowIndex,5,c.get_progress())

在这条路后,全球倡议坠毁,我收到以下信息:

QPixmap: 在德国马克read外使用图象是不安全的。

我的猜测是,在“Main/Gui”透镜之外,我可以改变QPix地图。 我不知道我如何能够解决这一问题,因此,我欢迎所有建议。

提前感谢。

问题回答

Don t试图从深处更新进展情况:使用信号。

from PyQt4 import QtCore, QtGui

class Thread(QtCore.QThread):
    def __init__(self,parent):
        QtCore.QThread.__init__(self, parent)

    def run (self):
        for step in range(5):
            self.sleep(1)
            self.emit(QtCore.SIGNAL( taskUpdated ))

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.button = QtGui.QPushButton( Start , self)
        self.progress = QtGui.QProgressBar(self)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.button)
        layout.addWidget(self.progress)
        self.connect(self.button, QtCore.SIGNAL( clicked() ),
                     self.handleButton)
        self.thread = Thread(self)
        self.connect(self.thread, QtCore.SIGNAL( taskUpdated ),
                     self.handleTaskUpdated)

    def handleButton(self):
        self.progress.setRange(0, 4)
        self.progress.setValue(0)
        self.thread.quit()
        self.thread.start()

    def handleTaskUpdated(self):
        self.progress.setValue(self.progress.value() + 1)

    def closeEvent(self, event):
        self.thread.wait()

if __name__ == "__main__":

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())




相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...

热门标签