Source code for kvalikirstu2.text_add_window

"""A module for the text adding window."""
import wx
from kvalikirstu2 import argument_parser
from kvalikirstu2 import gui_utils
from kvalikirstu2.localization import _


[docs]class TextAddWindow(wx.Dialog): """ Window for adding text to data files. """ def __init__(self, title, callback, confirm_action_msg=""): """ :param title: The title of the window. :param callback: The callback for the content string. """ super().__init__( None, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.args = argument_parser.get_args() self.confirm_action_msg = confirm_action_msg self.callback = callback self._init_window() def _init_window(self): self.panel = wx.Panel(self) sizer = wx.BoxSizer(wx.VERTICAL) self.multiline = wx.TextCtrl(self, style=wx.TE_MULTILINE) sizer.Add(self.multiline, 1, wx.ALL | wx.EXPAND, self.args.padding) button_sizer = wx.BoxSizer(wx.HORIZONTAL) button_sizer.AddStretchSpacer() self.add_button = wx.Button(self, label=_("Done")) button_sizer.Add(self.add_button, 0, wx.RIGHT, self.args.padding) self.cancel_button = wx.Button(self, label=_("Cancel")) button_sizer.Add(self.cancel_button) sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, self.args.padding) gui_utils.add_border_and_fit(self, sizer, self.panel) self.Center() self.SetSize(400, 300) self._bind_buttons() def _bind_buttons(self): self.Bind(wx.EVT_BUTTON, lambda evt: self.EndModal(wx.ID_CANCEL), self.cancel_button) self.Bind(wx.EVT_BUTTON, self._done_pressed, self.add_button) def _done_pressed(self, _evt): """Returns the text from the text field. """ if self.confirm_action_msg: with wx.MessageDialog(self, self.confirm_action_msg, style=wx.YES_NO) as dlg: dlg.SetYesNoLabels(_("Yes"), _("No")) dlg_return = dlg.ShowModal() if dlg_return != wx.ID_YES: return self.Close() self.callback(self.multiline.GetValue()) self.EndModal(wx.ID_OK)