cleaned filter dialogs. Added filter management (mostly done)

This commit is contained in:
2025-03-07 13:01:08 -06:00
parent 00e5766f90
commit 9ff772f098
9 changed files with 189 additions and 28 deletions

View File

@@ -49,4 +49,13 @@ def invalid_instance():
return wx.MessageDialog(None, _("the provided instance is invalid. Please try again."), _("Invalid instance"), wx.ICON_ERROR).ShowModal()
def error_adding_filter():
return wx.MessageDialog(None, _("TWBlue was unable to add or update the filter with the specified settings. Please try again."), _("Error"), wx.ICON_ERROR).ShowModal()
return wx.MessageDialog(None, _("TWBlue was unable to add or update the filter with the specified settings. Please try again."), _("Error"), wx.ICON_ERROR).ShowModal()
def error_loading_filters():
return wx.MessageDialog(None, _("TWBlue was unable to load your filters from the instance. Please try again."), _("Error"), wx.ICON_ERROR).ShowModal()
def remove_filter():
dlg = wx.MessageDialog(None, _("Do you really want to delete this filter ?"), _("Delete filter"), wx.ICON_QUESTION|wx.YES_NO)
return dlg.ShowModal()
def error_removing_filters():
return wx.MessageDialog(None, _("TWBlue was unable to remove the filter you specified. Please try again."), _("Error"), wx.ICON_ERROR).ShowModal()

View File

