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