wxglade_hmi/wxglade_hmi.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 28 Nov 2016 16:47:01 +0300
changeset 1581 2295fdc5c271
parent 1511 91538d0c242c
child 1680 6db967480b7d
permissions -rw-r--r--
fix translation strings with multiple parameters


this fixes a lot of warnings given by msgmerge:

../PLCOpenEditor.py:196: warning: 'msgid' format string with unnamed arguments cannot be properly localized:
The translator cannot reorder the arguments.
Please consider using a format string with named arguments,
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     1
#!/usr/bin/env python
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     2
# -*- coding: utf-8 -*-
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     8
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
     9
# See COPYING file for copyrights details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    10
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    11
# This program is free software; you can redistribute it and/or
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    12
# modify it under the terms of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    13
# as published by the Free Software Foundation; either version 2
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    14
# of the License, or (at your option) any later version.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    15
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    16
# This program is distributed in the hope that it will be useful,
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    19
# GNU General Public License for more details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    20
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    21
# You should have received a copy of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    22
# along with this program; if not, write to the Free Software
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1256
diff changeset
    24
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    25
import wx
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    26
import os, sys, shutil
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    27
from xml.dom import minidom
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    28
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    29
from py_ext import PythonFileCTNMixin
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    30
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    31
class WxGladeHMI(PythonFileCTNMixin):
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    32
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 427
diff changeset
    33
    ConfNodeMethods = [
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 728
diff changeset
    34
        {"bitmap" : "editWXGLADE",
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    35
         "name" : _("WXGLADE GUI"),
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    36
         "tooltip" : _("Edit a WxWidgets GUI with WXGlade"),
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    37
         "method" : "_editWXGLADE"},
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    38
    ]
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    39
1163
32599dcf311f Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents: 1155
diff changeset
    40
    def GetIconName(self):
32599dcf311f Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents: 1155
diff changeset
    41
        return "wxGlade"
32599dcf311f Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents: 1155
diff changeset
    42
728
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    43
    def ConfNodePath(self):
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    44
        return os.path.join(os.path.dirname(__file__))
e0424e96e3fd refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents: 725
diff changeset
    45
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    46
    def _getWXGLADEpath(self, project_path=None):
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    47
        if project_path is None:
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    48
            project_path = self.CTNPath()
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    49
        # define name for wxGlade gui file
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    50
        return os.path.join(project_path, "hmi.wxg")
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    51
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    52
    def launch_wxglade(self, options, wait=False):
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    53
        from wxglade import __file__ as fileName
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    54
        path = os.path.dirname(fileName)
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    55
        glade = os.path.join(path, 'wxglade.py')
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    56
        if wx.Platform == '__WXMSW__':
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    57
            glade = "\"%s\""%glade
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    58
        mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    59
        os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options)
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    60
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    61
    def OnCTNSave(self, from_project_path=None):
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    62
        if from_project_path is not None:
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    63
            shutil.copyfile(self._getWXGLADEpath(from_project_path),
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    64
                            self._getWXGLADEpath())
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
    65
        return PythonFileCTNMixin.OnCTNSave(self, from_project_path)
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    66
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    67
    def CTNGenerate_C(self, buildpath, locations):
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    68
        
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    69
        hmi_frames = []
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    70
        
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    71
        wxgfile_path=self._getWXGLADEpath()
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    72
        if os.path.exists(wxgfile_path):
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    73
            wxgfile = open(wxgfile_path, 'r')
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    74
            wxgtree = minidom.parse(wxgfile)
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    75
            wxgfile.close()
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    76
            
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    77
            for node in wxgtree.childNodes[1].childNodes:
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    78
                if node.nodeType == wxgtree.ELEMENT_NODE:
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    79
                    hmi_frames.append({
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    80
                        "name" : node.getAttribute("name"),
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    81
                        "class" : node.getAttribute("class"),
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    82
                        "handlers" : [
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    83
                            hnode.firstChild.data for hnode in 
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
    84
                            node.getElementsByTagName("handler")]})
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    85
                    
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    86
            hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py")
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    87
            if wx.Platform == '__WXMSW__':
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    88
                wxgfile_path = "\"%s\""%wxgfile_path
384
50f2069a06b3 Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents: 367
diff changeset
    89
                wxghmipyfile_path = "\"%s\""%hmipyfile_path
50f2069a06b3 Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents: 367
diff changeset
    90
            else:
50f2069a06b3 Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents: 367
diff changeset
    91
                wxghmipyfile_path = hmipyfile_path
