connect.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from PyQt5 import QtWidgets
  2. from PyQt5.QtCore import QObject, pyqtSignal, QThread
  3. from PyQt5.uic import loadUi
  4. from lyberry_qt.helpers import relative_path
  5. class Connector(QObject):
  6. finished = pyqtSignal(bool)
  7. def __init__(self, lbry):
  8. self._lbry = lbry
  9. super().__init__()
  10. def run(self):
  11. items = []
  12. for i,code in enumerate(self._lbry.connect()):
  13. if code == 0:
  14. self.finished.emit(True)
  15. break
  16. elif code == 1:
  17. self.finished.emit(False)
  18. break
  19. class ConnectingWidget(QtWidgets.QDialog):
  20. def __init__(self, lbry):
  21. super(ConnectingWidget, self).__init__()
  22. loadUi(relative_path('designer/connecting.ui'), self)
  23. self._lbry = lbry
  24. self.reconnect_button.clicked.connect(self.reconnect)
  25. self.thread = QThread()
  26. self.url = 'about:connecting'
  27. def reconnect(self):
  28. self.status.setText('RECONNECTING')
  29. if self._lbry.online():
  30. self.close()
  31. elif self._lbry.initialising():
  32. self.status.setText('INITIALISING')
  33. self.reconnect_button.setEnabled(False)
  34. self.worker = Connector(self._lbry)
  35. self.worker.moveToThread(self.thread)
  36. self.thread.started.connect(self.worker.run)
  37. self.worker.finished.connect(self.close)
  38. self.worker.finished.connect(self.worker.deleteLater)
  39. self.worker.finished.connect(self.thread.quit)
  40. self.thread.start()
  41. else:
  42. self.status.setText('OFFLINE')