From b2f9aef7f79ebe8733599485493f36c310852a32 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 21 Dec 2021 12:11:12 -0600 Subject: [PATCH] Added edit template controller --- src/controller/editTemplateController.py | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/controller/editTemplateController.py diff --git a/src/controller/editTemplateController.py b/src/controller/editTemplateController.py new file mode 100644 index 00000000..9d85bbda --- /dev/null +++ b/src/controller/editTemplateController.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +import re +import wx +from typing import List +from sessions.twitter.templates import tweet_variables, dm_variables, person_variables +from wxUI.dialogs.twitterDialogs import templateDialogs + +class editTemplateController(object): + def __init__(self, template: str, type: str) -> None: + super(editTemplateController, self).__init__() + self.default_template = template + if type == "tweet": + self.variables = tweet_variables + elif type == "dm": + self.variables = dm_variables + else: + self.variables = person_variables + self.template: str = template + + def validate_template(self, template: str) -> bool: + used_variables: List[str] = re.findall("\$\w+", template) + validated: bool = True + for var in used_variables: + if var[1:] not in self.variables: + validated = False + return validated + + def run_dialog(self) -> str: + dialog = templateDialogs.EditTemplateDialog(template=self.template, variables=self.variables, default_template=self.default_template) + response = dialog.ShowModal() + if response == wx.ID_SAVE: + validated: bool = self.validate_template(dialog.template.GetValue()) + if validated == False: + templateDialogs.invalid_template() + self.template = dialog.template.GetValue() + return self.run_dialog() + else: + return dialog.template.GetValue() + else: + return "" \ No newline at end of file