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