diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 56dc87b..d15c107 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -29,7 +29,8 @@ class Controller(object): self.connect_events() self.timer = wx.Timer(self.window) self.window.Bind(wx.EVT_TIMER, self.on_timer, self.timer) - self.timer.Start() + self.timer.Start(75) + self.window.vol_slider.SetValue(player.player.volume) # Shows window. self.window.Show() @@ -69,6 +70,7 @@ class Controller(object): self.window.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.on_time_change, self.window.time_slider) self.window.list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_play) self.window.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context) + self.window.Bind(wx.EVT_CLOSE, self.on_close) pub.subscribe(self.change_status, "change_status") # Event functions. These functions will call other functions in a thread and are bound to widget events. @@ -97,7 +99,7 @@ class Controller(object): if player.player.player.is_playing() == 1: return player.player.pause() else: - return self.on_play() + return player.player.player.play() def on_next(self, *args, **kwargs): return utils.call_threaded(player.player.next) @@ -114,10 +116,10 @@ class Controller(object): player.player.stop() def on_volume_down(self, *args, **kwargs): - player.player.volume = player.player.volume-5 + self.window.vol_slider.SetValue(self.window.volume_slider.GetValue()-5) def on_volume_up(self, *args, **kwargs): - player.player.volume = player.player.volume+5 + self.window.vol_slider.SetValue(self.window.volume_slider.GetValue()-5) def on_mute(self, *args, **kwargs): player.player.volume = 0 @@ -149,16 +151,19 @@ class Controller(object): volume = self.window.vol_slider.GetValue() player.player.player.audio_set_volume(volume) - def on_time_change(self, *args, **kwargs): - p = self.window.time_slider.GetValue()/100000.0 - print(p) - player.player.player.set_position(p) + def on_time_change(self, event, *args, **kwargs): + p = event.GetPosition() + player.player.player.set_position(p/100.0) + event.Skip() def on_timer(self, *args, **kwargs): - length = player.player.player.get_length() - self.window.time_slider.SetRange(-1, length) - time = player.player.player.get_time() - self.window.time_slider.SetValue(time) + if not self.window.time_slider.HasFocus(): + progress = player.player.player.get_position()*100 + self.window.time_slider.SetValue(progress) + + def on_close(self, event): + self.timer.Stop() + event.Skip() def change_status(self, status): """ Function used for changing the status bar from outside the main controller module.""" diff --git a/src/wxUI/mainWindow.py b/src/wxUI/mainWindow.py index 90a6c82..22d9a98 100644 --- a/src/wxUI/mainWindow.py +++ b/src/wxUI/mainWindow.py @@ -36,36 +36,36 @@ class mainWindow(wx.Frame): self.search = wx.Button(self.panel, wx.NewId(), _("Search")) self.search.SetDefault() box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(lbl2, 0, wx.ALL, 20) - box.Add(self.text, 0, wx.ALL, 5) - box.Add(self.search, 0, wx.ALL, 5) - self.sizer.Add(box, 0, wx.ALL, 5) + box.Add(lbl2, 0, wx.GROW) + box.Add(self.text, 1, wx.GROW) + box.Add(self.search, 0, wx.GROW) + self.sizer.Add(box, 0, wx.GROW) lbl = wx.StaticText(self.panel, wx.NewId(), _("Results")) self.list = wx.ListBox(self.panel, wx.NewId()) - self.sizer.Add(lbl, 0, wx.ALL, 5) - self.sizer.Add(self.list, 1, wx.EXPAND, 5) - self.time_slider = wx.Slider(self.panel, -1, 0, 0, 1000) - self.time_slider.SetRange(0, 1000) + self.sizer.Add(lbl, 0, wx.GROW) + self.sizer.Add(self.list, 1, wx.GROW) + box1 = wx.BoxSizer(wx.HORIZONTAL) + box2 = wx.BoxSizer(wx.HORIZONTAL) + box1.Add(wx.StaticText(self.panel, wx.NewId(), _("Position")), 0, wx.GROW) + self.time_slider = wx.Slider(self.panel, -1) + box1.Add(self.time_slider, 1, wx.GROW) + box1.Add(wx.StaticText(self.panel, wx.NewId(), _("Volume")), 0, wx.GROW) + self.vol_slider = wx.Slider(self.panel, -1, 0, 0, 100, size=(100, -1)) + box1.Add(self.vol_slider, 1, wx.GROW) self.previous = wx.Button(self.panel, wx.NewId(), _("Previous")) self.play = wx.Button(self.panel, wx.NewId(), _("Play")) self.stop = wx.Button(self.panel, wx.NewId(), _("Stop")) self.next = wx.Button(self.panel, wx.NewId(), _("Next")) - self.vol_slider = wx.Slider(self.panel, -1, 0, 0, 100, size=(100, -1)) - box1 = wx.BoxSizer(wx.HORIZONTAL) - box2 = wx.BoxSizer(wx.HORIZONTAL) - box1.Add(self.time_slider, 1) box2.Add(self.previous) box2.Add(self.play, flag=wx.RIGHT, border=5) box2.Add(self.stop) box2.Add(self.next) - box2.Add((-1, -1), 1) - box2.Add(self.vol_slider, flag=wx.TOP | wx.LEFT, border=5) - self.sizer.Add(box1, flag=wx.EXPAND | wx.BOTTOM, border=10) - self.sizer.Add(box2, flag=wx.EXPAND | wx.BOTTOM, border=10) - self.panel.SetSizer(self.sizer) - self.SetClientSize(self.sizer.CalcMin()) - self.Layout() - self.SetSize(self.GetBestSize()) + self.sizer.Add(box1, 0, wx.GROW) + self.sizer.Add(box2, 1, wx.GROW) + self.panel.SetSizerAndFit(self.sizer) +# self.SetClientSize(self.sizer.CalcMin()) +# self.Layout() +# self.SetSize(self.GetBestSize()) def change_status(self, status): self.sb.SetStatusText(status)