mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Added restore button for template edit dialog
This commit is contained in:
parent
4434a5b971
commit
95063cd472
@ -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()
|
||||
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()
|
Loading…
Reference in New Issue
Block a user