diff --git a/src/controller/buffers/mastodon/users.py b/src/controller/buffers/mastodon/users.py index 0550516c..b2287ce4 100644 --- a/src/controller/buffers/mastodon/users.py +++ b/src/controller/buffers/mastodon/users.py @@ -8,7 +8,7 @@ from mysc.thread_utils import call_threaded from controller.buffers.mastodon.base import BaseBuffer from controller.mastodon import messages from sessions.mastodon import templates, utils -from wxUI import buffers +from wxUI import buffers, commonMessageDialogs log = logging.getLogger("controller.buffers.mastodon.conversations") @@ -153,3 +153,18 @@ class UserBuffer(BaseBuffer): def ocr_image(self): pass + def remove_buffer(self, force=False): + if "-searchUser" in self.name: + if force == False: + dlg = commonMessageDialogs.remove_buffer() + else: + dlg = widgetUtils.YES + if dlg == widgetUtils.YES: + if self.name in self.session.db: + self.session.db.pop(self.name) + return True + elif dlg == widgetUtils.NO: + return False + else: + output.speak(_(u"This buffer is not a timeline; it can't be deleted."), True) + return False diff --git a/src/controller/mastodon/handler.py b/src/controller/mastodon/handler.py index 0547568b..99716069 100644 --- a/src/controller/mastodon/handler.py +++ b/src/controller/mastodon/handler.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import wx import logging from pubsub import pub +from wxUI.dialogs.mastodon import search as search_dialogs from sessions.twitter import utils from . import userActions @@ -62,7 +64,7 @@ class Handler(object): # lists_position =controller.view.search("lists", session.db["user_name"]) # for i in session.settings["other_buffers"]["lists"]: # pub.sendMessage("createBuffer", buffer_type="ListBuffer", session_type=session.type, buffer_title=_(u"List for {}").format(i), parent_tab=lists_position, start=False, kwargs=dict(parent=controller.view.nb, function="list_timeline", name="%s-list" % (i,), sessionObject=session, name, bufferType=None, sound="list_tweet.ogg", list_id=utils.find_list(i, session.db["lists"]), include_ext_alt_text=True, tweet_mode="extended")) -# pub.sendMessage("createBuffer", buffer_type="EmptyBuffer", session_type="base", buffer_title=_("Searches"), parent_tab=root_position, start=False, kwargs=dict(parent=controller.view.nb, name="searches", name)) + pub.sendMessage("createBuffer", buffer_type="EmptyBuffer", session_type="base", buffer_title=_("Searches"), parent_tab=root_position, start=False, kwargs=dict(parent=controller.view.nb, name="searches", account=name)) # searches_position =controller.view.search("searches", session.db["user_name"]) # for i in session.settings["other_buffers"]["tweet_searches"]: # pub.sendMessage("createBuffer", buffer_type="SearchBuffer", session_type=session.type, buffer_title=_(u"Search for {}").format(i), parent_tab=searches_position, start=False, kwargs=dict(parent=controller.view.nb, function="search_tweets", name="%s-searchterm" % (i,), sessionObject=session, name, bufferType="searchPanel", sound="search_updated.ogg", q=i, include_ext_alt_text=True, tweet_mode="extended")) @@ -98,3 +100,21 @@ class Handler(object): if item.account.acct not in users and item.account.id != buffer.session.db["user_id"]: users.insert(0, item.account.acct) u = userActions.userActionsController(buffer.session, users) + + def search(self, controller, session, value): + log.debug("Creating a new search...") + dlg = search_dialogs.searchDialog(value) + if dlg.ShowModal() == wx.ID_OK and dlg.term.GetValue() != "": + term = dlg.term.GetValue() + searches_position =controller.view.search("searches", session.get_name()) + if dlg.posts.GetValue() == True: + if term not in session.settings["other_buffers"]["post_searches"]: + session.settings["other_buffers"]["post_searches"].append(term) + session.settings.write() +# pub.sendMessage("createBuffer", buffer_type="SearchBuffer", session_type=session.type, buffer_title=_("Search for {}").format(term), parent_tab=searches_position, start=True, kwargs=dict(parent=controller.view.nb, function="search_tweets", name="%s-searchterm" % (term,), sessionObject=session, account=session.get_name(), bufferType="searchPanel", sound="search_updated.ogg", q=term, include_ext_alt_text=True, tweet_mode="extended")) + else: + log.error("A buffer for the %s search term is already created. You can't create a duplicate buffer." % (term,)) + return + elif dlg.users.GetValue() == True: + pub.sendMessage("createBuffer", buffer_type="UserBuffer", session_type=session.type, buffer_title=_("Search for {}").format(term), parent_tab=searches_position, start=True, kwargs=dict(parent=controller.view.nb, compose_func="compose_user", function="account_search", name="%s-searchUser" % (term,), sessionObject=session, account=session.get_name(), sound="search_updated.ogg", q=term)) + dlg.Destroy() \ No newline at end of file diff --git a/src/wxUI/dialogs/mastodon/search.py b/src/wxUI/dialogs/mastodon/search.py new file mode 100644 index 00000000..0cb75a5a --- /dev/null +++ b/src/wxUI/dialogs/mastodon/search.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +import wx + +class searchDialog(wx.Dialog): + def __init__(self, value=""): + super(searchDialog, self).__init__(parent=None, id=wx.ID_ANY) + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + self.SetTitle(_("Search")) + label = wx.StaticText(panel, wx.ID_ANY, _("&Search")) + self.term = wx.TextCtrl(panel, wx.ID_ANY, value) + self.term.SetFocus() + dc = wx.WindowDC(self.term) + dc.SetFont(self.term.GetFont()) + self.term.SetSize(dc.GetTextExtent("0"*40)) + sizer.Add(label, 0, wx.ALL, 5) + sizer.Add(self.term, 0, wx.ALL, 5) + self.posts = wx.RadioButton(panel, wx.ID_ANY, _("Posts"), style=wx.RB_GROUP) + self.users = wx.RadioButton(panel, wx.ID_ANY, _("Users")) + radioSizer = wx.BoxSizer(wx.HORIZONTAL) + radioSizer.Add(self.posts, 0, wx.ALL, 5) + radioSizer.Add(self.users, 0, wx.ALL, 5) + sizer.Add(radioSizer, 0, wx.ALL, 5) + ok = wx.Button(panel, wx.ID_OK, _(u"&OK")) + ok.SetDefault() + cancel = wx.Button(panel, wx.ID_CANCEL, _("&Close")) + self.SetEscapeId(cancel.GetId()) + btnsizer = wx.BoxSizer() + btnsizer.Add(ok, 0, wx.ALL, 5) + btnsizer.Add(cancel, 0, wx.ALL, 5) + sizer.Add(btnsizer, 0, wx.ALL, 5) + panel.SetSizer(sizer) + self.SetClientSize(sizer.CalcMin()) \ No newline at end of file