author | Surkov Sergey <surkovsv93@gmail.com> |
Tue, 23 May 2017 16:06:29 +0300 | |
changeset 1684 | 1447424a7029 |
parent 1680 | 6db967480b7d |
child 1730 | 64d8f52bc8c8 |
permissions | -rwxr-xr-x |
641 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
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:
1458
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
641 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
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:
1598
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
641 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
641 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
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:
1458
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:
1458
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:
1458
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
641 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
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:
1458
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:
1458
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:
1458
diff
changeset
|
20 |
# GNU General Public License for more details. |
641 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
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:
1458
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:
1458
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
641 | 25 |
|
26 |
import os, sys, getopt |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
27 |
from threading import Thread |
641 | 28 |
|
29 |
def usage(): |
|
30 |
print """ |
|
31 |
Usage of Beremiz PLC execution service :\n |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
32 |
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
641 | 33 |
-n - zeroconf service name (default:disabled) |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
34 |
-i - IP address of interface to bind to (default:localhost) |
641 | 35 |
-p - port number default:3000 |
36 |
-h - print this help text and quit |
|
37 |
-a - autostart PLC (0:disable 1:enable) (default:0) |
|
38 |
-x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) |
|
39 |
-t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
40 |
-w - web server port or "off" (default:8009) |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
41 |
-c - WAMP client config file or "off" (default:wampconf.json) |
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
42 |
-e - python extension (absolute path .py) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
43 |
|
641 | 44 |
working_dir - directory where are stored PLC files |
45 |
"""%sys.argv[0] |
|
46 |
||
47 |
try: |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
48 |
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:h") |
641 | 49 |
except getopt.GetoptError, err: |
50 |
# print help information and exit: |
|
51 |
print str(err) # will print something like "option -a not recognized" |
|
52 |
usage() |
|
53 |
sys.exit(2) |
|
54 |
||
55 |
# default values |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
56 |
given_ip = None |
641 | 57 |
port = 3000 |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
58 |
webport = 8009 |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
59 |
wampconf = "wampconf.json" |
641 | 60 |
servicename = None |
61 |
autostart = False |
|
62 |
enablewx = True |
|
63 |
havewx = False |
|
64 |
enabletwisted = True |
|
65 |
havetwisted = False |
|
66 |
||
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
67 |
extensions=[] |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
68 |
|
641 | 69 |
for o, a in opts: |
70 |
if o == "-h": |
|
71 |
usage() |
|
72 |
sys.exit() |
|
73 |
elif o == "-i": |
|
74 |
if len(a.split(".")) == 4 or a == "localhost": |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
75 |
given_ip = a |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
76 |
else: |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
77 |
usage() |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
78 |
sys.exit() |
641 | 79 |
elif o == "-p": |
80 |
# port: port that the service runs on |
|
81 |
port = int(a) |
|
82 |
elif o == "-n": |
|
83 |
servicename = a |
|
84 |
elif o == "-x": |
|
85 |
enablewx = int(a) |
|
86 |
elif o == "-t": |
|
87 |
enabletwisted = int(a) |
|
88 |
elif o == "-a": |
|
89 |
autostart = int(a) |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
90 |
elif o == "-w": |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
91 |
webport = None if a == "off" else int(a) |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
92 |
elif o == "-c": |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
1438
diff
changeset
|
93 |
wampconf = None if a == "off" else a |
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
94 |
elif o == "-e": |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
95 |
extensions.append(a) |
641 | 96 |
else: |
97 |
usage() |
|
98 |
sys.exit() |
|
99 |
||
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1598
diff
changeset
|
100 |
import util.paths as paths |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1598
diff
changeset
|
101 |
beremiz_dir = paths.AbsDir(__file__) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
102 |
|
641 | 103 |
if len(argv) > 1: |
104 |
usage() |
|
105 |
sys.exit() |
|
106 |
elif len(argv) == 1: |
|
107 |
WorkingDir = argv[0] |
|
108 |
os.chdir(WorkingDir) |
|
109 |
elif len(argv) == 0: |
|
110 |
WorkingDir = os.getcwd() |
|
111 |
argv=[WorkingDir] |
|
112 |
||
113 |
import __builtin__ |
|
114 |
if __name__ == '__main__': |
|
115 |
__builtin__.__dict__['_'] = lambda x: x |
|
116 |
||
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
117 |
def Bpath(*args): |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
118 |
return os.path.join(beremiz_dir,*args) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
119 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
120 |
def SetupI18n(): |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
121 |
# Import module for internationalization |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
122 |
import gettext |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
123 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
124 |
# Get folder containing translation files |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
125 |
localedir = os.path.join(beremiz_dir,"locale") |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
126 |
# Get the default language |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
127 |
langid = wx.LANGUAGE_DEFAULT |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
128 |
# Define translation domain (name of translation files) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
129 |
domain = "Beremiz" |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
130 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
131 |
# Define locale for wx |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
132 |
loc = __builtin__.__dict__.get('loc', None) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
133 |
if loc is None: |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
134 |
loc = wx.Locale(langid) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
135 |
__builtin__.__dict__['loc'] = loc |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
136 |
# Define location for searching translation files |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
137 |
loc.AddCatalogLookupPathPrefix(localedir) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
138 |
# Define locale domain |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
139 |
loc.AddCatalog(domain) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
140 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
141 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
142 |
import locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
143 |
global default_locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
144 |
default_locale = locale.getdefaultlocale()[1] |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
145 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
146 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
147 |
# sys.stdout.encoding = default_locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
148 |
# if Beremiz_service is started from Beremiz IDE |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
149 |
# sys.stdout.encoding is None (that means 'ascii' encoding'). |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
150 |
# And unicode string returned by wx.GetTranslation() are |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
151 |
# automatically converted to 'ascii' string. |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
152 |
def unicode_translation(message): |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
153 |
return wx.GetTranslation(message).encode(default_locale) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
154 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
155 |
if __name__ == '__main__': |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
156 |
__builtin__.__dict__['_'] = unicode_translation |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
157 |
# __builtin__.__dict__['_'] = wx.GetTranslation |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
158 |
|
641 | 159 |
if enablewx: |
160 |
try: |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
161 |
import wxversion |
1590
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
162 |
wxversion.select(['2.8', '3.0']) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
163 |
import wx |
641 | 164 |
havewx = True |
165 |
except: |
|
166 |
print "Wx unavailable !" |
|
167 |
havewx = False |
|
168 |
||
169 |
if havewx: |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
170 |
import re |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
171 |
from threading import Thread, currentThread |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
172 |
from types import * |
1590
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
173 |
|
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
174 |
if wx.VERSION >= (3, 0, 0): |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
175 |
app = wx.App(redirect=False) |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
176 |
else: |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
177 |
app = wx.PySimpleApp(redirect=False) |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
178 |
app.SetTopWindow(wx.Frame(None, -1)) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
179 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
180 |
default_locale = None |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
181 |
SetupI18n() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
182 |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
183 |
defaulticon = wx.Image(Bpath("images", "brz.png")) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
184 |
starticon = wx.Image(Bpath("images", "icoplay24.png")) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
185 |
stopicon = wx.Image(Bpath("images", "icostop24.png")) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
186 |
|
641 | 187 |
class ParamsEntryDialog(wx.TextEntryDialog): |
188 |
if wx.VERSION < (2, 6, 0): |
|
189 |
def Bind(self, event, function, id = None): |
|
190 |
if id is not None: |
|
191 |
event(self, id, function) |
|
192 |
else: |
|
193 |
event(self, function) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
194 |
|
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
195 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
196 |
def __init__(self, parent, message, caption = _("Please enter text"), defaultValue = "", |
641 | 197 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
198 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
199 |
|
641 | 200 |
self.Tests = [] |
201 |
if wx.VERSION >= (2, 8, 0): |
|
202 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
|
203 |
elif wx.VERSION >= (2, 6, 0): |
|
204 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
205 |
else: |
|
206 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
207 |
|
641 | 208 |
def OnOK(self, event): |
209 |
value = self.GetValue() |
|
210 |
texts = {"value" : value} |
|
211 |
for function, message in self.Tests: |
|
212 |
if not function(value): |
|
213 |
message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) |
|
214 |
message.ShowModal() |
|
215 |
message.Destroy() |
|
216 |
return |
|
217 |
self.EndModal(wx.ID_OK) |
|
218 |
event.Skip() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
219 |
|
641 | 220 |
def GetValue(self): |
221 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
222 |
|
641 | 223 |
def SetTests(self, tests): |
224 |
self.Tests = tests |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
225 |
|
641 | 226 |
class BeremizTaskBarIcon(wx.TaskBarIcon): |
227 |
TBMENU_START = wx.NewId() |
|
228 |
TBMENU_STOP = wx.NewId() |
|
229 |
TBMENU_CHANGE_NAME = wx.NewId() |
|
230 |
TBMENU_CHANGE_PORT = wx.NewId() |
|
231 |
TBMENU_CHANGE_INTERFACE = wx.NewId() |
|
232 |
TBMENU_LIVE_SHELL = wx.NewId() |
|
233 |
TBMENU_WXINSPECTOR = wx.NewId() |
|
234 |
TBMENU_CHANGE_WD = wx.NewId() |
|
235 |
TBMENU_QUIT = wx.NewId() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
236 |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
237 |
def __init__(self, pyroserver, level): |
641 | 238 |
wx.TaskBarIcon.__init__(self) |
239 |
self.pyroserver = pyroserver |
|
240 |
# Set the image |
|
241 |
self.UpdateIcon(None) |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
242 |
self.level = level |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
243 |
|
641 | 244 |
# bind some events |
245 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
|
246 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
|
247 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
|
248 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) |
|
249 |
self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) |
|
250 |
self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) |
|
251 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) |
|
252 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) |
|
253 |
self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
254 |
|
641 | 255 |
def CreatePopupMenu(self): |
256 |
""" |
|
257 |
This method is called by the base class when it needs to popup |
|
258 |
the menu for the default EVT_RIGHT_DOWN event. Just create |
|
259 |
the menu how you want it and return it from this function, |
|
260 |
the base class takes care of the rest. |
|
261 |
""" |
|
262 |
menu = wx.Menu() |
|
263 |
menu.Append(self.TBMENU_START, _("Start PLC")) |
|
264 |
menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
265 |
if self.level==1: |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
266 |
menu.AppendSeparator() |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
267 |
menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
268 |
menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
269 |
menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
270 |
menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
271 |
menu.AppendSeparator() |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
272 |
menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
273 |
menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
641 | 274 |
menu.AppendSeparator() |
275 |
menu.Append(self.TBMENU_QUIT, _("Quit")) |
|
276 |
return menu |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
277 |
|
641 | 278 |
def MakeIcon(self, img): |
279 |
""" |
|
280 |
The various platforms have different requirements for the |
|
281 |
icon size... |
|
282 |
""" |
|
283 |
if "wxMSW" in wx.PlatformInfo: |
|
284 |
img = img.Scale(16, 16) |
|
285 |
elif "wxGTK" in wx.PlatformInfo: |
|
286 |
img = img.Scale(22, 22) |
|
287 |
# wxMac can be any size upto 128x128, so leave the source img alone.... |
|
288 |
icon = wx.IconFromBitmap(img.ConvertToBitmap() ) |
|
289 |
return icon |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
290 |
|
641 | 291 |
def OnTaskBarStartPLC(self, evt): |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
292 |
if self.pyroserver.plcobj is not None: |
1592
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
293 |
plcstatus = self.pyroserver.plcobj.GetPLCstatus()[0] |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
294 |
if plcstatus is "Stopped": |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
295 |
self.pyroserver.plcobj.StartPLC() |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
296 |
else: |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
297 |
print _("PLC is empty or already started.") |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
298 |
|
641 | 299 |
def OnTaskBarStopPLC(self, evt): |
300 |
if self.pyroserver.plcobj is not None: |
|
1592
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
301 |
if self.pyroserver.plcobj.GetPLCstatus()[0] == "Started": |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
302 |
Thread(target=self.pyroserver.plcobj.StopPLC).start() |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
303 |
else: |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
304 |
print _("PLC is not started.") |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
305 |
|
641 | 306 |
def OnTaskBarChangeInterface(self, evt): |
1593
6a27490fed96
don't crash on trying to change IP interface for Beremiz_service using taskbar icon if IP wasn't previously
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1592
diff
changeset
|
307 |
ip_addr = self.pyroserver.ip_addr |
6a27490fed96
don't crash on trying to change IP interface for Beremiz_service using taskbar icon if IP wasn't previously
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1592
diff
changeset
|
308 |
ip_addr = '' if ip_addr is None else ip_addr |
6a27490fed96
don't crash on trying to change IP interface for Beremiz_service using taskbar icon if IP wasn't previously
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1592
diff
changeset
|
309 |
dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=ip_addr) |
641 | 310 |
dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
311 |
( lambda x :len([x for x in x.split(".") if 0 <= int(x) <= 255]) == 4, _("IP is not valid!")) |
641 | 312 |
]) |
313 |
if dlg.ShowModal() == wx.ID_OK: |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
314 |
self.pyroserver.ip_addr = dlg.GetValue() |
641 | 315 |
self.pyroserver.Stop() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
316 |
|
641 | 317 |
def OnTaskBarChangePort(self, evt): |
318 |
dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
|
319 |
dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) |
|
320 |
if dlg.ShowModal() == wx.ID_OK: |
|
321 |
self.pyroserver.port = int(dlg.GetValue()) |
|
322 |
self.pyroserver.Stop() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
323 |
|
641 | 324 |
def OnTaskBarChangeWorkingDir(self, evt): |
325 |
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
|
326 |
if dlg.ShowModal() == wx.ID_OK: |
|
327 |
self.pyroserver.workdir = dlg.GetPath() |
|
328 |
self.pyroserver.Stop() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
329 |
|
641 | 330 |
def OnTaskBarChangeName(self, evt): |
1594
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
331 |
servicename = self.pyroserver.servicename |
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
332 |
servicename = '' if servicename is None else servicename |
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
333 |
dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=servicename) |
641 | 334 |
dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) |
335 |
if dlg.ShowModal() == wx.ID_OK: |
|
1594
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
336 |
self.pyroserver.servicename = dlg.GetValue() |
641 | 337 |
self.pyroserver.Restart() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
338 |
|
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
339 |
def _LiveShellLocals(self): |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
340 |
if self.pyroserver.plcobj is not None: |
1049 | 341 |
return {"locals":self.pyroserver.plcobj.python_runtime_vars} |
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
342 |
else: |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
343 |
return {} |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
344 |
|
641 | 345 |
def OnTaskBarLiveShell(self, evt): |
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
346 |
from wx import py |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
347 |
frame = py.crust.CrustFrame(**self._LiveShellLocals()) |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
348 |
frame.Show() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
349 |
|
641 | 350 |
def OnTaskBarWXInspector(self, evt): |
351 |
# Activate the widget inspection tool |
|
352 |
from wx.lib.inspection import InspectionTool |
|
353 |
if not InspectionTool().initialized: |
|
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
354 |
InspectionTool().Init(**self._LiveShellLocals()) |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
355 |
|
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
356 |
wnd = wx.GetApp() |
641 | 357 |
InspectionTool().Show(wnd, True) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
358 |
|
641 | 359 |
def OnTaskBarQuit(self, evt): |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
360 |
if wx.Platform == '__WXMSW__': |
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
361 |
Thread(target=self.pyroserver.Quit).start() |
641 | 362 |
self.RemoveIcon() |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
363 |
wx.CallAfter(wx.GetApp().ExitMainLoop) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
364 |
|
641 | 365 |
def UpdateIcon(self, plcstatus): |
366 |
if plcstatus is "Started" : |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
367 |
currenticon = self.MakeIcon(starticon) |
641 | 368 |
elif plcstatus is "Stopped": |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
369 |
currenticon = self.MakeIcon(stopicon) |
641 | 370 |
else: |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
371 |
currenticon = self.MakeIcon(defaulticon) |
641 | 372 |
self.SetIcon(currenticon, "Beremiz Service") |
373 |
||
374 |
from runtime import PLCObject, PLCprint, ServicePublisher |
|
375 |
import Pyro.core as pyro |
|
376 |
||
377 |
if not os.path.isdir(WorkingDir): |
|
378 |
os.mkdir(WorkingDir) |
|
379 |
||
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
380 |
def default_evaluator(tocall, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
381 |
try: |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
382 |
res=(tocall(*args,**kwargs), None) |
1051
847d68c3e7ff
Extended exception info from evaluator. Problems in python runtime init/cleanup code now more readable
Edouard Tisserant
parents:
1049
diff
changeset
|
383 |
except Exception: |
847d68c3e7ff
Extended exception info from evaluator. Problems in python runtime init/cleanup code now more readable
Edouard Tisserant
parents:
1049
diff
changeset
|
384 |
res=(None, sys.exc_info()) |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
385 |
return res |
641 | 386 |
|
387 |
class Server(): |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
388 |
def __init__(self, servicename, ip_addr, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
389 |
workdir, argv, autostart=False, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
390 |
statuschange=None, evaluator=default_evaluator, |
1458 | 391 |
pyruntimevars=None): |
641 | 392 |
self.continueloop = True |
393 |
self.daemon = None |
|
394 |
self.servicename = servicename |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
395 |
self.ip_addr = ip_addr |
641 | 396 |
self.port = port |
397 |
self.workdir = workdir |
|
398 |
self.argv = argv |
|
399 |
self.plcobj = None |
|
400 |
self.servicepublisher = None |
|
401 |
self.autostart = autostart |
|
402 |
self.statuschange = statuschange |
|
403 |
self.evaluator = evaluator |
|
1458 | 404 |
self.pyruntimevars = pyruntimevars |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
405 |
|
641 | 406 |
def Loop(self): |
407 |
while self.continueloop: |
|
408 |
self.Start() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
409 |
|
641 | 410 |
def Restart(self): |
411 |
self.Stop() |
|
412 |
||
413 |
def Quit(self): |
|
414 |
self.continueloop = False |
|
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
415 |
if self.plcobj is not None: |
1596
f5868f866d2b
stop PLC before unloading
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
416 |
self.plcobj.StopPLC() |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
417 |
self.plcobj.UnLoadPLC() |
641 | 418 |
self.Stop() |
419 |
||
420 |
def Start(self): |
|
421 |
pyro.initServer() |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
422 |
self.daemon=pyro.Daemon(host=self.ip_addr, port=self.port) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
423 |
self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
424 |
self.statuschange, self.evaluator, |
1458 | 425 |
self.pyruntimevars) |
641 | 426 |
uri = self.daemon.connect(self.plcobj,"PLCObject") |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
427 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
428 |
print _("Pyro port :"), self.port |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
429 |
print _("Pyro object's uri :"), uri |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
430 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
431 |
# Beremiz IDE detects daemon start by looking |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
432 |
# for self.workdir in the daemon's stdout. |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
433 |
# Therefore don't delete the following line |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
434 |
print _("Current working directory :"), self.workdir |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
435 |
|
641 | 436 |
# Configure and publish service |
437 |
# Not publish service if localhost in address params |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
438 |
if (self.servicename is not None and |
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
439 |
self.ip_addr is not None and |
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
440 |
self.ip_addr != "localhost" and |
648
73295e742da2
Avoid starting Zeroconf if ip unspecified or set to localhost. Pick one interface address when given IP is 0.0.0.0
Edouard Tisserant
parents:
644
diff
changeset
|
441 |
self.ip_addr != "127.0.0.1"): |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
442 |
print _("Publishing service on local network") |
641 | 443 |
self.servicepublisher = ServicePublisher.ServicePublisher() |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
444 |
self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
445 |
|
1597
0e4182e9cc09
always load existing PLC program from the working directory
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1596
diff
changeset
|
446 |
self.plcobj.AutoLoad() |
0e4182e9cc09
always load existing PLC program from the working directory
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1596
diff
changeset
|
447 |
if self.plcobj.GetPLCstatus()[0] != "Empty": |
0e4182e9cc09
always load existing PLC program from the working directory
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1596
diff
changeset
|
448 |
if self.autostart : |
1447
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1446
diff
changeset
|
449 |
self.plcobj.StartPLC() |
1598
1445457547f7
update PLC status after initialization
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1597
diff
changeset
|
450 |
self.plcobj.StatusChange() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
451 |
|
641 | 452 |
sys.stdout.flush() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
453 |
|
641 | 454 |
self.daemon.requestLoop() |
1591
38e5f8847a45
close Pyro socket after daemon stop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1590
diff
changeset
|
455 |
self.daemon.sock.close() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
456 |
|
641 | 457 |
def Stop(self): |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
458 |
if self.plcobj is not None: |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
459 |
self.plcobj.StopPLC() |
641 | 460 |
if self.servicepublisher is not None: |
461 |
self.servicepublisher.UnRegisterService() |
|
462 |
self.servicepublisher = None |
|
463 |
self.daemon.shutdown(True) |
|
464 |
||
465 |
if enabletwisted: |
|
466 |
import warnings |
|
467 |
with warnings.catch_warnings(): |
|
468 |
warnings.simplefilter("ignore") |
|
469 |
try: |
|
470 |
from threading import Thread, currentThread |
|
471 |
if havewx: |
|
472 |
from twisted.internet import wxreactor |
|
473 |
wxreactor.install() |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
474 |
from twisted.internet import reactor |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
475 |
|
641 | 476 |
havetwisted = True |
477 |
except: |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
478 |
print _("Twisted unavailable.") |
641 | 479 |
havetwisted = False |
480 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
481 |
pyruntimevars = {} |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
482 |
statuschange = [] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
483 |
|
641 | 484 |
if havetwisted: |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
485 |
|
641 | 486 |
if havewx: |
487 |
reactor.registerWxApp(app) |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
488 |
|
641 | 489 |
if havewx: |
490 |
from threading import Semaphore |
|
491 |
wx_eval_lock = Semaphore(0) |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
492 |
main_thread = currentThread() |
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
493 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
494 |
def statuschangeTskBar(status): |
641 | 495 |
wx.CallAfter(taskbar_instance.UpdateIcon,status) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
496 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
497 |
statuschange.append(statuschangeTskBar) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
498 |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
499 |
def wx_evaluator(obj, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
500 |
tocall,args,kwargs = obj.call |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
501 |
obj.res = default_evaluator(tocall, *args, **kwargs) |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
502 |
wx_eval_lock.release() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
503 |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
504 |
def evaluator(tocall, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
505 |
global main_thread |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
506 |
if(main_thread == currentThread()): |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
507 |
# avoid dead lock if called from the wx mainloop |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
508 |
return default_evaluator(tocall, *args, **kwargs) |
641 | 509 |
else: |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
510 |
o=type('',(object,),dict(call=(tocall, args, kwargs), res=None)) |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
511 |
wx.CallAfter(wx_evaluator,o) |
641 | 512 |
wx_eval_lock.acquire() |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
513 |
return o.res |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
514 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
515 |
pyroserver = Server(servicename, given_ip, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
516 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
517 |
statuschange, evaluator, pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
518 |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
519 |
taskbar_instance = BeremizTaskBarIcon(pyroserver, enablewx) |
641 | 520 |
else: |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
521 |
pyroserver = Server(servicename, given_ip, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
522 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
523 |
statuschange, pyruntimevars=pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
524 |
|
641 | 525 |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
526 |
# Exception hooks s |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
527 |
import threading, traceback |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
528 |
def LogException(*exp): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
529 |
if pyroserver.plcobj is not None: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
530 |
pyroserver.plcobj.LogMessage(0,'\n'.join(traceback.format_exception(*exp))) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
531 |
else: |
1270 | 532 |
traceback.print_exception(*exp) |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
533 |
|
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
534 |
sys.excepthook = LogException |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
535 |
def installThreadExcepthook(): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
536 |
init_old = threading.Thread.__init__ |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
537 |
def init(self, *args, **kwargs): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
538 |
init_old(self, *args, **kwargs) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
539 |
run_old = self.run |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
540 |
def run_with_except_hook(*args, **kw): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
541 |
try: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
542 |
run_old(*args, **kw) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
543 |
except (KeyboardInterrupt, SystemExit): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
544 |
raise |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
545 |
except: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
546 |
sys.excepthook(*sys.exc_info()) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
547 |
self.run = run_with_except_hook |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
548 |
threading.Thread.__init__ = init |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
549 |
installThreadExcepthook() |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
550 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
551 |
if havetwisted: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
552 |
if webport is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
553 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
554 |
import runtime.NevowServer as NS |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
555 |
except Exception, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
556 |
print _("Nevow/Athena import failed :"), e |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
557 |
webport = None |
1453 | 558 |
NS.WorkingDir = WorkingDir |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
559 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
560 |
if wampconf is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
561 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
562 |
import runtime.WampClient as WC |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
563 |
except Exception, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
564 |
print _("WAMP import failed :"), e |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
565 |
wampconf = None |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
566 |
|
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
567 |
# Load extensions |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
568 |
for extfilename in extensions: |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
569 |
extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
570 |
sys.path.append(extension_folder) |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
571 |
execfile(extfilename, locals()) |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
572 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
573 |
if havetwisted: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
574 |
if webport is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
575 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
576 |
website = NS.RegisterWebsite(webport) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
577 |
pyruntimevars["website"] = website |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
578 |
statuschange.append(NS.website_statuslistener_factory(website)) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
579 |
except Exception, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
580 |
print _("Nevow Web service failed. "), e |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
581 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
582 |
if wampconf is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
583 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
584 |
WC.RegisterWampClient(wampconf) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
585 |
pyruntimevars["wampsession"] = WC.GetSession |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
586 |
WC.SetServer(pyroserver) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
587 |
except Exception, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
588 |
print _("WAMP client startup failed. "), e |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
589 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
590 |
|
641 | 591 |
if havetwisted or havewx: |
592 |
pyro_thread=Thread(target=pyroserver.Loop) |
|
593 |
pyro_thread.start() |
|
594 |
||
595 |
if havetwisted: |
|
596 |
reactor.run() |
|
597 |
elif havewx: |
|
598 |
app.MainLoop() |
|
599 |
else: |
|
600 |
try : |
|
601 |
pyroserver.Loop() |
|
602 |
except KeyboardInterrupt,e: |
|
603 |
pass |
|
604 |
pyroserver.Quit() |
|
605 |
sys.exit(0) |