|
1 # |
|
2 # This file is part of Beremiz, a Integrated Development Environment for |
|
3 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
|
4 # |
|
5 # Copyright (C) 2018: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
|
6 # |
|
7 # See COPYING file for copyrights details. |
|
8 # |
|
9 # This program is free software; you can redistribute it and/or |
|
10 # modify it under the terms of the GNU General Public License |
|
11 # as published by the Free Software Foundation; either version 2 |
|
12 # of the License, or (at your option) any later version. |
|
13 # |
|
14 # This program is distributed in the hope that it will be useful, |
|
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 # GNU General Public License for more details. |
|
18 # |
|
19 # You should have received a copy of the GNU General Public License |
|
20 # along with this program; if not, write to the Free Software |
|
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
22 |
|
23 from __future__ import absolute_import |
|
24 |
|
25 import wx |
|
26 |
|
27 |
|
28 class CommentEditDialog(wx.Dialog): |
|
29 """ |
|
30 This dialog behaves like wx.TextEntryDialog, |
|
31 but additionaly it allows to set custom font and |
|
32 exact size for wx.TextCtrl. |
|
33 That allows to edit comment and immediately |
|
34 see how it'll be shown on wiresheet. |
|
35 """ |
|
36 |
|
37 def __init__(self, parent, font, value="", size=wx.Size(400, 200)): |
|
38 """ |
|
39 Constructor |
|
40 |
|
41 :param parent: |
|
42 parent window (wx.Window) |
|
43 :param font: |
|
44 the font for text control |
|
45 :param value: |
|
46 the default value, which may be the empty string |
|
47 :param size: |
|
48 desired initial size for text control. |
|
49 Minimal size of text control is limited |
|
50 by (100,100) |
|
51 """ |
|
52 wx.Dialog.__init__(self, parent, title=_("Please enter comment text")) |
|
53 msg_label = wx.StaticText(self, label=_("Edit comment")) |
|
54 input_size = wx.Size(max(size[0], 100), max(size[1], 100)) |
|
55 input = wx.TextCtrl(self, style=wx.TE_MULTILINE) |
|
56 input.SetInitialSize(input_size) |
|
57 input.SetFont(font) |
|
58 input.SetValue(value) |
|
59 buttons = self.CreateButtonSizer(wx.OK | wx.CANCEL) |
|
60 sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
|
61 border = 20 |
|
62 |
|
63 sizer.Add(msg_label, 0, |
|
64 flag=wx.TOP | wx.LEFT | wx.RIGHT, |
|
65 border=border) |
|
66 sizer.Add(input, 1, |
|
67 flag=wx.EXPAND | wx.LEFT | wx.RIGHT, |
|
68 border=border) |
|
69 sizer.Add(buttons, 0, |
|
70 flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, |
|
71 border=border) |
|
72 |
|
73 self.SetSizerAndFit(sizer) |
|
74 self.input = input |
|
75 |
|
76 def SetValue(self, value): |
|
77 """Sets text value""" |
|
78 self.input.SetValue(value) |
|
79 |
|
80 def GetValue(self): |
|
81 """ |
|
82 Returns the text that the user has entered |
|
83 if the user has pressed wx.OK, |
|
84 or the original value if the user has pressed Cancel. |
|
85 """ |
|
86 return self.input.GetValue() |