gui.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """
  2. Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. """
  14. from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
  15. QApplication,
  16. QDialog,
  17. QVBoxLayout,
  18. QRadioButton,
  19. QPushButton,
  20. QMessageBox,
  21. QButtonGroup,
  22. QScrollArea,
  23. QWidget,
  24. )
  25. # pylint: disable=too-few-public-methods
  26. class InfoMsgBox:
  27. def __init__(self, icon: QMessageBox.Icon, title: str, text: str) -> None:
  28. self.app = QApplication([])
  29. self.title = title
  30. self.text = text
  31. self.icon = icon
  32. self.show_msg_box()
  33. self.app.exec_()
  34. def show_msg_box(self):
  35. self.message_box = QMessageBox()
  36. self.message_box.setIcon(self.icon)
  37. self.message_box.setWindowTitle(self.title)
  38. self.message_box.setText(self.text)
  39. self.message_box.show()
  40. class RadioButtonDialog(QDialog): # pylint: disable=too-few-public-methods
  41. def __init__(self, options: list[str], window_title: str):
  42. super().__init__()
  43. self.setWindowTitle(window_title)
  44. master_layout = QVBoxLayout(self)
  45. scroll_area = QScrollArea()
  46. scroll_area.setWidgetResizable(True)
  47. master_layout.addWidget(scroll_area)
  48. scroll_content = QWidget()
  49. scroll_area.setWidget(scroll_content)
  50. scroll_area_layout = QVBoxLayout(scroll_content)
  51. self.radio_button_group = QButtonGroup(self)
  52. self.chosen = ""
  53. self.radio_buttons = []
  54. for num, item in enumerate(options):
  55. radio_button = QRadioButton(item)
  56. if num == 0:
  57. radio_button.setChecked(True)
  58. self.radio_buttons.append(radio_button)
  59. self.radio_button_group.addButton(radio_button)
  60. scroll_area_layout.addWidget(radio_button)
  61. ok_button = QPushButton("OK")
  62. ok_button.clicked.connect(self.accept)
  63. master_layout.addWidget(ok_button)
  64. def accept(self):
  65. selected_button = self.radio_button_group.checkedButton()
  66. if selected_button:
  67. self.chosen = selected_button.text()
  68. # QMessageBox.information(
  69. # self, "Selection", f"You selected: {selected_button.text()}"
  70. # )
  71. super().accept()
  72. else:
  73. QMessageBox.warning(
  74. self,
  75. "No Selection",
  76. "Please select an option before proceeding.",
  77. )