log.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. import sys
  13. from termcolor import colored
  14. from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
  15. QApplication,
  16. QMessageBox,
  17. )
  18. # pylint: disable=too-few-public-methods
  19. class InfoMsgBox:
  20. def __init__(self, icon: QMessageBox.Icon, title: str, text: str) -> None:
  21. self.app = QApplication([])
  22. self.title = title
  23. self.text = text
  24. self.icon = icon
  25. self.show_msg_box()
  26. self.app.exec_()
  27. def show_msg_box(self):
  28. self.message_box = QMessageBox()
  29. self.message_box.setIcon(self.icon)
  30. self.message_box.setWindowTitle(self.title)
  31. self.message_box.setText(self.text)
  32. self.message_box.show()
  33. def error_msg(msg: str):
  34. print(colored("[*] Error: {}".format(msg), "red"))
  35. sys.exit(1)
  36. def warn(message: str) -> None:
  37. print(colored("[*] Warning: {}".format(message), "yellow"))
  38. def log(message: str, color="green") -> None:
  39. print(colored("[*] {}".format(message), color)) # pyright: ignore
  40. class CustomException(Exception):
  41. pass