开发者

pygtk progressbar is not working

when my program receiving new file file is copied fine but progress bar is not moving... if possible please suggest me a better algo.. Thanks

    def filetransfer(self):
        s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind(('',30098))
        s.listen(1)
        data='val'
        while True:
            request = s.accept()
            if request!=None:
                new_sock,addr=request
                break
        print 'Connected by', addr
        destination=open(data,'wb')
        while data!='':
            time.sleep(0.01)
            start=time.time()
            data=new_sock.recv(1024)
            end=time.time()
            xact=int(end-start)
            destination.write(data)
            self.run(xact)      
       new_sock.close()
       s.close()
       return


    def run_(self,xact):
       gobject.timeout_add(xact, self.update)
    def update(self):       
        if self.progressbar.get_fraction() &开发者_StackOverflow社区gt;= 1.0:
             value = 0.0
         else:
             value = self.progressbar.get_fraction() + 0.1
         self.progressbar.set_fraction(value) 
         percent = value * 100
         percent = str(int(percent))
         self.progressbar.set_text(percent + "%")
         return True


I'm not sure why so many people answer in the comments...

You need to call "Update()" inside of a loop, as in the question posted in the comment above.

Progress bar not updating during operation

However, if this doesn't work, please update the question so I can help you further.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