Source code for kvalikirstu2.text_add_window

"""A module for the text adding window."""
import wx.stc
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) 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.GridBagSizer(hgap=5, vgap=5) self.multiline = wx.TextCtrl(parent=self.panel, size=(500, 300), style=wx.TE_MULTILINE) sizer.Add(self.multiline, pos=(0, 0), border=self.args.padding) button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.add_button = wx.Button(self.panel, label=_("Done")) button_sizer.Add(self.add_button) self.cancel_button = wx.Button(self.panel, label=_("Cancel")) button_sizer.Add(self.cancel_button) sizer.Add(button_sizer, pos=(1, 0), flag=wx.ALIGN_RIGHT) sizer.AddGrowableCol(0) sizer.AddGrowableRow(1) gui_utils.add_border_and_fit(self, sizer, self.panel) 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)