Core: Update menu bar items when switching between Twitter and Mastodon session to use terms according to the focused network.

This commit is contained in:
Manuel Cortez 2022-12-20 12:21:30 -06:00
parent efd11b90fb
commit 250b248d25
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
5 changed files with 161 additions and 71 deletions

View File

@ -2,6 +2,7 @@ TWBlue Changelog
## changes in this version ## changes in this version
* In the graphical interface, TWBlue will update menu items, in the menu bar, depending on whether you are focusing a Twitter or Mastodon session. This makes it possible for TWBlue to display the correct terms in each social network. Take into account that there might be unavailable items for the currently active session.
* In the invisible interface, TWBlue will skip sessions that have not been started when using the keyboard shortcut to switch between different accounts. * In the invisible interface, TWBlue will skip sessions that have not been started when using the keyboard shortcut to switch between different accounts.
* Mastodon: * Mastodon:
* Added basic support to notifications buffer. This buffer shows mastodon notifications in real time. Every notification is attached to a kind of object (posts, users, relationships or polls). At the moment, the only supported action for notification is dismissing, which allows you to remove the notification from the buffer (take into account, though, that mention notifications will remove also the mention in its corresponding buffer, due to the way TWBlue reads mentions from mastodon instances). * Added basic support to notifications buffer. This buffer shows mastodon notifications in real time. Every notification is attached to a kind of object (posts, users, relationships or polls). At the moment, the only supported action for notification is dismissing, which allows you to remove the notification from the buffer (take into account, though, that mention notifications will remove also the mention in its corresponding buffer, due to the way TWBlue reads mentions from mastodon instances).

View File

