section_play_melody.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from widgets import *
  2. import audio_player
  3. import settings
  4. _melody_line_edit: QLineEdit
  5. def _on_default_melody_path_edited(new_path: str) -> None:
  6. settings.default_melody = new_path
  7. settings.save_settings()
  8. def _play_default_melody() -> None:
  9. melody = settings.default_melody
  10. audio_player.play(melody)
  11. def _pick_default_melody() -> None:
  12. global _melody_line_edit
  13. file_name = QFileDialog.getOpenFileName(caption='Выберите мелодию звонка по умолчанию', filter='*.wav')[0]
  14. if file_name == '':
  15. return
  16. settings.default_melody = file_name
  17. settings.save_settings()
  18. _melody_line_edit.setText(file_name)
  19. def create(style: QStyle) -> QWidget:
  20. global _melody_line_edit
  21. frame = SectionFrame()
  22. layout = QVBoxLayout(frame)
  23. top_bar_layout = QHBoxLayout()
  24. label = QLabel('Мелодия для проигрывания:')
  25. label.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
  26. button_pick = QPushButton(icon=style.standardIcon(QStyle.StandardPixmap.SP_DirOpenIcon))
  27. button_pick.clicked.connect(_pick_default_melody)
  28. top_bar_layout.addWidget(label)
  29. top_bar_layout.addWidget(button_pick)
  30. layout.addLayout(top_bar_layout)
  31. default_melody = settings.default_melody
  32. _melody_line_edit = QLineEdit(default_melody)
  33. _melody_line_edit.textEdited.connect(_on_default_melody_path_edited)
  34. layout.addWidget(_melody_line_edit)
  35. icon = style.standardIcon(QStyle.StandardPixmap.SP_MediaPlay)
  36. button_play = QPushButton(icon, 'Воспроизвести мелодию')
  37. button_play.clicked.connect(_play_default_melody)
  38. layout.addWidget(button_play)
  39. return frame