Beremiz.py
author lbessard
Fri, 16 Nov 2007 17:39:36 +0100
changeset 69 6a331a809986
parent 68 bd25fb3d4315
child 71 e0bb49781b80
permissions -rw-r--r--
Bug when close project fixed
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     3
3
6d8728efcdec Adding validity verifications on project folders opened
lbessard
parents: 2
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
6d8728efcdec Adding validity verifications on project folders opened
lbessard
parents: 2
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     6
#
3
6d8728efcdec Adding validity verifications on project folders opened
lbessard
parents: 2
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     8
#
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    10
#
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    15
#
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3
6d8728efcdec Adding validity verifications on project folders opened
lbessard
parents: 2
diff changeset
    19
#General Public License for more details.
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    20
#
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    24
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    25
__version__ = "$Revision$"
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    26
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    27
import wx
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
    28
import wx.lib.buttons
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
    29
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
    30
import types
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    31
48
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    32
import time
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    33
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    34
import os, re, platform, sys, time, traceback, getopt, commands
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
    35
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
    36
from plugger import PluginsRoot
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    37
48
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    38
from wxPopen import wxPopen3
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    39
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    40
class LogPseudoFile:
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    41
    """ Base class for file like objects to facilitate StdOut for the Shell."""
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    42
    def __init__(self, output = None):
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    43
        self.red_white = wx.TextAttr("RED", "WHITE")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    44
        self.red_yellow = wx.TextAttr("RED", "YELLOW")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    45
        self.black_white = wx.TextAttr("BLACK", "WHITE")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    46
        self.default_style = None
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    47
        self.output = output
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    48
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    49
    def writelines(self, l):
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    50
        map(self.write, l)
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    51
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    52
    def write(self, s, style = None):
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    53
        if not style : style=self.black_white
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    54
        if self.default_style != style: 
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    55
            self.output.SetDefaultStyle(style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    56
            self.default_style = style
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    57
        self.output.AppendText(s) 
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    58
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    59
    def write_warning(self, s):
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    60
        self.write(s,self.red_white)
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    61
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
    62
    def write_error(self, s):
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
    63
        self.write(s,self.red_yellow)
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    64
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    65
    def flush(self):
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    66
        self.output.SetValue("")
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    67
    
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    68
    def isatty(self):
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    69
        return false
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
    70
48
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    71
    def LogCommand(self, Command, sz_limit = 100, no_stdout=False):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    72
        self.errlen = 0
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    73
        self.exitcode = None
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    74
        self.outdata = ""
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    75
        self.errdata = ""
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    76
        
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    77
        def output(v):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    78
            self.outdata += v
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    79
            if not no_stdout:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    80
                self.write(v)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    81
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    82
        def errors(v):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    83
            self.errdata += v
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    84
            self.errlen += 1
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    85
            if self.errlen > sz_limit:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    86
                p.kill()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    87
            self.write_warning(v)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    88
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    89
        def fin(pid,ecode):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    90
            self.exitcode = ecode
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    91
            if self.exitcode != 0:
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 48
diff changeset
    92
                self.write(Command + "\n")
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 48
diff changeset
    93
                self.write_warning("exited with status %d (pid %d)\n"%(ecode,pid))
48
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    94
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    95
        def spin(p):
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    96
            while not p.finished:
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    97
                wx.Yield()
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    98
                time.sleep(0.01)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
    99
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
   100
        input = []
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
   101
        p = wxPopen3(Command, input, output, errors, fin, self.output)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
   102
        spin(p)
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
   103
6b30cfee163e Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents: 46
diff changeset
   104
        return (self.exitcode, self.outdata, self.errdata)
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   105
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   106
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   107
 ID_BEREMIZSECONDSPLITTER, ID_BEREMIZLEFTPANEL, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   108
 ID_BEREMIZPARAMSPANEL, ID_BEREMIZLOGCONSOLE, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   109
 ID_BEREMIZPLUGINTREE, ID_BEREMIZPLUGINCHILDS, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   110
 ID_BEREMIZADDBUTTON, ID_BEREMIZDELETEBUTTON,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   111
 ID_BEREMIZPARAMSSTATICBOX, ID_BEREMIZPARAMSENABLE, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   112
 ID_BEREMIZPARAMSTARGETTYPE, ID_BEREMIZPARAMSIECCHANNEL, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   113
 ID_BEREMIZPARAMSSTATICTEXT1, ID_BEREMIZPARAMSSTATICTEXT2, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   114
 ID_BEREMIZPARAMSATTRIBUTESGRID,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   115
] = [wx.NewId() for _init_ctrls in range(17)]
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   116
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   117
[ID_BEREMIZFILEMENUITEMS0, ID_BEREMIZFILEMENUITEMS1, 
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   118
 ID_BEREMIZFILEMENUITEMS2, ID_BEREMIZFILEMENUITEMS3, 
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   119
 ID_BEREMIZFILEMENUITEMS5, ID_BEREMIZFILEMENUITEMS7, 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   120
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)]
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   121
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   122
[ID_BEREMIZEDITMENUITEMS0, ID_BEREMIZEDITMENUITEMS2, 
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   123
 ID_BEREMIZEDITMENUITEMS3, 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   124
] = [wx.NewId() for _init_coll_EditMenu_Items in range(3)]
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   125
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   126
[ID_BEREMIZRUNMENUITEMS0, ID_BEREMIZRUNMENUITEMS2, 
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   127
 ID_BEREMIZRUNMENUITEMS3, ID_BEREMIZRUNMENUITEMS5, 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   128
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)]
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   129
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   130
[ID_BEREMIZHELPMENUITEMS0, ID_BEREMIZHELPMENUITEMS1, 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   131
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)]
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   132
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   133
class Beremiz(wx.Frame):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   134
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   135
    def _init_coll_FileMenu_Items(self, parent):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   136
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS0,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   137
              kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   138
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS1,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   139
              kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   140
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS2,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   141
              kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   142
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS3,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   143
              kind=wx.ITEM_NORMAL, text=u'Close Project')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   144
        parent.AppendSeparator()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   145
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS5,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   146
              kind=wx.ITEM_NORMAL, text=u'Properties')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   147
        parent.AppendSeparator()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   148
        parent.Append(help='', id=ID_BEREMIZFILEMENUITEMS7,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   149
              kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   150
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   151
              id=ID_BEREMIZFILEMENUITEMS0)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   152
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   153
              id=ID_BEREMIZFILEMENUITEMS1)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   154
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   155
              id=ID_BEREMIZFILEMENUITEMS2)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   156
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   157
              id=ID_BEREMIZFILEMENUITEMS3)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   158
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   159
              id=ID_BEREMIZFILEMENUITEMS5)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   160
        self.Bind(wx.EVT_MENU, self.OnQuitMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   161
              id=ID_BEREMIZFILEMENUITEMS7)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   162
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   163
    def _init_coll_EditMenu_Items(self, parent):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   164
        parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS0,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   165
              kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   166
        parent.AppendSeparator()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   167
        parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS2,
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   168
              kind=wx.ITEM_NORMAL, text=u'Add Plugin')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   169
        parent.Append(help='', id=ID_BEREMIZEDITMENUITEMS3,
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   170
              kind=wx.ITEM_NORMAL, text=u'Delete Plugin')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   171
        self.Bind(wx.EVT_MENU, self.OnEditPLCMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   172
              id=ID_BEREMIZEDITMENUITEMS0)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   173
        self.Bind(wx.EVT_MENU, self.OnAddMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   174
              id=ID_BEREMIZEDITMENUITEMS2)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   175
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   176
              id=ID_BEREMIZEDITMENUITEMS3)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   177
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   178
    def _init_coll_RunMenu_Items(self, parent):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   179
        parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS0,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   180
              kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   181
        parent.AppendSeparator()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   182
        parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS2,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   183
              kind=wx.ITEM_NORMAL, text=u'Simulate')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   184
        parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS3,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   185
              kind=wx.ITEM_NORMAL, text=u'Run')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   186
        parent.AppendSeparator()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   187
        parent.Append(help='', id=ID_BEREMIZRUNMENUITEMS5,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   188
              kind=wx.ITEM_NORMAL, text=u'Save Log')
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   189
        self.Bind(wx.EVT_MENU, self.OnBuildMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   190
              id=ID_BEREMIZRUNMENUITEMS0)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   191
        self.Bind(wx.EVT_MENU, self.OnSimulateMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   192
              id=ID_BEREMIZRUNMENUITEMS2)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   193
        self.Bind(wx.EVT_MENU, self.OnRunMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   194
              id=ID_BEREMIZRUNMENUITEMS3)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   195
        self.Bind(wx.EVT_MENU, self.OnSaveLogMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   196
              id=ID_BEREMIZRUNMENUITEMS5)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   197
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   198
    def _init_coll_HelpMenu_Items(self, parent):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   199
        parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS0,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   200
              kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1')
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   201
        parent.Append(help='', id=ID_BEREMIZHELPMENUITEMS1,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   202
              kind=wx.ITEM_NORMAL, text=u'About')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   203
        self.Bind(wx.EVT_MENU, self.OnBeremizMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   204
              id=ID_BEREMIZHELPMENUITEMS0)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   205
        self.Bind(wx.EVT_MENU, self.OnAboutMenu,
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   206
              id=ID_BEREMIZHELPMENUITEMS1)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   207
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   208
    def _init_coll_menuBar1_Menus(self, parent):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   209
        parent.Append(menu=self.FileMenu, title=u'File')
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   210
        #parent.Append(menu=self.EditMenu, title=u'Edit')
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   211
        #parent.Append(menu=self.RunMenu, title=u'Run')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   212
        parent.Append(menu=self.HelpMenu, title=u'Help')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   213
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   214
    def _init_utils(self):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   215
        self.menuBar1 = wx.MenuBar()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   216
        self.FileMenu = wx.Menu(title=u'')
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   217
        #self.EditMenu = wx.Menu(title=u'')
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   218
        #self.RunMenu = wx.Menu(title=u'')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   219
        self.HelpMenu = wx.Menu(title=u'')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   220
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   221
        self._init_coll_menuBar1_Menus(self.menuBar1)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   222
        self._init_coll_FileMenu_Items(self.FileMenu)
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   223
        #self._init_coll_EditMenu_Items(self.EditMenu)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   224
        #self._init_coll_RunMenu_Items(self.RunMenu)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   225
        self._init_coll_HelpMenu_Items(self.HelpMenu)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   226
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   227
    def _init_coll_LeftGridSizer_Items(self, parent):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   228
        parent.AddWindow(self.PluginTree, 0, border=0, flag=wx.GROW)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   229
        parent.AddSizer(self.ButtonGridSizer, 0, border=0, flag=wx.GROW)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   230
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   231
    def _init_coll_LeftGridSizer_Growables(self, parent):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   232
        parent.AddGrowableCol(0)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   233
        parent.AddGrowableRow(0)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   234
    
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   235
    def _init_coll_RightGridSizer_Items(self, parent):
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   236
        parent.AddSizer(self.MenuSizer, 0, border=0, flag=wx.GROW)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   237
        parent.AddWindow(self.SecondSplitter, 0, border=0, flag=wx.GROW)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   238
        
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   239
    def _init_coll_RightGridSizer_Growables(self, parent):
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   240
        parent.AddGrowableCol(0)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   241
        parent.AddGrowableRow(1)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   242
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   243
    def _init_coll_ButtonGridSizer_Items(self, parent):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   244
        parent.AddWindow(self.PluginChilds, 0, border=0, flag=wx.GROW)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   245
        parent.AddWindow(self.AddButton, 0, border=0, flag=0)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   246
        parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   247
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   248
    def _init_coll_ButtonGridSizer_Growables(self, parent):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   249
        parent.AddGrowableCol(0)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   250
        parent.AddGrowableRow(0)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   251
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   252
    def _init_sizers(self):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   253
        self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   254
        self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   255
        self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=2, rows=1, vgap=2)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   256
        self.MenuSizer = wx.BoxSizer(wx.HORIZONTAL)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   257
        self.ParamsPanelMainSizer = wx.BoxSizer(wx.VERTICAL)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   258
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   259
        self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   260
        self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   261
        self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   262
        self._init_coll_RightGridSizer_Items(self.RightGridSizer)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   263
        self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   264
        self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   265
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   266
        self.LeftPanel.SetSizer(self.LeftGridSizer)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   267
        self.RightPanel.SetSizer(self.RightGridSizer)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   268
        self.ParamsPanel.SetSizer(self.ParamsPanelMainSizer)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   269
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   270
    def _init_ctrls(self, prnt):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   271
        wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz',
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   272
              parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600),
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   273
              style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   274
        self._init_utils()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   275
        self.SetClientSize(wx.Size(1000, 600))
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   276
        self.SetMenuBar(self.menuBar1)
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   277
        self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   278
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   279
        self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   280
              name='MainSplitter', parent=self, point=wx.Point(0, 0),
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   281
              size=wx.Size(0, 0), style=wx.SP_3D)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   282
        self.MainSplitter.SetNeedUpdating(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   283
        self.MainSplitter.SetMinimumPaneSize(1)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   284
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   285
        self.LeftPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, 
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   286
              name='LeftPanel', parent=self.MainSplitter, pos=wx.Point(0, 0),
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   287
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   288
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   289
        self.PluginTree = wx.TreeCtrl(id=ID_BEREMIZPLUGINTREE,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   290
              name='PluginTree', parent=self.LeftPanel, pos=wx.Point(0, 0),
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   291
              size=wx.Size(-1, -1), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   292
        self.PluginTree.Bind(wx.EVT_RIGHT_UP, self.OnPluginTreeRightUp)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   293
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnPluginTreeItemSelected,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   294
              id=ID_BEREMIZPLUGINTREE)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   295
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   296
        self.PluginChilds = wx.Choice(id=ID_BEREMIZPLUGINCHILDS,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   297
              name='PluginChilds', parent=self.LeftPanel, pos=wx.Point(0, 0),
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   298
              size=wx.Size(-1, -1), style=0)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   299
        
68
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   300
        if wx.VERSION < (2, 8, 0):
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   301
            self.AddButton = wx.lib.buttons.GenBitmapButton(ID=ID_BEREMIZADDBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Add.png')),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   302
                  name='AddBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   303
                  size=wx.Size(32, 32), style=wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   304
        else:
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   305
            self.AddButton = wx.lib.buttons.GenBitmapButton(id=ID_BEREMIZADDBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Add.png')),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   306
                  name='AddBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   307
                  size=wx.Size(32, 32), style=wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   308
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   309
        self.AddButton.SetToolTipString("Add a plugin of the type selected")
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   310
        self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButton,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   311
              id=ID_BEREMIZADDBUTTON)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   312
        
68
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   313
        if wx.VERSION < (2, 8, 0):
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   314
            self.DeleteButton = wx.lib.buttons.GenBitmapButton(ID=ID_BEREMIZDELETEBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Delete.png')),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   315
                  name='DeleteBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   316
                  size=wx.Size(32, 32), style=wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   317
        else:
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   318
            self.DeleteButton = wx.lib.buttons.GenBitmapButton(id=ID_BEREMIZDELETEBUTTON, bitmap=wx.Bitmap(os.path.join('images', 'Delete.png')),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   319
                  name='DeleteBusButton', parent=self.LeftPanel, pos=wx.Point(0, 0),
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   320
                  size=wx.Size(32, 32), style=wx.NO_BORDER)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   321
        self.DeleteButton.SetToolTipString("Delete the current selected plugin")
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   322
        self.DeleteButton.Bind(wx.EVT_BUTTON, self.OnDeleteButton,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   323
              id=ID_BEREMIZDELETEBUTTON)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   324
        
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   325
        self.RightPanel = wx.Panel(id=ID_BEREMIZLEFTPANEL, 
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   326
              name='RightPanel', parent=self.MainSplitter, pos=wx.Point(0, 0),
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   327
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   328
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   329
        self.SecondSplitter = wx.SplitterWindow(id=ID_BEREMIZSECONDSPLITTER,
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   330
              name='SecondSplitter', parent=self.RightPanel, point=wx.Point(0, 0),
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   331
              size=wx.Size(0, 0), style=wx.SP_3D)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   332
        self.SecondSplitter.SetNeedUpdating(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   333
        self.SecondSplitter.SetMinimumPaneSize(1)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   334
        
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   335
        self.MainSplitter.SplitVertically(self.LeftPanel, self.RightPanel,
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   336
              300)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   337
        
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   338
        self.ParamsPanel = wx.ScrolledWindow(id=ID_BEREMIZPARAMSPANEL, 
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   339
              name='ParamsPanel', parent=self.SecondSplitter, pos=wx.Point(0, 0),
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   340
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   341
        self.ParamsPanel.SetScrollbars(10, 10, 0, 0, 0, 0)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   342
        
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   343
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   344
              name='LogConsole', parent=self.SecondSplitter, pos=wx.Point(0, 0),
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   345
              size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   346
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   347
        self.SecondSplitter.SplitHorizontally(self.ParamsPanel, self.LogConsole,
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   348
              -250)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   349
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   350
        self._init_sizers()
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   351
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   352
    def __init__(self, parent, projectOpen):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   353
        self._init_ctrls(parent)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   354
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   355
        self.Log = LogPseudoFile(self.LogConsole)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   356
        
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   357
        self.PluginRoot = PluginsRoot(self)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   358
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   359
        if projectOpen:
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   360
            self.PluginRoot.LoadProject(projectOpen, self.Log)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   361
            self.RefreshPluginTree()
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 48
diff changeset
   362
            self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   363
        
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   364
        self.RefreshPluginParams()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   365
        self.RefreshButtons()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   366
        self.RefreshMainMenu()
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   367
    
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   368
    def OnFrameActivated(self, event):
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   369
        if not event.GetActive():
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   370
            self.PluginRoot.RefreshPluginsBlockLists()
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   371
    
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   372
    def RefreshButtons(self):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   373
        if self.PluginRoot.HasProjectOpened():
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   374
            self.PluginChilds.Enable(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   375
            self.AddButton.Enable(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   376
            self.DeleteButton.Enable(True)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   377
        else:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   378
            self.PluginChilds.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   379
            self.AddButton.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   380
            self.DeleteButton.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   381
        
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   382
    def RefreshMainMenu(self):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   383
        if self.menuBar1:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   384
            if self.PluginRoot.HasProjectOpened():
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 36
diff changeset
   385
##                self.menuBar1.EnableTop(1, True)
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 36
diff changeset
   386
##                self.menuBar1.EnableTop(2, True)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   387
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   388
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   389
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   390
            else:
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 36
diff changeset
   391
##                self.menuBar1.EnableTop(1, False)
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 36
diff changeset
   392
##                self.menuBar1.EnableTop(2, False)
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   393
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS2, False)
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   394
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS3, False)
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   395
                self.FileMenu.Enable(ID_BEREMIZFILEMENUITEMS5, False)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   396
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   397
    def RefreshPluginTree(self):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   398
        infos = self.PluginRoot.GetPlugInfos()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   399
        root = self.PluginTree.GetRootItem()
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   400
        if not root.IsOk():
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   401
            root = self.PluginTree.AddRoot(infos["name"])
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   402
        last_selected = self.GetSelectedPluginName()
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   403
        self.GenerateTreeBranch(root, infos, True)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   404
        self.PluginTree.Expand(self.PluginTree.GetRootItem())
46
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   405
        self.SelectedPluginByName(root, last_selected)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   406
        self.RefreshPluginParams()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   407
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   408
    def SelectedPluginByName(self, root, name):
46
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   409
        if name:
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   410
            toks = name.split('.',1)
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   411
            item, root_cookie = self.PluginTree.GetFirstChild(root)
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   412
            while item.IsOk():
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   413
                if self.PluginTree.GetPyData(item) == toks[0]:
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   414
                    if len(toks)>1:
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   415
                        return self.SelectedPluginByName(item, toks[1])
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   416
                    else:
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   417
                        self.PluginTree.SelectItem(item, True)
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   418
                        return True
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   419
                item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   420
        return False
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   421
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   422
    def GenerateTreeBranch(self, root, infos, first = False):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   423
        to_delete = []
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   424
        self.PluginTree.SetItemText(root, infos["name"])
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   425
        self.PluginTree.SetPyData(root, infos["type"])
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   426
        item, root_cookie = self.PluginTree.GetFirstChild(root)
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   427
        for values in infos["values"]:
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   428
            if not item.IsOk():
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   429
                item = self.PluginTree.AppendItem(root, "")
60
e9667bec7f00 Test on wx version changed to test on platform
lbessard
parents: 50
diff changeset
   430
                if wx.Platform != '__WXMSW__':
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   431
                    item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   432
            self.GenerateTreeBranch(item, values)
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   433
            item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   434
        while item.IsOk():
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   435
            to_delete.append(item)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   436
            item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   437
        for item in to_delete:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   438
            self.PluginTree.Delete(item)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   439
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   440
    def GetSelectedPluginName(self):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   441
        selected = self.PluginTree.GetSelection()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   442
        if not selected.IsOk():
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   443
            return None
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   444
        if selected == self.PluginTree.GetRootItem():
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   445
            return ""
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   446
        else:
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   447
            name = self.PluginTree.GetPyData(selected)
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   448
            item = self.PluginTree.GetItemParent(selected)
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   449
            while item.IsOk() and item != self.PluginTree.GetRootItem():
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   450
                name = "%s.%s"%(self.PluginTree.GetPyData(item), name)
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   451
                item = self.PluginTree.GetItemParent(item)
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   452
            return name
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   453
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   454
    def GetSelectedPlugin(self):
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   455
        name = self.GetSelectedPluginName()
36
42e391e7c455 Fixed invisible root node
etisserant
parents: 33
diff changeset
   456
        if name is None:
33
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   457
            return None
59b84ab7bf8b Enhanced bahavior of plugin tree representation when changing IEC channel
etisserant
parents: 28
diff changeset
   458
        elif name == "":
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   459
            return self.PluginRoot
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   460
        else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   461
            return self.PluginRoot.GetChildByName(name)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   462
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   463
    def OnPluginTreeItemSelected(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   464
        wx.CallAfter(self.RefreshPluginParams)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   465
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   466
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   467
    def _GetAddPluginFunction(self, name):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   468
        def OnPluginMenu(event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   469
            self.AddPlugin(name)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   470
            event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   471
        return OnPluginMenu
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   472
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   473
    def OnPluginTreeRightUp(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   474
        plugin = self.GetSelectedPlugin()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   475
        if plugin:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   476
            main_menu = wx.Menu(title='')
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   477
            if len(plugin.PlugChildsTypes) > 0:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   478
                plugin_menu = wx.Menu(title='')
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   479
                for name, XSDClass in self.GetSelectedPlugin().PlugChildsTypes:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   480
                    new_id = wx.NewId()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   481
                    plugin_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=name)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   482
                    self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name), id=new_id)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   483
                main_menu.AppendMenu(-1, "Add", plugin_menu, '')
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   484
            new_id = wx.NewId()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   485
            main_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete")
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   486
            self.Bind(wx.EVT_MENU, self.OnDeleteButton, id=new_id)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   487
            rect = self.PluginTree.GetBoundingRect(self.PluginTree.GetSelection())
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   488
            self.PluginTree.PopupMenuXY(main_menu, rect.x + rect.width, rect.y)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   489
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   490
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   491
    def RefreshPluginParams(self):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   492
        plugin = self.GetSelectedPlugin()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   493
        if not plugin:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   494
            # Refresh ParamsPanel
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   495
            self.ParamsPanel.Hide()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   496
            
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   497
            # Refresh PluginChilds
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   498
            self.PluginChilds.Clear()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   499
            self.PluginChilds.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   500
            self.AddButton.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   501
            self.DeleteButton.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   502
        else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   503
            # Refresh ParamsPanel
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   504
            self.ParamsPanel.Show()
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   505
            infos = plugin.GetParamsAttributes()
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   506
            if wx.VERSION >= (2, 7, 0):
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   507
                self.MenuSizer.Clear(True)
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   508
                self.ParamsPanelMainSizer.Clear(True)
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   509
            else:
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   510
                self.ClearSizer(self.MenuSizer)
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   511
                self.ClearSizer(self.ParamsPanelMainSizer)
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   512
            if len(self.PluginRoot.PluginMethods) > 0:
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   513
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   514
                self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   515
                for plugin_infos in self.PluginRoot.PluginMethods:
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   516
                    if "method" in plugin_infos:
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   517
                        id = wx.NewId()
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   518
                        if "bitmap" in plugin_infos:
68
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   519
                            if wx.VERSION < (2, 8, 0):
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   520
                                button = wx.lib.buttons.GenBitmapTextButton(ID=id, parent=self.RightPanel,
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   521
                                    bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"],
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   522
                                    name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   523
                            else:
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   524
                                button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=self.RightPanel,
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   525
                                    bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"],
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   526
                                    name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   527
                            
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   528
                        else:
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   529
                            button = wx.Button(id=id, label=plugin_infos["name"], 
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   530
                                name=plugin_infos["name"], parent=self.RightPanel, 
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   531
                                pos=wx.Point(0, 0), style=wx.BU_EXACTFIT)
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   532
                        button.SetToolTipString(plugin_infos["tooltip"])
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   533
                        button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(self.PluginRoot, plugin_infos["method"]), id=id)
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   534
                        boxsizer.AddWindow(button, 0, border=5, flag=wx.GROW|wx.RIGHT)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   535
                self.RightGridSizer.Layout()
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   536
            self.RefreshSizerElement(self.ParamsPanelMainSizer, infos, None, False)
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   537
            if plugin != self.PluginRoot and len(plugin.PluginMethods) > 0:
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   538
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   539
                self.MenuSizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   540
                for plugin_infos in plugin.PluginMethods:
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   541
                    if "method" in plugin_infos:
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   542
                        id = wx.NewId()
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   543
                        if "bitmap" in plugin_infos:
68
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   544
                            if wx.VERSION < (2, 8, 0):
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   545
                                button = wx.lib.buttons.GenBitmapTextButton(ID=id, parent=self.RightPanel, 
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   546
                                    bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], 
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   547
                                    name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   548
                            else:
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   549
                                button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=self.RightPanel, 
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   550
                                    bitmap=wx.Bitmap(plugin_infos["bitmap"]), label=plugin_infos["name"], 
bd25fb3d4315 Bug with wx 2.8 fixed
lbessard
parents: 67
diff changeset
   551
                                    name=plugin_infos["name"], pos=wx.Point(0, 0), style=wx.BU_EXACTFIT|wx.NO_BORDER)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   552
                        else:
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   553
                            button = wx.Button(id=id, label=plugin_infos["name"], 
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   554
                                name=plugin_infos["name"], parent=self.RightPanel, 
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   555
                                pos=wx.Point(0, 0), style=wx.BU_EXACTFIT)
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   556
                        button.SetToolTipString(plugin_infos["tooltip"])
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   557
                        button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_infos["method"]), id=id)
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   558
                        boxsizer.AddWindow(button, 0, border=5, flag=wx.GROW|wx.RIGHT)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   559
                self.RightGridSizer.Layout()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   560
            self.ParamsPanelMainSizer.Layout()
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   561
            self.ParamsPanel.SetClientSize(self.ParamsPanel.GetClientSize())
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   562
            
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   563
            # Refresh PluginChilds
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   564
            self.PluginChilds.Clear()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   565
            if len(plugin.PlugChildsTypes) > 0:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   566
                self.PluginChilds.Append("")
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   567
                for name, XSDClass in plugin.PlugChildsTypes:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   568
                    self.PluginChilds.Append(name)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   569
                self.PluginChilds.Enable(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   570
                self.AddButton.Enable(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   571
            else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   572
                self.PluginChilds.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   573
                self.AddButton.Enable(False)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   574
            self.DeleteButton.Enable(True)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   575
    
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   576
    def GetButtonCallBackFunction(self, plugin, method):
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   577
        def OnButtonClick(event):
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   578
            method(plugin, self.Log)
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   579
            event.Skip()
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   580
        return OnButtonClick
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   581
    
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   582
    def GetChoiceCallBackFunction(self, choicectrl, path):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   583
        def OnChoiceChanged(event):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   584
            plugin = self.GetSelectedPlugin()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   585
            if plugin:
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   586
                res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   587
                if StructChanged: wx.CallAfter(self.RefreshPluginTree)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   588
                choicectrl.SetStringSelection(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   589
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   590
        return OnChoiceChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   591
    
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   592
    def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   593
        def OnChoiceContentChanged(event):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   594
            plugin = self.GetSelectedPlugin()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   595
            if plugin:
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   596
                res, StructChanged = plugin.SetParamsAttribute(path, choicectrl.GetStringSelection(), self.Log)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   597
                if StructChanged: wx.CallAfter(self.RefreshPluginTree)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   598
                choicectrl.SetStringSelection(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   599
                infos = self.PluginRoot.GetParamsAttributes(path)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   600
                staticbox = staticboxsizer.GetStaticBox()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   601
                staticbox.SetLabel("%(name)s - %(value)s"%infos)
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   602
                self.ParamsPanel.Freeze()
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   603
                self.RefreshSizerElement(staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]))
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   604
                self.ParamsPanelMainSizer.Layout()
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   605
                self.ParamsPanel.Thaw()
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   606
                self.ParamsPanel.Refresh()
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   607
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   608
        return OnChoiceContentChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   609
    
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   610
    def GetTextCtrlCallBackFunction(self, textctrl, path):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   611
        def OnTextCtrlChanged(event):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   612
            plugin = self.GetSelectedPlugin()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   613
            if plugin:
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   614
                res, StructChanged = plugin.SetParamsAttribute(path, textctrl.GetValue(), self.Log)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   615
                if StructChanged: wx.CallAfter(self.RefreshPluginTree)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   616
                textctrl.SetValue(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   617
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   618
        return OnTextCtrlChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   619
    
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   620
    def GetCheckBoxCallBackFunction(self, chkbx, path):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   621
        def OnCheckBoxChanged(event):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   622
            plugin = self.GetSelectedPlugin()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   623
            if plugin:
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   624
                res, StructChanged = plugin.SetParamsAttribute(path, chkbx.IsChecked(), self.Log)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   625
                if StructChanged: wx.CallAfter(self.RefreshPluginTree)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   626
                chkbx.SetValue(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   627
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   628
        return OnCheckBoxChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   629
    
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   630
    def ClearSizer(self, sizer):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   631
        staticboxes = []
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   632
        for item in sizer.GetChildren():
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   633
            if item.IsSizer():
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   634
                item_sizer = item.GetSizer()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   635
                self.ClearSizer(item_sizer)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   636
                if isinstance(item_sizer, wx.StaticBoxSizer):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   637
                    staticboxes.append(item_sizer.GetStaticBox())
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   638
        sizer.Clear(True)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   639
        for staticbox in staticboxes:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   640
            staticbox.Destroy()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   641
                
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   642
    def RefreshSizerElement(self, sizer, elements, path, clean = True):
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   643
        if clean:
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   644
            sizer.Clear(True)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   645
        first = True
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   646
        for element_infos in elements:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   647
            if path:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   648
                element_path = "%s.%s"%(path, element_infos["name"])
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   649
            else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   650
                element_path = element_infos["name"]
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   651
            if isinstance(element_infos["type"], types.ListType):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   652
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   653
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   654
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   655
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   656
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   657
                bitmappath = os.path.join("images", "%s.png"%element_infos["name"])
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   658
                if os.path.isfile(bitmappath):
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   659
                    staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath),
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   660
                        name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel,
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   661
                        pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   662
                    boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   663
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   664
                    name="%s_label"%element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   665
                    pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   666
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   667
                id = wx.NewId()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   668
                choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   669
                    pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   670
                boxsizer.AddWindow(choicectrl, 0, border=0, flag=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   671
                choicectrl.Append("")
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   672
                if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   673
                    for choice, xsdclass in element_infos["type"]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   674
                        choicectrl.Append(choice)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   675
                    staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   676
                        name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel,
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   677
                        pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   678
                    staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   679
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   680
                    self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   681
                    callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, element_path)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   682
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   683
                    for choice in element_infos["type"]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   684
                        choicectrl.Append(choice)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   685
                    callback = self.GetChoiceCallBackFunction(choicectrl, element_path)
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   686
                if element_infos["value"]:
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   687
                    choicectrl.SetStringSelection(element_infos["value"])
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   688
                choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   689
            elif isinstance(element_infos["type"], types.DictType):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   690
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   691
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   692
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   693
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   694
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   695
                bitmappath = os.path.join("images", "%s.png"%element_infos["name"])
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   696
                if os.path.isfile(bitmappath):
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   697
                    staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath),
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   698
                        name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel,
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   699
                        pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   700
                    boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   701
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   702
                    name="%s_label"%element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   703
                    pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   704
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   705
                id = wx.NewId()
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   706
                scmin = -(2**31)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   707
                scmax = 2**31-1
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   708
                if "min" in element_infos["type"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   709
                    scmin = element_infos["type"]["min"]
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   710
                if "max" in element_infos["type"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   711
                    scmax = element_infos["type"]["max"]
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   712
                spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   713
                    pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   714
                spinctrl.SetRange(scmin,scmax)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   715
                boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   716
                spinctrl.SetValue(element_infos["value"])
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   717
                spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   718
            elif element_infos["type"] == "element":
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   719
                staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   720
                    name='%s_staticbox'%element_infos["name"], parent=self.ParamsPanel,
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   721
                    pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   722
                staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   723
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   724
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   725
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   726
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   727
                self.RefreshSizerElement(staticboxsizer, element_infos["children"], element_path)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   728
            else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   729
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   730
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   731
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   732
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   733
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   734
                bitmappath = os.path.join("images", "%s.png"%element_infos["name"])
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   735
                if os.path.isfile(bitmappath):
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   736
                    staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath),
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   737
                        name="%s_bitmap"%element_infos["name"], parent=self.ParamsPanel,
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   738
                        pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 62
diff changeset
   739
                    boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   740
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   741
                    name="%s_label"%element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   742
                    pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   743
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   744
                id = wx.NewId()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   745
                if element_infos["type"] == "boolean":
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   746
                    checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   747
                        pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   748
                    boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   749
                    checkbox.SetValue(element_infos["value"])
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   750
                    checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   751
                elif element_infos["type"] in ["unsignedLong", "long","integer"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   752
                    if element_infos["type"].startswith("unsigned"):
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   753
                        scmin = 0
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   754
                    else:
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   755
                        scmin = -(2**31)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   756
                    scmax = 2**31-1
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   757
                    spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   758
                        pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   759
                    spinctrl.SetRange(scmin, scmax)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   760
                    boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   761
                    spinctrl.SetValue(element_infos["value"])
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   762
                    spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   763
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   764
                    textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   765
                        pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.TE_PROCESS_ENTER)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   766
                    boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   767
                    textctrl.SetValue(str(element_infos["value"]))
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   768
                    textctrl.Bind(wx.EVT_TEXT_ENTER, self.GetTextCtrlCallBackFunction(textctrl, element_path), id=id)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   769
                    textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, element_path))
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   770
            first = False
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   771
    
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   772
    def OnNewProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   773
        defaultpath = self.PluginRoot.GetProjectPath()
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   774
        if not defaultpath:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   775
            defaultpath = os.getcwd()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   776
        dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   777
        if dialog.ShowModal() == wx.ID_OK:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   778
            projectpath = dialog.GetPath()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   779
            dialog.Destroy()
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   780
            res = self.PluginRoot.NewProject(projectpath)
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   781
            if not res :
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   782
                self.RefreshPluginTree()
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   783
                self.RefreshButtons()
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   784
                self.RefreshMainMenu()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   785
            else:
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   786
                message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   787
                message.ShowModal()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   788
                message.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   789
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   790
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   791
    def OnOpenProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   792
        defaultpath = self.PluginRoot.GetProjectPath()
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   793
        if not defaultpath:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   794
            defaultpath = os.getcwd()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   795
        dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   796
        if dialog.ShowModal() == wx.ID_OK:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   797
            projectpath = dialog.GetPath()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   798
            if os.path.isdir(projectpath):
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   799
                result = self.PluginRoot.LoadProject(projectpath, self.Log)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   800
                if not result:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   801
                    self.RefreshPluginTree()
46
6f2689a2438b Corrections for Windows
lbessard
parents: 42
diff changeset
   802
                    self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   803
                    self.RefreshButtons()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   804
                    self.RefreshMainMenu()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   805
                else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   806
                    message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   807
                    message.ShowModal()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   808
                    message.Destroy()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   809
            else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   810
                message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n"%projectpath, "Error", wx.OK|wx.ICON_ERROR)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   811
                message.ShowModal()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   812
                message.Destroy()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   813
            dialog.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   814
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   815
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   816
    def OnCloseProjectMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   817
        self.PLCManager = None
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   818
        self.RefreshButtons()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   819
        self.RefreshMainMenu()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   820
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   821
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   822
    def OnSaveProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   823
        if self.PluginRoot.HasProjectOpened():
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   824
            self.PluginRoot.SaveProject()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   825
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   826
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   827
    def OnPropertiesMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   828
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   829
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   830
    def OnQuitMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   831
        self.Close()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   832
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   833
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   834
    def OnEditPLCMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   835
        self.EditPLC()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   836
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   837
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   838
    def OnAddMenu(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   839
        self.AddPlugin()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   840
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   841
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   842
    def OnDeleteMenu(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   843
        self.DeletePlugin()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   844
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   845
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   846
    def OnBuildMenu(self, event):
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   847
        #self.BuildAutom()
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   848
        event.Skip()
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   849
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   850
    def OnSimulateMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   851
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   852
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   853
    def OnRunMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   854
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   855
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   856
    def OnSaveLogMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   857
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   858
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   859
    def OnBeremizMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   860
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   861
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   862
    def OnAboutMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   863
        event.Skip()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   864
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   865
    def OnAddButton(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   866
        PluginType = self.PluginChilds.GetStringSelection()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   867
        if PluginType != "":
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   868
            self.AddPlugin(PluginType)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   869
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   870
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   871
    def OnDeleteButton(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   872
        self.DeletePlugin()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   873
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   874
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   875
    def CloseEditor(self, bus_id):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   876
        if self.BusManagers.get(bus_id, None) != None:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   877
            self.BusManagers[bus_id]["Editor"] = None
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   878
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   879
    def AddPlugin(self, PluginType):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   880
        dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL)
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   881
        if dialog.ShowModal() == wx.ID_OK:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   882
            PluginName = dialog.GetValue()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   883
            plugin = self.GetSelectedPlugin()
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   884
            plugin.PlugAddChild(PluginName, PluginType, self.Log)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   885
            self.RefreshPluginTree()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   886
        dialog.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   887
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   888
    def DeletePlugin(self):
50
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   889
        dialog = wx.MessageDialog(self,"Really delete plugin ?", "Remove plugin",wx.YES_NO|wx.NO_DEFAULT)
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   890
        if dialog.ShowModal() == wx.ID_YES:
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   891
            plugin = self.GetSelectedPlugin()
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   892
            plugin.PlugRemove()
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   893
            del plugin
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   894
            self.RefreshPluginTree()
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
   895
        dialog.Destroy()
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   896
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   897
#-------------------------------------------------------------------------------
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   898
#                               Exception Handler
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   899
#-------------------------------------------------------------------------------
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   900
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   901
Max_Traceback_List_Size = 20
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   902
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   903
def Display_Exception_Dialog(e_type,e_value,e_tb):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   904
    trcbck_lst = []
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   905
    for i,line in enumerate(traceback.extract_tb(e_tb)):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   906
        trcbck = " " + str(i+1) + ". "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   907
        if line[0].find(os.getcwd()) == -1:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   908
            trcbck += "file : " + str(line[0]) + ",   "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   909
        else:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   910
            trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   911
        trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   912
        trcbck_lst.append(trcbck)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   913
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   914
    # Allow clicking....
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   915
    cap = wx.Window_GetCapture()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   916
    if cap:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   917
        cap.ReleaseMouse()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   918
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   919
    dlg = wx.SingleChoiceDialog(None, 
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   920
        """
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   921
An error happens.
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   922
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   923
Click on OK for saving an error report.
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   924
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   925
Please contact LOLITech at:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   926
+33 (0)3 29 52 95 67
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   927
bugs_Beremiz@lolitech.fr
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   928
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   929
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   930
Error:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   931
""" +
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   932
        str(e_type) + " : " + str(e_value), 
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   933
        "Error",
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   934
        trcbck_lst)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   935
    try:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   936
        res = (dlg.ShowModal() == wx.ID_OK)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   937
    finally:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   938
        dlg.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   939
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   940
    return res
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   941
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   942
def Display_Error_Dialog(e_value):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   943
    message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   944
    message.ShowModal()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   945
    message.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   946
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   947
def get_last_traceback(tb):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   948
    while tb.tb_next:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   949
        tb = tb.tb_next
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   950
    return tb
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   951
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   952
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   953
def format_namespace(d, indent='    '):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   954
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   955
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   956
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   957
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   958
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
   959
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   960
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   961
    def handle_exception(e_type, e_value, e_traceback):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   962
        traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   963
        last_tb = get_last_traceback(e_traceback)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   964
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   965
        if str(e_value).startswith("!!!"):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   966
            Display_Error_Dialog(e_value)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   967
        elif ex not in ignored_exceptions:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   968
            result = Display_Exception_Dialog(e_type,e_value,e_traceback)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   969
            if result:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   970
                ignored_exceptions.append(ex)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   971
                info = {
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   972
                    'app-title' : wx.GetApp().GetAppName(), # app_title
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   973
                    'app-version' : app_version,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   974
                    'wx-version' : wx.VERSION_STRING,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   975
                    'wx-platform' : wx.Platform,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   976
                    'python-version' : platform.python_version(), #sys.version.split()[0],
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   977
                    'platform' : platform.platform(),
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   978
                    'e-type' : e_type,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   979
                    'e-value' : e_value,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   980
                    'date' : time.ctime(),
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   981
                    'cwd' : os.getcwd(),
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   982
                    }
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   983
                if e_traceback:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   984
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   985
                    last_tb = get_last_traceback(e_traceback)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   986
                    exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   987
                    info['locals'] = format_namespace(exception_locals)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   988
                    if 'self' in exception_locals:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   989
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   990
                
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   991
                output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   992
                lst = info.keys()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   993
                lst.sort()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   994
                for a in lst:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   995
                    output.write(a+":\n"+str(info[a])+"\n\n")
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   996
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   997
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   998
    sys.excepthook = handle_exception
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   999
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1000
if __name__ == '__main__':
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1001
    def usage():
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1002
        print "\nUsage of Beremiz.py :"
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1003
        print "\n   %s [Projectpath]\n"%sys.argv[0]
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1004
    
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1005
    try:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1006
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1007
    except getopt.GetoptError:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1008
        # print help information and exit:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1009
        usage()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1010
        sys.exit(2)
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1011
    
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1012
    for o, a in opts:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1013
        if o in ("-h", "--help"):
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1014
            usage()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1015
            sys.exit()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1016
    
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1017
    if len(args) > 1:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1018
        usage()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1019
        sys.exit()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1020
    elif len(args) == 1:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1021
        projectOpen = args[0]
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1022
    else:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1023
        projectOpen = None
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1024
    
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
  1025
    app = wx.PySimpleApp()
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
  1026
    wx.InitAllImageHandlers()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1027
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1028
    # Install a exception handle for bug reports
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
  1029
    AddExceptHook(os.getcwd(),__version__)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1030
    
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1031
    frame = Beremiz(None, projectOpen)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1032
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1033
    frame.Show()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1034
    app.MainLoop()