python - Simple torrent client with PyQt -


recently have started python practice. it's useful pl, when you're using linux. here's problem: simplicity of qt , power of python has overgrown me little bit. want build simple torrent client using pyqt , libtorrent. i've got ready use code of downloading 1 torrent @ time. although, i'm having trouble integrating app code qt's code. here's code of torrent.py: #!/usr/bin/python import sys pyqt4 import qtcore, qtgui import libtorrent lt import time

from torrent_ui import ui_form, ses   class myform(qtgui.qmainwindow):     def __init__(self, parent=none):         qtgui.qwidget.__init__(self, parent)         self.ui = ui_form()         self.ui.setupui(self)   if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     myapp = myform()     myapp.show()       ses.listen_on(6881, 6891)     #e = lt.bdecode(open("test.torrent", 'rb').read())     info = lt.torrent_info("g.torrent")     h = ses.add_torrent({'ti': info, 'save_path': './'})     print 'starting', h.name()      while (not h.is_seed()):        s = h.status()         state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']        print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]),        sys.stdout.flush()        #ses.pause()         time.sleep(1)      print h.name(), 'complete'     sys.exit(app.exec_()) 

the code generated pyqt:

#!/usr/bin/python # -*- coding: utf-8 -*-  # form implementation generated reading ui file 'untitled.ui' # # created: mon apr 29 21:13:06 2013 #      by: pyqt4 ui code generator 4.10 # # warning! changes made in file lost!  pyqt4 import qtcore, qtgui import sys import libtorrent lt ses = lt.session() try:     _fromutf8 = qtcore.qstring.fromutf8 except attributeerror:     def _fromutf8(s):         return s  try:     _encoding = qtgui.qapplication.unicodeutf8     def _translate(context, text, disambig):         return qtgui.qapplication.translate(context, text, disambig, _encoding) except attributeerror:     def _translate(context, text, disambig):         return qtgui.qapplication.translate(context, text, disambig)  class ui_form(object):     def setupui(self, form):         form.setobjectname(_fromutf8("form"))         form.resize(640, 480)         self.closeb = qtgui.qpushbutton(form)         self.closeb.setgeometry(qtcore.qrect(520, 440, 98, 27))         self.closeb.setobjectname(_fromutf8("closeb"))         self.listview = qtgui.qlistview(form)         self.listview.setgeometry(qtcore.qrect(30, 20, 581, 261))         self.listview.setobjectname(_fromutf8("listview"))         self.newtorb = qtgui.qpushbutton(form)         self.newtorb.setgeometry(qtcore.qrect(30, 300, 98, 27))         self.newtorb.setobjectname(_fromutf8("newtorb"))         self.stopb = qtgui.qpushbutton(form)         self.stopb.setgeometry(qtcore.qrect(130, 300, 98, 27))         self.stopb.setobjectname(_fromutf8("stopb"))         self.pauseb = qtgui.qpushbutton(form)         self.pauseb.setgeometry(qtcore.qrect(230, 300, 98, 27))         self.pauseb.setobjectname(_fromutf8("pauseb"))         self.selectallb = qtgui.qpushbutton(form)         self.selectallb.setgeometry(qtcore.qrect(330, 300, 141, 27))         self.selectallb.setobjectname(_fromutf8("selectallb"))         #self.ses = lt.session()         self.retranslateui(form)         qtcore.qobject.connect(self.closeb, qtcore.signal(_fromutf8("clicked()")), form.close)         qtcore.qobject.connect(self.pauseb, qtcore.signal(_fromutf8("clicked()")), self.pausef)         qtcore.qobject.connect(self.stopb, qtcore.signal(_fromutf8("clicked()")), self.stopb.click)         qtcore.qobject.connect(self.newtorb, qtcore.signal(_fromutf8("clicked()")), self.newtorb.click)         qtcore.qobject.connect(self.selectallb, qtcore.signal(_fromutf8("clicked()")), self.listview.selectall)         qtcore.qmetaobject.connectslotsbyname(form)      def retranslateui(self, form):         form.setwindowtitle(_translate("form", "jktorrent", none))         self.closeb.settext(_translate("form", "close", none))         self.newtorb.settext(_translate("form", "dodaj newtor", none))         self.stopb.settext(_translate("form", "stop", none))         self.pauseb.settext(_translate("form", "pause", none))         self.selectallb.settext(_translate("form", "zaznacz wszystkie", none))     def pausef(self):         self.ses.pause() 

the main problem is, when torrent downloading works, qt app window not show up. other problem's don't know how put libtorrent code fancy qt window (to print of data list view). please, me that.

your problem have code before app.exec_(). window shows when executed. part

ses.listen_on(6881, 6891) #e = lt.bdecode(open("test.torrent", 'rb').read()) info = lt.torrent_info("g.torrent") h = ses.add_torrent({'ti': info, 'save_path': './'}) print 'starting', h.name()  while (not h.is_seed()):    s = h.status()     state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']    print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]),    sys.stdout.flush()    #ses.pause()     time.sleep(1) 

should removed main function , should running, maybe in separate thread, in function started in __init__ of myform.

it's bit unclear problems qlistview are. recommend use qtreewidget instead, found documentation quite helpful.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -