Skip to content

Commit 0790e25

Browse files
committed
feat(media): add 'controls_hide' option to manage media controls visibility
- Introduced a new boolean property 'controls_hide' to the MediaWidget. - Updated validation schema and documentation to reflect this new option. - Adjusted media control rendering logic based on the 'controls_hide' setting.
1 parent 6238e34 commit 0790e25

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

docs/widgets/(Widget)-Media.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| `show_thumbnail` | boolean | true | Whether to show the media thumbnail. |
1111
| `controls_only` | boolean | false | Whether to show only the media controls. |
1212
| `controls_left` | boolean | true | Whether to position the controls on the left. |
13+
| `controls_hide` | boolean | false | Whether to hide the media controls buttons |
1314
| `hide_empty` | boolean | true | Whether to hide the widget when there is no media information. |
1415
| `thumbnail_alpha` | integer | 50 | The alpha transparency value for the thumbnail. |
1516
| `thumbnail_padding` | integer | 8 | The padding around the thumbnail. |
@@ -40,6 +41,7 @@ media:
4041
show_thumbnail: true
4142
controls_only: false
4243
controls_left: true
44+
controls_hide: false
4345
thumbnail_alpha: 80
4446
thumbnail_padding: 8
4547
thumbnail_corner_radius: 16
@@ -59,6 +61,7 @@ media:
5961
- **show_thumbnail:** Whether to show the media thumbnail.
6062
- **controls_only:** Whether to show only the media controls.
6163
- **controls_left:** Whether to place the media controls on the left.
64+
- **controls_hide:** Whether to hide the media controls buttons.
6265
- **thumbnail_alpha:** The alpha (transparency) value for the media thumbnail.
6366
- **thumbnail_padding:** The padding around the media thumbnail.
6467
- **thumbnail_corner_radius:** The corner radius for the media thumbnail. Set to 0 for square corners.

src/core/validation/widgets/yasb/media.py

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
'type': 'boolean',
117117
'default': True
118118
},
119+
'controls_hide': {
120+
'type': 'boolean',
121+
'default': False
122+
},
119123
'thumbnail_alpha': {
120124
'type': 'integer',
121125
'default': 50,

src/core/widgets/yasb/media.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(
3232
show_thumbnail: bool,
3333
controls_only: bool,
3434
controls_left: bool,
35+
controls_hide: bool,
3536
thumbnail_alpha: int,
3637
thumbnail_padding: int,
3738
thumbnail_corner_radius: int,
@@ -49,6 +50,7 @@ def __init__(
4950
self._media_button_icons = icons
5051
self._controls_only = controls_only
5152
self._controls_left = controls_left
53+
self._controls_hide = controls_hide
5254
self._thumbnail_padding = thumbnail_padding
5355
self._thumbnail_corner_radius = thumbnail_corner_radius
5456
self._hide_empty = hide_empty
@@ -157,17 +159,18 @@ def _on_session_status_changed(self, has_session: bool):
157159
@QtCore.pyqtSlot(GlobalSystemMediaTransportControlsSessionPlaybackInfo)
158160
def _on_playback_info_changed(self, playback_info: GlobalSystemMediaTransportControlsSessionPlaybackInfo):
159161
# Set play-pause state icon
160-
self._play_label.setText(self._media_button_icons['pause' if playback_info.playback_status == 4 else 'play'])
162+
if not self._controls_hide:
163+
self._play_label.setText(self._media_button_icons['pause' if playback_info.playback_status == 4 else 'play'])
161164

162-
enabled_if = lambda enabled: "disabled" if not enabled else ""
163-
self._prev_label.setProperty("class", f"btn prev {enabled_if(playback_info.controls.is_previous_enabled)}")
164-
self._play_label.setProperty("class", f"btn play {enabled_if(playback_info.controls.is_play_pause_toggle_enabled)}")
165-
self._next_label.setProperty("class", f"btn next {enabled_if(playback_info.controls.is_next_enabled)}")
165+
enabled_if = lambda enabled: "disabled" if not enabled else ""
166+
self._prev_label.setProperty("class", f"btn prev {enabled_if(playback_info.controls.is_previous_enabled)}")
167+
self._play_label.setProperty("class", f"btn play {enabled_if(playback_info.controls.is_play_pause_toggle_enabled)}")
168+
self._next_label.setProperty("class", f"btn next {enabled_if(playback_info.controls.is_next_enabled)}")
166169

167-
# Refresh style sheets
168-
self._prev_label.setStyleSheet('')
169-
self._play_label.setStyleSheet('')
170-
self._next_label.setStyleSheet('')
170+
# Refresh style sheets
171+
self._prev_label.setStyleSheet('')
172+
self._play_label.setStyleSheet('')
173+
self._next_label.setStyleSheet('')
171174

172175
@QtCore.pyqtSlot(object) # None or dict
173176
def _on_media_properties_changed(self, media_info: Optional[dict[str, Any]]):
@@ -236,12 +239,13 @@ def _format_max_field_size(self, text: str):
236239
return text
237240

238241
def _create_media_button(self, icon, action):
239-
label = ClickableLabel(self)
240-
label.setProperty("class", "btn")
241-
label.setText(icon)
242-
label.data = action
243-
self._widget_container_layout.addWidget(label)
244-
return label
242+
if not self._controls_hide:
243+
label = ClickableLabel(self)
244+
label.setProperty("class", "btn")
245+
label.setText(icon)
246+
label.data = action
247+
self._widget_container_layout.addWidget(label)
248+
return label
245249

246250
def _create_media_buttons(self):
247251
return (self._create_media_button(self._media_button_icons['prev_track'], WindowsMedia.prev),

0 commit comments

Comments
 (0)