diff --git a/background_music_player.py b/background_music_player.py index f8fe421..659c74a 100644 --- a/background_music_player.py +++ b/background_music_player.py @@ -12,47 +12,78 @@ def __init__(self, parent): self.player = self.vlc_instance.media_player_new() self.player.audio_set_volume(50) self.player.audio_set_mute(False) - self.window = BackgroundMusicFrame(self.parent) + self.window = BackgroundMusicFrame(self.parent) # None self.playlist = None + self._fade_in_out = True + + @property + def fade_in_out(self): + return self._fade_in_out + + @fade_in_out.setter + def fade_in_out(self, value): + self.window.fade_in_out_switch.SetValue(value) + self._fade_in_out = value def show_window(self): if not isinstance(self.window, BackgroundMusicFrame): self.window = BackgroundMusicFrame(self.parent) self.window.Show() + self.window.fade_in_out_switch.SetValue(self.fade_in_out) - def play(self, fade_in=True): - pass + def play(self): + + if self.fade_in_out: + pass - def pause(self, fade_out=True): + def pause(self): + + if self.fade_in_out: + pass pass def load_files(self, dir): file_names = sorted(os.listdir(dir)) self.playlist = [{'name': f.rsplit('.', 1)[0], 'path': os.path.join(dir, f)} for f in file_names] - self.window.grid.DeleteRows(0, self.window.grid.GetNumberRows(), False) + if self.window.grid.GetNumberRows() > 0: + self.window.grid.DeleteRows(0, self.window.grid.GetNumberRows(), False) self.window.grid.AppendRows(len(self.playlist)) for i in range(len(self.playlist)): self.window.grid.SetCellValue(i, 0, self.playlist[i]['name']) self.window.grid.SetReadOnly(i, 0) self.window.grid.AutoSize() + self.window.Layout() class BackgroundMusicFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, title='Background Music Player', size=(400, 500)) + self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_FRAMEBK)) # ---------------------------------------------- Layout ----------------------------------------------------- main_sizer = wx.BoxSizer(wx.VERTICAL) self.toolbar = wx.BoxSizer(wx.HORIZONTAL) + toolbar_base_height = 20 + + self.fade_in_out_switch = wx.CheckBox(self, label='FAD') + self.toolbar.Add(self.fade_in_out_switch, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3) + + self.play_btn = wx.Button(self, label="Play", size=(70, toolbar_base_height + 2)) + self.toolbar.Add(self.play_btn, 0) + self.play_btn.Bind(wx.EVT_BUTTON, parent.background_play) + # Forwarding events through the main window, because this frame is optional and may be absent. + + self.stop_btn = wx.Button(self, label="Stop", size=(70, toolbar_base_height + 2)) + self.toolbar.Add(self.stop_btn, 0) + self.stop_btn.Bind(wx.EVT_BUTTON, parent.background_stop) # --- Table --- self.grid = wx.grid.Grid(self) - self.grid.CreateGrid(1, 1) + self.grid.CreateGrid(0, 1) self.grid.HideColLabels() self.grid.DisableDragRowSize() self.grid.SetRowLabelSize(20) - self.grid.SetCellValue(0, 0, "Empty Playlist") self.grid.SetSelectionMode(wx.grid.Grid.wxGridSelectRows) def select_row(e): @@ -68,4 +99,5 @@ def select_row(e): main_sizer.Add(self.grid, 1, wx.EXPAND | wx.TOP, border=1) self.SetSizer(main_sizer) + self.Layout() diff --git a/main.py b/main.py index 79ede6b..9b1526f 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,8 @@ def __init__(self, parent, title): self.grid_default_bg_color = None self.full_grid_data = None + self.bg_player = BackgroundMusicPlayer(self) + # ------------------ Menu ------------------ menu_bar = wx.MenuBar() @@ -98,6 +100,13 @@ def on_settings(e): bg_music_menu.Append(wx.ID_ANY, "&Load Files")) self.Bind(wx.EVT_MENU, lambda e: self.bg_player.show_window(), bg_music_menu.Append(wx.ID_ANY, "&Open Window")) + + def fade_switched(e): + self.bg_player.fade_in_out = bool(e.Int) + self.fade_switch = bg_music_menu.Append(wx.ID_ANY, "&Fade In/Out", kind=wx.ITEM_CHECK) + self.fade_switch.Check(self.bg_player.fade_in_out) + self.Bind(wx.EVT_MENU, fade_switched, self.fade_switch) + menu_bar.Append(bg_music_menu, "&Background Music") # --- Fire (Play) --- @@ -170,11 +179,10 @@ def search_box_leave_handler(e): # --- Table --- self.grid = wx.grid.Grid(self) - self.grid.CreateGrid(1, 1) + self.grid.CreateGrid(0, 0) self.grid.HideRowLabels() self.grid.DisableDragRowSize() self.grid.SetColLabelSize(20) - self.grid.SetCellValue(0, 0, "Hello World") self.grid.SetSelectionMode(wx.grid.Grid.wxGridSelectRows) def select_row(e): @@ -207,8 +215,6 @@ def select_row(e): self.vol_control.SetValue(self.player.audio_get_volume()) self.player_status("VLC v.%s: %s" % (vlc.libvlc_get_version(), self.player_state_parse(self.player.get_state()))) - - self.bg_player = BackgroundMusicPlayer(self) self.bg_player_status("Background Player: %s" % self.player_state_parse(self.bg_player.player.get_state())) self.Show(True) @@ -220,7 +226,8 @@ def select_row(e): def grid_set_shape(self, new_rows, new_cols, readonly_cols=None): current_rows, current_cols = self.grid.GetNumberRows(), self.grid.GetNumberCols() - self.grid.DeleteRows(0, current_rows, False) + if current_rows > 0: + self.grid.DeleteRows(0, current_rows, False) self.grid.AppendRows(new_rows) if new_cols < current_cols: self.grid.DeleteCols(0, current_cols - new_cols, False) @@ -613,6 +620,17 @@ def on_timer(self, e): self.play_bar.SetValue(0) self.switch_to_zad() + # -------------------------------------------- Background Music Player -------------------------------------------- + + def background_play(self, e=None): + self.bg_player.play() + pass + + def background_stop(self, e=None): + self.bg_player.stop() + pass + + if __name__ == "__main__": app = wx.App(False)