@@ -8,7 +8,7 @@ class FilterKeywordPanel(wx.Panel):
self.keywords = []
# Add widgets
list_panel = wx.Panel(self)
self.keyword_list = wx.ListCtrl(list_panel, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
self.keyword_list = wx.ListCtrl(list_panel, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
self.keyword_list.InsertColumn(0, _("Keyword"))
self.keyword_list.InsertColumn(1, _("Whole word"))
self.keyword_list.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
@@ -16,14 +16,14 @@ class FilterKeywordPanel(wx.Panel):
list_sizer = wx.BoxSizer(wx.VERTICAL)
list_sizer.Add(self.keyword_list, 1, wx.EXPAND)
list_panel.SetSizer(list_sizer)
keyword_label = wx.StaticText(self, label=_("Keyword:"))
self.keyword_text = wx.TextCtrl(self)
keyword_label = wx.StaticText(self, wx.ID_ANY, label=_("Keyword:"))
self.keyword_text = wx.TextCtrl(self, wx.ID_ANY)
keyword_sizer = wx.BoxSizer(wx.VERTICAL)
keyword_sizer.Add(keyword_label, 0, wx.RIGHT, 5)
keyword_sizer.Add(self.keyword_text, 0, wx.EXPAND)
self.whole_word_checkbox = wx.CheckBox(self, label=_("Whole word"))
self.add_button = wx.Button(self, label=_("Add"))
self.remove_button = wx.Button(self, label=_("Remove"))
self.whole_word_checkbox = wx.CheckBox(self, wx.ID_ANY, label=_("Whole word"))
self.add_button = wx.Button(self, wx.ID_ANY, label=_("Add"))
self.remove_button = wx.Button(self, wx.ID_ANY, label=_("Remove"))
input_sizer = wx.BoxSizer(wx.HORIZONTAL)
input_sizer.Add(keyword_sizer, 1, wx.RIGHT, 5)
input_sizer.Add(self.whole_word_checkbox, 0)
@@ -70,9 +70,9 @@ class FilterKeywordPanel(wx.Panel):
self.keyword_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.keyword_list.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
class MastodonFilterDialog(wx.Dialog):
class CreateFilterDialog(wx.Dialog):
def __init__(self, parent, title=_("New filter")):
super(MastodonFilterDialog, self).__init__(parent, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
super(CreateFilterDialog, self).__init__(parent, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
self.contexts = ["home", "public", "notifications", "thread", "account"]
self.context_labels = {
"home": _("Home timeline"),
@@ -94,35 +94,36 @@ class MastodonFilterDialog(wx.Dialog):
("months", _("months"))
]
main_sizer = wx.BoxSizer(wx.VERTICAL)
name_label = wx.StaticText(self, label=_("Title:"))
self.name_ctrl = wx.TextCtrl(self)
name_label = wx.StaticText(self, wx.ID_ANY, label=_("Title:"))
self.name_ctrl = wx.TextCtrl(self, wx.ID_ANY)
name_sizer = wx.BoxSizer(wx.HORIZONTAL)
name_sizer.Add(name_label, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
name_sizer.Add(self.name_ctrl, 1, wx.EXPAND)
main_sizer.Add(name_sizer, 0, wx.EXPAND | wx.ALL, 10)
static_box = wx.StaticBox(self, label=_("Apply to:"))
static_box = wx.StaticBox(self, wx.ID_ANY, label=_("Apply to:"))
context_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)
self.context_checkboxes = {}
context_grid = wx.FlexGridSizer(rows=3, cols=2, vgap=5, hgap=10)
for context in self.contexts:
checkbox = wx.CheckBox(static_box, label=self.context_labels[context])
checkbox = wx.CheckBox(static_box, wx.ID_ANY, label=self.context_labels[context])
self.context_checkboxes[context] = checkbox
context_grid.Add(checkbox)
context_sizer.Add(context_grid, 0, wx.ALL, 10)
main_sizer.Add(context_sizer, 0, wx.EXPAND | wx.ALL, 10)
action_label = wx.StaticText(self, label=_("Action:"))
self.action_choice = wx.Choice(self)
action_label = wx.StaticText(self, wx.ID_ANY, label=_("Action:"))
self.action_choice = wx.Choice(self, wx.ID_ANY)
for action in self.actions:
self.action_choice.Append(self.action_labels[action])
action_sizer = wx.BoxSizer(wx.HORIZONTAL)
action_sizer.Add(action_label, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
action_sizer.Add(self.action_choice, 1)
main_sizer.Add(action_sizer, 0, wx.EXPAND | wx.ALL, 10)
expiration_label = wx.StaticText(self, label=_("Expires in:"))
self.expiration_choice = wx.Choice(self)
expiration_label = wx.StaticText(self, wx.ID_ANY, label=_("Expires in:"))
self.expiration_choice = wx.Choice(self, wx.ID_ANY)
for e, label in self.expiration_options:
self.expiration_choice.Append(label)
self.expiration_value = wx.SpinCtrl(self, min=1, max=9999, initial=1)
self.expiration_value = wx.SpinCtrl(self, wx.ID_ANY, min=1, max=9999, initial=1)
self.expiration_value.Enable(False)
self.expiration_choice.Bind(wx.EVT_CHOICE, self.on_expiration_changed)
expiration_sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -138,8 +139,8 @@ class MastodonFilterDialog(wx.Dialog):
self.SetSize((450, 550))
self.action_choice.SetSelection(0)
self.expiration_choice.SetSelection(0)
wx.CallAfter(self.name_ctrl.SetFocus)
def on_expiration_changed(self, event):
selection = self.expiration_choice.GetSelection()
self.expiration_value.Enable(selection != 0)

View File

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
import wx
class ManageFiltersDialog(wx.Dialog):
"""
A dialog that displays a list of Mastodon filters and provides controls
to add, edit and remove them.
"""
def __init__(self, parent, title=_("Filters"), *args, **kwargs):
"""Initialize the filters view dialog. """
super(ManageFiltersDialog, self).__init__(parent, title=title, *args, **kwargs)
main_sizer = wx.BoxSizer(wx.VERTICAL)
self.filter_list = wx.ListCtrl(self, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.BORDER_SUNKEN)
self.filter_list.InsertColumn(0, _("Title"), width=150)
self.filter_list.InsertColumn(1, _("Keywords"), width=80)
self.filter_list.InsertColumn(2, _("Contexts"), width=150)
self.filter_list.InsertColumn(3, _("Action"), width=100)
self.filter_list.InsertColumn(4, _("Expires"), width=150)
main_sizer.Add(self.filter_list, 1, wx.EXPAND | wx.ALL, 10)
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.add_button = wx.Button(self, label=_("Add"))
self.edit_button = wx.Button(self, label=_("Edit"))
self.remove_button = wx.Button(self, label=_("Remove"))
close_button = wx.Button(self, wx.ID_CLOSE)
self.edit_button.Disable()
self.remove_button.Disable()
button_sizer.Add(self.add_button, 0, wx.RIGHT, 5)
button_sizer.Add(self.edit_button, 0, wx.RIGHT, 5)
button_sizer.Add(self.remove_button, 0, wx.RIGHT, 5)
button_sizer.Add((0, 0), 1, wx.EXPAND) # Spacer to push close button to right
button_sizer.Add(close_button, 0)
self.SetEscapeId(close_button.GetId())
main_sizer.Add(button_sizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
self.SetSizer(main_sizer)