bauiv1lib.soundtrack.macmusicapp

UI functionality related to using the macOS Music app for soundtracks.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI functionality related to using the macOS Music app for soundtracks."""
  4
  5from __future__ import annotations
  6
  7import copy
  8from typing import TYPE_CHECKING
  9
 10import bauiv1 as bui
 11
 12if TYPE_CHECKING:
 13    from typing import Any, Callable
 14
 15
 16class MacMusicAppPlaylistSelectWindow(bui.MainWindow):
 17    """Window for selecting an iTunes playlist."""
 18
 19    def __init__(
 20        self,
 21        callback: Callable[[Any], Any],
 22        existing_playlist: str | None,
 23        existing_entry: Any,
 24        transition: str | None = 'in_right',
 25        origin_widget: bui.Widget | None = None,
 26    ):
 27        from baclassic.macmusicapp import MacMusicAppMusicPlayer
 28
 29        self._r = 'editSoundtrackWindow'
 30        self._callback = callback
 31        self._existing_playlist = existing_playlist
 32        self._existing_entry = copy.deepcopy(existing_entry)
 33        self._width = 520.0
 34        self._height = 520.0
 35        self._spacing = 45.0
 36        v = self._height - 90.0
 37        v -= self._spacing * 1.0
 38        super().__init__(
 39            root_widget=bui.containerwidget(size=(self._width, self._height)),
 40            transition=transition,
 41            origin_widget=origin_widget,
 42        )
 43        btn = bui.buttonwidget(
 44            parent=self._root_widget,
 45            position=(35, self._height - 65),
 46            size=(130, 50),
 47            label=bui.Lstr(resource='cancelText'),
 48            on_activate_call=self._back,
 49            autoselect=True,
 50        )
 51        bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 52        assert bui.app.classic is not None
 53        bui.textwidget(
 54            parent=self._root_widget,
 55            position=(20, self._height - 54),
 56            size=(self._width, 25),
 57            text=bui.Lstr(resource=f'{self._r}.selectAPlaylistText'),
 58            color=bui.app.ui_v1.title_color,
 59            h_align='center',
 60            v_align='center',
 61            maxwidth=200,
 62        )
 63        self._scrollwidget = bui.scrollwidget(
 64            parent=self._root_widget,
 65            position=(40, v - 340),
 66            size=(self._width - 80, 400),
 67            claims_tab=True,
 68            selection_loops_to_parent=True,
 69        )
 70        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
 71        self._column = bui.columnwidget(
 72            parent=self._scrollwidget,
 73            claims_tab=True,
 74            selection_loops_to_parent=True,
 75        )
 76
 77        bui.textwidget(
 78            parent=self._column,
 79            size=(self._width - 80, 22),
 80            text=bui.Lstr(resource=f'{self._r}.fetchingITunesText'),
 81            color=(0.6, 0.9, 0.6, 1.0),
 82            scale=0.8,
 83        )
 84        assert bui.app.classic is not None
 85        musicplayer = bui.app.classic.music.get_music_player()
 86        assert isinstance(musicplayer, MacMusicAppMusicPlayer)
 87        musicplayer.get_playlists(self._playlists_cb)
 88        bui.containerwidget(
 89            edit=self._root_widget, selected_child=self._scrollwidget
 90        )
 91
 92    def _playlists_cb(self, playlists: list[str]) -> None:
 93        if self._column:
 94            for widget in self._column.get_children():
 95                widget.delete()
 96            for i, playlist in enumerate(playlists):
 97                txt = bui.textwidget(
 98                    parent=self._column,
 99                    size=(self._width - 80, 30),
100                    text=playlist,
101                    v_align='center',
102                    maxwidth=self._width - 110,
103                    selectable=True,
104                    on_activate_call=bui.Call(self._sel, playlist),
105                    click_activate=True,
106                )
107                bui.widget(edit=txt, show_buffer_top=40, show_buffer_bottom=40)
108                if playlist == self._existing_playlist:
109                    bui.columnwidget(
110                        edit=self._column, selected_child=txt, visible_child=txt
111                    )
112                if i == len(playlists) - 1:
113                    bui.widget(edit=txt, down_widget=txt)
114
115    def _sel(self, selection: str) -> None:
116        if self._root_widget:
117            # bui.containerwidget(
118            # edit=self._root_widget, transition='out_right')
119            self._callback({'type': 'iTunesPlaylist', 'name': selection})
120            self.main_window_back()
121
122    def _back(self) -> None:
123        # bui.containerwidget(edit=self._root_widget, transition='out_right')
124        self.main_window_back()
125        self._callback(self._existing_entry)
class MacMusicAppPlaylistSelectWindow(bauiv1._uitypes.MainWindow):
 17class MacMusicAppPlaylistSelectWindow(bui.MainWindow):
 18    """Window for selecting an iTunes playlist."""
 19
 20    def __init__(
 21        self,
 22        callback: Callable[[Any], Any],
 23        existing_playlist: str | None,
 24        existing_entry: Any,
 25        transition: str | None = 'in_right',
 26        origin_widget: bui.Widget | None = None,
 27    ):
 28        from baclassic.macmusicapp import MacMusicAppMusicPlayer
 29
 30        self._r = 'editSoundtrackWindow'
 31        self._callback = callback
 32        self._existing_playlist = existing_playlist
 33        self._existing_entry = copy.deepcopy(existing_entry)
 34        self._width = 520.0
 35        self._height = 520.0
 36        self._spacing = 45.0
 37        v = self._height - 90.0
 38        v -= self._spacing * 1.0
 39        super().__init__(
 40            root_widget=bui.containerwidget(size=(self._width, self._height)),
 41            transition=transition,
 42            origin_widget=origin_widget,
 43        )
 44        btn = bui.buttonwidget(
 45            parent=self._root_widget,
 46            position=(35, self._height - 65),
 47            size=(130, 50),
 48            label=bui.Lstr(resource='cancelText'),
 49            on_activate_call=self._back,
 50            autoselect=True,
 51        )
 52        bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 53        assert bui.app.classic is not None
 54        bui.textwidget(
 55            parent=self._root_widget,
 56            position=(20, self._height - 54),
 57            size=(self._width, 25),
 58            text=bui.Lstr(resource=f'{self._r}.selectAPlaylistText'),
 59            color=bui.app.ui_v1.title_color,
 60            h_align='center',
 61            v_align='center',
 62            maxwidth=200,
 63        )
 64        self._scrollwidget = bui.scrollwidget(
 65            parent=self._root_widget,
 66            position=(40, v - 340),
 67            size=(self._width - 80, 400),
 68            claims_tab=True,
 69            selection_loops_to_parent=True,
 70        )
 71        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
 72        self._column = bui.columnwidget(
 73            parent=self._scrollwidget,
 74            claims_tab=True,
 75            selection_loops_to_parent=True,
 76        )
 77
 78        bui.textwidget(
 79            parent=self._column,
 80            size=(self._width - 80, 22),
 81            text=bui.Lstr(resource=f'{self._r}.fetchingITunesText'),
 82            color=(0.6, 0.9, 0.6, 1.0),
 83            scale=0.8,
 84        )
 85        assert bui.app.classic is not None
 86        musicplayer = bui.app.classic.music.get_music_player()
 87        assert isinstance(musicplayer, MacMusicAppMusicPlayer)
 88        musicplayer.get_playlists(self._playlists_cb)
 89        bui.containerwidget(
 90            edit=self._root_widget, selected_child=self._scrollwidget
 91        )
 92
 93    def _playlists_cb(self, playlists: list[str]) -> None:
 94        if self._column:
 95            for widget in self._column.get_children():
 96                widget.delete()
 97            for i, playlist in enumerate(playlists):
 98                txt = bui.textwidget(
 99                    parent=self._column,
100                    size=(self._width - 80, 30),
101                    text=playlist,
102                    v_align='center',
103                    maxwidth=self._width - 110,
104                    selectable=True,
105                    on_activate_call=bui.Call(self._sel, playlist),
106                    click_activate=True,
107                )
108                bui.widget(edit=txt, show_buffer_top=40, show_buffer_bottom=40)
109                if playlist == self._existing_playlist:
110                    bui.columnwidget(
111                        edit=self._column, selected_child=txt, visible_child=txt
112                    )
113                if i == len(playlists) - 1:
114                    bui.widget(edit=txt, down_widget=txt)
115
116    def _sel(self, selection: str) -> None:
117        if self._root_widget:
118            # bui.containerwidget(
119            # edit=self._root_widget, transition='out_right')
120            self._callback({'type': 'iTunesPlaylist', 'name': selection})
121            self.main_window_back()
122
123    def _back(self) -> None:
124        # bui.containerwidget(edit=self._root_widget, transition='out_right')
125        self.main_window_back()
126        self._callback(self._existing_entry)

Window for selecting an iTunes playlist.

MacMusicAppPlaylistSelectWindow( callback: Callable[[Any], Any], existing_playlist: str | None, existing_entry: Any, transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
20    def __init__(
21        self,
22        callback: Callable[[Any], Any],
23        existing_playlist: str | None,
24        existing_entry: Any,
25        transition: str | None = 'in_right',
26        origin_widget: bui.Widget | None = None,
27    ):
28        from baclassic.macmusicapp import MacMusicAppMusicPlayer
29
30        self._r = 'editSoundtrackWindow'
31        self._callback = callback
32        self._existing_playlist = existing_playlist
33        self._existing_entry = copy.deepcopy(existing_entry)
34        self._width = 520.0
35        self._height = 520.0
36        self._spacing = 45.0
37        v = self._height - 90.0
38        v -= self._spacing * 1.0
39        super().__init__(
40            root_widget=bui.containerwidget(size=(self._width, self._height)),
41            transition=transition,
42            origin_widget=origin_widget,
43        )
44        btn = bui.buttonwidget(
45            parent=self._root_widget,
46            position=(35, self._height - 65),
47            size=(130, 50),
48            label=bui.Lstr(resource='cancelText'),
49            on_activate_call=self._back,
50            autoselect=True,
51        )
52        bui.containerwidget(edit=self._root_widget, cancel_button=btn)
53        assert bui.app.classic is not None
54        bui.textwidget(
55            parent=self._root_widget,
56            position=(20, self._height - 54),
57            size=(self._width, 25),
58            text=bui.Lstr(resource=f'{self._r}.selectAPlaylistText'),
59            color=bui.app.ui_v1.title_color,
60            h_align='center',
61            v_align='center',
62            maxwidth=200,
63        )
64        self._scrollwidget = bui.scrollwidget(
65            parent=self._root_widget,
66            position=(40, v - 340),
67            size=(self._width - 80, 400),
68            claims_tab=True,
69            selection_loops_to_parent=True,
70        )
71        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
72        self._column = bui.columnwidget(
73            parent=self._scrollwidget,
74            claims_tab=True,
75            selection_loops_to_parent=True,
76        )
77
78        bui.textwidget(
79            parent=self._column,
80            size=(self._width - 80, 22),
81            text=bui.Lstr(resource=f'{self._r}.fetchingITunesText'),
82            color=(0.6, 0.9, 0.6, 1.0),
83            scale=0.8,
84        )
85        assert bui.app.classic is not None
86        musicplayer = bui.app.classic.music.get_music_player()
87        assert isinstance(musicplayer, MacMusicAppMusicPlayer)
88        musicplayer.get_playlists(self._playlists_cb)
89        bui.containerwidget(
90            edit=self._root_widget, selected_child=self._scrollwidget
91        )

Create a MainWindow given a root widget and transition info.

Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.

Inherited Members
bauiv1._uitypes.MainWindow
main_window_back_state
main_window_close
can_change_main_window
main_window_back
main_window_replace
on_main_window_close
get_main_window_state
bauiv1._uitypes.Window
get_root_widget