author | laurent |
Wed, 12 Aug 2009 11:46:22 +0200 | |
changeset 371 | b7cb57a2da08 |
parent 369 | bd54d41a7573 |
child 381 | 5c0f34a9ab00 |
permissions | -rw-r--r-- |
262 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import os, sys, getopt |
|
26 |
||
27 |
def usage(): |
|
28 |
print """ |
|
29 |
Usage of Beremiz PLC execution service :\n |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
30 |
%s {[-n name] [-i ip] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
262 | 31 |
-n - zeroconf service name |
32 |
-i - ip of interface to bind to (x.x.x.x) |
|
33 |
-p - port number |
|
34 |
-h - print this help text and quit |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
35 |
-a - autostart PLC (0:disable 1:enable) |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
36 |
-x - enable/disable wxTaskbarIcon (0:disable 1:enable) |
368 | 37 |
-t - enable/disable Twisted web interface (0:disable 1:enable) |
262 | 38 |
|
39 |
working_dir - directory where are stored PLC files |
|
40 |
"""%sys.argv[0] |
|
41 |
||
42 |
try: |
|
368 | 43 |
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:h") |
262 | 44 |
except getopt.GetoptError, err: |
45 |
# print help information and exit: |
|
46 |
print str(err) # will print something like "option -a not recognized" |
|
47 |
usage() |
|
48 |
sys.exit(2) |
|
49 |
||
50 |
# default values |
|
51 |
ip = "" |
|
52 |
port = 3000 |
|
53 |
name = os.environ[{ |
|
54 |
"linux2":"USER", |
|
55 |
"win32":"USERNAME", |
|
56 |
}.get(sys.platform, "USER")] |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
57 |
autostart = False |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
58 |
enablewx = True |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
59 |
havewx = False |
368 | 60 |
enabletwisted = True |
61 |
havetwisted = False |
|
262 | 62 |
|
63 |
for o, a in opts: |
|
64 |
if o == "-h": |
|
65 |
usage() |
|
66 |
sys.exit() |
|
67 |
elif o == "-i": |
|
68 |
if len(a.split(".")) == 4 or a == "localhost": |
|
69 |
ip = a |
|
70 |
elif o == "-p": |
|
71 |
# port: port that the service runs on |
|
72 |
port = int(a) |
|
73 |
elif o == "-n": |
|
74 |
name = a |
|
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
75 |
elif o == "-x": |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
76 |
enablewx = int(a) |
368 | 77 |
elif o == "-t": |
78 |
enabletwisted = int(a) |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
79 |
elif o == "-a": |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
80 |
autostart = int(a) |
262 | 81 |
else: |
82 |
usage() |
|
83 |
sys.exit() |
|
84 |
||
301 | 85 |
if len(argv) > 1: |
262 | 86 |
usage() |
87 |
sys.exit() |
|
301 | 88 |
elif len(argv) == 1: |
89 |
WorkingDir = argv[0] |
|
90 |
elif len(argv) == 0: |
|
262 | 91 |
WorkingDir = os.getcwd() |
301 | 92 |
argv=[WorkingDir] |
262 | 93 |
|
361 | 94 |
import __builtin__ |
95 |
if __name__ == '__main__': |
|
96 |
__builtin__.__dict__['_'] = lambda x: x |
|
97 |
||
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
98 |
if enablewx: |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
99 |
try: |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
100 |
import wx, re |
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
101 |
from threading import Thread, currentThread |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
102 |
from types import * |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
103 |
havewx = True |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
104 |
except: |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
105 |
havewx = False |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
106 |
|
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
107 |
if havewx: |
361 | 108 |
app=wx.App(redirect=False) |
109 |
||
110 |
# Import module for internationalization |
|
111 |
import gettext |
|
112 |
||
113 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
|
114 |
||
115 |
# Get folder containing translation files |
|
116 |
localedir = os.path.join(CWD,"locale") |
|
117 |
# Get the default language |
|
118 |
langid = wx.LANGUAGE_DEFAULT |
|
119 |
# Define translation domain (name of translation files) |
|
120 |
domain = "Beremiz" |
|
121 |
||
122 |
# Define locale for wx |
|
123 |
loc = __builtin__.__dict__.get('loc', None) |
|
124 |
if loc is None: |
|
125 |
loc = wx.Locale(langid) |
|
126 |
__builtin__.__dict__['loc'] = loc |
|
127 |
# Define location for searching translation files |
|
128 |
loc.AddCatalogLookupPathPrefix(localedir) |
|
129 |
# Define locale domain |
|
130 |
loc.AddCatalog(domain) |
|
131 |
||
132 |
def unicode_translation(message): |
|
133 |
return wx.GetTranslation(message).encode("utf-8") |
|
134 |
||
135 |
if __name__ == '__main__': |
|
136 |
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
137 |
||
294
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
138 |
try: |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
139 |
from wx.lib.embeddedimage import PyEmbeddedImage |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
140 |
except: |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
141 |
import cStringIO |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
142 |
import base64 |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
143 |
|
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
144 |
class PyEmbeddedImage: |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
145 |
def __init__(self, image_string): |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
146 |
stream = cStringIO.StringIO(base64.b64decode(image_string)) |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
147 |
self.Image = wx.ImageFromStream(stream) |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
148 |
def GetImage(self): |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
149 |
return self.Image |
39b3d4a2195b
Fix problem with embeddedimage module not present in wx versions older than 2.8.8.0
lbessard
parents:
290
diff
changeset
|
150 |
|
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
151 |
defaulticon = PyEmbeddedImage( |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
152 |
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAABc5J" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
153 |
"REFUSIl9lW1MW9cZx3/n2vf6BQO2MZiXGBISILCVUEUlitYpjaKpXZJ1XZZ2kzJVY9r6IeLD" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
154 |
"pGTaNG3KtGmNNGlbpW3VFhRp0l6aZCllpVUqtVNJtBFKE5QXLxCjpCYEY7DBr9hcm3vPPgQY" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
155 |
"IQmPdKR7/vd5/v/n5dxzhZSSNeYBOoGDQGcoFPINDAyUDQ0NOUdGRmyGYSiBQGCpoaGhuGnT" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
156 |
"psShQ4f6WltbewEBVAK3gCBgrjJKKZFSKlLKeillt5Ty40gkMnnw4MFFQG60ysrKZHd3dyoe" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
157 |
"j//bNM0Le/fuPd/e3r5lmRMpJWK5ghrgFeBIT09P4/Hjx73pdFo47HaaNlfRutnJru0OKsoE" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
158 |
"E3GVqaSNa6EUw1dvIKWkoqKCrVu3FoeHh9WamppfRiKRn6wUYAUcwE7g2e7u7vrTp09XGIZB" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
159 |
"W1Mdv3qtmoBPrG0hHVsMhKLj6nqOqOWn/Pjnv2dgYIC5uTl1uSM71/pbgUbg6bNnz/rPnDnj" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
160 |
"dzoddO0P8Oo+jY2suDDD1Zv9DA1dfghXVbVBCFEqpcwAKEDTxMSE58SJE8+oqsq3nq/l1X0a" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
161 |
"QihYtNLHLqRET03wuYp7fO9r26mpKlsVUBSl0W63V6/shZTyyIEDB344Njb21JYaG7/5bgkA" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
162 |
"Dm8zTS/+7bHZLy0mSN+7yNztt8nPjYHFwfvXDf1P70zZ0ok0LS0tZy9fvvxNAGswGFQnJyef" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
163 |
"KnM5+NHLzuUDsrFZ7R68zS/hrGon1PcNMPI0BIzs9tcCNvNfDqxW64uqqvqKxWJc6e3trVVV" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
164 |
"leaAk6ryJ5N/9tH3GXv7Je7/5xermN3diMPXCkDfgrkg3UU0txWLxeLw+/1fB1BGR0frbTYb" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
165 |
"TXWWDbNeysUoZKbIRIZBPviOzKU8ejLMHyPFcMprrweQ7iUAXC7XPiGEak2lUk02m42mWn1D" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
166 |
"gfrnTiKNIrbyzSAUjEKWCx+/Mf+HyELBrLBvBhAIKDdgGsrLy+sAv1UIUa1pGv7yxQ0FbGX1" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
167 |
"D+0LQmHW7fVavE5Mo/gAFCCcoOs6NpvNA7gVRVGCmqYRz1hXg7NFU39rjshawjcuvs4P+o/y" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
168 |
"24uvE1+I4VCdfGfXUb76+VdWfQQCkbJSKBQoFApJTdMsCvApQDSlAjCTN7I/y5CNllpq1wqE" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
169 |
"YmPciIzwwdi7BKevreK7Gp5dfbYoFoozJrquo+v6rMViWbQCV4QQzGTsQJY3kzIhvFpgfYte" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
170 |
"7jhCMp9kk7uep+ueWcWj6f8Xqioq8ck0xcIS6XT6vpRy3gqMqKpqRBfKLLNF1ZRV6YBiPDrw" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
171 |
"vduefwTL6hl6b74FgFVR0T4rJTU3jcvlymcymal8Ph+z9vf3p7u6uv5y/vz5bw994ld2fmUH" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
172 |
"7nYFRVG4Gb3Guv8FpmmQzCcIJ+5w8c5HRFL3UYRC+ZKX633j6LpObW3tDcMwrsODq4Jbt27V" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
173 |
"HT58+N7o6KgCYHfY2f2lXfi+6CJbnsAwjUeyXzFFKLgdHqb+mmL8xh22bduWmJycfHN2dvbX" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
174 |
"uVwuoQC0tbXlKisrYytBi/lFZsKzOErtTyQWCOxWO36ljvl/FLk+dJOSkhJTUZR35+fn+3K5" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
175 |
"XAIeXNcASz6fbxzwrxDYVQdqpARvs498IYchDUxpogiBVVFxqE7U/5Zx4c8fEo/FKS0tlR0d" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
176 |
"HZ8ODg6+l06nr6zwrAp4PJ6Qpmlf2L9/fywYDFaOXB0RI1dHaGpuoq29Fa1Uxe62YeZMInei" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
177 |
"jAY/IRqNAtDZ2blUV1fXPzg4+F5VVdU/H6p0eYjqsWPHvnz37t0XwuHw7d27d4eTyeTvLl26" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
178 |
"FJiamnpim6qrq9mzZ094fHz875FI5J3p6ekr631WBARgaWlpCezYsePeuXPnzFAo5Dp58uS+" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
179 |
"dDp91GKxNBYKBW82m3Vomqa7XK7pbDYbnJmZuR2LxYL5fP79WCyWeeys1h/D9e97enqsp06d" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
180 |
"8mWzWU+xWPTkcjmXaZpxwzDCsVhsbqNggP8BMJOU3UUUf+0AAAAASUVORK5CYII=") |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
181 |
|
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
182 |
#---------------------------------------------------------------------- |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
183 |
starticon = PyEmbeddedImage( |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
184 |
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAABbpJ" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
185 |
"REFUSIl9lltsFNcdxn9nZnbHs15fd23j9TXYC0UCKzEhMQ+oIS2g1kQ1pbFStX0opFWsovSh" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
186 |
"rUqp2pS2ioTUolaKFOGHqGkiJcKRuDhOaZRiZCsCXyBgCBBfMfbu+oa9s17wzuzl9MH24mDD" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
187 |
"XzoPc/6fft+c72jOGSGlZEVlAU8D9cB20zQ9HR0duRcvXszq7e01EomEUlFREa+srLR8Pl+g" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
188 |
"sbHx3zk5ORcAFfACA8Bt4CFUSomUUkgpS6SUB6SUH5umOXLgwIEHqqrKJfGao7S0VB49ejRo" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
189 |
"2/YnUsrT+/fvb66pqSldYiKlRCytoBB4Gfjx6dOnq5qamjwTExOKqqqU+QrYUJFN7QY32Qbc" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
190 |
"vSeYCGtcux1i5M5dAPx+P1VVVQvnzp0ziouLfx8MBt9cXoAGZABbgZ1HjhwpO378eEEymaSi" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
191 |
"tIBjPy9lU5nKoyWExF2yjy+mN3HsH+/Q3d3NwMCAsZTI9pVaDXgK2Hr27Nn85ubmEpdh8IMX" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
192 |
"ffxirwshVrGXHBQSC/dIRvoZGuz/WkvTtHIhhCGlXABQgI2Tk5P5hw8f3uZwOGj8VjGHXnoC" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
193 |
"HJCpJFbkLtr8FXbX+XC79HRPVVW/qqre9LtIKX/S0NDwy76+vq1lhTr/fM2NAmTk+fHv/dea" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
194 |
"BlZkDHP0PHODH2NHg1gykw8/X7Dfb7vjTNgJqqurT3R1db0GoF2/fl0fGhqqdWca/K7RhZLO" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
195 |
"WSBU55oGGXlVZORVkeV7nsFPDqKL+9TWJCI3n9rojX2mYhjGj4QQv5FSziunTp0qdjqd4hvl" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
196 |
"Lnz5j49lrPMNhv7zM6b63knPuQpryMj3A9A2L++nvDaZXheqqrrXrVu3D0C5detWudPpxO/T" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
197 |
"Hk8HYnOD3J+8yr3bH6XnZNImHg3xfsgenfHo5QAyJwFAdnb2HiGEppmmWa3rOhtKrCcalNT9" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
198 |
"llTSwvBsXISn4nRdbJ5/czRsWvlGhQAEYtFg0kl2dnYZUKgB5U6nk5L82BMNXIU1X3uOWFH5" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
199 |
"eWIuy/YYWcjU4qQAxQ22bWMYhgfIU1RV/UrXdWaiDyOyUiLROktoJfDtC8fZfWQbb//v75ix" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
200 |
"MDlGnvjVC3+gflNDWiMQKPMalmVh2/a8w+HQFKAHIBR2ABCOS+uN6cTMoFstXmlwZbSba7tv" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
201 |
"8hfzT7z+7k+ZnZ0BoK5yR1qjCBV7MoVt29i2PaWqqq0BvUIIQqYORHlrKj6R9BoVj0b04oY9" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
202 |
"nEt+yvz3Y5yR/+Xap3XsDb/EtvV1aY1DdTA7HsW2bCKRyLiUclYBelRVldNWAfPSm4oV5ZQJ" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
203 |
"Vn/G9Zv2oWt6Ous7e4K81XiC1wNNBO6OIWKgB7Mwp000TYuFw+GxWCw2qbS2tk7k5uae/eDD" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
204 |
"Fn594p6SFyxRCjKLUBWF8fBoegTNMVLLm/kwdMyGGON/nePLklv0dl/Cii3gdrtvAzdg8aig" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
205 |
"vb296uDBgwMjIyMCwFvoZXv9NvRnIKqHSckUyQdJrtfexPqm5LGVAuNdVaofcCVywfpexLYD" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
206 |
"CsDOnTvnioqKzGXdzNQMV9tvkJEyUITyeOAjpYyAc9gxYc/GWyK2HYDF4xog6fV6h1i8FwCo" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
207 |
"LK/EncwhkWGxEH9AXLMXM2H1CpQBifI3yeapZ+70d43+cSo4+95yL23g8XiGFUWp3bVrV/Ty" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
208 |
"5ctZnR2ddHZ08uxzz1K9eT1GRhJls1gFlsfieK+WpJ5e/3z7pcuXzmia1rJSs3xlOg8dOvTD" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
209 |
"8fHx7wQCgb4tW7bMm6b55/Pnz+eGw+FFGJDT5iT1XRWlfxHMZ06+/Vz9dCAQeG9kZKR1x44d" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
210 |
"nSdPnkyuZSAArbq6eqOiKAP9/f3xlpaWgra2tlei0eiryWSyKGKa2TcaL+muwcxU5aDf9Gi+" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
211 |
"L0Oh0BehUOiaZVlnAoHAzFr7Ih75bVnVb2pqcvf09Phi0ei6+/rUC6lw1k0p5bSUctThcIwP" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
212 |
"Dw/HnwT4P6CDl+TMvD0JAAAAAElFTkSuQmCC") |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
213 |
|
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
214 |
#---------------------------------------------------------------------- |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
215 |
stopicon = PyEmbeddedImage( |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
216 |
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAABPRJ" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
217 |
"REFUSImdlllsVGUUx3/f/e4sd5iZLjNt6XSFdtgkjWFRePABDaCBGgjamIg81CU0aoxbRHww" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
218 |
"+EDkhWjEB5rYGEMUxQTCJg8EoQ2BbgrFCNJWltplgC63naEzd+bO50NLLVAq4STfwz3nfP/f" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
219 |
"PSf3O98VSikmmQ94HFgDLDdNM1BfX5955swZX0tLi5FKpbSSkpJkaWlpIhQKdVdVVX2XkZFx" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
220 |
"EpBAEGgHLgH/iSqlUEoJpVSBUqpaKXXYNM0r1dXVt6WUajx5ylVYWKi2bdvWY1nWUaXUgQ0b" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
221 |
"NtRWVFQUjmuilEKMV5ALvAhsPHDgQFlNTU2gr69Pk1JSFMphTomfRXO8+A243i/oG9I5f6mX" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
222 |
"K1evAxAOhykrKxs9duyYkZ+f/0lPT8/2OwXogBtYDKzYunVr0c6dO3Ns26akMIcdbxQyv0hy" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
223 |
"rwmh8Bas5/eb89nxRR1NTU20t7cb4x1ZPjlXB2YBiw8ePJhdW1tb4DEMXng6xJtrPQhxn/Y4" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
224 |
"QSM12o89fJnOjst3hXRdLxZCGEqpUQANmBuJRLK3bNmy1OFwUPVMPm9VTiMOqLRNYvg6+shv" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
225 |
"rFoWwutxTcSklGEpZXDiXZRSr6xbt+6dtra2xUW5Lr7c7EUD3Flhwmu/nRKQGO7CvHaCwY7D" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
226 |
"WNEeEmoGe0+PWnuOXHWmrBTl5eW7GxsbNwPoFy5ccHV2di7yzjD4uMqDNtFngZDOKQHurDLc" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
227 |
"WWX4Qk/ScfRVXCLGoorU8J+z5gbjxyWGYbwshPhQKTWi7d+/P9/pdIp5xR5C2Q9uS1fDp3T+" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
228 |
"8jo32uomfJ7cCtzZYQCOjKhYOmgxI+hBSumdOXPmegDt4sWLxU6nk3BIf7A6EB/sIBY5R/+l" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
229 |
"nyd8yrZIRnvZ02tduxVwFQOojBQAfr9/tRBC103TLHe5XMwpSEwLKFj2EWk7gRGYOyaeTtJ4" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
230 |
"pnZk+7UhM5FtlAhAIMYAESd+v78IyNWBYqfTSUF2fFqAJ7firufhRFSdTg36rIDhQ6XHnAI0" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
231 |
"L1iWhWEYASBLl1L+JaWcfSuqk+u3AUikRer4ADffg/w7gt80fs35r34k3BYh2xNAarooAJ4d" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
232 |
"vsHgaP8EWMR17GiaVo8r0+Fw6DrQDDzXO+RgQSjBUFIlPh+wB0vLZD6TrLWrkWRXB29fGAK6" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
233 |
"pql1rNXVmrCklJYGtAgh6DXHDsuuG8k+O9M5895tq+atpSwwZ9o2TjZlWTGl1IAGNEsp1c1E" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
234 |
"DiMqmI7nZRQJ7j/G6xZWMS/vsYcGkEzG4vF4RDt06FBfZmbmwR/27uOD3f1aVk+BljMjD6lp" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
235 |
"/DN07a4VTYw8tL4rrQZgbNixadOm90+dOvX82cZmcbaxmWBukOVrlvJudw1R1xDp8a+kuPM6" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
236 |
"Gx8S4LXtCIwNO1asWDGYl5dn3gneunGLc7/+gTttoAntQRrTmgMmpimAHQwGOycnlBaX4rUz" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
237 |
"8LszMRweXLr7kWB35oMdCAT+1jRt0cqVK6Otra2+hvoGGuobWPLEEsoXzkbPkLhvR4CBRwJY" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
238 |
"Xq/3SGVlZbq7u7utsrJyxDTNz06cOJHZ0tRCS1MLAKuRwNQT9v8AyV27dn1fXl7eqmlae11d" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
239 |
"XXLfvn0/+Xy+l6LR6Gu2befFYjFfzrk2FzeHp7mK7jdxz2/LffGamhpvc3NzyLKsbFd3z1PG" |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
240 |
"aHyBTKdjum0POGzbFAp7qo0xVOtJZdf/C/wRDnL5FYGSAAAAAElFTkSuQmCC") |
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
241 |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
242 |
class ParamsEntryDialog(wx.TextEntryDialog): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
243 |
if wx.VERSION < (2, 6, 0): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
244 |
def Bind(self, event, function, id = None): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
245 |
if id is not None: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
246 |
event(self, id, function) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
247 |
else: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
248 |
event(self, function) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
249 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
250 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
251 |
def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
252 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
253 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
254 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
255 |
self.Tests = [] |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
256 |
if wx.VERSION >= (2, 8, 0): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
257 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
258 |
elif wx.VERSION >= (2, 6, 0): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
259 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
260 |
else: |
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
261 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
262 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
263 |
def OnOK(self, event): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
264 |
value = self.GetValue() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
265 |
texts = {"value" : value} |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
266 |
for function, message in self.Tests: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
267 |
if not function(value): |
361 | 268 |
message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) |
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
269 |
message.ShowModal() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
270 |
message.Destroy() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
271 |
return |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
272 |
self.EndModal(wx.ID_OK) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
273 |
event.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
274 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
275 |
def GetValue(self): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
276 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
277 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
278 |
def SetTests(self, tests): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
279 |
self.Tests = tests |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
280 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
281 |
class BeremizTaskBarIcon(wx.TaskBarIcon): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
282 |
TBMENU_START = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
283 |
TBMENU_STOP = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
284 |
TBMENU_CHANGE_NAME = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
285 |
TBMENU_CHANGE_PORT = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
286 |
TBMENU_CHANGE_INTERFACE = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
287 |
TBMENU_LIVE_SHELL = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
288 |
TBMENU_WXINSPECTOR = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
289 |
TBMENU_CHANGE_WD = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
290 |
TBMENU_QUIT = wx.NewId() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
291 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
292 |
def __init__(self, pyroserver): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
293 |
wx.TaskBarIcon.__init__(self) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
294 |
self.pyroserver = pyroserver |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
295 |
# Set the image |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
296 |
self.UpdateIcon(None) |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
297 |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
298 |
# bind some events |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
299 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
300 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
301 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
302 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
303 |
self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
304 |
self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
305 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
306 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
307 |
self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
308 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
309 |
def CreatePopupMenu(self): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
310 |
""" |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
311 |
This method is called by the base class when it needs to popup |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
312 |
the menu for the default EVT_RIGHT_DOWN event. Just create |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
313 |
the menu how you want it and return it from this function, |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
314 |
the base class takes care of the rest. |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
315 |
""" |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
316 |
menu = wx.Menu() |
361 | 317 |
menu.Append(self.TBMENU_START, _("Start PLC")) |
318 |
menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
|
319 |
menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
|
320 |
menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
|
321 |
menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
|
322 |
menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
|
323 |
menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
324 |
menu.AppendSeparator() |
361 | 325 |
menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
326 |
menu.Append(self.TBMENU_QUIT, _("Quit")) |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
327 |
return menu |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
328 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
329 |
def MakeIcon(self, img): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
330 |
""" |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
331 |
The various platforms have different requirements for the |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
332 |
icon size... |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
333 |
""" |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
334 |
if "wxMSW" in wx.PlatformInfo: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
335 |
img = img.Scale(16, 16) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
336 |
elif "wxGTK" in wx.PlatformInfo: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
337 |
img = img.Scale(22, 22) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
338 |
# wxMac can be any size upto 128x128, so leave the source img alone.... |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
339 |
icon = wx.IconFromBitmap(img.ConvertToBitmap() ) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
340 |
return icon |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
341 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
342 |
def OnTaskBarStartPLC(self, evt): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
343 |
if self.pyroserver.plcobj is not None: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
344 |
self.pyroserver.plcobj.StartPLC() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
345 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
346 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
347 |
def OnTaskBarStopPLC(self, evt): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
348 |
if self.pyroserver.plcobj is not None: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
349 |
self.pyroserver.plcobj.StopPLC() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
350 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
351 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
352 |
def OnTaskBarChangeInterface(self, evt): |
361 | 353 |
dlg = ParamsEntryDialog(None, _("Enter the ip of the interface to bind"), defaultValue=self.pyroserver.ip) |
354 |
dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("Ip is not valid!")), |
|
355 |
( lambda ip :len([x for x in ip.split(".") if 0 <= int(x) <= 255]) == 4, _("Ip is not valid!")) |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
356 |
]) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
357 |
if dlg.ShowModal() == wx.ID_OK: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
358 |
self.pyroserver.ip = dlg.GetValue() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
359 |
self.pyroserver.Stop() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
360 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
361 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
362 |
def OnTaskBarChangePort(self, evt): |
361 | 363 |
dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
364 |
dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
365 |
if dlg.ShowModal() == wx.ID_OK: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
366 |
self.pyroserver.port = int(dlg.GetValue()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
367 |
self.pyroserver.Stop() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
368 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
369 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
370 |
def OnTaskBarChangeWorkingDir(self, evt): |
361 | 371 |
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
372 |
if dlg.ShowModal() == wx.ID_OK: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
373 |
self.pyroserver.workdir = dlg.GetPath() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
374 |
self.pyroserver.Stop() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
375 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
376 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
377 |
def OnTaskBarChangeName(self, evt): |
361 | 378 |
dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=self.pyroserver.name) |
379 |
dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
380 |
if dlg.ShowModal() == wx.ID_OK: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
381 |
self.pyroserver.name = dlg.GetValue() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
382 |
self.pyroserver.Restart() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
383 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
384 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
385 |
def OnTaskBarLiveShell(self, evt): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
386 |
if self.pyroserver.plcobj is not None and self.pyroserver.plcobj.python_threads_vars is not None: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
387 |
from wx import py |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
388 |
#frame = py.shell.ShellFrame(locals=self.pyroserver.plcobj.python_threads_vars) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
389 |
frame = py.crust.CrustFrame(locals=self.pyroserver.plcobj.python_threads_vars) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
390 |
frame.Show() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
391 |
else: |
361 | 392 |
wx.MessageBox(_("No runnning PLC"), _("Error")) |
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
393 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
394 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
395 |
def OnTaskBarWXInspector(self, evt): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
396 |
# Activate the widget inspection tool |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
397 |
from wx.lib.inspection import InspectionTool |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
398 |
if not InspectionTool().initialized: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
399 |
InspectionTool().Init(locals=self.pyroserver.plcobj.python_threads_vars) |
271
ea7928fd07da
add the possibility to enable or disable wxTaskbarIcon for Beremiz_service
greg
parents:
269
diff
changeset
|
400 |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
401 |
# Find a widget to be selected in the tree. Use either the |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
402 |
# one under the cursor, if any, or this frame. |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
403 |
wnd = wx.FindWindowAtPointer() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
404 |
if not wnd: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
405 |
wnd = wx.GetApp() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
406 |
InspectionTool().Show(wnd, True) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
407 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
408 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
409 |
def OnTaskBarQuit(self, evt): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
410 |
self.pyroserver.Quit() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
411 |
self.RemoveIcon() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
412 |
wx.CallAfter(wx.GetApp().Exit) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
413 |
evt.Skip() |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
414 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
415 |
def UpdateIcon(self, plcstatus): |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
416 |
if plcstatus is "Started" : |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
417 |
currenticon = self.MakeIcon(starticon.GetImage()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
418 |
elif plcstatus is "Stopped": |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
419 |
currenticon = self.MakeIcon(stopicon.GetImage()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
420 |
else: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
421 |
currenticon = self.MakeIcon(defaulticon.GetImage()) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
422 |
self.SetIcon(currenticon, "Beremiz Service") |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
423 |
|
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
424 |
from runtime import PLCObject, PLCprint, ServicePublisher |
262 | 425 |
import Pyro.core as pyro |
426 |
||
427 |
if not os.path.isdir(WorkingDir): |
|
428 |
os.mkdir(WorkingDir) |
|
429 |
||
319 | 430 |
def default_evaluator(callable, *args, **kwargs): |
431 |
return callable(*args,**kwargs) |
|
432 |
||
262 | 433 |
class Server(): |
368 | 434 |
def __init__(self, name, ip, port, workdir, argv, autostart=False, statuschange=None, evaluator=default_evaluator, website=None): |
262 | 435 |
self.continueloop = True |
436 |
self.daemon = None |
|
437 |
self.name = name |
|
438 |
self.ip = ip |
|
439 |
self.port = port |
|
440 |
self.workdir = workdir |
|
301 | 441 |
self.argv = argv |
262 | 442 |
self.plcobj = None |
263 | 443 |
self.servicepublisher = None |
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
444 |
self.autostart = autostart |
269
d29c5f71574f
add a TaskBarIcon to configure beremiz_service and display plc states (started, stopped)
greg
parents:
263
diff
changeset
|
445 |
self.statuschange = statuschange |
301 | 446 |
self.evaluator = evaluator |
368 | 447 |
self.website = website |
301 | 448 |
|
449 |
def Loop(self): |
|
262 | 450 |
while self.continueloop: |
451 |
self.Start() |
|
452 |
||
453 |
def Restart(self): |
|
454 |
self.Stop() |
|
455 |
||
456 |
def Quit(self): |
|
457 |
self.continueloop = False |
|
458 |
self.Stop() |
|
459 |
||
460 |
def Start(self): |
|
461 |
pyro.initServer() |
|
462 |
self.daemon=pyro.Daemon(host=self.ip, port=self.port) |
|
368 | 463 |
self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, self.statuschange, self.evaluator, self.website) |
262 | 464 |
uri = self.daemon.connect(self.plcobj,"PLCObject") |
465 |
||
466 |
print "The daemon runs on port :",self.port |
|
467 |
print "The object's uri is :",uri |
|
468 |
print "The working directory :",self.workdir |
|
469 |
||
470 |
# Configure and publish service |
|
471 |
# Not publish service if localhost in address params |
|
472 |
if self.ip != "localhost" and self.ip != "127.0.0.1": |
|
263 | 473 |
print "Publish service on local network" |
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
474 |
self.servicepublisher = ServicePublisher.ServicePublisher() |
262 | 475 |
self.servicepublisher.RegisterService(self.name, self.ip, self.port) |
476 |
||
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
477 |
if self.autostart: |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
478 |
self.plcobj.StartPLC() |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
479 |
|
262 | 480 |
sys.stdout.flush() |
481 |
||
482 |
self.daemon.requestLoop() |
|
483 |
||
484 |
def Stop(self): |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
485 |
self.plcobj.StopPLC() |
263 | 486 |
if self.servicepublisher is not None: |
487 |
self.servicepublisher.UnRegisterService() |
|
488 |
del self.servicepublisher |
|
262 | 489 |
self.daemon.shutdown(True) |
368 | 490 |
|
491 |
if enabletwisted: |
|
492 |
try: |
|
493 |
if havewx: |
|
494 |
from twisted.internet import wxreactor |
|
495 |
wxreactor.install() |
|
496 |
from twisted.internet import reactor, task |
|
497 |
from twisted.python import log, util |
|
498 |
from nevow import rend, appserver, inevow, tags, loaders, athena |
|
499 |
from nevow.page import renderer |
|
500 |
||
501 |
havetwisted = True |
|
502 |
except: |
|
503 |
havetwisted = False |
|
504 |
||
505 |
if havetwisted: |
|
506 |
||
507 |
xhtml_header = '''<?xml version="1.0" encoding="utf-8"?> |
|
508 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
|
509 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
510 |
''' |
|
511 |
||
512 |
||
513 |
class DefaultPLCStartedHMI(athena.LiveElement): |
|
514 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
515 |
tags.h1["PLC IS NOW STARTED"], |
|
516 |
]) |
|
517 |
class PLCStoppedHMI(athena.LiveElement): |
|
518 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
519 |
tags.h1["PLC IS STOPPED"] |
|
520 |
]) |
|
521 |
||
522 |
class MainPage(athena.LiveElement): |
|
523 |
jsClass = u"WebInterface.PLC" |
|
524 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
525 |
tags.div(id='content')[ |
|
526 |
tags.div(render = tags.directive('PLCElement')), |
|
527 |
]]) |
|
528 |
||
529 |
def __init__(self, *a, **kw): |
|
530 |
athena.LiveElement.__init__(self, *a, **kw) |
|
531 |
self.pcl_state = False |
|
532 |
self.HMI = None |
|
533 |
self.resetPLCStartedHMI() |
|
534 |
||
535 |
def setPLCState(self, state): |
|
536 |
self.pcl_state = state |
|
537 |
if self.HMI is not None: |
|
538 |
self.callRemote('updateHMI') |
|
539 |
||
540 |
def setPLCStartedHMI(self, hmi): |
|
541 |
self.PLCStartedHMIClass = hmi |
|
542 |
||
543 |
def resetPLCStartedHMI(self): |
|
544 |
self.PLCStartedHMIClass = DefaultPLCStartedHMI |
|
545 |
||
546 |
def getHMI(self): |
|
547 |
return self.HMI |
|
548 |
||
549 |
def HMIexec(self, function, *args, **kwargs): |
|
550 |
if self.HMI is not None: |
|
551 |
getattr(self.HMI, function, lambda:None)(*args, **kwargs) |
|
369 | 552 |
athena.expose(HMIexec) |
368 | 553 |
|
554 |
def resetHMI(self): |
|
555 |
self.HMI = None |
|
556 |
||
557 |
def PLCElement(self, ctx, data): |
|
558 |
return self.getPLCElement() |
|
559 |
renderer(PLCElement) |
|
560 |
||
561 |
def getPLCElement(self): |
|
562 |
self.detachFragmentChildren() |
|
563 |
if self.pcl_state: |
|
564 |
f = self.PLCStartedHMIClass() |
|
565 |
else: |
|
566 |
f = PLCStoppedHMI() |
|
369 | 567 |
f.setFragmentParent(self) |
368 | 568 |
self.HMI = f |
569 |
return f |
|
570 |
athena.expose(getPLCElement) |
|
571 |
||
572 |
def detachFragmentChildren(self): |
|
573 |
for child in self.liveFragmentChildren[:]: |
|
574 |
child.detach() |
|
575 |
||
576 |
class WebInterface(athena.LivePage): |
|
577 |
||
578 |
docFactory = loaders.stan([tags.raw(xhtml_header), |
|
579 |
tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
|
580 |
tags.head(render=tags.directive('liveglue')), |
|
581 |
tags.body[ |
|
582 |
tags.div[ |
|
583 |
tags.div( render = tags.directive( "MainPage" )) |
|
584 |
]]]]) |
|
585 |
MainPage = MainPage() |
|
586 |
||
587 |
def __init__(self, plcState=False, *a, **kw): |
|
588 |
super(WebInterface, self).__init__(*a, **kw) |
|
589 |
self.jsModules.mapping[u'WebInterface'] = util.sibpath(__file__, 'webinterface.js') |
|
590 |
self.plcState = plcState |
|
591 |
self.MainPage.setPLCState(plcState) |
|
592 |
||
593 |
def getHMI(self): |
|
594 |
return self.MainPage.getHMI() |
|
595 |
||
369 | 596 |
def LoadHMI(self, hmi, jsmodules): |
368 | 597 |
for name, path in jsmodules.iteritems(): |
598 |
self.jsModules.mapping[name] = os.path.join(WorkingDir, path) |
|
369 | 599 |
self.MainPage.setPLCStartedHMI(hmi) |
368 | 600 |
|
601 |
def UnLoadHMI(self): |
|
602 |
self.MainPage.resetPLCStartedHMI() |
|
603 |
||
604 |
def PLCStarted(self): |
|
605 |
self.plcState = True |
|
606 |
self.MainPage.setPLCState(True) |
|
607 |
||
608 |
def PLCStopped(self): |
|
609 |
self.plcState = False |
|
610 |
self.MainPage.setPLCState(False) |
|
611 |
||
612 |
def renderHTTP(self, ctx): |
|
613 |
""" |
|
614 |
Force content type to fit with SVG |
|
615 |
""" |
|
616 |
req = inevow.IRequest(ctx) |
|
617 |
req.setHeader('Content-type', 'application/xhtml+xml') |
|
618 |
return super(WebInterface, self).renderHTTP(ctx) |
|
619 |
||
620 |
def render_MainPage(self, ctx, data): |
|
621 |
f = self.MainPage |
|
622 |
f.setFragmentParent(self) |
|
623 |
return ctx.tag[f] |
|
624 |
||
625 |
def child_(self, ctx): |
|
626 |
self.MainPage.detachFragmentChildren() |
|
627 |
return WebInterface(plcState=self.plcState) |
|
628 |
||
629 |
def beforeRender(self, ctx): |
|
630 |
d = self.notifyOnDisconnect() |
|
631 |
d.addErrback(self.disconnected) |
|
632 |
||
633 |
def disconnected(self, reason): |
|
634 |
self.MainPage.resetHMI() |
|
635 |
#print reason |
|
636 |
#print "We will be called back when the client disconnects" |
|
637 |
||
638 |
if havewx: |
|
639 |
reactor.registerWxApp(app) |
|
640 |
res = WebInterface() |
|
641 |
site = appserver.NevowSite(res) |
|
642 |
reactor.listenTCP(8009, site) |
|
643 |
else: |
|
644 |
res = None |
|
262 | 645 |
|
646 |
if havewx: |
|
301 | 647 |
from threading import Semaphore |
648 |
wx_eval_lock = Semaphore(0) |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
649 |
mythread = currentThread() |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
650 |
|
269
d29c5f71574f
add a TaskBarIcon to configure beremiz_service and display plc states (started, stopped)
greg
parents:
263
diff
changeset
|
651 |
def statuschange(status): |
d29c5f71574f
add a TaskBarIcon to configure beremiz_service and display plc states (started, stopped)
greg
parents:
263
diff
changeset
|
652 |
wx.CallAfter(taskbar_instance.UpdateIcon,status) |
301 | 653 |
|
654 |
eval_res = None |
|
655 |
def wx_evaluator(callable, *args, **kwargs): |
|
656 |
global eval_res |
|
343
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
657 |
try: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
658 |
eval_res=callable(*args,**kwargs) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
659 |
except Exception,e: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
660 |
PLCprint("#EXCEPTION : "+str(e)) |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
661 |
finally: |
fe2d1936b546
Add try/except in wx_evaluator to get and print exception when command failed and unlock in all cases to not block the python thread
greg
parents:
330
diff
changeset
|
662 |
wx_eval_lock.release() |
301 | 663 |
|
664 |
def evaluator(callable, *args, **kwargs): |
|
330
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
665 |
# call directly the callable function if call from the wx mainloop (avoid dead lock) |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
666 |
if(mythread == currentThread()): |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
667 |
callable(*args,**kwargs) |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
668 |
else: |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
669 |
wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
fdf81615ed04
add autostart plc feature for beremiz_service (bug fixed)
greg
parents:
319
diff
changeset
|
670 |
wx_eval_lock.acquire() |
301 | 671 |
return eval_res |
672 |
||
368 | 673 |
pyroserver = Server(name, ip, port, WorkingDir, argv, autostart, statuschange, evaluator, res) |
301 | 674 |
taskbar_instance = BeremizTaskBarIcon(pyroserver) |
675 |
||
676 |
pyro_thread=Thread(target=pyroserver.Loop) |
|
262 | 677 |
pyro_thread.start() |
368 | 678 |
else: |
679 |
pyroserver = Server(name, ip, port, WorkingDir, argv, autostart, website=res) |
|
680 |
||
681 |
if havetwisted: |
|
682 |
reactor.run() |
|
683 |
elif havewx: |
|
262 | 684 |
app.MainLoop() |
685 |
else: |
|
686 |
pyroserver.Loop() |