mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-01-15 06:23:17 +01:00
feat(mastodon): Add support for editing announcement templates
Updated the template editor and account settings to allow customization of announcement display: - Added default announcement template to mastodon.defaults. - Updated templateEditor to recognize announcement variables. - Added 'Edit template for announcements' button to account configuration dialog. - Implemented template saving logic in settings controller.
This commit is contained in:
@@ -52,10 +52,12 @@ class accountSettingsController(globalSettingsController):
|
||||
post_template = self.config["templates"]["post"]
|
||||
conversation_template = self.config["templates"]["conversation"]
|
||||
person_template = self.config["templates"]["person"]
|
||||
self.dialog.create_templates(post_template=post_template, conversation_template=conversation_template, person_template=person_template)
|
||||
announcement_template = self.config.get("templates", {}).get("announcement", "$text. Published $published_at. $read")
|
||||
self.dialog.create_templates(post_template=post_template, conversation_template=conversation_template, person_template=person_template, announcement_template=announcement_template)
|
||||
widgetUtils.connect_event(self.dialog.templates.post, widgetUtils.BUTTON_PRESSED, self.edit_post_template)
|
||||
widgetUtils.connect_event(self.dialog.templates.conversation, widgetUtils.BUTTON_PRESSED, self.edit_conversation_template)
|
||||
widgetUtils.connect_event(self.dialog.templates.person, widgetUtils.BUTTON_PRESSED, self.edit_person_template)
|
||||
widgetUtils.connect_event(self.dialog.templates.announcement, widgetUtils.BUTTON_PRESSED, self.edit_announcement_template)
|
||||
self.dialog.create_other_buffers()
|
||||
buffer_values = self.get_buffers_list()
|
||||
self.dialog.buffers.insert_buffers(buffer_values)
|
||||
@@ -109,6 +111,15 @@ class accountSettingsController(globalSettingsController):
|
||||
self.config.write()
|
||||
self.dialog.templates.person.SetLabel(_("Edit template for persons. Current template: {}").format(result))
|
||||
|
||||
def edit_announcement_template(self, *args, **kwargs):
|
||||
template = self.config.get("templates", {}).get("announcement", "$text. Published $published_at. $read")
|
||||
control = EditTemplate(template=template, type="announcement")
|
||||
result = control.run_dialog()
|
||||
if result != "": # Template has been saved.
|
||||
self.config["templates"]["announcement"] = result
|
||||
self.config.write()
|
||||
self.dialog.templates.announcement.SetLabel(_("Edit template for announcements. Current template: {}").format(result))
|
||||
|
||||
def save_configuration(self):
|
||||
if self.config["general"]["relative_times"] != self.dialog.get_value("general", "relative_time"):
|
||||
self.needs_restart = True
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import re
|
||||
import wx
|
||||
from typing import List
|
||||
from sessions.mastodon.templates import post_variables, conversation_variables, person_variables
|
||||
from sessions.mastodon.templates import post_variables, conversation_variables, person_variables, announcement_variables
|
||||
from wxUI.dialogs import templateDialogs
|
||||
|
||||
class EditTemplate(object):
|
||||
@@ -13,6 +13,8 @@ class EditTemplate(object):
|
||||
self.variables = post_variables
|
||||
elif type == "conversation":
|
||||
self.variables = conversation_variables
|
||||
elif type == "announcement":
|
||||
self.variables = announcement_variables
|
||||
else:
|
||||
self.variables = person_variables
|
||||
self.template: str = template
|
||||
|
||||
@@ -54,6 +54,7 @@ post = string(default="$display_name, $safe_text $image_descriptions $date. $vis
|
||||
person = string(default="$display_name (@$screen_name). $followers followers, $following following, $posts posts. Joined $created_at.")
|
||||
conversation = string(default="Conversation with $users. Last message: $last_post")
|
||||
notification = string(default="$display_name $text, $date")
|
||||
announcement = string(default="$text. Published $published_at. $read")
|
||||
|
||||
[filters]
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class generalAccount(wx.Panel, baseDialog.BaseWXDialog):
|
||||
self.SetSizer(sizer)
|
||||
|
||||
class templates(wx.Panel, baseDialog.BaseWXDialog):
|
||||
def __init__(self, parent, post_template, conversation_template, person_template):
|
||||
def __init__(self, parent, post_template, conversation_template, person_template, announcement_template):
|
||||
super(templates, self).__init__(parent)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.post = wx.Button(self, wx.ID_ANY, _("Edit template for &posts. Current template: {}").format(post_template))
|
||||
@@ -56,6 +56,8 @@ class templates(wx.Panel, baseDialog.BaseWXDialog):
|
||||
sizer.Add(self.conversation, 0, wx.ALL, 5)
|
||||
self.person = wx.Button(self, wx.ID_ANY, _("Edit template for p&ersons. Current template: {}").format(person_template))
|
||||
sizer.Add(self.person, 0, wx.ALL, 5)
|
||||
self.announcement = wx.Button(self, wx.ID_ANY, _("Edit template for &announcements. Current template: {}").format(announcement_template))
|
||||
sizer.Add(self.announcement, 0, wx.ALL, 5)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
class sound(wx.Panel):
|
||||
@@ -152,8 +154,8 @@ class configurationDialog(baseDialog.BaseWXDialog):
|
||||
self.buffers = other_buffers(self.notebook)
|
||||
self.notebook.AddPage(self.buffers, _(u"Buffers"))
|
||||
|
||||
def create_templates(self, post_template, conversation_template, person_template):
|
||||
self.templates = templates(self.notebook, post_template=post_template, conversation_template=conversation_template, person_template=person_template)
|
||||
def create_templates(self, post_template, conversation_template, person_template, announcement_template):
|
||||
self.templates = templates(self.notebook, post_template=post_template, conversation_template=conversation_template, person_template=person_template, announcement_template=announcement_template)
|
||||
self.notebook.AddPage(self.templates, _("Templates"))
|
||||
|
||||
def create_sound(self, output_devices, input_devices, soundpacks):
|
||||
|
||||
Reference in New Issue
Block a user