gui.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. QHBoxLayout,
  19. QStyle,
  20. QLabel,
  21. QRadioButton,
  22. QPushButton,
  23. QMessageBox,
  24. QButtonGroup,
  25. QScrollArea,
  26. QWidget,
  27. )
  28. from PyQt5.QtCore import QSize
  29. # pylint: disable=too-few-public-methods
  30. class InfoMsgBox:
  31. def __init__(self, icon: QMessageBox.Icon, title: str, text: str) -> None:
  32. self.app = QApplication([])
  33. self.title = title
  34. self.text = text
  35. self.icon = icon
  36. self.show_msg_box()
  37. self.app.exec_()
  38. def show_msg_box(self):
  39. self.message_box = QMessageBox()
  40. self.message_box.setIcon(self.icon)
  41. self.message_box.setWindowTitle(self.title)
  42. self.message_box.setText(self.text)
  43. self.message_box.show()
  44. class RadioButtonDialog(QDialog): # pylint: disable=too-few-public-methods
  45. def __init__(self, options: list[str], window_title: str):
  46. super().__init__()
  47. self.setWindowTitle(window_title)
  48. master_layout = QVBoxLayout(self)
  49. scroll_area = QScrollArea()
  50. scroll_area.setWidgetResizable(True)
  51. master_layout.addWidget(scroll_area)
  52. scroll_content = QWidget()
  53. scroll_area.setWidget(scroll_content)
  54. scroll_area_layout = QVBoxLayout(scroll_content)
  55. self.radio_button_group = QButtonGroup(self)
  56. self.chosen = ""
  57. for num, item in enumerate(options):
  58. radio_button = QRadioButton(item)
  59. if num == 0:
  60. radio_button.setChecked(True)
  61. self.radio_button_group.addButton(radio_button)
  62. scroll_area_layout.addWidget(radio_button)
  63. ok_button = QPushButton("OK")
  64. ok_button.clicked.connect(self.accept)
  65. master_layout.addWidget(ok_button)
  66. def accept(self):
  67. selected_button = self.radio_button_group.checkedButton()
  68. if selected_button:
  69. self.chosen = selected_button.text()
  70. # QMessageBox.information(
  71. # self, "Selection", f"You selected: {selected_button.text()}"
  72. # )
  73. super().accept()
  74. else:
  75. QMessageBox.warning(
  76. self,
  77. "No Selection",
  78. "Please select an option before proceeding.",
  79. )
  80. class SheetAndPreviewChooser(QDialog): # pylint: disable=too-few-public-methods
  81. def __init__(
  82. self, base_dir: str, options: list[str], window_title: str
  83. ) -> None:
  84. super().__init__()
  85. self.setWindowTitle(window_title)
  86. master_layout = QVBoxLayout(self)
  87. scroll_area = QScrollArea()
  88. scroll_area.setWidgetResizable(True)
  89. master_layout.addWidget(scroll_area)
  90. scroll_content = QWidget()
  91. scroll_area.setWidget(scroll_content)
  92. scroll_area_layout = QVBoxLayout(scroll_content)
  93. self.radio_button_group = QButtonGroup(self)
  94. self.chosen = ""
  95. for num, item in enumerate(options):
  96. radio_button = QRadioButton(item)
  97. if num == 0:
  98. radio_button.setChecked(True)
  99. button_layout = QHBoxLayout()
  100. self.radio_button_group.addButton(radio_button)
  101. button_layout.addWidget(radio_button)
  102. play_button = self.get_player_button("SP_MediaPlay")
  103. play_button.setToolTip("Play CD Preview")
  104. pause_button = self.get_player_button("SP_MediaPause")
  105. pause_button.setToolTip("Pause CD Preview")
  106. stop_button = self.get_player_button("SP_MediaStop")
  107. stop_button.setToolTip("Stop CD Preview")
  108. seek_bwd_button = self.get_player_button("SP_MediaSeekBackward")
  109. seek_bwd_button.setToolTip("Seek 10 seconds backwards")
  110. seek_fwd_button = self.get_player_button("SP_MediaSeekForward")
  111. seek_fwd_button.setToolTip("Seek 10 seconds forwards")
  112. button_layout.addWidget(play_button)
  113. button_layout.addWidget(pause_button)
  114. button_layout.addWidget(stop_button)
  115. button_layout.addWidget(seek_bwd_button)
  116. button_layout.addWidget(seek_fwd_button)
  117. button_layout.addWidget(QLabel("01:23 / 80:00"))
  118. scroll_area_layout.addLayout(button_layout)
  119. ok_button = QPushButton("OK")
  120. ok_button.clicked.connect(self.accept)
  121. master_layout.addWidget(ok_button)
  122. def get_player_button(self, icon_name: str) -> QPushButton:
  123. stop_button = QPushButton("")
  124. stop_button.setMinimumSize(QSize(40, 40))
  125. stop_button.setMaximumSize(QSize(40, 40))
  126. pixmapi = getattr(QStyle, icon_name)
  127. icon = self.style().standardIcon(pixmapi) # pyright: ignore
  128. stop_button.setIcon(icon)
  129. return stop_button
  130. def accept(self):
  131. selected_button = self.radio_button_group.checkedButton()
  132. if selected_button:
  133. self.chosen = selected_button.text()
  134. # QMessageBox.information(
  135. # self, "Selection", f"You selected: {selected_button.text()}"
  136. # )
  137. super().accept()
  138. else:
  139. QMessageBox.warning(
  140. self,
  141. "No Selection",
  142. "Please select an option before proceeding.",
  143. )