Beremiz_service.py
author greg
Mon, 27 Oct 2008 07:58:57 +0100
changeset 264 06420c9fb656
parent 263 0bc32427a459
child 269 d29c5f71574f
permissions -rw-r--r--
Update test_master and test_slave examples for linux
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     1
#!/usr/bin/env python
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     2
# -*- coding: utf-8 -*-
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     3
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     6
#
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     8
#
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
     9
#See COPYING file for copyrights details.
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    10
#
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    11
#This library is free software; you can redistribute it and/or
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    12
#modify it under the terms of the GNU General Public
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    13
#License as published by the Free Software Foundation; either
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    15
#
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    16
#This library is distributed in the hope that it will be useful,
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    19
#General Public License for more details.
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    20
#
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    21
#You should have received a copy of the GNU General Public
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    22
#License along with this library; if not, write to the Free Software
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    24
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    25
import os, sys, getopt
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    26
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    27
try:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    28
    import wx, re
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    29
    from wx.lib.embeddedimage import PyEmbeddedImage
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    30
    from threading import Thread
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    31
    from types import *
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    32
    havewx = True
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    33
except:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    34
    havewx = False
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    35
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    36
BeremizIcon = PyEmbeddedImage(
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    37
"iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhkiAAADopJ"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    38
"REFUaIG1mntwXNV9xz/n3rt79+5KWq1WsiRLWlkyfgnHsiwMtnkUYptQMBGFMjRhCDANJmMe"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    39
"pYV/gJZkpoHMJJm2NG1JBzKBQNIUGlLbmMG1MWAZ25LAtmwZW5Yta/WyHtZ7tSvt7r2nf1yt"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    40
"vJJWtmyH386Z3XvuOff+vr/zO7/XWSG4JAlAAzxANlAIFAMBS8oCYF5jY2NhdXV1UWtrq7u9"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    41
"vV1vbW1VY7GYMAxDulwuy+VyxUpLS0MVFRVdGzZsqPFnZTUBLUAr0AUMAGHAAhyAAehAbKI/"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    42
"CsiUzF0CgDrxMD+wAFhiSbkUKN2/f3/Ztm3bCj/66CNXfX39HORgk8PhoKysLL5p06bWxx9/"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    43
"fHtxIFALnAI6gDEgHZg/8X1+AuQgYKZ8oJi9aQKyBJQL+K6U8qdSyg+qq6vb1q9fb05I5Kpa"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    44
"enq6vP/++wf27NnzCwF/IeA2AQ8I+Acp5Y8feuih1wRsFOCcjc/ZmHcKyBdws4BnpJS/PXr0"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    45
"aNM999wTF0JcNePTm2EYcsuWLe2jo6P/LqV8OxwO77333ntbASngOQHpswo6xdo7gRxgKbDO"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    46
"knLt22+/vW7Lli3eUCiUchV1XWfJNYWUzE8jkGtQnGfg0SWmVBmNarR2R2nuGOZ0sJ8zZ4NY"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    47
"lpXyOcuXL5cvvfTSwCuvvJJ+5MgRB8DKlSv/q/7IkV8Be7H3xBSaDsCBre9lwI3RWGztM888"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    48
"c8trr73mkVIipUyaKCi/toQ7bsimaq1Bmm4iLROwIDFOKCAUhFARqgNFMwj2G7y/d5D/23eS"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    49
"YGt7SiDJtGDBghPBlpafA78Fxi8GQAUygcXA2tDo6M1VVVW3V1dXu6WUWJaFZVlIKVlUWsDf"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    50
"PRBg3VKQVhxkaolOexVCURCqjmb40TMX8Yf9Mf7ll/9NR0fnrLNycnK6z/f2/gz4DyAy/b6S"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    51
"9O0BCoAyS8qljz766K0HDx50q6pKonncbp7/60r+54dFrF0cR5rROTIPIJGWBdJCCA2Hnsb3"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    52
"v/stDny2g7zc3FlnjY6Opl+7fHk6tmrPIA17LziALGChJeXCp59+ev2uXbsyVVVFURQsyyI3"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    53
"x8dPNhdTVmgizRmqODcSAqFoqE4Pqp5JU/A8D27eQld396xTwuGw2+l0uoEMYJhp/kAVtupk"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    54
"ACVAme5y3fnGG2+UCyFQFAUhBIH5Pn71XDGFWbHp8y8fg6KhqE4+qevggcd/Sld37yXnBAKB"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    55
"zo6Oji+A3ukMKNhL4wPyjh47ds3rr7++RlVVNE1DVVVystJ59Yn5ZLhmdYaXQRJpjhML91FZ"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    56
"Ms4/PnUTq1cUX3KW1+tdj60hM4ymKsCLrfsL+gcGHgwGg/MSkjcMnZ98fz4Bf8JvTaDWDBzu"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    57
"HFRn+pybUDSs+JhtoawYwopwzXyV+24LcNdtZTh0D83tg4xH4zMAFBYWGoVFRefbWls/BaYM"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    58
"EAKKgGX/u3XrhmefffY50zRFwupsvjuPu1czY6NmltxO4M9evqTkppMZGyU60sFA03b6Gt9D"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    59
"WhZCURGqE1VzExUedtYO8PuPmjh8vG1y3ooVKygpKenZtnXrLUATdsw0uQL5QH5ff/8TQ0ND"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    60
"OQnpF+en8bdVOsiZIYjLtxDvgvWXDUBRnTgMP+mF68hcsIHhtk8xoyNIK440xxBWmCWFGlXr"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    61
"S83himXCOegRfX19ABQVFXl0l8vo7uraTZJDU4UdXV5rGMbDYDsoRVF48tuZ5Gemjp+uFEAy"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    62
"aa5M3NllDJ7ZwWRUIU2kGeWr/pGBwz7LPc+by+J5y1BVFZfLha7r+c3NzR8DPUysggJoTzz5"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    63
"5A2Kokxu3KXF6VSWWlz9pr04eXIrSC+6eVqv5MDwWGgsFmGooIfx2Bh+vx8pJbqu5wPfJMkn"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    64
"aIBobGy8TtM0LMtCCMHNyzVkCtWZC50//juG2/YCoDjceOaVk1F8G3pGIOV4w7+U4dbPJq9H"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    65
"4zJ6Ik3PEUikM47pj6L0XPBhK8rL1x2tr38PO5+wNCBjeHh4maqqCCHQNJW1ixWmbfY50/hw"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    66
"K6GuLyevh9uqGQru4ZpNb6Uc7zD8U67f6ol1Cr+xIHFt5Y1PAZCVlXUtsARoB6IK8A1VVUXC"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    67
"9i8qcJHuujLpz0ZjQy12zJTq3mDz5O/fn4u2ns1yTVkqmRudYv3dbvcCYBF29IDy8COP+JMd"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    68
"V0muQP4pdV8oZC2qQijajFtWfIyh4B4AXu2ItnyZZQQQQkkeI3UL6bpgxoUQaobXOw/bfwlt"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    69
"ZGTEr6oqUkqEEPjT5YVw+Aooa1EVnrxKAFSnB3fON1Cd6TPGSStGR+0/yR0tHZ2fWIoSz76g"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    70
"Nkno7XDZZULkAi6Px5M5PDSUA3Rr4+PjOckb2Jd2ZbqfICN7GUb2souOGeiqN1/d/uOuz8Mt"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    71
"GUqGq2C2cQJQhIJ0WrbTEwIhBG63OwO7wKAoQE4iXNY0jQwjkel9fRQx/Gppxe0Fvkz/zKWZ"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    72
"hkCgIHVJPB7HNE1M08TlcmVg5y5CAULJeyBuJbB/fTTfW8j3rnuMf7vvTUr9iy46VhECxVQm"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    73
"mTdNE2wn5gSEJqXsUBRbvxRFYXRc4WIrYEnk6bAyFLAlMIP2t3zGye7jgO3Vi32lLM8vZ15a"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    74
"3oyx89Ly+PuNr/DYu3+Fac20fAKBoqhEw/YKKIqCoijE4/EwdhqA9uGOHZ13bdo0+UIbQGqq"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    75
"GYz3vCdV520BMr85y5gv2mrY8dX7M/o3r/0b7lvxnRn9Bd4ibiy5lb1nPk4JQBUqsRFbfRJB"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    76
"pmmaISaySQVoS540MKqmZGx7T6z9PaczS7i1lJK/FH341R9nvXdN9pIUvfaGdahOxoaiU1Ro"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    77
"AsAYIDXgdPK0pm59xqPeOhcNNviM4kuV8S5Gq4pumPVemjNtJvsCNEVD9GuMj4xPpraqqkbi"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    78
"8XgEGEkAOIBdm/QBDIZVuoY08ry2Oe2OmKFjma6CuTKf4cogNz3fZgLBgqxSyudXsn7xn886"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    79
"p6GrfkafIhScmk64KYZpmliWxUTA2WbZhaXBBIC4lPJDRVEeTITSp3rSyMscBin5db/VJ7LF"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    80
"pfO+CXpk9Q94ZPUP5jocgPrOL6dc27qvYTjcdJzowjRNhBAJZ3u2o73dBLoBSwH4cMeOPyqK"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    81
"gsfjwe/3c2aoALQMxoUjNpDtKRTYn6+DDgb30Td6fkqfIhRcDhei08Fg19CkDwDMWCzWBIwy"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    82
"kRMkTM5OVVVHdF2npqaGSNxFMFZBt6M45PP4VJfDQFU0hFD+pEC+aDvIy7temNKX2LjpupfT"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    83
"H7VP2bxpaWldIyMjo9iGJwp2PgAQMgzjX/Py8l5sbGykoaGBbdvyuOPOG9wl31pMJD3EQKSf"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    84
"0PgI4/ExFDG7qZ0LtQ+1UhPcx5u1vyRqRpPZR1M00vR0osclnWfOTdp+KaU0DKN2ZGRkDDjJ"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    85
"RLk9eW/mv/DiiyfeeecdbzAYnOxUNZXrb72OVXeuIHOJh/PhXjJ0L6sKr8eUJnIOlbloPMpA"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    86
"pI/+cB9tg0G6R87NGCMQqIpKmp5OjjqfT392kOH+kcnaVFFRUUc0Gn23tqamCXgbCMGFFQAY"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    87
"9vv9v8nLy3sqGYAZNzmwu4YDu2vIL8rjpm+vxXeLn+rmj+kN9TAaDWFa5lWF4AmP63GmMc+d"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    88
"T90vjtHX3Z+QPE6n08rJydl3+PDhEFBPUpE3eQVcwMq7Nm3a88EHHxgXe6GmqZTduISlf1lC"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    89
"xBghGo9eMQAhbIvjcXrIzyjk2K+bOHbgK5Irg+Xl5c1DQ0Nbaw4ePINdpR5MzE9WZgsYzMvL"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    90
"23epl1pSUrSkEHe2a0rJ/bIYR9i2XtXJNHwEvCWc/l0Hh/bWT1qdeDxOIBAYcrlcu2oOHhwA"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    91
"qplQnQQlq5AEIgsXLjwObJztxf4cP1tefoxI3hDB/masOVenLzCOEGiKiksz8Lmz8Ms8dv1k"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    92
"LycbGiclL6WksLAwumzZsh01NTX9wDHsotaUhCUZgAWMvfD8881chAJFATLcGVjqGG6nh7gV"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    93
"J2qOY0kLS14kmxMCRdhWxqnqZLi85KblEzoU4zf/+S7ne89PqoyUEp/PZ95000276+rqOhtP"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    94
"nmwFPseOf6Y/dpIU7DzzZs3heD8Wi6WO6rDD7o13buD676wkkj7CYKSf0HiIaHwcU8ZtIEkS"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    95
"FxOMuxwG6XoGWW4/Yyctdr65h+PHLoTeCZNZUFAQ37hx4ycnTpxo+HzfvhbgfaCTpJJiKgAC"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    96
"SANWFxYV/aGtrS0TQNd16fV6RU9PTwqhClasXEHlrSuZf10O+EzGYhFiVgzTshACVKHi1HQM"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    97
"zc1Y0OT0vha+3HeIlpaWlMJZs2bN+Jo1a3bU1dUF93/+eTuwFbsGlLJUMh2AASwvX7nynSNH"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    98
"jizKzs6Obt68+ZDf74/s3Llzza5du4yLbdrMzExKF5biy/aBkCiKQnQsxrn2Ttra2olEZpwQ"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
    99
"TZLT6eTuu+8+n5ub+2FtbW3Xl198EQR2AkEuUqSaDsAJBNasXfvPXV1dy6uqqurOnDnTE4lE"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   100
"Rj7evTv01NNPV23fvn3V2bNnr84VJ5Gqqtxyyy3hioqKA8FgsKmhoeH8qcbGr4DdQD+zHXCn"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   101
"AAAXTmtWA+6KVauuO3zoUA+wB/vUfNEPf/SjO7q6uu6pr69fVFdX54jHr6yK4fF4qKysjFRW"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   102
"Vh7q7e09cerUqYG62to+oBaoww7YLmmjpwNI/C9Cxz4rrsS2vX3YG0jHzhtueOLJJ9fqur6s"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   103
"tbW14ty5c9nNzc3Ozs7OWSM9VVXJycmRZWVl4dLS0jav13u0vb194OzZs8N1tbUD2GayDlvq"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   104
"cz6ES5WnJLo07BUZ54IkEgfkLuz/MiwFKr738MMlPp8vDfBHIpFcKaXHNE0jGo3idDrDHo+n"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   105
"z+Vy9YRCoUhvb2+ku7s73NPTM9p48mQPdkZ4DHuFL/sQ7kqzxMQ0xwSYTOxzhvyJ5l934406"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   106
"IGKxmBUOh83jDQ1j2JnfAHAOOJvEdPxyGb9aADOeg+1HkhvYADVs5sax1XB6uyr6fzqK/HuW"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   107
"ycvmAAAAAElFTkSuQmCC")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   108
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   109
def usage():
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   110
    print """
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   111
Usage of Beremiz PLC execution service :\n
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   112
%s {[-n name] [-i ip] [-p port]|-h|--help} working_dir
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   113
           -n        - zeroconf service name
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   114
           -i        - ip of interface to bind to (x.x.x.x)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   115
           -p        - port number
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   116
           -h        - print this help text and quit
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   117
           
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   118
           working_dir - directory where are stored PLC files
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   119
"""%sys.argv[0]
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   120
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   121
try:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   122
    opts, args = getopt.getopt(sys.argv[1:], "i:p:n:h")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   123
