dialogs/PouDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 09 Aug 2017 14:13:17 +0300
changeset 1724 fde6ad246866
parent 1708 24416137cda7
child 1734 750eeb7230a1
permissions -rw-r--r--
manual: add untranslated po files for French and Korean
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
     7
# Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    10
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    15
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    20
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1421
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
from plcopen.structures import TestIdentifier, IEC_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
def GetPouTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
    _ = lambda x : x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
    return [_("function"), _("functionBlock"), _("program")]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
def GetPouLanguages():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
    _ = lambda x : x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
    return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
class PouDialog(wx.Dialog):
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    40
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    41
    POU_LANGUAGES = GetPouLanguages()
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    42
    POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES])
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    43
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1696
diff changeset
    44
    def __init__(self, parent, pou_type=None, type_readonly=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        wx.Dialog.__init__(self, id=-1, parent=parent,
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    46
              name='PouDialog', title=_('Create a new POU'),
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    47
              style=wx.DEFAULT_DIALOG_STYLE)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    48
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        main_sizer.AddGrowableRow(0)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    52
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        infos_sizer.AddGrowableCol(1)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    55
        main_sizer.AddSizer(infos_sizer, border=20,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    57
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        pouname_label = wx.StaticText(self, label=_('POU Name:'))
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    59
        infos_sizer.AddWindow(pouname_label, border=4,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
              flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    61
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        self.PouName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        infos_sizer.AddWindow(self.PouName, flag=wx.GROW)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    64
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        poutype_label = wx.StaticText(self, label=_('POU Type:'))
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    66
        infos_sizer.AddWindow(poutype_label, border=4,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
              flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    68
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        self.PouType = wx.ComboBox(self, style=wx.CB_READONLY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, self.PouType)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        infos_sizer.AddWindow(self.PouType, flag=wx.GROW)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    72
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        language_label = wx.StaticText(self, label=_('Language:'))
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    74
        infos_sizer.AddWindow(language_label, border=4,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
              flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    76
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        self.Language = wx.ComboBox(self, style=wx.CB_READONLY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        infos_sizer.AddWindow(self.Language, flag=wx.GROW)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    79
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    82
        main_sizer.AddSizer(button_sizer, border=20,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    84
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        self.SetSizer(main_sizer)
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
    86
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        for option in GetPouTypes():
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1696
diff changeset
    88
            if not type_readonly or _(option) == _(pou_type):
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1696
diff changeset
    89
                self.PouType.Append(_(option))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        if pou_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
            self.PouType.SetStringSelection(_(pou_type))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.RefreshLanguage()
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    93
        self.Fit()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.PouNames = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        self.PouElementNames = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    def OnOK(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        error = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        pou_name = self.PouName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        if pou_name == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
            error.append(_("POU Name"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        if self.PouType.GetSelection() == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
            error.append(_("POU Type"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        if self.Language.GetSelection() == -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
            error.append(_("Language"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        question = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        if len(error) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
            text = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
            for i, item in enumerate(error):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
                if i == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
                    text += item
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
                elif i == len(error) - 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
                    text += _(" and %s")%item
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
                else:
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
   116
                    text += _(", %s")%item
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
            message = _("Form isn't complete. %s must be filled!") % text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        elif not TestIdentifier(pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
            message = _("\"%s\" is not a valid identifier!") % pou_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        elif pou_name.upper() in IEC_KEYWORDS:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
            message = _("\"%s\" is a keyword. It can't be used!") % pou_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        elif pou_name.upper() in self.PouNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
            message = _("\"%s\" pou already exists!") % pou_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        elif pou_name.upper() in self.PouElementNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
            message = _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?") % pou_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
            question = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
            if question:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
                dialog = wx.MessageDialog(self, message, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
                result = dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
                dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
                if result == wx.ID_YES:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
                    self.EndModal(wx.ID_OK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
                dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
                dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
                dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
            self.EndModal(wx.ID_OK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
    def RefreshLanguage(self):
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
   142
        selection = self.POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        self.Language.Clear()
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
   144
        for language in self.POU_LANGUAGES:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
            if language != "SFC" or POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
                self.Language.Append(_(language))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        if self.Language.FindString(_(selection)) != wx.NOT_FOUND:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            self.Language.SetStringSelection(_(selection))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
    def OnTypeChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.RefreshLanguage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
    def SetPouNames(self, pou_names):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
    def SetPouElementNames(self, element_names):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        self.PouElementNames = [element_name.upper() for element_name in element_names]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
    def SetValues(self, values):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        for item, value in values.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
            if item == "pouName":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
                self.PouName.SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
            elif item == "pouType":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
                self.PouType.SetStringSelection(_(value))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
            elif item == "language":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
                self.Language.SetStringSelection(_(value))
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
   168
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
    def GetValues(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
        values = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        values["pouName"] = self.PouName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        values["pouType"] = POU_TYPES_DICT[self.PouType.GetStringSelection()]
1421
0e1a6fcf4670 Enable overloading of availables languages in POU creation dialog
Edouard Tisserant
parents: 814
diff changeset
   173
        values["language"] = self.POU_LANGUAGES_DICT[self.Language.GetStringSelection()]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
        return values