50f2069a06b3 Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents: 367
diff changeset
    92
            self.launch_wxglade(['-o', wxghmipyfile_path, '-g', 'python', wxgfile_path], wait=True)
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    93
            
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    94
            hmipyfile = open(hmipyfile_path, 'r')
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
    95
            define_hmi = hmipyfile.read().decode('utf-8')
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    96
            hmipyfile.close()
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
    97
        
1256
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
    98
        else:
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
    99
            define_hmi = ""
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
   100
        
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   101
        declare_hmi = "\n".join(["%(name)s = None\n" % x + 
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   102
                          "\n".join(["%(class)s.%(h)s = %(h)s"%
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   103
                            dict(x,h=h) for h in x['handlers']])
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   104
                                for x in hmi_frames])
1256
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
   105
        global_hmi = ("global %s\n"%",".join(
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
   106
                         [x["name"] for x in hmi_frames]) 
02a710c7b5ed Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents: 1163
diff changeset
   107
                      if len(hmi_frames) > 0 else "")
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   108
        init_hmi = "\n".join(["""\
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   109
def OnCloseFrame(evt):
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   110
    wx.MessageBox(_("Please stop PLC to close"))
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   111
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   112
%(name)s = %(class)s(None)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   113
%(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame)
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   114
%(name)s.Show()
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   115
""" % x for x in hmi_frames])
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   116
        cleanup_hmi = "\n".join(
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   117
            ["if %(name)s is not None: %(name)s.Destroy()" % x 
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   118
                for x in hmi_frames])
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1062
diff changeset
   119
        
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   120
        self.PreSectionsTexts = {
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   121
            "globals":define_hmi,
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   122
            "start":global_hmi,
1151
38d6aaad8ffd Fixed bug wxGlade hmi not closed when stopping PLC
Laurent Bessard
parents: 1132
diff changeset
   123
            "stop":global_hmi + cleanup_hmi
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   124
        }
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   125
        self.PostSectionsTexts = {
1155
412e30abf7e5 Extended WxGlade HMI with automatic mapping of event handlers declared in wxglade editor
Edouard Tisserant
parents: 1151
diff changeset
   126
            "globals":declare_hmi,
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   127
            "start":init_hmi,
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   128
        }
1124
b1705000eba1 Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents: 1062
diff changeset
   129
1132
28f96aa9c070 Rewrote py_ext and wxglade generators in a clean factored way, added C skeleton for python access to PLC global vars
Edouard Tisserant
parents: 1131
diff changeset
   130
        return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations)
367
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
   131
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
   132
    def _editWXGLADE(self):
a76ee5307bb7 Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff changeset
   133
        wxg_filename = self._getWXGLADEpath()
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   134
        open_wxglade = True
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   135
        if not self.GetCTRoot().CheckProjectPathPerm():
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   136
            dialog = wx.MessageDialog(self.GetCTRoot().AppFrame,
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   137
                                      _("You don't have write permissions.\nOpen wxGlade anyway ?"),
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   138
                                      _("Open wxGlade"),
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   139
                                      wx.YES_NO|wx.ICON_QUESTION)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   140
            open_wxglade = dialog.ShowModal() == wx.ID_YES
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   141
            dialog.Destroy()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   142
        if open_wxglade:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   143
            if not os.path.exists(wxg_filename):
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   144
                hmi_name = self.BaseParams.getName()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   145
                open(wxg_filename,"w").write("""<?xml version="1.0"?>
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   146
    <application path="" name="" class="" option="0" language="python" top_window="%(name)s" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0">
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   147
        <object class="%(class)s" name="%(name)s" base="EditFrame">
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   148
            <style>wxDEFAULT_FRAME_STYLE</style>
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   149
            <title>frame_1</title>
834
d613696aad01 Adding default sizer in main frame in default wxGlade GUI file
laurent
parents: 734
diff changeset
   150
            <object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
d613696aad01 Adding default sizer in main frame in default wxGlade GUI file
laurent
parents: 734
diff changeset
   151
                <orient>wxVERTICAL</orient>
d613696aad01 Adding default sizer in main frame in default wxGlade GUI file
laurent
parents: 734
diff changeset
   152
            <object class="sizerslot" />
d613696aad01 Adding default sizer in main frame in default wxGlade GUI file
laurent
parents: 734
diff changeset
   153
        </object>
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   154
        </object>
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   155
    </application>
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   156
    """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   157
            if wx.Platform == '__WXMSW__':
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   158
                wxg_filename = "\"%s\""%wxg_filename
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 384
diff changeset
   159
            self.launch_wxglade([wxg_filename])
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 1014
diff changeset
   160