@ -152,7 +152,7 @@ class Controller(object):
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.edit_keystrokes, menuitem=self.view.keystroke_editor) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.edit_keystrokes, menuitem=self.view.keystroke_editor)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_tweet, self.view.compose) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_tweet, self.view.compose)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_reply, self.view.reply) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_reply, self.view.reply)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_retweet, self.view.retweet) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.post_retweet, self.view.share)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.add_to_favourites, self.view.fav) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.add_to_favourites, self.view.fav)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.remove_from_favourites, self.view.unfav) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.remove_from_favourites, self.view.unfav)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.view_item, self.view.view) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.view_item, self.view.view)
@ -234,6 +234,8 @@ class Controller(object):
self.accounts = [] self.accounts = []
# This saves the current account (important in invisible mode) # This saves the current account (important in invisible mode)
self.current_account = "" self.current_account = ""
# this saves current menu bar layout.
self.menubar_current_handler = ""
# Handlers are special objects as they manage the mapping of available features and events in different social networks. # Handlers are special objects as they manage the mapping of available features and events in different social networks.
self.handlers = dict() self.handlers = dict()
self.view.prepare() self.view.prepare()
@ -284,6 +286,9 @@ class Controller(object):
self.started = True self.started = True
self.streams_checker_function = RepeatingTimer(60, self.check_streams) self.streams_checker_function = RepeatingTimer(60, self.check_streams)
self.streams_checker_function.start() self.streams_checker_function.start()
if len(self.accounts) > 0:
b = self.get_first_buffer(self.accounts[0])
self.update_menus(handler=self.get_handler(b.session.type))
def create_ignored_session_buffer(self, session): def create_ignored_session_buffer(self, session):
pub.sendMessage("core.create_account", name=session.get_name(), session_id=session.session_id) pub.sendMessage("core.create_account", name=session.get_name(), session_id=session.session_id)
@ -675,8 +680,15 @@ class Controller(object):
def buffer_changed(self, *args, **kwargs): def buffer_changed(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
if buffer.account != self.current_account: old_account = self.current_account
new_account = buffer.account
if new_account != old_account:
self.current_account = buffer.account self.current_account = buffer.account
new_first_buffer = self.get_first_buffer(new_account)
if new_first_buffer.session.type != self.menubar_current_handler:
handler = self.get_handler(new_first_buffer.session.type)
self.menubar_current_handler = new_first_buffer.session.type
self.update_menus(handler)
if not hasattr(buffer, "session") or buffer.session == None: if not hasattr(buffer, "session") or buffer.session == None:
return return
muted = autoread = False muted = autoread = False
@ -687,6 +699,17 @@ class Controller(object):
self.view.check_menuitem("mute_buffer", muted) self.view.check_menuitem("mute_buffer", muted)
self.view.check_menuitem("autoread", autoread) self.view.check_menuitem("autoread", autoread)
def update_menus(self, handler):
if hasattr(handler, "menus"):
for m in list(handler.menus.keys()):
if hasattr(self.view, m):
menu_item = getattr(self.view, m)
if handler.menus[m] == None:
menu_item.Enable(False)
else:
menu_item.Enable(True)
menu_item.SetItemLabel(handler.menus[m])
def fix_wrong_buffer(self): def fix_wrong_buffer(self):
buf = self.get_best_buffer() buf = self.get_best_buffer()
if buf == None: if buf == None:
@ -1207,7 +1230,7 @@ class Controller(object):
self.notify(buffer.session, sound_to_play) self.notify(buffer.session, sound_to_play)
def toggle_share_settings(self, shareable=True): def toggle_share_settings(self, shareable=True):
self.view.retweet.Enable(shareable) self.view.share.Enable(shareable)
def check_streams(self): def check_streams(self):
if self.started == False: if self.started == False:

View File

@ -16,6 +16,40 @@ class Handler(object):
def __init__(self): def __init__(self):
super(Handler, self).__init__() super(Handler, self).__init__()
# Structure to hold names for menu bar items.
# empty names mean the item will be Disabled.
self.menus = dict(
# In application menu.
updateProfile=None,
menuitem_search=_("&Search"),
lists=None,
manageAliases=None,
# In item menu.
compose=_("&Post"),
reply=_("Re&ply"),
share=_("&Boost"),
fav=_("&Add to favorites"),
unfav=_("Remove from favorites"),
view=_("&Show post"),
view_coordinates=None,
view_conversation=_("View conversa&tion"),
ocr=None,
delete=_("&Delete"),
# In user menu.
follow=_("&Actions..."),
timeline=_("&View timeline..."),
dm=_("Direct me&ssage"),
addAlias=None,
addToList=None,
removeFromList=None,
viewLists=None,
details=None,
favs=None,
# In buffer Menu.
trends=None,
filter=None,
manage_filters=None
)
def create_buffers(self, session, createAccounts=True, controller=None): def create_buffers(self, session, createAccounts=True, controller=None):
session.get_user_info() session.get_user_info()

View File

@ -16,6 +16,40 @@ class Handler(object):
def __init__(self): def __init__(self):
super(Handler, self).__init__() super(Handler, self).__init__()
# Structure to hold names for menu bar items.
# empty names mean the item will be Disabled.
self.menus = dict(
# In application menu.
updateProfile=_("&Update profile"),
menuitem_search=_("&Search"),
lists=_("&Lists manager"),
manageAliases=_("Manage user aliases"),
# In Item Menu.
compose=_("&Tweet"),
reply=_("Re&ply"),
share=_("&Retweet"),
fav=_("&Like"),
unfav=_("&Unlike"),
view=_("&Show tweet"),
view_coordinates=_("View &address"),
view_conversation=_("View conversa&tion"),
ocr=_("Read text in picture"),
delete=_("&Delete"),
# In user menu.
follow=_("&Actions..."),
timeline=_("&View timeline..."),
dm=_("Direct me&ssage"),
addAlias=_("Add a&lias"),
addToList=_("&Add to list"),
removeFromList=_("R&emove from list"),
viewLists=_("&View lists"),
details=_("Show user &profile"),
favs=_("View likes"),
# In buffer menu.
trends=_("New &trending topics buffer..."),
filter=_("Create a &filter"),
manage_filters=_("&Manage filters"),
)
def create_buffers(self, session, createAccounts=True, controller=None): def create_buffers(self, session, createAccounts=True, controller=None):
session.get_user_info() session.get_user_info()

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import range
import wx import wx
import wx.adv import wx.adv
import application import application
@ -11,88 +9,88 @@ class mainFrame(wx.Frame):
### MENU ### MENU
def makeMenus(self): def makeMenus(self):
""" Creates, bind and returns the menu bar for the application. Also in this function, the accel table is created.""" """ Creates, bind and returns the menu bar for the application. Also in this function, the accel table is created."""
menuBar = wx.MenuBar() self.menubar = wx.MenuBar()
# Application menu # Application menu
app = wx.Menu() self.menubar_application = wx.Menu()
self.manage_accounts = app.Append(wx.ID_ANY, _(u"&Manage accounts")) self.manage_accounts = self.menubar_application.Append(wx.ID_ANY, _(u"&Manage accounts"))
self.updateProfile = app.Append(wx.ID_ANY, _(u"&Update profile")) self.updateProfile = self.menubar_application.Append(wx.ID_ANY, _("&Update profile"))
self.show_hide = app.Append(wx.ID_ANY, _(u"&Hide window")) self.show_hide = self.menubar_application.Append(wx.ID_ANY, _(u"&Hide window"))
self.menuitem_search = app.Append(wx.ID_ANY, _(u"&Search")) self.menuitem_search = self.menubar_application.Append(wx.ID_ANY, _(u"&Search"))
self.lists = app.Append(wx.ID_ANY, _(u"&Lists manager")) self.lists = self.menubar_application.Append(wx.ID_ANY, _(u"&Lists manager"))
self.manageAliases = app.Append(wx.ID_ANY, _("Manage user aliases")) self.manageAliases = self.menubar_application.Append(wx.ID_ANY, _("Manage user aliases"))
self.keystroke_editor = app.Append(wx.ID_ANY, _(u"&Edit keystrokes")) self.keystroke_editor = self.menubar_application.Append(wx.ID_ANY, _(u"&Edit keystrokes"))
self.account_settings = app.Append(wx.ID_ANY, _(u"Account se&ttings")) self.account_settings = self.menubar_application.Append(wx.ID_ANY, _(u"Account se&ttings"))
self.prefs = app.Append(wx.ID_PREFERENCES, _(u"&Global settings")) self.prefs = self.menubar_application.Append(wx.ID_PREFERENCES, _(u"&Global settings"))
self.close = app.Append(wx.ID_EXIT, _(u"E&xit")) self.close = self.menubar_application.Append(wx.ID_EXIT, _(u"E&xit"))
# Tweet menu # Tweet menu
tweet = wx.Menu() self.menubar_item = wx.Menu()
self.compose = tweet.Append(wx.ID_ANY, _(u"&Tweet")) self.compose = self.menubar_item.Append(wx.ID_ANY, _(u"&Tweet"))
self.reply = tweet.Append(wx.ID_ANY, _(u"Re&ply")) self.reply = self.menubar_item.Append(wx.ID_ANY, _(u"Re&ply"))
self.retweet = tweet.Append(wx.ID_ANY, _(u"&Retweet")) self.share = self.menubar_item.Append(wx.ID_ANY, _(u"&Retweet"))
self.fav = tweet.Append(wx.ID_ANY, _(u"&Like")) self.fav = self.menubar_item.Append(wx.ID_ANY, _(u"&Like"))
self.unfav = tweet.Append(wx.ID_ANY, _(u"&Unlike")) self.unfav = self.menubar_item.Append(wx.ID_ANY, _(u"&Unlike"))
self.view = tweet.Append(wx.ID_ANY, _(u"&Show tweet")) self.view = self.menubar_item.Append(wx.ID_ANY, _(u"&Show tweet"))
self.view_coordinates = tweet.Append(wx.ID_ANY, _(u"View &address")) self.view_coordinates = self.menubar_item.Append(wx.ID_ANY, _(u"View &address"))
self.view_conversation = tweet.Append(wx.ID_ANY, _(u"View conversa&tion")) self.view_conversation = self.menubar_item.Append(wx.ID_ANY, _(u"View conversa&tion"))
self.ocr = tweet.Append(wx.ID_ANY, _(u"Read text in picture")) self.ocr = self.menubar_item.Append(wx.ID_ANY, _(u"Read text in picture"))
self.delete = tweet.Append(wx.ID_ANY, _(u"&Delete")) self.delete = self.menubar_item.Append(wx.ID_ANY, _(u"&Delete"))
# User menu # User menu
user = wx.Menu() self.menubar_user = wx.Menu()
self.follow = user.Append(wx.ID_ANY, _(u"&Actions...")) self.follow = self.menubar_user.Append(wx.ID_ANY, _(u"&Actions..."))
self.timeline = user.Append(wx.ID_ANY, _(u"&View timeline...")) self.timeline = self.menubar_user.Append(wx.ID_ANY, _(u"&View timeline..."))
self.dm = user.Append(wx.ID_ANY, _(u"Direct me&ssage")) self.dm = self.menubar_user.Append(wx.ID_ANY, _(u"Direct me&ssage"))
self.addAlias = user.Append(wx.ID_ANY, _("Add a&lias")) self.addAlias = self.menubar_user.Append(wx.ID_ANY, _("Add a&lias"))
self.addToList = user.Append(wx.ID_ANY, _(u"&Add to list")) self.addToList = self.menubar_user.Append(wx.ID_ANY, _(u"&Add to list"))
self.removeFromList = user.Append(wx.ID_ANY, _(u"R&emove from list")) self.removeFromList = self.menubar_user.Append(wx.ID_ANY, _(u"R&emove from list"))
self.viewLists = user.Append(wx.ID_ANY, _(u"&View lists")) self.viewLists = self.menubar_user.Append(wx.ID_ANY, _(u"&View lists"))
self.details = user.Append(wx.ID_ANY, _(u"Show user &profile")) self.details = self.menubar_user.Append(wx.ID_ANY, _(u"Show user &profile"))
self.favs = user.Append(wx.ID_ANY, _(u"V&iew likes")) self.favs = self.menubar_user.Append(wx.ID_ANY, _(u"V&iew likes"))
# buffer menu # buffer menu
buffer = wx.Menu() self.menubar_buffer = wx.Menu()
self.update_buffer = buffer.Append(wx.ID_ANY, _(u"&Update buffer")) self.update_buffer = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Update buffer"))
self.trends = buffer.Append(wx.ID_ANY, _(u"New &trending topics buffer...")) self.trends = self.menubar_buffer.Append(wx.ID_ANY, _(u"New &trending topics buffer..."))
self.filter = buffer.Append(wx.ID_ANY, _(u"Create a &filter")) self.filter = self.menubar_buffer.Append(wx.ID_ANY, _(u"Create a &filter"))
self.manage_filters = buffer.Append(wx.ID_ANY, _(u"&Manage filters")) self.manage_filters = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Manage filters"))
self.find = buffer.Append(wx.ID_ANY, _(u"Find a string in the currently focused buffer...")) self.find = self.menubar_buffer.Append(wx.ID_ANY, _(u"Find a string in the currently focused buffer..."))
self.load_previous_items = buffer.Append(wx.ID_ANY, _(u"&Load previous items")) self.load_previous_items = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Load previous items"))
buffer.AppendSeparator() self.menubar_buffer.AppendSeparator()
self.mute_buffer = buffer.AppendCheckItem(wx.ID_ANY, _(u"&Mute")) self.mute_buffer = self.menubar_buffer.AppendCheckItem(wx.ID_ANY, _(u"&Mute"))
self.autoread = buffer.AppendCheckItem(wx.ID_ANY, _(u"&Autoread")) self.autoread = self.menubar_buffer.AppendCheckItem(wx.ID_ANY, _(u"&Autoread"))
self.clear = buffer.Append(wx.ID_ANY, _(u"&Clear buffer")) self.clear = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Clear buffer"))
self.deleteTl = buffer.Append(wx.ID_ANY, _(u"&Destroy")) self.deleteTl = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Destroy"))
# audio menu # audio menu
audio = wx.Menu() self.menubar_audio = wx.Menu()
self.seekLeft = audio.Append(wx.ID_ANY, _(u"&Seek back 5 seconds")) self.seekLeft = self.menubar_audio.Append(wx.ID_ANY, _(u"&Seek back 5 seconds"))
self.seekRight = audio.Append(wx.ID_ANY, _(u"&Seek forward 5 seconds")) self.seekRight = self.menubar_audio.Append(wx.ID_ANY, _(u"&Seek forward 5 seconds"))
# Help Menu # Help Menu
help = wx.Menu() self.menubar_help = wx.Menu()
self.doc = help.Append(-1, _(u"&Documentation")) self.doc = self.menubar_help.Append(-1, _(u"&Documentation"))
self.sounds_tutorial = help.Append(wx.ID_ANY, _(u"Sounds &tutorial")) self.sounds_tutorial = self.menubar_help.Append(wx.ID_ANY, _(u"Sounds &tutorial"))
self.changelog = help.Append(wx.ID_ANY, _(u"&What's new in this version?")) self.changelog = self.menubar_help.Append(wx.ID_ANY, _(u"&What's new in this version?"))
self.check_for_updates = help.Append(wx.ID_ANY, _(u"&Check for updates")) self.check_for_updates = self.menubar_help.Append(wx.ID_ANY, _(u"&Check for updates"))
self.reportError = help.Append(wx.ID_ANY, _(u"&Report an error")) self.reportError = self.menubar_help.Append(wx.ID_ANY, _(u"&Report an error"))
self.visit_website = help.Append(-1, _(u"{0}'s &website").format(application.name,)) self.visit_website = self.menubar_help.Append(-1, _(u"{0}'s &website").format(application.name,))
self.get_soundpacks = help.Append(-1, _(u"Get soundpacks for TWBlue")) self.get_soundpacks = self.menubar_help.Append(-1, _(u"Get soundpacks for TWBlue"))
self.about = help.Append(-1, _(u"About &{0}").format(application.name,)) self.about = self.menubar_help.Append(-1, _(u"About &{0}").format(application.name,))
# Add all to the menu Bar # Add all to the menu Bar
menuBar.Append(app, _(u"&Application")) self.menubar.Append(self.menubar_application, _(u"&Application"))
menuBar.Append(tweet, _(u"&Tweet")) self.menubar.Append(self.menubar_item, _(u"&Item"))
menuBar.Append(user, _(u"&User")) self.menubar.Append(self.menubar_user, _(u"&User"))
menuBar.Append(buffer, _(u"&Buffer")) self.menubar.Append(self.menubar_buffer, _(u"&Buffer"))
menuBar.Append(audio, _(u"&Audio")) self.menubar.Append(self.menubar_audio, _(u"&Audio"))
menuBar.Append(help, _(u"&Help")) self.menubar.Append(self.menubar_help, _(u"&Help"))
self.accel_tbl = wx.AcceleratorTable([ self.accel_tbl = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('N'), self.compose.GetId()), (wx.ACCEL_CTRL, ord('N'), self.compose.GetId()),
(wx.ACCEL_CTRL, ord('R'), self.reply.GetId()), (wx.ACCEL_CTRL, ord('R'), self.reply.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('R'), self.retweet.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('R'), self.share.GetId()),
(wx.ACCEL_CTRL, ord('F'), self.fav.GetId()), (wx.ACCEL_CTRL, ord('F'), self.fav.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), self.unfav.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), self.unfav.GetId()),
(wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('V'), self.view.GetId()), (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('V'), self.view.GetId()),
@ -110,7 +108,6 @@ class mainFrame(wx.Frame):
]) ])
self.SetAcceleratorTable(self.accel_tbl) self.SetAcceleratorTable(self.accel_tbl)
return menuBar
### MAIN ### MAIN
def __init__(self): def __init__(self):
@ -119,7 +116,8 @@ class mainFrame(wx.Frame):
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetTitle(application.name) self.SetTitle(application.name)
self.SetMenuBar(self.makeMenus()) self.makeMenus()
self.SetMenuBar(self.menubar)
self.nb = wx.Treebook(self.panel, wx.ID_ANY) self.nb = wx.Treebook(self.panel, wx.ID_ANY)
self.buffers = {} self.buffers = {}