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