except getopt.GetoptError, err:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   124
    # print help information and exit:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   125
    print str(err) # will print something like "option -a not recognized"
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   126
    usage()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   127
    sys.exit(2)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   128
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   129
# default values
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   130
ip = ""
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   131
port = 3000
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   132
name = os.environ[{
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   133
     "linux2":"USER",
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   134
     "win32":"USERNAME",
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   135
     }.get(sys.platform, "USER")]
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   136
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   137
for o, a in opts:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   138
    if o == "-h":
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   139
        usage()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   140
        sys.exit()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   141
    elif o == "-i":
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   142
        if len(a.split(".")) == 4 or a == "localhost":
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   143
            ip = a
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   144
    elif o == "-p":
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   145
        # port: port that the service runs on
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   146
        port = int(a)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   147
    elif o == "-n":
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   148
        name = a
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   149
    else:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   150
        usage()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   151
        sys.exit()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   152
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   153
if len(args) > 1:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   154
    usage()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   155
    sys.exit()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   156
elif len(args) == 1:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   157
    WorkingDir = args[0]
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   158
elif len(args) == 0:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   159
    WorkingDir = os.getcwd()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   160
    args=[WorkingDir]
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   161
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   162
from runtime import PLCObject, ServicePublisher
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   163
import Pyro.core as pyro
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   164
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   165
if not os.path.isdir(WorkingDir):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   166
    os.mkdir(WorkingDir)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   167
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   168
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   169
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   170
class Server():
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   171
    def __init__(self, name, ip, port, workdir, args):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   172
        self.continueloop = True
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   173
        self.daemon = None
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   174
        self.name = name
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   175
        self.ip = ip
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   176
        self.port = port
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   177
        self.workdir = workdir
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   178
        self.args = args
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   179
        self.plcobj = None
