From 95063cd472918be083bfbb8be4ff829c33b4f929 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 21 Dec 2021 12:10:15 -0600 Subject: [PATCH] Added restore button for template edit dialog --- .../dialogs/twitterDialogs/templateDialogs.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wxUI/dialogs/twitterDialogs/templateDialogs.py b/src/wxUI/dialogs/twitterDialogs/templateDialogs.py index 3b9d5243..9efa96aa 100644 --- a/src/wxUI/dialogs/twitterDialogs/templateDialogs.py +++ b/src/wxUI/dialogs/twitterDialogs/templateDialogs.py @@ -1,9 +1,12 @@ # -*- coding: UTF-8 -*- import wx +import output +from typing import List class EditTemplateDialog(wx.Dialog): - def __init__(self, template, variables=[], *args, **kwds): + def __init__(self, template: str, variables: List[str] = [], default_template: str = "", *args, **kwds) -> None: super(EditTemplateDialog, self).__init__(parent=None, title=_("Edit Template"), *args, **kwds) + self.default_template = default_template mainSizer = wx.BoxSizer(wx.VERTICAL) sizer_1 = wx.BoxSizer(wx.HORIZONTAL) mainSizer.Add(sizer_1, 1, wx.EXPAND, 0) @@ -23,6 +26,9 @@ class EditTemplateDialog(wx.Dialog): sizer_3.AddButton(self.button_SAVE) self.button_CANCEL = wx.Button(self, wx.ID_CANCEL) sizer_3.AddButton(self.button_CANCEL) + self.button_RESTORE = wx.Button(self, wx.ID_ANY, _("Restore template")) + self.button_RESTORE.Bind(wx.EVT_BUTTON, self.on_restore) + sizer_3.AddButton(self.button_CANCEL) sizer_3.Realize() self.SetSizer(mainSizer) mainSizer.Fit(self) @@ -33,5 +39,14 @@ class EditTemplateDialog(wx.Dialog): def on_keypress(self, event, *args, **kwargs): if event.GetKeyCode() == wx.WXK_RETURN: self.template.ChangeValue(self.template.GetValue()+self.variables.GetStringSelection()+", ") + output.speak(self.template.GetValue()+self.variables.GetStringSelection()+", ") return - event.Skip() \ No newline at end of file + event.Skip() + + def on_restore(self, *args, **kwargs) -> None: + self.template.ChangeValue(self.default_template) + output.speak(_("Restored template to {}.").format(self.default_template)) + self.template.SetFocus() + +def invalid_template() -> None: + wx.MessageDialog(None, _("the template you have specified include variables that do not exists for the object. Please fix the template and try again. For your reference, you can see a list of all available variables in the variables list while editing your template."), _("Invalid template"), wx.ICON_ERROR).ShowModal() \ No newline at end of file