Move icons to subclass (object) __icons

This commit is contained in:
Wiktor Zykubek 2023-07-16 16:20:48 +02:00
parent 1fc5660c31
commit 338c18ae92
No known key found for this signature in database
GPG Key ID: 0DAA9DC01449FCA2

View File

@ -20,10 +20,17 @@ class MainWindow(QMainWindow):
super().__init__() super().__init__()
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
volume_icon = self.style().standard_icon(QStyle.SP_MediaVolume)
playback_icon = self.style().standard_icon(QStyle.SP_MediaPlay) class __icons(object):
self.ui.volumeToolButton.icon = volume_icon volume = self.style().standard_icon(QStyle.SP_MediaVolume)
self.ui.playbackToolButton.icon = playback_icon muted = self.style().standard_icon(QStyle.SP_MediaVolumeMuted)
play = self.style().standard_icon(QStyle.SP_MediaPlay)
stop = self.style().standard_icon(QStyle.SP_MediaStop)
self.__icons = __icons
self.ui.volumeToolButton.icon = self.__icons.volume
self.ui.playbackToolButton.icon = self.__icons.play
self.__stations_data = self.get_stations_data() self.__stations_data = self.get_stations_data()
self.__player = QMediaPlayer() self.__player = QMediaPlayer()
@ -86,12 +93,12 @@ class MainWindow(QMainWindow):
"""Toggle playback volume between 0 and DEFAULT_VOLUME.""" """Toggle playback volume between 0 and DEFAULT_VOLUME."""
if self.ui.volumeHorizontalSlider.value == 0: if self.ui.volumeHorizontalSlider.value == 0:
self.ui.volumeHorizontalSlider.value = self.previous_volume self.ui.volumeHorizontalSlider.value = self.previous_volume
icon = self.style().standard_icon(QStyle.SP_MediaVolume) icon = self.__icons.volume
self.set_volume(self.previous_volume) self.set_volume(self.previous_volume)
else: else:
self.previous_volume = self.__audio.volume * 100 self.previous_volume = self.__audio.volume * 100
self.ui.volumeHorizontalSlider.value = 0 self.ui.volumeHorizontalSlider.value = 0
icon = self.style().standard_icon(QStyle.SP_MediaVolumeMuted) icon = self.__icons.muted
self.set_volume(0) self.set_volume(0)
self.ui.volumeToolButton.icon = icon self.ui.volumeToolButton.icon = icon
@ -118,10 +125,10 @@ class MainWindow(QMainWindow):
pb_state = QMediaPlayer.PlaybackState pb_state = QMediaPlayer.PlaybackState
if self.__player.playback_state == pb_state.PlayingState: if self.__player.playback_state == pb_state.PlayingState:
self.__player.stop() self.__player.stop()
icon = self.style().standard_icon(QStyle.SP_MediaPlay) icon = self.__icons.play
elif self.__player.playback_state == pb_state.StoppedState: elif self.__player.playback_state == pb_state.StoppedState:
self.__player.play() self.__player.play()
icon = self.style().standard_icon(QStyle.SP_MediaStop) icon = self.__icons.stop
else: else:
pass pass