author | Edouard Tisserant |
Tue, 15 Oct 2019 17:14:48 +0200 | |
branch | svghmi |
changeset 2798 | ddb2c4668a6b |
parent 2625 | e5ce6c4a8672 |
child 3750 | f62625418bff |
permissions | -rw-r--r-- |
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 |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1256
diff
changeset
|
9 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1256
diff
changeset
|
10 |
# 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
|
11 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1256
diff
changeset
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# 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
|
16 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1256
diff
changeset
|
17 |
# 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
|
18 |
# 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
|
19 |
# 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
|
20 |
# 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
|
21 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1256
diff
changeset
|
22 |
# 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
|
23 |
# 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
|
24 |
# 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
|
25 |
|
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
26 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
27 |
from __future__ import absolute_import |
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
28 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
30 |
import shutil |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
31 |
from xml.dom import minidom |
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
32 |
|
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
33 |
import wx |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
|
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
35 |
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
|
36 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
37 |
|
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
38 |
class WxGladeHMI(PythonFileCTNMixin): |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
39 |
|
717 | 40 |
ConfNodeMethods = [ |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
41 |
{ |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
42 |
"bitmap": "editWXGLADE", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
43 |
"name": _("WXGLADE GUI"), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
44 |
"tooltip": _("Edit a WxWidgets GUI with WXGlade"), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
45 |
"method": "_editWXGLADE" |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
46 |
}, |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
47 |
] |
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
48 |
|
1163
32599dcf311f
Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents:
1155
diff
changeset
|
49 |
def GetIconName(self): |
32599dcf311f
Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents:
1155
diff
changeset
|
50 |
return "wxGlade" |
32599dcf311f
Added icon for wxGlade_hmi extension editor
Laurent Bessard
parents:
1155
diff
changeset
|
51 |
|
1061 | 52 |
def _getWXGLADEpath(self, project_path=None): |
53 |
if project_path is None: |
|
54 |
project_path = self.CTNPath() |
|
55 |
# define name for wxGlade gui file |
|
56 |
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
|
57 |
|
1688
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
58 |
def GetWxGladePath(self): |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
59 |
path = None |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
60 |
try: |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
61 |
from wxglade import __file__ as fileName |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
62 |
path = os.path.dirname(fileName) |
1688
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
63 |
return path |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
64 |
except ImportError: |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
65 |
pass |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
66 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
67 |
defLibDir = "/usr/share/wxglade" |
1688
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
68 |
if os.path.isdir(defLibDir): |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
69 |
path = defLibDir |
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
70 |
|
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
71 |
return path |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
72 |
|
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
73 |
def launch_wxglade(self, options, wait=False): |
1688
457155545922
fix running wxGlade on current Debian systems
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
74 |
path = self.GetWxGladePath() |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
75 |
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
|
76 |
if wx.Platform == '__WXMSW__': |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
77 |
glade = "\"%s\"" % glade |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
78 |
mode = {False: os.P_NOWAIT, True: os.P_WAIT}[wait] |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
79 |
os.spawnv(mode, sys.executable, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
80 |
["\"%s\"" % sys.executable] + [glade] + options) |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
81 |
|
1061 | 82 |
def OnCTNSave(self, from_project_path=None): |
83 |
if from_project_path is not None: |
|
84 |
shutil.copyfile(self._getWXGLADEpath(from_project_path), |
|
85 |
self._getWXGLADEpath()) |
|
86 |
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
|
87 |
|
718 | 88 |
def CTNGenerate_C(self, buildpath, locations): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
89 |
|
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
90 |
# list containing description of all objects declared in wxglade |
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
91 |
hmi_objects = [] |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
92 |
# list containing only description of the main frame object |
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
93 |
main_frames = [] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
94 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
95 |
wxgfile_path = self._getWXGLADEpath() |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
96 |
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
|
97 |
wxgfile = open(wxgfile_path, 'r') |
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
98 |
wxgtree = minidom.parse(wxgfile) |
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
99 |
wxgfile.close() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
100 |
|
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
101 |
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
|
102 |
if node.nodeType == wxgtree.ELEMENT_NODE: |
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
103 |
name = node.getAttribute("name") |
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
104 |
wxglade_object_desc = { |
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
105 |
"name": name, |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
106 |
"class": node.getAttribute("class"), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
107 |
"handlers": [ |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
108 |
hnode.firstChild.data for hnode in |
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
109 |
node.getElementsByTagName("handler")]} |
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
110 |
|
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
111 |
hmi_objects.append(wxglade_object_desc) |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
112 |
if name == self.CTNName(): |
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
113 |
main_frames.append(wxglade_object_desc) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
114 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
115 |
hmipyfile_path = os.path.join(self._getBuildPath(), "hmi.py") |
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
116 |
if wx.Platform == '__WXMSW__': |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
117 |
wxgfile_path = "\"%s\"" % wxgfile_path |
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
118 |
wxghmipyfile_path = "\"%s\"" % hmipyfile_path |
384
50f2069a06b3
Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents:
367
diff
changeset
|
119 |
else: |
50f2069a06b3
Bug on windows when trying to open wxglade generated 'hmi.py' file fixed
laurent
parents:
367
diff
changeset
|
120 |
wxghmipyfile_path = hmipyfile_path |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
121 |
self.launch_wxglade( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
122 |
['-o', wxghmipyfile_path, '-g', 'python', wxgfile_path], wait=True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
123 |
|
367
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
hmipyfile.close() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
127 |
|
1256
02a710c7b5ed
Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents:
1163
diff
changeset
|
128 |
else: |
02a710c7b5ed
Fixed bug in wxGlade extension when compiling and starting project with no hmi defined
Laurent Bessard
parents:
1163
diff
changeset
|
129 |
define_hmi = "" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1688
diff
changeset
|
130 |
|
2489
27e4fd37fea6
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Edouard Tisserant
parents:
2488
diff
changeset
|
131 |
global_hmi = ("global %s\n" % ",".join( |
27e4fd37fea6
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Edouard Tisserant
parents:
2488
diff
changeset
|
132 |
[x["name"] for x in main_frames]) if len(main_frames) > 0 else "") |
27e4fd37fea6
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Edouard Tisserant
parents:
2488
diff
changeset
|
133 |
|
2488
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
134 |
declare_hmi = \ |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
135 |
"\n".join(["%(name)s = None\n" % x for x in main_frames]) + \ |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
136 |
"\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" % dict(x, h=h) |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
137 |
for h in x['handlers']]) |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
138 |
for x in hmi_objects]) + """\ |
2488
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
139 |
|
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
140 |
def OnCloseFrame(evt): |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
141 |
wx.MessageBox(_("Please stop PLC to close")) |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
142 |
|
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
143 |
def InitHMI(): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
144 |
""" + global_hmi + "\n" + "\n".join(["""\ |
2488
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
145 |
%(name)s = %(class)s(None) |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
146 |
%(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
147 |
%(name)s.Show() |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
148 |
|
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
149 |
""" % x for x in main_frames]) + """\ |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
150 |
def CleanupHMI(): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
151 |
""" + global_hmi + "\n" + "\n".join(["""\ |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2489
diff
changeset
|
152 |
if %(name)s is not None: |
2488
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
153 |
%(name)s.Destroy() |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
154 |
""" % x for x in main_frames]) |
889c43872f4c
Fix startup of wxGlade base HMI. Wx calls were issued from non-wx thread (main).
Edouard Tisserant
parents:
2248
diff
changeset
|
155 |
|
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
|
156 |
self.PreSectionsTexts = { |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
157 |
"globals": define_hmi, |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
158 |
"start": global_hmi, |
2489
27e4fd37fea6
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Edouard Tisserant
parents:
2488
diff
changeset
|
159 |
"stop": "CleanupHMI()\n" |
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
|
160 |
} |
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
|
161 |
self.PostSectionsTexts = { |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
162 |
"globals": declare_hmi, |
2489
27e4fd37fea6
Fix previous commit : Using wx.CallAfter shouldn't have been necessary, and was a symptom of failing evaluator's deadlock detection.
Edouard Tisserant
parents:
2488
diff
changeset
|
163 |
"start": "InitHMI()\n", |
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
|
164 |
} |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1062
diff
changeset
|
165 |
|
2188
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
166 |
if len(main_frames) == 0 and \ |
7f59aa398669
WxGlade HMI extension now does only instanciate wx object who's name match extension's name. If no object match the name and no code is provided in 'start' user python code section, then a warning is issued
Edouard Tisserant
parents:
1881
diff
changeset
|
167 |
len(getattr(self.CodeFile, "start").getanyText().strip()) == 0: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
168 |
self.GetCTRoot().logger.write_warning( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
169 |
_("Warning: WxGlade HMI has no object with name identical to extension name, and no python code is provided in start section to create object.\n")) |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2188
diff
changeset
|
170 |
|
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
|
171 |
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
|
172 |
|
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
173 |
def _editWXGLADE(self): |
a76ee5307bb7
Adding support for python plugin wxglade_hmi allowing creation of PLC HMI using wxglade
laurent
parents:
diff
changeset
|
174 |
wxg_filename = self._getWXGLADEpath() |
427 | 175 |
open_wxglade = True |
718 | 176 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
177 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
|
427 | 178 |
_("You don't have write permissions.\nOpen wxGlade anyway ?"), |
179 |
_("Open wxGlade"), |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
180 |
wx.YES_NO | wx.ICON_QUESTION) |
427 | 181 |
open_wxglade = dialog.ShowModal() == wx.ID_YES |
182 |
dialog.Destroy() |
|
183 |
if open_wxglade: |
|
184 |
if not os.path.exists(wxg_filename): |
|
185 |
hmi_name = self.BaseParams.getName() |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
186 |
open(wxg_filename, "w").write("""<?xml version="1.0"?> |
427 | 187 |
<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"> |
188 |
<object class="%(class)s" name="%(name)s" base="EditFrame"> |
|
189 |
<style>wxDEFAULT_FRAME_STYLE</style> |
|
190 |
<title>frame_1</title> |
|
834
d613696aad01
Adding default sizer in main frame in default wxGlade GUI file
laurent
parents:
734
diff
changeset
|
191 |
<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
|
192 |
<orient>wxVERTICAL</orient> |
d613696aad01
Adding default sizer in main frame in default wxGlade GUI file
laurent
parents:
734
diff
changeset
|
193 |
<object class="sizerslot" /> |
d613696aad01
Adding default sizer in main frame in default wxGlade GUI file
laurent
parents:
734
diff
changeset
|
194 |
</object> |
427 | 195 |
</object> |
196 |
</application> |
|
197 |
""" % {"name": hmi_name, "class": "Class_%s" % hmi_name}) |
|
198 |
if wx.Platform == '__WXMSW__': |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
199 |
wxg_filename = "\"%s\"" % wxg_filename |
427 | 200 |
self.launch_wxglade([wxg_filename]) |