thread.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ########################################################################
  2. # Wiizard - A Wii games manager
  3. # Copyright (C) 2023 CYBERDEViL
  4. #
  5. # This file is part of Wiizard.
  6. #
  7. # Wiizard is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Wiizard is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. from PyQt5.QtCore import QThread, pyqtSignal
  22. THREAD_FLAG_IS_CANCELLABLE = 1
  23. THREAD_FLAG_IS_STOPABLE = 2
  24. class AbstractThread(QThread):
  25. completed = pyqtSignal()
  26. def __init__(self, flags=0):
  27. QThread.__init__(self)
  28. self.__flags = flags
  29. self.__cancel = False
  30. @property
  31. def flags(self):
  32. return self.__flags
  33. @property
  34. def cancelled(self):
  35. return self.__cancel
  36. def cancel(self):
  37. self.__cancel = True
  38. def run(self):
  39. raise Exception("Re-implement this!")
  40. def stop(self):
  41. raise Exception("Re-implement this if your thread is stoppable!")