andrej@2347: # andrej@2347: # This file is part of Beremiz, a Integrated Development Environment for andrej@2347: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@2347: # andrej@2347: # Copyright (C) 2018: Andrey Skvortsov andrej@2347: # andrej@2347: # See COPYING file for copyrights details. andrej@2347: # andrej@2347: # This program is free software; you can redistribute it and/or andrej@2347: # modify it under the terms of the GNU General Public License andrej@2347: # as published by the Free Software Foundation; either version 2 andrej@2347: # of the License, or (at your option) any later version. andrej@2347: # andrej@2347: # This program is distributed in the hope that it will be useful, andrej@2347: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@2347: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@2347: # GNU General Public License for more details. andrej@2347: # andrej@2347: # You should have received a copy of the GNU General Public License andrej@2347: # along with this program; if not, write to the Free Software andrej@2347: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@2347: andrej@2347: from __future__ import absolute_import andrej@2347: andrej@2347: import wx andrej@2347: andrej@2347: andrej@2347: class CommentEditDialog(wx.Dialog): andrej@2347: """ andrej@2347: This dialog behaves like wx.TextEntryDialog, andrej@2347: but additionaly it allows to set custom font and andrej@2347: exact size for wx.TextCtrl. andrej@2347: That allows to edit comment and immediately andrej@2347: see how it'll be shown on wiresheet. andrej@2347: """ andrej@2347: andrej@2347: def __init__(self, parent, font, value="", size=wx.Size(400, 200)): andrej@2347: """ andrej@2347: Constructor andrej@2347: andrej@2347: :param parent: andrej@2347: parent window (wx.Window) andrej@2347: :param font: andrej@2347: the font for text control andrej@2347: :param value: andrej@2347: the default value, which may be the empty string andrej@2347: :param size: andrej@2347: desired initial size for text control. andrej@2347: Minimal size of text control is limited andrej@2347: by (100,100) andrej@2347: """ andrej@2347: wx.Dialog.__init__(self, parent, title=_("Please enter comment text")) andrej@2347: msg_label = wx.StaticText(self, label=_("Edit comment")) andrej@2347: input_size = wx.Size(max(size[0], 100), max(size[1], 100)) andrej@2347: input = wx.TextCtrl(self, style=wx.TE_MULTILINE) andrej@2347: input.SetInitialSize(input_size) andrej@2347: input.SetFont(font) andrej@2347: input.SetValue(value) andrej@2347: buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL) andrej@2347: sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) andrej@2347: border = 20 andrej@2347: andrej@2347: sizer.Add(msg_label, 0, andrej@2347: flag=wx.TOP | wx.LEFT | wx.RIGHT, andrej@2347: border=border) andrej@2347: sizer.Add(input, 1, andrej@2347: flag=wx.EXPAND | wx.LEFT | wx.RIGHT, andrej@2347: border=border) andrej@2347: sizer.Add(buttons, 0, andrej@2347: flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, andrej@2347: border=border) andrej@2347: andrej@2347: self.SetSizerAndFit(sizer) andrej@2347: self.input = input andrej@2347: andrej@2347: def SetValue(self, value): andrej@2347: """Sets text value""" andrej@2347: self.input.SetValue(value) andrej@2347: andrej@2347: def GetValue(self): andrej@2347: """ andrej@2347: Returns the text that the user has entered andrej@2347: if the user has pressed wx.OK, andrej@2347: or the original value if the user has pressed Cancel. andrej@2347: """ andrej@2347: return self.input.GetValue()