gui.py 6.2 KB

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