def __init__(self, parent=None): QWidget.__init__(self, parent) self.ui = DStream_Form() self.downloadthread = DP() self.ui.setupUi(self) self.completer = None self.initUi() self.initSignals()
class DownloadWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.ui = DStream_Form() self.downloadthread = DP() self.ui.setupUi(self) self.completer = None self.initUi() self.initSignals() def initUi(self): self.initModel() self.initCompleter() self.ui.listView.setModel(self.model) def initModel(self): words = [] for contact in Config.openContacts(): words.append(contact[1]) self.model = QStringListModel(words) def initCompleter(self): self.completer = QCompleter(None, self.ui.lineEdit) self.completer.setModel(self.model) self.ui.lineEdit.setCompleter(self.completer) def setpath(self): dialog = QFileDialog() self.path = dialog.getExistingDirectory(self,'Select Directory') self.ui.label_3.setText(str(self.path)) self.downloadthread.config(self.ui.lineEdit.text(), folderpath=self.path) def setfile(self): dialog = QFileDialog() self.filepath = dialog.getOpenFileName() def download(self): self.downloadthread.config(self.ui.lineEdit.text()) self.downloadthread.start() def percentUpdate(self, msg): self.ui.progressBar.setValue(msg) self.ui.progressBar.update() def speedUpdate(self, msg): self.speed = msg self.ui.label_3.setText('<span style="color: green;">'+str(msg)+' kbps'+"</span>") def timeUpdate(self, msg): self.time = msg self.ui.label_4.setText('Time left: ' + str(self.time) + ' seconds') def test(self, msg): print(msg) def setIp(self,index): name = index.data(Qt.DisplayRole) ip = None for contact in Config.openContacts(): if contact[1] == name: ip = contact[0] if ip is not None: self.ui.lineEdit.setText(ip) else: print('Couldn\'t get ip') def initSignals(self): QObject.connect(self.ui.pushButton_2, SIGNAL('clicked()'), self.setpath) QObject.connect(self.ui.pushButton_3, SIGNAL('clicked()'), self.setfile) QObject.connect(self.ui.pushButton, SIGNAL('clicked()'), self.download) QObject.connect(self.downloadthread.DM, SIGNAL('percentUpdate(int)'), self.percentUpdate) QObject.connect(self.downloadthread.DM, SIGNAL('timeUpdate(PyQt_PyObject)'), self.timeUpdate) QObject.connect(self.downloadthread.DM, SIGNAL('speedUpdate(int)'), self.speedUpdate) QObject.connect(self.completer, SIGNAL('activated(QString)'), self.test) QObject.connect(self.ui.listView, SIGNAL('clicked(QModelIndex)'),self.setIp)