263
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   180
        self.servicepublisher = None
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   181
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   182
    def Loop(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   183
        while self.continueloop:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   184
            self.Start()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   185
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   186
    def Restart(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   187
        self.Stop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   188
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   189
    def Quit(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   190
        self.continueloop = False
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   191
        self.Stop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   192
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   193
    def Start(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   194
        pyro.initServer()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   195
        self.daemon=pyro.Daemon(host=self.ip, port=self.port)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   196
        self.plcobj = PLCObject(self.workdir, self.daemon, self.args)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   197
        uri = self.daemon.connect(self.plcobj,"PLCObject")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   198
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   199
        print "The daemon runs on port :",self.port
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   200
        print "The object's uri is :",uri
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   201
        print "The working directory :",self.workdir
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   202
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   203
        # Configure and publish service
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   204
        # Not publish service if localhost in address params
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   205
        if self.ip != "localhost" and self.ip != "127.0.0.1":    
263
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   206
            print "Publish service on local network"
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   207
            self.servicepublisher = ServicePublisher.ServicePublisher()            
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   208
            self.servicepublisher.RegisterService(self.name, self.ip, self.port)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   209
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   210
        sys.stdout.flush()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   211
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   212
        self.daemon.requestLoop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   213
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   214
    def Stop(self):
263
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   215
        if self.servicepublisher is not None:
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   216
            self.servicepublisher.UnRegisterService()
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   217
            del self.servicepublisher
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   218
        self.daemon.shutdown(True)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   219
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   220
class ParamsEntryDialog(wx.TextEntryDialog):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   221
    if wx.VERSION < (2, 6, 0):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   222
        def Bind(self, event, function, id = None):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   223
            if id is not None:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   224
                event(self, id, function)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   225
            else:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   226
                event(self, function)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   227
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   228
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   229
    def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", 
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   230
                       style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   231
        wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   232
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   233
        self.Tests = []
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   234
        if wx.VERSION >= (2, 8, 0):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   235
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId())
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   236
        elif wx.VERSION >= (2, 6, 0):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   237
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   238
        else:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   239
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   240
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   241
    def OnOK(self, event):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   242
        value = self.GetValue()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   243
        texts = {"value" : value}
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   244
        for function, message in self.Tests:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   245
            if not function(value):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   246
                message = wx.MessageDialog(self, message%texts, "Error", wx.OK|wx.ICON_ERROR)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   247
                message.ShowModal()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   248
                message.Destroy()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   249
                return
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   250
        self.EndModal(wx.ID_OK)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   251
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   252
    def GetValue(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   253
        return self.GetSizer().GetItem(1).GetWindow().GetValue()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   254
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   255
    def SetTests(self, tests):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   256
        self.Tests = tests
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   257
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   258
class DemoTaskBarIcon(wx.TaskBarIcon):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   259
    TBMENU_CHANGE_NAME = wx.NewId()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   260
    TBMENU_CHANGE_PORT = wx.NewId()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   261
    TBMENU_CHANGE_INTERFACE = wx.NewId()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   262
    TBMENU_CHANGE_WD = wx.NewId()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   263
    TBMENU_QUIT = wx.NewId()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   264
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   265
    def __init__(self, pyroserver):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   266
        wx.TaskBarIcon.__init__(self)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   267
        # Set the image
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   268
        icon = self.MakeIcon(BeremizIcon.GetImage())
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   269
        self.SetIcon(icon, "Beremiz Service")        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   270
        # bind some events
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   271
        #self.Bind(wx.EVT_TASKBAR_CLICK, self.OnClick)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   272
        #self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   273
        self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   274
        self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   275
        self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   276
        self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   277
        self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   278
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   279
    def CreatePopupMenu(self):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   280
        """
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   281
        This method is called by the base class when it needs to popup
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   282
        the menu for the default EVT_RIGHT_DOWN event.  Just create
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   283
        the menu how you want it and return it from this function,
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   284
        the base class takes care of the rest.
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   285
        """
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   286
        menu = wx.Menu()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   287
        menu.Append(self.TBMENU_CHANGE_NAME, "Change Name")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   288
        menu.Append(self.TBMENU_CHANGE_INTERFACE, "Change IP of interface to bind")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   289
        menu.Append(self.TBMENU_CHANGE_PORT, "Change Port Number")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   290
        menu.AppendSeparator()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   291
        menu.Append(self.TBMENU_CHANGE_WD, "Change working directory")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   292
        menu.Append(self.TBMENU_QUIT, "Quit")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   293
        return menu
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   294
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   295
    def MakeIcon(self, img):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   296
        """
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   297
        The various platforms have different requirements for the
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   298
        icon size...
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   299
        """
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   300
        if "wxMSW" in wx.PlatformInfo:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   301
            img = img.Scale(16, 16)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   302
        elif "wxGTK" in wx.PlatformInfo:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   303
            img = img.Scale(22, 22)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   304
        # wxMac can be any size upto 128x128, so leave the source img alone....
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   305
        icon = wx.IconFromBitmap(img.ConvertToBitmap() )
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   306
        return icon
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   307
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   308
    def OnTaskBarChangeInterface(self,evt):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   309
        dlg = ParamsEntryDialog(None, "Enter the ip of the interface to bind", defaultValue=pyroserver.ip)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   310
        dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, "Ip is not valid!"),
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   311
                       ( lambda ip :len([x for x in ip.split(".") if 0 <= int(x) <= 255]) == 4, "Ip is not valid!")
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   312
                       ])
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   313
        if dlg.ShowModal() == wx.ID_OK:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   314
            pyroserver.ip = dlg.GetValue()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   315
            pyroserver.Stop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   316
            
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   317
    def OnTaskBarChangePort(self,evt):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   318
        dlg = ParamsEntryDialog(None, "Enter a port number ", defaultValue=str(pyroserver.port))
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   319
        dlg.SetTests([(UnicodeType.isdigit, "Port number must be an integer!"), (lambda port : 0 <= int(port) <= 65535 , "Port number must be 0 <= port <= 65535!")])
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   320
        if dlg.ShowModal() == wx.ID_OK:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   321
            pyroserver.port = int(dlg.GetValue())
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   322
            pyroserver.Stop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   323
            
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   324
    
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   325
    def OnTaskBarChangeWorkingDir(self,evt):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   326
        dlg = wx.DirDialog(None, "Choose a working directory ", pyroserver.workdir, wx.DD_NEW_DIR_BUTTON)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   327
        if dlg.ShowModal() == wx.ID_OK:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   328
            pyroserver.workdir = dlg.GetPath()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   329
            pyroserver.Stop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   330
            
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   331
    def OnTaskBarChangeName(self,evt):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   332
        dlg = ParamsEntryDialog(None, "Enter a name ", defaultValue=pyroserver.name)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   333
        dlg.SetTests([(lambda name : len(name) is not 0 , "Name must not be null!")])
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   334
        if dlg.ShowModal() == wx.ID_OK:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   335
            pyroserver.name = dlg.GetValue()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   336
            pyroserver.Restart()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   337
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   338
    def OnTaskBarQuit(self,evt):
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   339
        pyroserver.Quit()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   340
        self.RemoveIcon()
263
0bc32427a459 fix bug in beremiz_service with the MainLoop
greg
parents: 262
diff changeset
   341
        wx.GetApp().ExitMainLoop()
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   342
        
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   343
pyroserver = Server(name, ip, port, WorkingDir, args)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   344
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   345
if havewx:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   346
    app=wx.App(redirect=False)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   347
    taskbar_instance = DemoTaskBarIcon(pyroserver)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   348
    pyro_thread=Thread(target=pyroserver.Loop)
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   349
    pyro_thread.start()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   350
    app.MainLoop()
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   351
else:
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 217
diff changeset
   352
    pyroserver.Loop()