author | Edouard Tisserant |
Sat, 01 Sep 2012 16:32:15 +0200 | |
changeset 809 | b86b8898fd52 |
parent 719 | db54ccc96309 |
child 835 | 8145be14a2ae |
permissions | -rwxr-xr-x |
641 | 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 |
|
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
|
30 |
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
641 | 31 |
-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
|
32 |
-i - IP address of interface to bind to (default:localhost) |
641 | 33 |
-p - port number default:3000 |
34 |
-h - print this help text and quit |
|
35 |
-a - autostart PLC (0:disable 1:enable) (default:0) |
|
36 |
-x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) |
|
37 |
-t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) |
|
38 |
||
39 |
working_dir - directory where are stored PLC files |
|
40 |
"""%sys.argv[0] |
|
41 |
||
42 |
try: |
|
43 |
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:h") |
|
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 |
|
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
|
51 |
given_ip = None |
641 | 52 |
port = 3000 |
53 |
servicename = None |
|
54 |
autostart = False |
|
55 |
enablewx = True |
|
56 |
havewx = False |
|
57 |
enabletwisted = True |
|
58 |
havetwisted = False |
|
59 |
||
60 |
for o, a in opts: |
|
61 |
if o == "-h": |
|
62 |
usage() |
|
63 |
sys.exit() |
|
64 |
elif o == "-i": |
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
sys.exit() |
641 | 70 |
elif o == "-p": |
71 |
# port: port that the service runs on |
|
72 |
port = int(a) |
|
73 |
elif o == "-n": |
|
74 |
servicename = a |
|
75 |
elif o == "-x": |
|
76 |
enablewx = int(a) |
|
77 |
elif o == "-t": |
|
78 |
enabletwisted = int(a) |
|
79 |
elif o == "-a": |
|
80 |
autostart = int(a) |
|
81 |
else: |
|
82 |
usage() |
|
83 |
sys.exit() |
|
84 |
||
85 |
if len(argv) > 1: |
|
86 |
usage() |
|
87 |
sys.exit() |
|
88 |
elif len(argv) == 1: |
|
89 |
WorkingDir = argv[0] |
|
90 |
os.chdir(WorkingDir) |
|
91 |
elif len(argv) == 0: |
|
92 |
WorkingDir = os.getcwd() |
|
93 |
argv=[WorkingDir] |
|
94 |
||
95 |
import __builtin__ |
|
96 |
if __name__ == '__main__': |
|
97 |
__builtin__.__dict__['_'] = lambda x: x |
|
98 |
||
99 |
if enablewx: |
|
100 |
try: |
|
101 |
import wx, re |
|
102 |
from threading import Thread, currentThread |
|
103 |
from types import * |
|
104 |
havewx = True |
|
105 |
except: |
|
106 |
print "Wx unavailable !" |
|
107 |
havewx = False |
|
108 |
||
109 |
if havewx: |
|
110 |
app=wx.App(redirect=False) |
|
111 |
||
112 |
# Import module for internationalization |
|
113 |
import gettext |
|
114 |
||
115 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
|
116 |
||
117 |
# Get folder containing translation files |
|
118 |
localedir = os.path.join(CWD,"locale") |
|
119 |
# Get the default language |
|
120 |
langid = wx.LANGUAGE_DEFAULT |
|
121 |
# Define translation domain (name of translation files) |
|
122 |
domain = "Beremiz" |
|
123 |
||
124 |
# Define locale for wx |
|
125 |
loc = __builtin__.__dict__.get('loc', None) |
|
126 |
if loc is None: |
|
127 |
loc = wx.Locale(langid) |
|
128 |
__builtin__.__dict__['loc'] = loc |
|
129 |
# Define location for searching translation files |
|
130 |
loc.AddCatalogLookupPathPrefix(localedir) |
|
131 |
# Define locale domain |
|
132 |
loc.AddCatalog(domain) |
|
133 |
||
134 |
def unicode_translation(message): |
|
135 |
return wx.GetTranslation(message).encode("utf-8") |
|
136 |
||
137 |
if __name__ == '__main__': |
|
138 |
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
139 |
||
140 |
try: |
|
141 |
from wx.lib.embeddedimage import PyEmbeddedImage |
|
142 |
except: |
|
143 |
import cStringIO |
|
144 |
import base64 |
|
145 |
||
146 |
class PyEmbeddedImage: |
|
147 |
def __init__(self, image_string): |
|
148 |
stream = cStringIO.StringIO(base64.b64decode(image_string)) |
|
149 |
self.Image = wx.ImageFromStream(stream) |
|
150 |
def GetImage(self): |
|
151 |
return self.Image |
|
152 |
||
153 |
defaulticon = PyEmbeddedImage( |
|
154 |
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAABc5J" |
|
155 |
"REFUSIl9lW1MW9cZx3/n2vf6BQO2MZiXGBISILCVUEUlitYpjaKpXZJ1XZZ2kzJVY9r6IeLD" |
|
156 |
"pGTaNG3KtGmNNGlbpW3VFhRp0l6aZCllpVUqtVNJtBFKE5QXLxCjpCYEY7DBr9hcm3vPPgQY" |
|
157 |
"IQmPdKR7/vd5/v/n5dxzhZSSNeYBOoGDQGcoFPINDAyUDQ0NOUdGRmyGYSiBQGCpoaGhuGnT" |
|
158 |
"psShQ4f6WltbewEBVAK3gCBgrjJKKZFSKlLKeillt5Ty40gkMnnw4MFFQG60ysrKZHd3dyoe" |
|
159 |
"j//bNM0Le/fuPd/e3r5lmRMpJWK5ghrgFeBIT09P4/Hjx73pdFo47HaaNlfRutnJru0OKsoE" |
|
160 |
"E3GVqaSNa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6b74FgFVR0T4rJTU3jcvlymcymal8Ph+z9vf3p7u6uv5y/vz5bw994ld2fmUH" |
|
174 |
"7nYFRVG4Gb3Guv8FpmmQzCcIJ+5w8c5HRFL3UYRC+ZKX633j6LpObW3tDcMwrsODq4Jbt27V" |
|
175 |
"HT58+N7o6KgCYHfY2f2lXfi+6CJbnsAwjUeyXzFFKLgdHqb+mmL8xh22bduWmJycfHN2dvbX" |
|
176 |
"uVwuoQC0tbXlKisrYytBi/lFZsKzOErtTyQWCOxWO36ljvl/FLk+dJOSkhJTUZR35+fn+3K5" |
|
177 |
"XAIeXNcASz6fbxzwrxDYVQdqpARvs498IYchDUxpogiBVVFxqE7U/5Zx4c8fEo/FKS0tlR0d" |
|
178 |
"HZ8ODg6+l06nr6zwrAp4PJ6Qpmlf2L9/fywYDFaOXB0RI1dHaGpuoq29Fa1Uxe62YeZMInei" |
|
179 |
"jAY/IRqNAtDZ2blUV1fXPzg4+F5VVdU/H6p0eYjqsWPHvnz37t0XwuHw7d27d4eTyeTvLl26" |
|
180 |
"FJiamnpim6qrq9mzZ094fHz875FI5J3p6ekr631WBARgaWlpCezYsePeuXPnzFAo5Dp58uS+" |
|
181 |
"dDp91GKxNBYKBW82m3Vomqa7XK7pbDYbnJmZuR2LxYL5fP79WCyWeeys1h/D9e97enqsp06d" |
|
182 |
"8mWzWU+xWPTkcjmXaZpxwzDCsVhsbqNggP8BMJOU3UUUf+0AAAAASUVORK5CYII=") |
|
183 |
||
184 |
#---------------------------------------------------------------------- |
|
185 |
starticon = PyEmbeddedImage( |
|
186 |
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAABbpJ" |
|
187 |
"REFUSIl9lltsFNcdxn9nZnbHs15fd23j9TXYC0UCKzEhMQ+oIS2g1kQ1pbFStX0opFWsovSh" |
|
188 |
"rUqp2pS2ioTUolaKFOGHqGkiJcKRuDhOaZRiZCsCXyBgCBBfMfbu+oa9s17wzuzl9MH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|
"MDlGnvjVC3+gflNDWiMQKPMalmVh2/a8w+HQFKAHIBR2ABCOS+uN6cTMoFstXmlwZbSba7tv" |
|
203 |
"8hfzT7z+7k+ZnZ0BoK5yR1qjCBV7MoVt29i2PaWqqq0BvUIIQqYORHlrKj6R9BoVj0b04oY9" |
|
204 |
"nEt+yvz3Y5yR/+Xap3XsDb/EtvV1aY1DdTA7HsW2bCKRyLiUclYBelRVldNWAfPSm4oV5ZQJ" |
|
205 |
"Vn/G9Zv2oWt6Ous7e4K81XiC1wNNBO6OIWKgB7Mwp000TYuFw+GxWCw2qbS2tk7k5uae/eDD" |
|
206 |
"Fn594p6SFyxRCjKLUBWF8fBoegTNMVLLm/kwdMyGGON/nePLklv0dl/Cii3gdrtvAzdg8aig" |
|
207 |
"vb296uDBgwMjIyMCwFvoZXv9NvRnIKqHSckUyQdJrtfexPqm5LGVAuNdVaofcCVywfpexLYD" |
|
208 |
"CsDOnTvnioqKzGXdzNQMV9tvkJEyUITyeOAjpYyAc9gxYc/GWyK2HYDF4xog6fV6h1i8FwCo" |
|
209 |
"LK/EncwhkWGxEH9AXLMXM2H1CpQBifI3yeapZ+70d43+cSo4+95yL23g8XiGFUWp3bVrV/Ty" |
|
210 |
"5ctZnR2ddHZ08uxzz1K9eT1GRhJls1gFlsfieK+WpJ5e/3z7pcuXzmia1rJSs3xlOg8dOvTD" |
|
211 |
"8fHx7wQCgb4tW7bMm6b55/Pnz+eGw+FFGJDT5iT1XRWlfxHMZ06+/Vz9dCAQeG9kZKR1x44d" |
|
212 |
"nSdPnkyuZSAArbq6eqOiKAP9/f3xlpaWgra2tlei0eiryWSyKGKa2TcaL+muwcxU5aDf9Gi+" |
|
213 |
"L0Oh0BehUOiaZVlnAoHAzFr7Ih75bVnVb2pqcvf09Phi0ei6+/rUC6lw1k0p5bSUctThcIwP" |
|
214 |
"Dw/HnwT4P6CDl+TMvD0JAAAAAElFTkSuQmCC") |
|
215 |
||
216 |
#---------------------------------------------------------------------- |
|
217 |
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IBY5R/+l" |
|
231 |
"nyd8yrZIRnvZ02tduxVwFQOojBQAfr9/tRBC103TLHe5XMwpSEwLKFj2EWk7gRGYOyaeTtJ4" |
|
232 |
"pnZk+7UhM5FtlAhAIMYAESd+v78IyNWBYqfTSUF2fFqAJ7firufhRFSdTg36rIDhQ6XHnAI0" |
|
233 |
"L1iWhWEYASBLl1L+JaWcfSuqk+u3AUikRer4ADffg/w7gt80fs35r34k3BYh2xNAarooAJ4d" |
|
234 |
"vsHgaP8EWMR17GiaVo8r0+Fw6DrQDDzXO+RgQSjBUFIlPh+wB0vLZD6TrLWrkWRXB29fGAK6" |
|
235 |
"pql1rNXVmrCklJYGtAgh6DXHDsuuG8k+O9M5895tq+atpSwwZ9o2TjZlWTGl1IAGNEsp1c1E" |
|
236 |
"DiMqmI7nZRQJ7j/G6xZWMS/vsYcGkEzG4vF4RDt06FBfZmbmwR/27uOD3f1aVk+BljMjD6lp" |
|
237 |
"/DN07a4VTYw8tL4rrQZgbNixadOm90+dOvX82cZmcbaxmWBukOVrlvJudw1R1xDp8a+kuPM6" |
|
238 |
"Gx8S4LXtCIwNO1asWDGYl5dn3gneunGLc7/+gTttoAntQRrTmgMmpimAHQwGOycnlBaX4rUz" |
|
239 |
"8LszMRweXLr7kWB35oMdCAT+1jRt0cqVK6Otra2+hvoGGuobWPLEEsoXzkbPkLhvR4CBRwJY" |
|
240 |
"Xq/3SGVlZbq7u7utsrJyxDTNz06cOJHZ0tRCS1MLAKuRwNQT9v8AyV27dn1fXl7eqmlae11d" |
|
241 |
"XXLfvn0/+Xy+l6LR6Gu2befFYjFfzrk2FzeHp7mK7jdxz2/LffGamhpvc3NzyLKsbFd3z1PG" |
|
242 |
"aHyBTKdjum0POGzbFAp7qo0xVOtJZdf/C/wRDnL5FYGSAAAAAElFTkSuQmCC") |
|
243 |
||
244 |
class ParamsEntryDialog(wx.TextEntryDialog): |
|
245 |
if wx.VERSION < (2, 6, 0): |
|
246 |
def Bind(self, event, function, id = None): |
|
247 |
if id is not None: |
|
248 |
event(self, id, function) |
|
249 |
else: |
|
250 |
event(self, function) |
|
251 |
||
252 |
||
253 |
def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
|
254 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
255 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
256 |
||
257 |
self.Tests = [] |
|
258 |
if wx.VERSION >= (2, 8, 0): |
|
259 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
|
260 |
elif wx.VERSION >= (2, 6, 0): |
|
261 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
262 |
else: |
|
263 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
264 |
||
265 |
def OnOK(self, event): |
|
266 |
value = self.GetValue() |
|
267 |
texts = {"value" : value} |
|
268 |
for function, message in self.Tests: |
|
269 |
if not function(value): |
|
270 |
message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) |
|
271 |
message.ShowModal() |
|
272 |
message.Destroy() |
|
273 |
return |
|
274 |
self.EndModal(wx.ID_OK) |
|
275 |
event.Skip() |
|
276 |
||
277 |
def GetValue(self): |
|
278 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
279 |
||
280 |
def SetTests(self, tests): |
|
281 |
self.Tests = tests |
|
282 |
||
283 |
class BeremizTaskBarIcon(wx.TaskBarIcon): |
|
284 |
TBMENU_START = wx.NewId() |
|
285 |
TBMENU_STOP = wx.NewId() |
|
286 |
TBMENU_CHANGE_NAME = wx.NewId() |
|
287 |
TBMENU_CHANGE_PORT = wx.NewId() |
|
288 |
TBMENU_CHANGE_INTERFACE = wx.NewId() |
|
289 |
TBMENU_LIVE_SHELL = wx.NewId() |
|
290 |
TBMENU_WXINSPECTOR = wx.NewId() |
|
291 |
TBMENU_CHANGE_WD = wx.NewId() |
|
292 |
TBMENU_QUIT = wx.NewId() |
|
293 |
||
294 |
def __init__(self, pyroserver): |
|
295 |
wx.TaskBarIcon.__init__(self) |
|
296 |
self.pyroserver = pyroserver |
|
297 |
# Set the image |
|
298 |
self.UpdateIcon(None) |
|
299 |
||
300 |
# bind some events |
|
301 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
|
302 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
|
303 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
|
304 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) |
|
305 |
self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) |
|
306 |
self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) |
|
307 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) |
|
308 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) |
|
309 |
self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT) |
|
310 |
||
311 |
def CreatePopupMenu(self): |
|
312 |
""" |
|
313 |
This method is called by the base class when it needs to popup |
|
314 |
the menu for the default EVT_RIGHT_DOWN event. Just create |
|
315 |
the menu how you want it and return it from this function, |
|
316 |
the base class takes care of the rest. |
|
317 |
""" |
|
318 |
menu = wx.Menu() |
|
319 |
menu.Append(self.TBMENU_START, _("Start PLC")) |
|
320 |
menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
|
321 |
menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
|
322 |
menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
|
323 |
menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
|
324 |
menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
|
325 |
menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
|
326 |
menu.AppendSeparator() |
|
327 |
menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
|
328 |
menu.Append(self.TBMENU_QUIT, _("Quit")) |
|
329 |
return menu |
|
330 |
||
331 |
def MakeIcon(self, img): |
|
332 |
""" |
|
333 |
The various platforms have different requirements for the |
|
334 |
icon size... |
|
335 |
""" |
|
336 |
if "wxMSW" in wx.PlatformInfo: |
|
337 |
img = img.Scale(16, 16) |
|
338 |
elif "wxGTK" in wx.PlatformInfo: |
|
339 |
img = img.Scale(22, 22) |
|
340 |
# wxMac can be any size upto 128x128, so leave the source img alone.... |
|
341 |
icon = wx.IconFromBitmap(img.ConvertToBitmap() ) |
|
342 |
return icon |
|
343 |
||
344 |
def OnTaskBarStartPLC(self, evt): |
|
345 |
if self.pyroserver.plcobj is not None: |
|
346 |
self.pyroserver.plcobj.StartPLC() |
|
347 |
evt.Skip() |
|
348 |
||
349 |
def OnTaskBarStopPLC(self, evt): |
|
350 |
if self.pyroserver.plcobj is not None: |
|
351 |
self.pyroserver.plcobj.StopPLC() |
|
352 |
evt.Skip() |
|
353 |
||
354 |
def OnTaskBarChangeInterface(self, evt): |
|
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
|
355 |
dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=self.pyroserver.ip_addr) |
641 | 356 |
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
|
357 |
( lambda x :len([x for x in x.split(".") if 0 <= int(x) <= 255]) == 4, _("IP is not valid!")) |
641 | 358 |
]) |
359 |
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
|
360 |
self.pyroserver.ip_addr = dlg.GetValue() |
641 | 361 |
self.pyroserver.Stop() |
362 |
evt.Skip() |
|
363 |
||
364 |
def OnTaskBarChangePort(self, evt): |
|
365 |
dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
|
366 |
dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) |
|
367 |
if dlg.ShowModal() == wx.ID_OK: |
|
368 |
self.pyroserver.port = int(dlg.GetValue()) |
|
369 |
self.pyroserver.Stop() |
|
370 |
evt.Skip() |
|
371 |
||
372 |
def OnTaskBarChangeWorkingDir(self, evt): |
|
373 |
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
|
374 |
if dlg.ShowModal() == wx.ID_OK: |
|
375 |
self.pyroserver.workdir = dlg.GetPath() |
|
376 |
self.pyroserver.Stop() |
|
377 |
evt.Skip() |
|
378 |
||
379 |
def OnTaskBarChangeName(self, evt): |
|
380 |
dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=self.pyroserver.name) |
|
381 |
dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) |
|
382 |
if dlg.ShowModal() == wx.ID_OK: |
|
383 |
self.pyroserver.name = dlg.GetValue() |
|
384 |
self.pyroserver.Restart() |
|
385 |
evt.Skip() |
|
386 |
||
387 |
def OnTaskBarLiveShell(self, evt): |
|
388 |
if self.pyroserver.plcobj is not None and self.pyroserver.plcobj.python_threads_vars is not None: |
|
389 |
from wx import py |
|
390 |
#frame = py.shell.ShellFrame(locals=self.pyroserver.plcobj.python_threads_vars) |
|
391 |
frame = py.crust.CrustFrame(locals=self.pyroserver.plcobj.python_threads_vars) |
|
392 |
frame.Show() |
|
393 |
else: |
|
394 |
wx.MessageBox(_("No running PLC"), _("Error")) |
|
395 |
evt.Skip() |
|
396 |
||
397 |
def OnTaskBarWXInspector(self, evt): |
|
398 |
# Activate the widget inspection tool |
|
399 |
from wx.lib.inspection import InspectionTool |
|
400 |
if not InspectionTool().initialized: |
|
401 |
InspectionTool().Init(locals=self.pyroserver.plcobj.python_threads_vars) |
|
402 |
||
403 |
# Find a widget to be selected in the tree. Use either the |
|
404 |
# one under the cursor, if any, or this frame. |
|
405 |
wnd = wx.FindWindowAtPointer() |
|
406 |
if not wnd: |
|
407 |
wnd = wx.GetApp() |
|
408 |
InspectionTool().Show(wnd, True) |
|
409 |
evt.Skip() |
|
410 |
||
411 |
def OnTaskBarQuit(self, evt): |
|
412 |
self.pyroserver.Quit() |
|
413 |
self.RemoveIcon() |
|
414 |
wx.CallAfter(wx.GetApp().Exit) |
|
415 |
evt.Skip() |
|
416 |
||
417 |
def UpdateIcon(self, plcstatus): |
|
418 |
if plcstatus is "Started" : |
|
419 |
currenticon = self.MakeIcon(starticon.GetImage()) |
|
420 |
elif plcstatus is "Stopped": |
|
421 |
currenticon = self.MakeIcon(stopicon.GetImage()) |
|
422 |
else: |
|
423 |
currenticon = self.MakeIcon(defaulticon.GetImage()) |
|
424 |
self.SetIcon(currenticon, "Beremiz Service") |
|
425 |
||
426 |
from runtime import PLCObject, PLCprint, ServicePublisher |
|
427 |
import Pyro.core as pyro |
|
428 |
||
429 |
if not os.path.isdir(WorkingDir): |
|
430 |
os.mkdir(WorkingDir) |
|
431 |
||
432 |
def default_evaluator(callable, *args, **kwargs): |
|
433 |
return callable(*args,**kwargs) |
|
434 |
||
435 |
class Server(): |
|
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
|
436 |
def __init__(self, servicename, ip_addr, port, workdir, argv, autostart=False, statuschange=None, evaluator=default_evaluator, website=None): |
641 | 437 |
self.continueloop = True |
438 |
self.daemon = None |
|
439 |
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
|
440 |
self.ip_addr = ip_addr |
641 | 441 |
self.port = port |
442 |
self.workdir = workdir |
|
443 |
self.argv = argv |
|
444 |
self.plcobj = None |
|
445 |
self.servicepublisher = None |
|
446 |
self.autostart = autostart |
|
447 |
self.statuschange = statuschange |
|
448 |
self.evaluator = evaluator |
|
449 |
self.website = website |
|
450 |
||
451 |
def Loop(self): |
|
452 |
while self.continueloop: |
|
453 |
self.Start() |
|
454 |
||
455 |
def Restart(self): |
|
456 |
self.Stop() |
|
457 |
||
458 |
def Quit(self): |
|
459 |
self.continueloop = False |
|
460 |
self.Stop() |
|
461 |
||
462 |
def Start(self): |
|
463 |
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
|
464 |
self.daemon=pyro.Daemon(host=self.ip_addr, port=self.port) |
641 | 465 |
self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, self.statuschange, self.evaluator, self.website) |
466 |
uri = self.daemon.connect(self.plcobj,"PLCObject") |
|
467 |
||
468 |
print "Pyro port :",self.port |
|
469 |
print "Pyro object's uri :",uri |
|
470 |
print "Current working directory :",self.workdir |
|
471 |
||
472 |
# Configure and publish service |
|
473 |
# Not publish service if localhost in address params |
|
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
|
474 |
if (self.servicename is not None and |
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
|
475 |
self.ip_addr is not None and |
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
|
476 |
self.ip_addr != "localhost" and |
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
|
477 |
self.ip_addr != "127.0.0.1"): |
641 | 478 |
print "Publishing service on local network" |
479 |
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
|
480 |
self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) |
641 | 481 |
|
482 |
if self.autostart: |
|
483 |
self.plcobj.StartPLC() |
|
484 |
||
485 |
sys.stdout.flush() |
|
486 |
||
487 |
self.daemon.requestLoop() |
|
488 |
||
489 |
def Stop(self): |
|
490 |
self.plcobj.StopPLC() |
|
491 |
if self.servicepublisher is not None: |
|
492 |
self.servicepublisher.UnRegisterService() |
|
493 |
self.servicepublisher = None |
|
494 |
self.daemon.shutdown(True) |
|
495 |
||
496 |
if enabletwisted: |
|
497 |
import warnings |
|
498 |
with warnings.catch_warnings(): |
|
499 |
warnings.simplefilter("ignore") |
|
500 |
try: |
|
501 |
from threading import Thread, currentThread |
|
502 |
if havewx: |
|
503 |
from twisted.internet import wxreactor |
|
504 |
wxreactor.install() |
|
505 |
from twisted.internet import reactor, task |
|
506 |
from twisted.python import log, util |
|
507 |
from nevow import rend, appserver, inevow, tags, loaders, athena |
|
508 |
from nevow.page import renderer |
|
509 |
||
510 |
havetwisted = True |
|
511 |
except: |
|
512 |
print "Twisted unavailable !" |
|
513 |
havetwisted = False |
|
514 |
||
515 |
if havetwisted: |
|
516 |
||
517 |
xhtml_header = '''<?xml version="1.0" encoding="utf-8"?> |
|
518 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
|
519 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
520 |
''' |
|
521 |
||
522 |
class PLCHMI(athena.LiveElement): |
|
523 |
||
524 |
initialised = False |
|
525 |
||
526 |
def HMIinitialised(self, result): |
|
527 |
self.initialised = True |
|
528 |
||
529 |
def HMIinitialisation(self): |
|
530 |
self.HMIinitialised(None) |
|
531 |
||
532 |
class DefaultPLCStartedHMI(PLCHMI): |
|
533 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
534 |
tags.h1["PLC IS NOW STARTED"], |
|
535 |
]) |
|
536 |
||
537 |
class PLCStoppedHMI(PLCHMI): |
|
538 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
539 |
tags.h1["PLC IS STOPPED"], |
|
540 |
]) |
|
541 |
||
542 |
class MainPage(athena.LiveElement): |
|
543 |
jsClass = u"WebInterface.PLC" |
|
544 |
docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[ |
|
545 |
tags.div(id='content')[ |
|
546 |
tags.div(render = tags.directive('PLCElement')), |
|
547 |
]]) |
|
548 |
||
549 |
def __init__(self, *a, **kw): |
|
550 |
athena.LiveElement.__init__(self, *a, **kw) |
|
551 |
self.pcl_state = False |
|
552 |
self.HMI = None |
|
553 |
self.resetPLCStartedHMI() |
|
554 |
||
555 |
def setPLCState(self, state): |
|
556 |
self.pcl_state = state |
|
557 |
if self.HMI is not None: |
|
558 |
self.callRemote('updateHMI') |
|
559 |
||
560 |
def setPLCStartedHMI(self, hmi): |
|
561 |
self.PLCStartedHMIClass = hmi |
|
562 |
||
563 |
def resetPLCStartedHMI(self): |
|
564 |
self.PLCStartedHMIClass = DefaultPLCStartedHMI |
|
565 |
||
566 |
def getHMI(self): |
|
567 |
return self.HMI |
|
568 |
||
569 |
def HMIexec(self, function, *args, **kwargs): |
|
570 |
if self.HMI is not None: |
|
571 |
getattr(self.HMI, function, lambda:None)(*args, **kwargs) |
|
572 |
athena.expose(HMIexec) |
|
573 |
||
574 |
def resetHMI(self): |
|
575 |
self.HMI = None |
|
576 |
||
577 |
def PLCElement(self, ctx, data): |
|
578 |
return self.getPLCElement() |
|
579 |
renderer(PLCElement) |
|
580 |
||
581 |
def getPLCElement(self): |
|
582 |
self.detachFragmentChildren() |
|
583 |
if self.pcl_state: |
|
584 |
f = self.PLCStartedHMIClass() |
|
585 |
else: |
|
586 |
f = PLCStoppedHMI() |
|
587 |
f.setFragmentParent(self) |
|
588 |
self.HMI = f |
|
589 |
return f |
|
590 |
athena.expose(getPLCElement) |
|
591 |
||
592 |
def detachFragmentChildren(self): |
|
593 |
for child in self.liveFragmentChildren[:]: |
|
594 |
child.detach() |
|
595 |
||
596 |
class WebInterface(athena.LivePage): |
|
597 |
||
598 |
docFactory = loaders.stan([tags.raw(xhtml_header), |
|
599 |
tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
|
600 |
tags.head(render=tags.directive('liveglue')), |
|
601 |
tags.body[ |
|
602 |
tags.div[ |
|
603 |
tags.div( render = tags.directive( "MainPage" )) |
|
604 |
]]]]) |
|
605 |
MainPage = MainPage() |
|
606 |
PLCHMI = PLCHMI |
|
607 |
||
608 |
def __init__(self, plcState=False, *a, **kw): |
|
609 |
super(WebInterface, self).__init__(*a, **kw) |
|
719 | 610 |
self.jsModules.mapping[u'WebInterface'] = util.sibpath(__file__, os.path.join('runtime', 'webinterface.js')) |
641 | 611 |
self.plcState = plcState |
612 |
self.MainPage.setPLCState(plcState) |
|
613 |
||
614 |
def getHMI(self): |
|
615 |
return self.MainPage.getHMI() |
|
616 |
||
617 |
def LoadHMI(self, hmi, jsmodules): |
|
618 |
for name, path in jsmodules.iteritems(): |
|
619 |
self.jsModules.mapping[name] = os.path.join(WorkingDir, path) |
|
620 |
self.MainPage.setPLCStartedHMI(hmi) |
|
621 |
||
622 |
def UnLoadHMI(self): |
|
623 |
self.MainPage.resetPLCStartedHMI() |
|
624 |
||
625 |
def PLCStarted(self): |
|
626 |
self.plcState = True |
|
627 |
self.MainPage.setPLCState(True) |
|
628 |
||
629 |
def PLCStopped(self): |
|
630 |
self.plcState = False |
|
631 |
self.MainPage.setPLCState(False) |
|
632 |
||
633 |
def renderHTTP(self, ctx): |
|
634 |
""" |
|
635 |
Force content type to fit with SVG |
|
636 |
""" |
|
637 |
req = inevow.IRequest(ctx) |
|
638 |
req.setHeader('Content-type', 'application/xhtml+xml') |
|
639 |
return super(WebInterface, self).renderHTTP(ctx) |
|
640 |
||
641 |
def render_MainPage(self, ctx, data): |
|
642 |
f = self.MainPage |
|
643 |
f.setFragmentParent(self) |
|
644 |
return ctx.tag[f] |
|
645 |
||
646 |
def child_(self, ctx): |
|
647 |
self.MainPage.detachFragmentChildren() |
|
648 |
return WebInterface(plcState=self.plcState) |
|
649 |
||
650 |
def beforeRender(self, ctx): |
|
651 |
d = self.notifyOnDisconnect() |
|
652 |
d.addErrback(self.disconnected) |
|
653 |
||
654 |
def disconnected(self, reason): |
|
655 |
self.MainPage.resetHMI() |
|
656 |
#print reason |
|
657 |
#print "We will be called back when the client disconnects" |
|
658 |
||
659 |
if havewx: |
|
660 |
reactor.registerWxApp(app) |
|
661 |
website = WebInterface() |
|
662 |
site = appserver.NevowSite(website) |
|
663 |
||
664 |
website_port = 8009 |
|
665 |
listening = False |
|
666 |
while not listening: |
|
667 |
try: |
|
668 |
reactor.listenTCP(website_port, site) |
|
669 |
listening = True |
|
670 |
except: |
|
671 |
website_port += 1 |
|
672 |
print "Http interface port :",website_port |
|
673 |
else: |
|
674 |
website = None |
|
675 |
||
676 |
if havewx: |
|
677 |
from threading import Semaphore |
|
678 |
wx_eval_lock = Semaphore(0) |
|
679 |
mythread = currentThread() |
|
680 |
||
681 |
def statuschange(status): |
|
682 |
wx.CallAfter(taskbar_instance.UpdateIcon,status) |
|
683 |
||
684 |
eval_res = None |
|
685 |
def wx_evaluator(callable, *args, **kwargs): |
|
686 |
global eval_res |
|
687 |
try: |
|
688 |
eval_res=callable(*args,**kwargs) |
|
689 |
except Exception,e: |
|
690 |
PLCprint("#EXCEPTION : "+str(e)) |
|
691 |
finally: |
|
692 |
wx_eval_lock.release() |
|
693 |
||
694 |
def evaluator(callable, *args, **kwargs): |
|
695 |
# call directly the callable function if call from the wx mainloop (avoid dead lock) |
|
696 |
if(mythread == currentThread()): |
|
697 |
callable(*args,**kwargs) |
|
698 |
else: |
|
699 |
wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
|
700 |
wx_eval_lock.acquire() |
|
701 |
return eval_res |
|
702 |
||
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
|
703 |
pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, statuschange, evaluator, website) |
641 | 704 |
taskbar_instance = BeremizTaskBarIcon(pyroserver) |
705 |
else: |
|
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
|
706 |
pyroserver = Server(servicename, given_ip, port, WorkingDir, argv, autostart, website=website) |
641 | 707 |
|
708 |
if havetwisted or havewx: |
|
709 |
pyro_thread=Thread(target=pyroserver.Loop) |
|
710 |
pyro_thread.start() |
|
711 |
||
712 |
if havetwisted: |
|
713 |
reactor.run() |
|
714 |
elif havewx: |
|
715 |
app.MainLoop() |
|
716 |
else: |
|
717 |
try : |
|
718 |
pyroserver.Loop() |
|
719 |
except KeyboardInterrupt,e: |
|
720 |
pass |
|
721 |
pyroserver.Quit() |
|
722 |
sys.exit(0) |