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