Convert method names to snake_case

PEP8 rules
This commit is contained in:
Wiktor Zykubek 2023-07-16 15:50:43 +02:00
parent 79b270794e
commit 1fc5660c31
No known key found for this signature in database
GPG Key ID: 0DAA9DC01449FCA2

View File

@ -25,22 +25,22 @@ class MainWindow(QMainWindow):
self.ui.volumeToolButton.icon = volume_icon
self.ui.playbackToolButton.icon = playback_icon
self.__stations_data = self.getStationsData()
self.__stations_data = self.get_stations_data()
self.__player = QMediaPlayer()
self.__audio = QAudioOutput()
self.__player.audio_output = self.__audio
self.printGroups()
self.print_groups()
self.setVolume(DEFAULT_VOLUME)
self.set_volume(DEFAULT_VOLUME)
self.ui.volumeHorizontalSlider.value = DEFAULT_VOLUME
self.ui.groupsListWidget.itemClicked.connect(self.printStations)
self.ui.stationsListWidget.itemClicked.connect(self.playRadio)
self.ui.playbackToolButton.clicked.connect(self.togglePlayer)
self.ui.volumeHorizontalSlider.valueChanged.connect(self.setVolume)
self.ui.volumeToolButton.clicked.connect(self.toggleMute)
self.ui.groupsListWidget.itemClicked.connect(self.print_stations)
self.ui.stationsListWidget.itemClicked.connect(self.play_radio)
self.ui.playbackToolButton.clicked.connect(self.toggle_player)
self.ui.volumeHorizontalSlider.valueChanged.connect(self.set_volume)
self.ui.volumeToolButton.clicked.connect(self.toggle_mute)
def getStationsData(self) -> dict:
def get_stations_data(self) -> dict:
"""Get JSON data from API and convert it to dict."""
try:
resp = requests.get(API_URL)
@ -57,12 +57,12 @@ class MainWindow(QMainWindow):
)
error_box.exec()
def printGroups(self) -> None:
def print_groups(self) -> None:
"""Print groups (categories) in groupsListWidget."""
self.ui.groupsListWidget.add_items(
[e["name"] for e in self.__stations_data["groups"]])
def printStations(self) -> None:
def print_stations(self) -> None:
"""Print stations (channels) in stationsListWidget."""
group = self.ui.groupsListWidget.selected_items()[0].text()
group_id = None
@ -76,27 +76,27 @@ class MainWindow(QMainWindow):
if e["group_id"] == group_id
])
def setVolume(self, volume: int = None) -> None:
def set_volume(self, volume: int = None) -> None:
"""Set playback volume to given number or slider value."""
if not volume:
volume = self.ui.volumeHorizontalSlider.value
self.__audio.volume = volume / 100
def toggleMute(self) -> None:
def toggle_mute(self) -> None:
"""Toggle playback volume between 0 and DEFAULT_VOLUME."""
if self.ui.volumeHorizontalSlider.value == 0:
self.ui.volumeHorizontalSlider.value = self.previous_volume
icon = self.style().standard_icon(QStyle.SP_MediaVolume)
self.setVolume(self.previous_volume)
self.set_volume(self.previous_volume)
else:
self.previous_volume = self.__audio.volume * 100
self.ui.volumeHorizontalSlider.value = 0
icon = self.style().standard_icon(QStyle.SP_MediaVolumeMuted)
self.setVolume(0)
self.set_volume(0)
self.ui.volumeToolButton.icon = icon
def playRadio(self) -> None:
def play_radio(self) -> None:
"""Play station selected by user."""
station = self.ui.stationsListWidget.selected_items()[0].text()
stream_url = None
@ -111,9 +111,9 @@ class MainWindow(QMainWindow):
# the station for the first time, you need to stop and resume playback.
# If you won't, application would crash.
for _ in range(3):
self.togglePlayer()
self.toggle_player()
def togglePlayer(self) -> None:
def toggle_player(self) -> None:
"""Toggle playback (play/stop)."""
pb_state = QMediaPlayer.PlaybackState
if self.__player.playback_state == pb_state.PlayingState: