From 2f7eb121049031411911e92141871b3326605998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 1 Dec 2014 05:55:25 -0600 Subject: [PATCH] There is a context menu on buffers. When the applications key or the right mouse button is pressed that menu is displayed. It only works for the GUI --- .gitignore | 4 -- src/gui/buffers/base.py | 18 ++++++ src/gui/buffers/dm.py | 12 +++- src/gui/buffers/events.py | 14 ++++- src/gui/buffers/menus.py | 120 ++++++++++++++++++++++++++++++++++++++ src/gui/buffers/people.py | 12 ++++ 6 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 src/gui/buffers/menus.py diff --git a/.gitignore b/.gitignore index 964ff7f9..17b0002a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,8 @@ *.pyc *~ -#windows-dependencies/* src/build/ src/dist/ src/config/ -src/config1/ -src/config2/ -src/config3/ src/dropbox/ src/logs/ src/documentation/ diff --git a/src/gui/buffers/base.py b/src/gui/buffers/base.py index 8ec2ade2..2c85a5fe 100644 --- a/src/gui/buffers/base.py +++ b/src/gui/buffers/base.py @@ -27,6 +27,7 @@ import logging as original_logger import output import platform import datetime +import menus from twitter import prettydate from multiplatform_widgets import widgets from mysc import event @@ -39,6 +40,8 @@ class basePanel(wx.Panel): def bind_events(self): self.Bind(event.MyEVT_OBJECT, self.update) self.Bind(event.MyEVT_DELETED, self.Remove) + self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.showMenu, self.list.list) + self.Bind(wx.EVT_LIST_KEY_DOWN, self.showMenuByKey, self.list.list) self.list.list.Bind(wx.EVT_CHAR_HOOK, self.interact) if self.system == "Windows": self.list.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.onFocus) @@ -369,3 +372,18 @@ class basePanel(wx.Panel): self.list.select_item(len(self.db.settings[self.name_buffer])-1) else: self.list.select_item(0) + + def showMenu(self, ev): + if self.list.get_count() == 0: return + if self.name_buffer == "sent": + self.PopupMenu(menus.sentPanelMenu(self), ev.GetPosition()) + else: + self.PopupMenu(menus.basePanelMenu(self), ev.GetPosition()) + + def showMenuByKey(self, ev): + if self.list.get_count() == 0: return + if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU: + if self.name_buffer == "sent": + self.PopupMenu(menus.sentPanelMenu(self), self.list.list.GetPosition()) + else: + self.PopupMenu(menus.basePanelMenu(self), self.list.list.GetPosition()) diff --git a/src/gui/buffers/dm.py b/src/gui/buffers/dm.py index 32d277da..e0675b7d 100644 --- a/src/gui/buffers/dm.py +++ b/src/gui/buffers/dm.py @@ -19,6 +19,7 @@ import wx import sound import gui.dialogs +import menus import logging as original_logger from base import basePanel from mysc.thread_utils import call_threaded @@ -46,4 +47,13 @@ class dmPanel(basePanel): if dlg.ShowModal() == wx.ID_OK: call_threaded(self.twitter.api_call, call_name="send_direct_message", _sound="dm_sent.ogg", text=dlg.text.GetValue(), screen_name=dlg.cb.GetValue()) if ev != None: - self.list.list.SetFocus() \ No newline at end of file + self.list.list.SetFocus() + + def showMenu(self, ev): + if self.list.get_count() == 0: return + self.PopupMenu(menus.dmPanelMenu(self), ev.GetPosition()) + + def showMenuByKey(self, ev): + if self.list.get_count() == 0: return + if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU: + self.PopupMenu(menus.dmPanelMenu(self), self.list.list.GetPosition()) diff --git a/src/gui/buffers/events.py b/src/gui/buffers/events.py index 0b67d697..6908e387 100644 --- a/src/gui/buffers/events.py +++ b/src/gui/buffers/events.py @@ -21,6 +21,7 @@ import sound import config import platform import gui.dialogs +import menus import output import logging as original_logger from multiplatform_widgets import widgets @@ -36,6 +37,8 @@ class eventsPanel(wx.Panel): def bind_events(self): self.Bind(event.MyEVT_OBJECT, self.update) + self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.showMenu, self.list.list) + self.Bind(wx.EVT_LIST_KEY_DOWN, self.showMenuByKey, self.list.list) def put_items(self, items): pass @@ -131,4 +134,13 @@ class eventsPanel(wx.Panel): try: ev.Skip() except: - pass \ No newline at end of file + pass + + def showMenu(self, ev): + if self.list.get_count() == 0: return + self.PopupMenu(menus.eventsPanelMenu(self), ev.GetPosition()) + + def showMenuByKey(self, ev): + if self.list.get_count() == 0: return + if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU: + self.PopupMenu(menus.eventsPanelMenu(self), self.list.list.GetPosition()) diff --git a/src/gui/buffers/menus.py b/src/gui/buffers/menus.py new file mode 100644 index 00000000..16678bef --- /dev/null +++ b/src/gui/buffers/menus.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +import wx + +class basePanelMenu(wx.Menu): + def __init__(self, parent): + super(basePanelMenu, self).__init__() + self.window = parent + retweet = wx.MenuItem(self, wx.NewId(), _(u"&Retweet")) + self.Bind(wx.EVT_MENU, self.window.onRetweet, retweet) + self.AppendItem(retweet) + reply = wx.MenuItem(self, wx.NewId(), _(u"Re&ply")) + self.Bind(wx.EVT_MENU, self.window.onResponse, reply) + self.AppendItem(reply) + fav = wx.MenuItem(self, wx.NewId(), _(u"Add to &favourites")) + self.Bind(wx.EVT_MENU, self.window.parent.fav, fav) + self.AppendItem(fav) + unfav = wx.MenuItem(self, wx.NewId(), _(u"Remove from favo&urites")) + self.Bind(wx.EVT_MENU, self.window.parent.unfav, unfav) + self.AppendItem(unfav) + openUrl = wx.MenuItem(self, wx.NewId(), _(u"&Open URL")) + self.Bind(wx.EVT_MENU, self.window.parent.url, openUrl) + self.AppendItem(openUrl) + play = wx.MenuItem(self, wx.NewId(), _(u"&Play audio")) + self.Bind(wx.EVT_MENU, self.window.parent.audio, play) + self.AppendItem(play) + view = wx.MenuItem(self, wx.NewId(), _(u"&Show tweet")) + self.Bind(wx.EVT_MENU, self.window.parent.view, view) + self.AppendItem(view) + copy = wx.MenuItem(self, wx.NewId(), _(u"&Copy to clipboard")) + self.Bind(wx.EVT_MENU, self.window.parent.copy_to_clipboard, copy) + self.AppendItem(copy) + remove = wx.MenuItem(self, wx.NewId(), _(u"&Delete")) + self.Bind(wx.EVT_MENU, self.window.parent.delete, remove) + self.AppendItem(remove) + userActions = wx.MenuItem(self, wx.NewId(), _(u"&User actions...")) + self.Bind(wx.EVT_MENU, self.window.parent.onFollow, userActions) + self.AppendItem(userActions) + +class dmPanelMenu(wx.Menu): + def __init__(self, parent): + super(dmPanelMenu, self).__init__() + self.window = parent + reply = wx.MenuItem(self, wx.NewId(), _(u"Re&ply")) + self.Bind(wx.EVT_MENU, self.window.onResponse, reply) + self.AppendItem(reply) + openUrl = wx.MenuItem(self, wx.NewId(), _(u"&Open URL")) + self.Bind(wx.EVT_MENU, self.window.parent.url, openUrl) + self.AppendItem(openUrl) + play = wx.MenuItem(self, wx.NewId(), _(u"&Play audio")) + self.Bind(wx.EVT_MENU, self.window.parent.audio, play) + self.AppendItem(play) + view = wx.MenuItem(self, wx.NewId(), _(u"&Show direct message")) + self.Bind(wx.EVT_MENU, self.window.parent.view, view) + self.AppendItem(view) + copy = wx.MenuItem(self, wx.NewId(), _(u"&Copy to clipboard")) + self.Bind(wx.EVT_MENU, self.window.parent.copy_to_clipboard, copy) + self.AppendItem(copy) + remove = wx.MenuItem(self, wx.NewId(), _(u"&Delete")) + self.Bind(wx.EVT_MENU, self.window.parent.delete, remove) + self.AppendItem(remove) + userActions = wx.MenuItem(self, wx.NewId(), _(u"&User actions...")) + self.Bind(wx.EVT_MENU, self.window.parent.onFollow, userActions) + self.AppendItem(userActions) + +class sentPanelMenu(wx.Menu): + def __init__(self, parent): + super(sentPanelMenu, self).__init__() + self.window = parent + openUrl = wx.MenuItem(self, wx.NewId(), _(u"&Open URL")) + self.Bind(wx.EVT_MENU, self.window.parent.url, openUrl) + self.AppendItem(openUrl) + play = wx.MenuItem(self, wx.NewId(), _(u"&Play audio")) + self.Bind(wx.EVT_MENU, self.window.parent.audio, play) + self.AppendItem(play) + view = wx.MenuItem(self, wx.NewId(), _(u"&Show tweet")) + self.Bind(wx.EVT_MENU, self.window.parent.view, view) + self.AppendItem(view) + copy = wx.MenuItem(self, wx.NewId(), _(u"&Copy to clipboard")) + self.Bind(wx.EVT_MENU, self.window.parent.copy_to_clipboard, copy) + self.AppendItem(copy) + remove = wx.MenuItem(self, wx.NewId(), _(u"&Delete")) + self.Bind(wx.EVT_MENU, self.window.parent.delete, remove) + self.AppendItem(remove) + +class eventsPanelMenu(wx.Menu): + def __init__(self, parent): + super(eventsPanelMenu, self).__init__() + self.window = parent + view = wx.MenuItem(self, wx.NewId(), _(u"&Show event")) + self.Bind(wx.EVT_MENU, self.window.parent.view, view) + self.AppendItem(view) + copy = wx.MenuItem(self, wx.NewId(), _(u"&Copy to clipboard")) + self.Bind(wx.EVT_MENU, self.window.parent.copy_to_clipboard, copy) + self.AppendItem(copy) + remove = wx.MenuItem(self, wx.NewId(), _(u"&Delete")) + self.Bind(wx.EVT_MENU, self.window.parent.delete, remove) + self.AppendItem(remove) + +class peoplePanelMenu(wx.Menu): + def __init__(self, parent): + super(peoplePanelMenu, self).__init__() + self.window = parent + reply = wx.MenuItem(self, wx.NewId(), _(u"&Mention")) + self.Bind(wx.EVT_MENU, self.window.onResponse, reply) + self.AppendItem(reply) + lists = wx.MenuItem(self, wx.NewId(), _(u"&View lists")) + self.Bind(wx.EVT_MENU, self.window.parent.view_user_lists, lists) + self.AppendItem(lists) + details = wx.MenuItem(self, wx.NewId(), _(u"Show user &profile")) + self.Bind(wx.EVT_MENU, self.window.parent.details, details) + self.AppendItem(details) + view = wx.MenuItem(self, wx.NewId(), _(u"&Show user")) + self.Bind(wx.EVT_MENU, self.window.parent.view, view) + self.AppendItem(view) + copy = wx.MenuItem(self, wx.NewId(), _(u"&Copy to clipboard")) + self.Bind(wx.EVT_MENU, self.window.parent.copy_to_clipboard, copy) + self.AppendItem(copy) + userActions = wx.MenuItem(self, wx.NewId(), _(u"&User actions...")) + self.Bind(wx.EVT_MENU, self.window.parent.onFollow, userActions) + self.AppendItem(userActions) diff --git a/src/gui/buffers/people.py b/src/gui/buffers/people.py index 86367c72..488cc516 100644 --- a/src/gui/buffers/people.py +++ b/src/gui/buffers/people.py @@ -21,6 +21,7 @@ import sound import config import twitter import gui.dialogs +import menus import logging as original_logger import output from multiplatform_widgets import widgets @@ -36,6 +37,8 @@ class peoplePanel(basePanel): self.Bind(event.MyEVT_OBJECT, self.update) self.Bind(event.MyEVT_DELETED, self.Remove) self.list.list.Bind(wx.EVT_CHAR_HOOK, self.interact) + self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.showMenu, self.list.list) + self.Bind(wx.EVT_LIST_KEY_DOWN, self.showMenuByKey, self.list.list) def create_list(self): self.list = widgets.list(self, _(u"User"), style=wx.LC_REPORT|wx.LC_SINGLE_SEL, size=(800, 800)) @@ -146,3 +149,12 @@ class peoplePanel(basePanel): else: list = self.compose_function(self.db.settings[self.name_buffer][self.list.get_selected()], self.db) return " ".join(list) + + def showMenu(self, ev): + if self.list.get_count() == 0: return + self.PopupMenu(menus.peoplePanelMenu(self), ev.GetPosition()) + + def showMenuByKey(self, ev): + if self.list.get_count() == 0: return + if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU: + self.PopupMenu(menus.peoplePanelMenu(self), self.list.list.GetPosition())