diff --git a/src/controller/buffers.py b/src/controller/buffers.py index e7161c1..4dd7706 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -5,10 +5,12 @@ import messages import utils import posts import player +import output from wxUI.tabs import home from pubsub import pub from sessionmanager import session from mysc.thread_utils import call_threaded +from wxUI import commonMessages class baseBuffer(object): """ a basic representation of a buffer. Other buffers should be derived from this class""" @@ -117,6 +119,8 @@ class baseBuffer(object): def pause_audio(self, *args, **kwargs): player.player.pause() + def remove_buffer(self): return False + class feedBuffer(baseBuffer): def get_items(self, show_nextpage=False): @@ -161,6 +165,19 @@ class audioBuffer(feedBuffer): audios = [i for i in self.session.db[self.name]["items"][selected:]] pub.sendMessage("play-audios", audios=audios) + def remove_buffer(self): + if "me_audio" == self.name or "popular_audio" == self.name or "recommended_audio" == self.name: + output.speak(_(u"This buffer can't be deleted")) + return False + else: + dlg = commonMessages.remove_buffer() + if dlg == widgetUtils.YES: + self.session.db.pop(self.name) + return True + else: + return False + + class empty(object): def __init__(self, name=None, parent=None, *args, **kwargs): @@ -171,4 +188,6 @@ class empty(object): pass def update(self, *args, **kwargs): - pass \ No newline at end of file + pass + + def remove_buffer(self): return False diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 760e1a7..2ed84bc 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -78,6 +78,7 @@ class Controller(object): widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.window.about_dialog, menuitem=self.window.about) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_audios, menuitem=self.window.search_audios) + widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_) def disconnect_events(self): pub.unsubscribe(self.in_post, "posted") @@ -152,4 +153,14 @@ class Controller(object): self.window.insert_buffer(newbuff.tab, _(u"Search for {0}").format(q.decode("utf-8"),), self.window.search("audios")) def update_status_bar(self, status): - self.window.change_status(status) \ No newline at end of file + self.window.change_status(status) + + def remove_buffer(self, *args, **kwargs): + buffer = self.get_current_buffer() + buff = self.window.search(buffer.name) + answer = buffer.remove_buffer() + if answer == False: + return + self.window.remove_buffer(buff) + self.buffers.remove(buffer) + del buffer \ No newline at end of file diff --git a/src/wxUI/commonMessages.py b/src/wxUI/commonMessages.py index e4b0d59..4b509bd 100644 --- a/src/wxUI/commonMessages.py +++ b/src/wxUI/commonMessages.py @@ -6,4 +6,7 @@ def no_data_entered(): return wx.MessageDialog(None, _(u"You must provide Both user and password."), _(u"Information needed"), wx.ICON_ERROR).ShowModal() def no_update_available(): - return wx.MessageDialog(None, _(u"Your {0} version is up to date").format(application.name,), _(u"Update"), style=wx.OK).ShowModal() \ No newline at end of file + return wx.MessageDialog(None, _(u"Your {0} version is up to date").format(application.name,), _(u"Update"), style=wx.OK).ShowModal() + +def remove_buffer(): + return wx.MessageDialog(None, _(u"Do you really want to dismiss this buffer?"), _(u"Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() \ No newline at end of file diff --git a/src/wxUI/mainWindow.py b/src/wxUI/mainWindow.py index d862d4c..3d51ed0 100644 --- a/src/wxUI/mainWindow.py +++ b/src/wxUI/mainWindow.py @@ -12,6 +12,7 @@ class mainWindow(wx.Frame): self.update_buffer = buffer.Append(wx.NewId(), _(u"Update current buffer")) self.load_previous_items = buffer.Append(wx.NewId(), _(u"Load previous items")) self.load_previous_items.Enable(False) + self.remove_buffer_ = buffer.Append(wx.NewId(), _(u"&Remove buffer")) mb.Append(buffer, _(u"Buffer")) help_ = wx.Menu() self.about = help_.Append(wx.NewId(), _(u"About {0}").format(application.name,)) @@ -84,13 +85,5 @@ class mainWindow(wx.Frame): info.AddDeveloper(application.author) wx.AboutBox(info) - def about_dialog(self, *args, **kwargs): - info = wx.AboutDialogInfo() - info.SetName(application.name) - info.SetVersion(application.version) - info.SetDescription(application.description) - info.SetCopyright(application.copyright) -# info.SetTranslators(application.translators) -# info.SetLicence(application.licence) - info.AddDeveloper(application.author) - wx.AboutBox(info) + def remove_buffer(self, pos): + self.tb.DeletePage(pos) \ No newline at end of file