bauiv1lib.soundtrack.entrytypeselect
Provides UI for selecting soundtrack entry types.
1# Released under the MIT License. See LICENSE for details. 2# 3"""Provides UI for selecting soundtrack entry types.""" 4from __future__ import annotations 5 6import copy 7from typing import TYPE_CHECKING 8 9import bauiv1 as bui 10 11if TYPE_CHECKING: 12 from typing import Any, Callable 13 14 15class SoundtrackEntryTypeSelectWindow(bui.Window): 16 """Window for selecting a soundtrack entry type.""" 17 18 def __init__( 19 self, 20 callback: Callable[[Any], Any], 21 current_entry: Any, 22 selection_target_name: str, 23 transition: str = 'in_right', 24 ): 25 assert bui.app.classic is not None 26 music = bui.app.classic.music 27 self._r = 'editSoundtrackWindow' 28 29 self._callback = callback 30 self._current_entry = copy.deepcopy(current_entry) 31 32 self._width = 580 33 self._height = 220 34 spacing = 80 35 36 # FIXME: Generalize this so new custom soundtrack types can add 37 # themselves here. 38 do_default = True 39 do_mac_music_app_playlist = music.supports_soundtrack_entry_type( 40 'iTunesPlaylist' 41 ) 42 do_music_file = music.supports_soundtrack_entry_type('musicFile') 43 do_music_folder = music.supports_soundtrack_entry_type('musicFolder') 44 45 if do_mac_music_app_playlist: 46 self._height += spacing 47 if do_music_file: 48 self._height += spacing 49 if do_music_folder: 50 self._height += spacing 51 52 uiscale = bui.app.ui_v1.uiscale 53 54 # NOTE: When something is selected, we close our UI and kick off 55 # another window which then calls us back when its done, so the 56 # standard UI-cleanup-check complains that something is holding on 57 # to our instance after its ui is gone. Should restructure in a 58 # cleaner way, but just disabling that check for now. 59 super().__init__( 60 root_widget=bui.containerwidget( 61 size=(self._width, self._height), 62 transition=transition, 63 scale=( 64 1.7 65 if uiscale is bui.UIScale.SMALL 66 else 1.4 67 if uiscale is bui.UIScale.MEDIUM 68 else 1.0 69 ), 70 ), 71 cleanupcheck=False, 72 ) 73 btn = bui.buttonwidget( 74 parent=self._root_widget, 75 position=(35, self._height - 65), 76 size=(160, 60), 77 scale=0.8, 78 text_scale=1.2, 79 label=bui.Lstr(resource='cancelText'), 80 on_activate_call=self._on_cancel_press, 81 ) 82 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 83 bui.textwidget( 84 parent=self._root_widget, 85 position=(self._width * 0.5, self._height - 32), 86 size=(0, 0), 87 text=bui.Lstr(resource=self._r + '.selectASourceText'), 88 color=bui.app.ui_v1.title_color, 89 maxwidth=230, 90 h_align='center', 91 v_align='center', 92 ) 93 94 bui.textwidget( 95 parent=self._root_widget, 96 position=(self._width * 0.5, self._height - 56), 97 size=(0, 0), 98 text=selection_target_name, 99 color=bui.app.ui_v1.infotextcolor, 100 scale=0.7, 101 maxwidth=230, 102 h_align='center', 103 v_align='center', 104 ) 105 106 v = self._height - 155 107 108 current_entry_type = music.get_soundtrack_entry_type(current_entry) 109 110 if do_default: 111 btn = bui.buttonwidget( 112 parent=self._root_widget, 113 size=(self._width - 100, 60), 114 position=(50, v), 115 label=bui.Lstr(resource=self._r + '.useDefaultGameMusicText'), 116 on_activate_call=self._on_default_press, 117 ) 118 if current_entry_type == 'default': 119 bui.containerwidget(edit=self._root_widget, selected_child=btn) 120 v -= spacing 121 122 if do_mac_music_app_playlist: 123 btn = bui.buttonwidget( 124 parent=self._root_widget, 125 size=(self._width - 100, 60), 126 position=(50, v), 127 label=bui.Lstr(resource=self._r + '.useITunesPlaylistText'), 128 on_activate_call=self._on_mac_music_app_playlist_press, 129 icon=None, 130 ) 131 if current_entry_type == 'iTunesPlaylist': 132 bui.containerwidget(edit=self._root_widget, selected_child=btn) 133 v -= spacing 134 135 if do_music_file: 136 btn = bui.buttonwidget( 137 parent=self._root_widget, 138 size=(self._width - 100, 60), 139 position=(50, v), 140 label=bui.Lstr(resource=self._r + '.useMusicFileText'), 141 on_activate_call=self._on_music_file_press, 142 icon=bui.gettexture('file'), 143 ) 144 if current_entry_type == 'musicFile': 145 bui.containerwidget(edit=self._root_widget, selected_child=btn) 146 v -= spacing 147 148 if do_music_folder: 149 btn = bui.buttonwidget( 150 parent=self._root_widget, 151 size=(self._width - 100, 60), 152 position=(50, v), 153 label=bui.Lstr(resource=self._r + '.useMusicFolderText'), 154 on_activate_call=self._on_music_folder_press, 155 icon=bui.gettexture('folder'), 156 icon_color=(1.1, 0.8, 0.2), 157 ) 158 if current_entry_type == 'musicFolder': 159 bui.containerwidget(edit=self._root_widget, selected_child=btn) 160 v -= spacing 161 162 def _on_mac_music_app_playlist_press(self) -> None: 163 assert bui.app.classic is not None 164 music = bui.app.classic.music 165 from bauiv1lib.soundtrack.macmusicapp import ( 166 MacMusicAppPlaylistSelectWindow, 167 ) 168 169 bui.containerwidget(edit=self._root_widget, transition='out_left') 170 171 current_playlist_entry: str | None 172 if ( 173 music.get_soundtrack_entry_type(self._current_entry) 174 == 'iTunesPlaylist' 175 ): 176 current_playlist_entry = music.get_soundtrack_entry_name( 177 self._current_entry 178 ) 179 else: 180 current_playlist_entry = None 181 bui.app.ui_v1.set_main_menu_window( 182 MacMusicAppPlaylistSelectWindow( 183 self._callback, current_playlist_entry, self._current_entry 184 ).get_root_widget() 185 ) 186 187 def _on_music_file_press(self) -> None: 188 from babase import android_get_external_files_dir 189 from baclassic.osmusic import OSMusicPlayer 190 from bauiv1lib.fileselector import FileSelectorWindow 191 192 bui.containerwidget(edit=self._root_widget, transition='out_left') 193 base_path = android_get_external_files_dir() 194 assert bui.app.classic is not None 195 bui.app.ui_v1.set_main_menu_window( 196 FileSelectorWindow( 197 base_path, 198 callback=self._music_file_selector_cb, 199 show_base_path=False, 200 valid_file_extensions=( 201 OSMusicPlayer.get_valid_music_file_extensions() 202 ), 203 allow_folders=False, 204 ).get_root_widget() 205 ) 206 207 def _on_music_folder_press(self) -> None: 208 from bauiv1lib.fileselector import FileSelectorWindow 209 from babase import android_get_external_files_dir 210 211 bui.containerwidget(edit=self._root_widget, transition='out_left') 212 base_path = android_get_external_files_dir() 213 assert bui.app.classic is not None 214 bui.app.ui_v1.set_main_menu_window( 215 FileSelectorWindow( 216 base_path, 217 callback=self._music_folder_selector_cb, 218 show_base_path=False, 219 valid_file_extensions=[], 220 allow_folders=True, 221 ).get_root_widget() 222 ) 223 224 def _music_file_selector_cb(self, result: str | None) -> None: 225 if result is None: 226 self._callback(self._current_entry) 227 else: 228 self._callback({'type': 'musicFile', 'name': result}) 229 230 def _music_folder_selector_cb(self, result: str | None) -> None: 231 if result is None: 232 self._callback(self._current_entry) 233 else: 234 self._callback({'type': 'musicFolder', 'name': result}) 235 236 def _on_default_press(self) -> None: 237 bui.containerwidget(edit=self._root_widget, transition='out_right') 238 self._callback(None) 239 240 def _on_cancel_press(self) -> None: 241 bui.containerwidget(edit=self._root_widget, transition='out_right') 242 self._callback(self._current_entry)
class
SoundtrackEntryTypeSelectWindow(bauiv1._uitypes.Window):
16class SoundtrackEntryTypeSelectWindow(bui.Window): 17 """Window for selecting a soundtrack entry type.""" 18 19 def __init__( 20 self, 21 callback: Callable[[Any], Any], 22 current_entry: Any, 23 selection_target_name: str, 24 transition: str = 'in_right', 25 ): 26 assert bui.app.classic is not None 27 music = bui.app.classic.music 28 self._r = 'editSoundtrackWindow' 29 30 self._callback = callback 31 self._current_entry = copy.deepcopy(current_entry) 32 33 self._width = 580 34 self._height = 220 35 spacing = 80 36 37 # FIXME: Generalize this so new custom soundtrack types can add 38 # themselves here. 39 do_default = True 40 do_mac_music_app_playlist = music.supports_soundtrack_entry_type( 41 'iTunesPlaylist' 42 ) 43 do_music_file = music.supports_soundtrack_entry_type('musicFile') 44 do_music_folder = music.supports_soundtrack_entry_type('musicFolder') 45 46 if do_mac_music_app_playlist: 47 self._height += spacing 48 if do_music_file: 49 self._height += spacing 50 if do_music_folder: 51 self._height += spacing 52 53 uiscale = bui.app.ui_v1.uiscale 54 55 # NOTE: When something is selected, we close our UI and kick off 56 # another window which then calls us back when its done, so the 57 # standard UI-cleanup-check complains that something is holding on 58 # to our instance after its ui is gone. Should restructure in a 59 # cleaner way, but just disabling that check for now. 60 super().__init__( 61 root_widget=bui.containerwidget( 62 size=(self._width, self._height), 63 transition=transition, 64 scale=( 65 1.7 66 if uiscale is bui.UIScale.SMALL 67 else 1.4 68 if uiscale is bui.UIScale.MEDIUM 69 else 1.0 70 ), 71 ), 72 cleanupcheck=False, 73 ) 74 btn = bui.buttonwidget( 75 parent=self._root_widget, 76 position=(35, self._height - 65), 77 size=(160, 60), 78 scale=0.8, 79 text_scale=1.2, 80 label=bui.Lstr(resource='cancelText'), 81 on_activate_call=self._on_cancel_press, 82 ) 83 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 84 bui.textwidget( 85 parent=self._root_widget, 86 position=(self._width * 0.5, self._height - 32), 87 size=(0, 0), 88 text=bui.Lstr(resource=self._r + '.selectASourceText'), 89 color=bui.app.ui_v1.title_color, 90 maxwidth=230, 91 h_align='center', 92 v_align='center', 93 ) 94 95 bui.textwidget( 96 parent=self._root_widget, 97 position=(self._width * 0.5, self._height - 56), 98 size=(0, 0), 99 text=selection_target_name, 100 color=bui.app.ui_v1.infotextcolor, 101 scale=0.7, 102 maxwidth=230, 103 h_align='center', 104 v_align='center', 105 ) 106 107 v = self._height - 155 108 109 current_entry_type = music.get_soundtrack_entry_type(current_entry) 110 111 if do_default: 112 btn = bui.buttonwidget( 113 parent=self._root_widget, 114 size=(self._width - 100, 60), 115 position=(50, v), 116 label=bui.Lstr(resource=self._r + '.useDefaultGameMusicText'), 117 on_activate_call=self._on_default_press, 118 ) 119 if current_entry_type == 'default': 120 bui.containerwidget(edit=self._root_widget, selected_child=btn) 121 v -= spacing 122 123 if do_mac_music_app_playlist: 124 btn = bui.buttonwidget( 125 parent=self._root_widget, 126 size=(self._width - 100, 60), 127 position=(50, v), 128 label=bui.Lstr(resource=self._r + '.useITunesPlaylistText'), 129 on_activate_call=self._on_mac_music_app_playlist_press, 130 icon=None, 131 ) 132 if current_entry_type == 'iTunesPlaylist': 133 bui.containerwidget(edit=self._root_widget, selected_child=btn) 134 v -= spacing 135 136 if do_music_file: 137 btn = bui.buttonwidget( 138 parent=self._root_widget, 139 size=(self._width - 100, 60), 140 position=(50, v), 141 label=bui.Lstr(resource=self._r + '.useMusicFileText'), 142 on_activate_call=self._on_music_file_press, 143 icon=bui.gettexture('file'), 144 ) 145 if current_entry_type == 'musicFile': 146 bui.containerwidget(edit=self._root_widget, selected_child=btn) 147 v -= spacing 148 149 if do_music_folder: 150 btn = bui.buttonwidget( 151 parent=self._root_widget, 152 size=(self._width - 100, 60), 153 position=(50, v), 154 label=bui.Lstr(resource=self._r + '.useMusicFolderText'), 155 on_activate_call=self._on_music_folder_press, 156 icon=bui.gettexture('folder'), 157 icon_color=(1.1, 0.8, 0.2), 158 ) 159 if current_entry_type == 'musicFolder': 160 bui.containerwidget(edit=self._root_widget, selected_child=btn) 161 v -= spacing 162 163 def _on_mac_music_app_playlist_press(self) -> None: 164 assert bui.app.classic is not None 165 music = bui.app.classic.music 166 from bauiv1lib.soundtrack.macmusicapp import ( 167 MacMusicAppPlaylistSelectWindow, 168 ) 169 170 bui.containerwidget(edit=self._root_widget, transition='out_left') 171 172 current_playlist_entry: str | None 173 if ( 174 music.get_soundtrack_entry_type(self._current_entry) 175 == 'iTunesPlaylist' 176 ): 177 current_playlist_entry = music.get_soundtrack_entry_name( 178 self._current_entry 179 ) 180 else: 181 current_playlist_entry = None 182 bui.app.ui_v1.set_main_menu_window( 183 MacMusicAppPlaylistSelectWindow( 184 self._callback, current_playlist_entry, self._current_entry 185 ).get_root_widget() 186 ) 187 188 def _on_music_file_press(self) -> None: 189 from babase import android_get_external_files_dir 190 from baclassic.osmusic import OSMusicPlayer 191 from bauiv1lib.fileselector import FileSelectorWindow 192 193 bui.containerwidget(edit=self._root_widget, transition='out_left') 194 base_path = android_get_external_files_dir() 195 assert bui.app.classic is not None 196 bui.app.ui_v1.set_main_menu_window( 197 FileSelectorWindow( 198 base_path, 199 callback=self._music_file_selector_cb, 200 show_base_path=False, 201 valid_file_extensions=( 202 OSMusicPlayer.get_valid_music_file_extensions() 203 ), 204 allow_folders=False, 205 ).get_root_widget() 206 ) 207 208 def _on_music_folder_press(self) -> None: 209 from bauiv1lib.fileselector import FileSelectorWindow 210 from babase import android_get_external_files_dir 211 212 bui.containerwidget(edit=self._root_widget, transition='out_left') 213 base_path = android_get_external_files_dir() 214 assert bui.app.classic is not None 215 bui.app.ui_v1.set_main_menu_window( 216 FileSelectorWindow( 217 base_path, 218 callback=self._music_folder_selector_cb, 219 show_base_path=False, 220 valid_file_extensions=[], 221 allow_folders=True, 222 ).get_root_widget() 223 ) 224 225 def _music_file_selector_cb(self, result: str | None) -> None: 226 if result is None: 227 self._callback(self._current_entry) 228 else: 229 self._callback({'type': 'musicFile', 'name': result}) 230 231 def _music_folder_selector_cb(self, result: str | None) -> None: 232 if result is None: 233 self._callback(self._current_entry) 234 else: 235 self._callback({'type': 'musicFolder', 'name': result}) 236 237 def _on_default_press(self) -> None: 238 bui.containerwidget(edit=self._root_widget, transition='out_right') 239 self._callback(None) 240 241 def _on_cancel_press(self) -> None: 242 bui.containerwidget(edit=self._root_widget, transition='out_right') 243 self._callback(self._current_entry)
Window for selecting a soundtrack entry type.
SoundtrackEntryTypeSelectWindow( callback: Callable[[Any], Any], current_entry: Any, selection_target_name: str, transition: str = 'in_right')
19 def __init__( 20 self, 21 callback: Callable[[Any], Any], 22 current_entry: Any, 23 selection_target_name: str, 24 transition: str = 'in_right', 25 ): 26 assert bui.app.classic is not None 27 music = bui.app.classic.music 28 self._r = 'editSoundtrackWindow' 29 30 self._callback = callback 31 self._current_entry = copy.deepcopy(current_entry) 32 33 self._width = 580 34 self._height = 220 35 spacing = 80 36 37 # FIXME: Generalize this so new custom soundtrack types can add 38 # themselves here. 39 do_default = True 40 do_mac_music_app_playlist = music.supports_soundtrack_entry_type( 41 'iTunesPlaylist' 42 ) 43 do_music_file = music.supports_soundtrack_entry_type('musicFile') 44 do_music_folder = music.supports_soundtrack_entry_type('musicFolder') 45 46 if do_mac_music_app_playlist: 47 self._height += spacing 48 if do_music_file: 49 self._height += spacing 50 if do_music_folder: 51 self._height += spacing 52 53 uiscale = bui.app.ui_v1.uiscale 54 55 # NOTE: When something is selected, we close our UI and kick off 56 # another window which then calls us back when its done, so the 57 # standard UI-cleanup-check complains that something is holding on 58 # to our instance after its ui is gone. Should restructure in a 59 # cleaner way, but just disabling that check for now. 60 super().__init__( 61 root_widget=bui.containerwidget( 62 size=(self._width, self._height), 63 transition=transition, 64 scale=( 65 1.7 66 if uiscale is bui.UIScale.SMALL 67 else 1.4 68 if uiscale is bui.UIScale.MEDIUM 69 else 1.0 70 ), 71 ), 72 cleanupcheck=False, 73 ) 74 btn = bui.buttonwidget( 75 parent=self._root_widget, 76 position=(35, self._height - 65), 77 size=(160, 60), 78 scale=0.8, 79 text_scale=1.2, 80 label=bui.Lstr(resource='cancelText'), 81 on_activate_call=self._on_cancel_press, 82 ) 83 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 84 bui.textwidget( 85 parent=self._root_widget, 86 position=(self._width * 0.5, self._height - 32), 87 size=(0, 0), 88 text=bui.Lstr(resource=self._r + '.selectASourceText'), 89 color=bui.app.ui_v1.title_color, 90 maxwidth=230, 91 h_align='center', 92 v_align='center', 93 ) 94 95 bui.textwidget( 96 parent=self._root_widget, 97 position=(self._width * 0.5, self._height - 56), 98 size=(0, 0), 99 text=selection_target_name, 100 color=bui.app.ui_v1.infotextcolor, 101 scale=0.7, 102 maxwidth=230, 103 h_align='center', 104 v_align='center', 105 ) 106 107 v = self._height - 155 108 109 current_entry_type = music.get_soundtrack_entry_type(current_entry) 110 111 if do_default: 112 btn = bui.buttonwidget( 113 parent=self._root_widget, 114 size=(self._width - 100, 60), 115 position=(50, v), 116 label=bui.Lstr(resource=self._r + '.useDefaultGameMusicText'), 117 on_activate_call=self._on_default_press, 118 ) 119 if current_entry_type == 'default': 120 bui.containerwidget(edit=self._root_widget, selected_child=btn) 121 v -= spacing 122 123 if do_mac_music_app_playlist: 124 btn = bui.buttonwidget( 125 parent=self._root_widget, 126 size=(self._width - 100, 60), 127 position=(50, v), 128 label=bui.Lstr(resource=self._r + '.useITunesPlaylistText'), 129 on_activate_call=self._on_mac_music_app_playlist_press, 130 icon=None, 131 ) 132 if current_entry_type == 'iTunesPlaylist': 133 bui.containerwidget(edit=self._root_widget, selected_child=btn) 134 v -= spacing 135 136 if do_music_file: 137 btn = bui.buttonwidget( 138 parent=self._root_widget, 139 size=(self._width - 100, 60), 140 position=(50, v), 141 label=bui.Lstr(resource=self._r + '.useMusicFileText'), 142 on_activate_call=self._on_music_file_press, 143 icon=bui.gettexture('file'), 144 ) 145 if current_entry_type == 'musicFile': 146 bui.containerwidget(edit=self._root_widget, selected_child=btn) 147 v -= spacing 148 149 if do_music_folder: 150 btn = bui.buttonwidget( 151 parent=self._root_widget, 152 size=(self._width - 100, 60), 153 position=(50, v), 154 label=bui.Lstr(resource=self._r + '.useMusicFolderText'), 155 on_activate_call=self._on_music_folder_press, 156 icon=bui.gettexture('folder'), 157 icon_color=(1.1, 0.8, 0.2), 158 ) 159 if current_entry_type == 'musicFolder': 160 bui.containerwidget(edit=self._root_widget, selected_child=btn) 161 v -= spacing
Inherited Members
- bauiv1._uitypes.Window
- get_root_widget