Beremiz.py
author greg
Fri, 23 May 2008 10:52:55 +0200
changeset 146 ad2d8431104e
parent 136 f49f586a0a43
child 153 b352a2012691
permissions -rw-r--r--
bug fix
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
117
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    27
import os, sys, getopt, wx
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    28
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    29
CWD = os.path.split(os.path.realpath(__file__))[0]
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    30
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    31
if __name__ == '__main__':
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    32
    def usage():
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    33
        print "\nUsage of Beremiz.py :"
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    34
        print "\n   %s [Projectpath]\n"%sys.argv[0]
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    35
    
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    36
    try:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    37
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    38
    except getopt.GetoptError:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    39
        # print help information and exit:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    40
        usage()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    41
        sys.exit(2)
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    42
    
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    43
    for o, a in opts:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    44
        if o in ("-h", "--help"):
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    45
            usage()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    46
            sys.exit()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    47
    
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    48
    if len(args) > 1:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    49
        usage()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    50
        sys.exit()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    51
    elif len(args) == 1:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    52
        projectOpen = args[0]
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    53
    else:
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    54
        projectOpen = None
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    55
    
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    56
    app = wx.PySimpleApp()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    57
    wx.InitAllImageHandlers()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    58
    
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    59
    bmp = wx.Image(os.path.join(CWD,"images","splash.png")).ConvertToBitmap()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    60
    splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None)
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    61
    wx.Yield()
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    62
134
517db40c30b7 docutils is now used for displaying pdf and html
greg
parents: 133
diff changeset
    63
import wx.lib.buttons, wx.lib.statbmp
117
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
    64
import types, time, re, platform, time, traceback, commands
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
    65
from plugger import PluginsRoot
122
7676dba61281 use docclass for opening pdf on win32 or linux
greg
parents: 121
diff changeset
    66
120
8c3150858dd3 create doc directory and add about.html + manual_beremiz.pdf
greg
parents: 119
diff changeset
    67
base_folder = os.path.split(sys.path[0])[0]
136
f49f586a0a43 import all docutils in 1 time
greg
parents: 134
diff changeset
    68
sys.path.append(base_folder)
f49f586a0a43 import all docutils in 1 time
greg
parents: 134
diff changeset
    69
from docutils import *
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
    70
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    71
SCROLLBAR_UNIT = 10
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    72
WINDOW_COLOUR = wx.Colour(240,240,240)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
    73
TITLE_COLOUR = wx.Colour(200,200,220)
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
    74
CHANGED_TITLE_COLOUR = wx.Colour(220,200,220)
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
    75
CHANGED_WINDOW_COLOUR = wx.Colour(255,240,240)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    76
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    77
if wx.Platform == '__WXMSW__':
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    78
    faces = { 'times': 'Times New Roman',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    79
              'mono' : 'Courier New',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    80
              'helv' : 'Arial',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    81
              'other': 'Comic Sans MS',
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
    82
              'size' : 16,
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    83
             }
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    84
else:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    85
    faces = { 'times': 'Times',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    86
              'mono' : 'Courier',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    87
              'helv' : 'Helvetica',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    88
              'other': 'new century schoolbook',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    89
              'size' : 18,
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    90
             }
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
    91
72
dc107daa2135 Bug on LeftPanelSizer with Windows fixed
lbessard
parents: 71
diff changeset
    92
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
    93
# Some helpers to tweak GenBitmapTextButtons
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
    94
# TODO: declare customized classes instead.
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
    95
gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID)
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
    96
gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,))
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
    97
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
    98
def make_genbitmaptogglebutton_flat(button):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
    99
    button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   100
    button.labelDelta = 0
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   101
    button.SetBezelWidth(0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   102
    button.SetUseFocusIndicator(False)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   103
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   104
# Patch wx.lib.imageutils so that gray is supported on alpha images
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   105
import wx.lib.imageutils
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   106
from wx.lib.imageutils import grayOut as old_grayOut
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   107
def grayOut(anImage):
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   108
    if anImage.HasAlpha():
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   109
        AlphaData = anImage.GetAlphaData()
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   110
    else :
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   111
        AlphaData = None
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   112
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   113
    old_grayOut(anImage)
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   114
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   115
    if AlphaData is not None:
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   116
        anImage.SetAlphaData(AlphaData)
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   117
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   118
wx.lib.imageutils.grayOut = grayOut
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   119
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   120
class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   121
    def _GetLabelSize(self):
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   122
        return wx.lib.buttons.GenBitmapTextButton._GetLabelSize(self)[:-1] + (False,)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   123
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   124
class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   125
    """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, 
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   126
    and accept image name as __init__ parameter, fail silently if file do not exist"""
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   127
    def __init__(self, parent, ID, bitmapname,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   128
                 pos = wx.DefaultPosition, size = wx.DefaultSize,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   129
                 style = 0,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   130
                 name = "genstatbmp"):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   131
        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   132
        bitmappath = os.path.join(CWD, "images", bitmapname)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   133
        if os.path.isfile(bitmappath):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   134
            bitmap = wx.Bitmap(bitmappath)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   135
        else:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   136
            bitmap = None
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   137
        wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   138
                 pos, size,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   139
                 style,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   140
                 name)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   141
        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   142
    def OnPaint(self, event):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   143
        dc = wx.PaintDC(self)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   144
        colour = self.GetParent().GetBackgroundColour()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   145
        dc.SetPen(wx.Pen(colour))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   146
        dc.SetBrush(wx.Brush(colour ))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   147
        dc.DrawRectangle(0, 0, *dc.GetSizeTuple())
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   148
        if self._bitmap:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   149
            dc.DrawBitmap(self._bitmap, 0, 0, True)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   150
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   151
                        
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   152
class LogPseudoFile:
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   153
    """ Base class for file like objects to facilitate StdOut for the Shell."""
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   154
    def __init__(self, output):
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   155
        self.red_white = wx.TextAttr("RED", "WHITE")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   156
        self.red_yellow = wx.TextAttr("RED", "YELLOW")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   157
        self.black_white = wx.TextAttr("BLACK", "WHITE")
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   158
        self.default_style = None
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   159
        self.output = output
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   160
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   161
    def write(self, s, style = None):
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   162
        if style is None : style=self.black_white
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   163
        self.output.Freeze(); 
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   164
        if self.default_style != style: 
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   165
            self.output.SetDefaultStyle(style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   166
            self.default_style = style
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   167
        self.output.AppendText(s)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   168
        self.output.ScrollLines(s.count('\n')+1)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   169
        self.output.ShowPosition(self.output.GetLastPosition())
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   170
        self.output.Thaw()
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   171
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   172
    def write_warning(self, s):
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   173
        self.write(s,self.red_white)
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   174
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
   175
    def write_error(self, s):
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
   176
        self.write(s,self.red_yellow)
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   177
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   178
    def flush(self):
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   179
        self.output.SetValue("")
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   180
    
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   181
    def isatty(self):
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   182
        return false
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   183
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   184
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, 
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   185
 ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, 
121
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   186
 ID_BEREMIZINSPECTOR] = [wx.NewId() for _init_ctrls in range(5)]
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   187
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   188
[ID_BEREMIZRUNMENUBUILD, ID_BEREMIZRUNMENUSIMULATE, 
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   189
 ID_BEREMIZRUNMENURUN, ID_BEREMIZRUNMENUSAVELOG, 
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   190
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)]
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   191
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   192
class Beremiz(wx.Frame):
120
8c3150858dd3 create doc directory and add about.html + manual_beremiz.pdf
greg
parents: 119
diff changeset
   193
	
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   194
    def _init_coll_FileMenu_Items(self, parent):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   195
        parent.Append(help='', id=wx.ID_NEW,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   196
              kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   197
        parent.Append(help='', id=wx.ID_OPEN,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   198
              kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   199
        parent.Append(help='', id=wx.ID_SAVE,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   200
              kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   201
        parent.Append(help='', id=wx.ID_CLOSE,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   202
              kind=wx.ITEM_NORMAL, text=u'Close Project')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   203
        parent.AppendSeparator()
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   204
        parent.Append(help='', id=wx.ID_PROPERTIES,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   205
              kind=wx.ITEM_NORMAL, text=u'Properties')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   206
        parent.AppendSeparator()
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   207
        parent.Append(help='', id=wx.ID_EXIT,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   208
              kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   209
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   210
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   211
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   212
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   213
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   214
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   215
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   216
    def _init_coll_EditMenu_Items(self, parent):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   217
        parent.Append(help='', id=wx.ID_EDIT,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   218
              kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   219
        parent.AppendSeparator()
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   220
        parent.Append(help='', id=wx.ID_ADD,
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   221
              kind=wx.ITEM_NORMAL, text=u'Add Plugin')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   222
        parent.Append(help='', id=wx.ID_DELETE,
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   223
              kind=wx.ITEM_NORMAL, text=u'Delete Plugin')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   224
        self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   225
        self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   226
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   227
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   228
    def _init_coll_RunMenu_Items(self, parent):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   229
        parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   230
              kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   231
        parent.AppendSeparator()
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   232
        parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   233
              kind=wx.ITEM_NORMAL, text=u'Simulate')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   234
        parent.Append(help='', id=ID_BEREMIZRUNMENURUN,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   235
              kind=wx.ITEM_NORMAL, text=u'Run')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   236
        parent.AppendSeparator()
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   237
        parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   238
              kind=wx.ITEM_NORMAL, text=u'Save Log')
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
   239
        self.Bind(wx.EVT_MENU, self.OnBuildMenu,
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   240
              id=ID_BEREMIZRUNMENUBUILD)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   241
        self.Bind(wx.EVT_MENU, self.OnSimulateMenu,
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   242
              id=ID_BEREMIZRUNMENUSIMULATE)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   243
        self.Bind(wx.EVT_MENU, self.OnRunMenu,
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   244
              id=ID_BEREMIZRUNMENURUN)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   245
        self.Bind(wx.EVT_MENU, self.OnSaveLogMenu,
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   246
              id=ID_BEREMIZRUNMENUSAVELOG)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   247
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   248
    def _init_coll_HelpMenu_Items(self, parent):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   249
        parent.Append(help='', id=wx.ID_HELP,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   250
              kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   251
        parent.Append(help='', id=wx.ID_ABOUT,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   252
              kind=wx.ITEM_NORMAL, text=u'About')
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   253
        self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   254
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   255
    
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   256
    def _init_coll_MenuBar_Menus(self, parent):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   257
        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
   258
        #parent.Append(menu=self.EditMenu, title=u'Edit')
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   259
        #parent.Append(menu=self.RunMenu, title=u'Run')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   260
        parent.Append(menu=self.HelpMenu, title=u'Help')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   261
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   262
    def _init_utils(self):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   263
        self.MenuBar = wx.MenuBar()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   264
        self.FileMenu = wx.Menu(title=u'')
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   265
        #self.EditMenu = wx.Menu(title=u'')
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   266
        #self.RunMenu = wx.Menu(title=u'')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   267
        self.HelpMenu = wx.Menu(title=u'')
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   268
        
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   269
        self._init_coll_MenuBar_Menus(self.MenuBar)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   270
        self._init_coll_FileMenu_Items(self.FileMenu)
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   271
        #self._init_coll_EditMenu_Items(self.EditMenu)
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
   272
        #self._init_coll_RunMenu_Items(self.RunMenu)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   273
        self._init_coll_HelpMenu_Items(self.HelpMenu)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   274
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   275
    def _init_coll_PLCConfigMainSizer_Items(self, parent):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   276
        parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   277
        parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   278
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   279
    def _init_coll_PLCConfigMainSizer_Growables(self, parent):
67
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   280
        parent.AddGrowableCol(0)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   281
        parent.AddGrowableRow(1)
862da764c5b5 Layout changed for making buttons at top of the frame always visible
lbessard
parents: 65
diff changeset
   282
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   283
    def _init_coll_PluginTreeSizer_Growables(self, parent):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   284
        parent.AddGrowableCol(0)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   285
        parent.AddGrowableCol(1)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   286
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   287
    def _init_sizers(self):
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   288
        self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   289
        self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   290
        #self.PluginTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   291
        self.PluginTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   292
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   293
        self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   294
        self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   295
        self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   296
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   297
        self.PLCConfig.SetSizer(self.PLCConfigMainSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   298
        
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   299
    def _init_ctrls(self, prnt):
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
   300
        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
   301
              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
   302
              style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   303
        self._init_utils()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   304
        self.SetClientSize(wx.Size(1000, 600))
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   305
        self.SetMenuBar(self.MenuBar)
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   306
        self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated)
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   307
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
121
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   308
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   309
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   310
        accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, wx.WXK_F12, ID_BEREMIZINSPECTOR)])
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   311
        self.SetAcceleratorTable(accel)
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   312
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   313
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   314
        
71
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   315
        if wx.VERSION < (2, 8, 0):
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   316
            self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER,
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   317
                  name='MainSplitter', parent=self, point=wx.Point(0, 0),
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   318
                  size=wx.Size(0, 0), style=wx.SP_3D)
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   319
            self.MainSplitter.SetNeedUpdating(True)
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   320
            self.MainSplitter.SetMinimumPaneSize(1)
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   321
        
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   322
            parent = self.MainSplitter
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   323
        else:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   324
            parent = self
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   325
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   326
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   327
              name='PLCConfig', parent=parent, pos=wx.Point(0, 0),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   328
              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   329
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   330
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   331
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   332
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   333
                  name='LogConsole', parent=parent, pos=wx.Point(0, 0),
71
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   334
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   335
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   336
        if wx.VERSION < (2, 8, 0):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   337
            self.MainSplitter.SplitHorizontally(self.PLCConfig, self.LogConsole, -250)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   338
            
71
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   339
        else:
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   340
            self.AUIManager = wx.aui.AuiManager(self)
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   341
            self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   342
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   343
            self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane())
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   344
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   345
            self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo().
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   346
                Caption("Log Console").Bottom().Layer(1).
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   347
                BestSize(wx.Size(800, 200)).CloseButton(False))
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   348
        
71
e0bb49781b80 Improving Beremiz for using wx2.8 AUI
lbessard
parents: 69
diff changeset
   349
            self.AUIManager.Update()
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   350
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   351
        self._init_sizers()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   352
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   353
    def __init__(self, parent, projectOpen):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   354
        self._init_ctrls(parent)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   355
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   356
        self.Log = LogPseudoFile(self.LogConsole)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   357
        
116
ff860001a377 add wx.icon in init for class beremiz class
greg
parents: 110
diff changeset
   358
        # Add beremiz's icon in top left corner of the frame
124
b9aba2d44b3e SetIcon for Beremiz fixed
lbessard
parents: 123
diff changeset
   359
        self.SetIcon(wx.Icon(os.path.join(CWD, "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
116
ff860001a377 add wx.icon in init for class beremiz class
greg
parents: 110
diff changeset
   360
        
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
   361
        self.PluginRoot = PluginsRoot(self)
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   362
        self.DisableEvents = False
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   363
        
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   364
        self.PluginInfos = {}
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   365
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   366
        if projectOpen:
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   367
            self.PluginRoot.LoadProject(projectOpen, self.Log)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   368
            self.RefreshPLCParams()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   369
            self.RefreshPluginTree()
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   370
        
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   371
        self.RefreshMainMenu()
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   372
121
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   373
    def OnOpenWidgetInspector(self, evt):
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   374
        # Activate the widget inspection tool
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   375
        from wx.lib.inspection import InspectionTool
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   376
        if not InspectionTool().initialized:
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   377
            InspectionTool().Init()
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   378
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   379
        # Find a widget to be selected in the tree.  Use either the
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   380
        # one under the cursor, if any, or this frame.
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   381
        wnd = wx.FindWindowAtPointer()
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   382
        if not wnd:
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   383
            wnd = self
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   384
        InspectionTool().Show(wnd, True)
ccb1812f8323 Added ctrl+f12 wxpython inspector shortcut for debuging
etisserant
parents: 120
diff changeset
   385
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   386
    def OnCloseFrame(self, event):
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   387
        if self.PluginRoot.HasProjectOpened():
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   388
            if self.PluginRoot.runningPLC is not None:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   389
                wx.MessageBox("Please stop any running PLC before closing")
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   390
                event.Veto()
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   391
                return
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   392
            if self.PluginRoot.ProjectTestModified():
119
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   393
                dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   394
                answer = dialog.ShowModal()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   395
                dialog.Destroy()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   396
                if answer == wx.ID_YES:
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   397
                    self.PluginRoot.SaveProject()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   398
                    event.Skip()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   399
                    return
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   400
                elif answer == wx.ID_NO:
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   401
                    event.Skip()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   402
                    return
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   403
                else:
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   404
                    event.Veto()
f3819d2e8eff Added question dialog for unsaved close
etisserant
parents: 118
diff changeset
   405
                    return
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   406
        event.Skip()
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   407
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   408
    def OnMoveWindow(self, event):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   409
        self.GetBestSize()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   410
        self.RefreshScrollBars()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   411
        event.Skip()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   412
    
62
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   413
    def OnFrameActivated(self, event):
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   414
        if not event.GetActive():
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   415
            self.PluginRoot.RefreshPluginsBlockLists()
ddf0cdd71558 Adding support for refresh block list where beremiz loose focus
lbessard
parents: 60
diff changeset
   416
    
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
   417
    def RefreshMainMenu(self):
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   418
        if self.MenuBar:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   419
            if self.PluginRoot.HasProjectOpened():
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   420
##                self.MenuBar.EnableTop(1, True)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   421
##                self.MenuBar.EnableTop(2, True)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   422
                self.FileMenu.Enable(wx.ID_SAVE, True)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   423
                self.FileMenu.Enable(wx.ID_CLOSE, True)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   424
                self.FileMenu.Enable(wx.ID_PROPERTIES, True)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   425
            else:
127
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   426
##                self.MenuBar.EnableTop(1, False)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   427
##                self.MenuBar.EnableTop(2, False)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   428
                self.FileMenu.Enable(wx.ID_SAVE, False)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   429
                self.FileMenu.Enable(wx.ID_CLOSE, False)
36bb6be88a3b Adding icons to Beremiz menus
lbessard
parents: 126
diff changeset
   430
                self.FileMenu.Enable(wx.ID_PROPERTIES, False)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   431
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   432
    def RefreshScrollBars(self):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   433
        xstart, ystart = self.PLCConfig.GetViewStart()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   434
        window_size = self.PLCConfig.GetClientSize()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   435
        sizer = self.PLCConfig.GetSizer()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   436
        if sizer:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   437
            maxx, maxy = sizer.GetMinSize()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   438
            self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
101
93e487ccee14 Display bugs on Windows fixed
lbessard
parents: 99
diff changeset
   439
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, xstart, ystart)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   440
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   441
    def RefreshPLCParams(self):
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   442
        self.Freeze()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   443
        self.ClearSizer(self.PLCParamsSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   444
        
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   445
        if self.PluginRoot.HasProjectOpened():    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   446
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   447
            if self.PluginRoot.PlugTestModified():
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   448
                bkgdclr = CHANGED_TITLE_COLOUR
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   449
            else:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   450
                bkgdclr = TITLE_COLOUR
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   451
                
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   452
            if self.PluginRoot not in self.PluginInfos:
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   453
                self.PluginInfos[self.PluginRoot] = {"middle_visible" : False}
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   454
            
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   455
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   456
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   457
            
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   458
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   459
            plcwindow.SetSizer(plcwindowsizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   460
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   461
            st = wx.StaticText(plcwindow, -1)
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   462
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   463
            st.SetLabel(self.PluginRoot.GetProjectName())
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   464
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   465
            
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   466
            addbutton_id = wx.NewId()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   467
            addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Add16x16.png')),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   468
                  name='AddBusButton', parent=plcwindow, pos=wx.Point(0, 0),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   469
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   470
            addbutton.SetToolTipString("Add a sub plugin")
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   471
            addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   472
            plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   473
    
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   474
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   475
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   476
            
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   477
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   478
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   479
            
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   480
            msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["middle_visible"])
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   481
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   482
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   483
            paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1))
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   484
            paramswindow.SetBackgroundColour(TITLE_COLOUR)
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   485
            plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   486
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   487
            psizer = wx.BoxSizer(wx.HORIZONTAL)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   488
            paramswindow.SetSizer(psizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   489
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   490
            plugin_infos = self.PluginRoot.GetParamsAttributes()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   491
            self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   492
            
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   493
            if not self.PluginInfos[self.PluginRoot]["middle_visible"]:
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   494
                paramswindow.Hide()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   495
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   496
            minimizebutton_id = wx.NewId()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   497
            minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   498
                  name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   499
                  size=wx.Size(24, 24), style=wx.NO_BORDER)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   500
            make_genbitmaptogglebutton_flat(minimizebutton)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   501
            minimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Minimize.png')))
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   502
            plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   503
            
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   504
#            if len(self.PluginRoot.PlugChildsTypes) > 0:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   505
#                addsizer = self.GenerateAddButtonSizer(self.PluginRoot, plcwindow)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   506
#                plcwindowbuttonsizer.AddSizer(addsizer, 0, border=0, flag=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   507
#            else:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   508
#                addsizer = None
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   509
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   510
            def togglewindow(event):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   511
                if minimizebutton.GetToggle():
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   512
                    paramswindow.Show()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   513
                    msizer.SetCols(1)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   514
#                    if addsizer is not None:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   515
#                        addsizer.SetCols(1)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   516
                else:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   517
                    paramswindow.Hide()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   518
                    msizer.SetCols(len(self.PluginRoot.PluginMethods))
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   519
#                    if addsizer is not None:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   520
#                        addsizer.SetCols(len(self.PluginRoot.PlugChildsTypes))
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   521
                self.PluginInfos[self.PluginRoot]["middle_visible"] = minimizebutton.GetToggle()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   522
                self.PLCConfigMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   523
                self.RefreshScrollBars()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   524
                event.Skip()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   525
            minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id)
101
93e487ccee14 Display bugs on Windows fixed
lbessard
parents: 99
diff changeset
   526
        
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   527
            self.PluginInfos[self.PluginRoot]["main"] = plcwindow
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   528
            self.PluginInfos[self.PluginRoot]["params"] = paramswindow
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   529
            
101
93e487ccee14 Display bugs on Windows fixed
lbessard
parents: 99
diff changeset
   530
        self.PLCConfigMainSizer.Layout()
93e487ccee14 Display bugs on Windows fixed
lbessard
parents: 99
diff changeset
   531
        self.RefreshScrollBars()
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   532
        self.Thaw()
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   533
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   534
#    def GenerateAddButtonSizer(self, plugin, parent, horizontal = True):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   535
#        if horizontal:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   536
#            addsizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   537
#        else:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   538
#            addsizer = wx.FlexGridSizer(cols=1)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   539
#        for name, XSDClass, help in plugin.PlugChildsTypes:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   540
#            addbutton_id = wx.NewId()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   541
#            addbutton = wx.lib.buttons.GenButton(id=addbutton_id, label="Add %s"%help,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   542
#                  name='AddBusButton', parent=parent, pos=wx.Point(0, 0),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   543
#                  style=wx.NO_BORDER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   544
#            font = addbutton.GetFont()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   545
#            font.SetUnderlined(True)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   546
#            addbutton.SetFont(font)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   547
#            addbutton._GetLabelSize = gen_textbutton_GetLabelSize(addbutton)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   548
#            addbutton.SetForegroundColour(wx.BLUE)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   549
#            addbutton.SetToolTipString("Add a \"%s\" plugin to this one"%name)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   550
#            addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   551
#            addsizer.AddWindow(addbutton, 0, border=0, flag=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   552
#        return addsizer
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   553
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   554
    def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   555
        if horizontal:
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   556
            msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   557
        else:
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   558
            msizer = wx.FlexGridSizer(cols=1)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   559
        for plugin_method in plugin.PluginMethods:
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   560
            if "method" in plugin_method:
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   561
                id = wx.NewId()
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   562
                button = GenBitmapTextButton(id=id, parent=parent,
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   563
                    bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], 
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   564
                    name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   565
                button.SetToolTipString(plugin_method["tooltip"])
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   566
                button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   567
                #hack to force size to mini
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   568
                if not plugin_method.get("enabled",True):
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   569
                    button.Disable()
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   570
                msizer.AddWindow(button, 0, border=0, flag=0)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   571
        return msizer
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   572
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   573
    def RefreshPluginTree(self):
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   574
        self.Freeze()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   575
        self.ClearSizer(self.PluginTreeSizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   576
        if self.PluginRoot.HasProjectOpened():
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   577
            for child in self.PluginRoot.IECSortedChilds():
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   578
                self.GenerateTreeBranch(child)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   579
                if not self.PluginInfos[child]["expanded"]:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   580
                    self.CollapsePlugin(child)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   581
        self.PLCConfigMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   582
        self.RefreshScrollBars()
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   583
        self.Thaw()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   584
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   585
    def SetPluginParamsAttribute(self, plugin, *args, **kwargs):
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   586
        res, StructChanged = plugin.SetParamsAttribute(*args, **kwargs)
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   587
        if StructChanged:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   588
            wx.CallAfter(self.RefreshPluginTree)
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   589
        else:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   590
            if plugin == self.PluginRoot:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   591
                bkgdclr = CHANGED_TITLE_COLOUR
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   592
                items = ["main", "params"]
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   593
            else:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   594
                bkgdclr = CHANGED_WINDOW_COLOUR
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   595
                items = ["left", "middle", "params"]
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   596
            for i in items:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   597
                self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr)
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   598
                self.PluginInfos[plugin][i].Refresh()
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   599
        return res
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   600
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   601
    def ExpandPlugin(self, plugin, force = False):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   602
        for child in self.PluginInfos[plugin]["children"]:
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   603
            self.PluginInfos[child]["left"].Show()
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   604
            self.PluginInfos[child]["middle"].Show()
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   605
#            self.PluginTreeSizer.Show(self.PluginInfos[child]["right"])
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   606
            if force or not self.PluginInfos[child]["expanded"]:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   607
                self.ExpandPlugin(child, force)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   608
                if force:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   609
                    self.PluginInfos[child]["expanded"] = True
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   610
    
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   611
    def CollapsePlugin(self, plugin, force = False):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   612
        for child in self.PluginInfos[plugin]["children"]:
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   613
            self.PluginInfos[child]["left"].Hide()
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   614
            self.PluginInfos[child]["middle"].Hide()
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   615
#            self.PluginTreeSizer.Hide(self.PluginInfos[child]["right"])
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   616
            if force or self.PluginInfos[child]["expanded"]:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   617
                self.CollapsePlugin(child, force)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   618
                if force:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   619
                    self.PluginInfos[child]["expanded"] = False
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   620
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   621
    def GenerateTreeBranch(self, plugin):
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   622
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   623
        if plugin.PlugTestModified():
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   624
            bkgdclr=CHANGED_WINDOW_COLOUR
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   625
        else:
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   626
            bkgdclr=WINDOW_COLOUR
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   627
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   628
        leftwindow.SetBackgroundColour(bkgdclr)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   629
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   630
        if plugin not in self.PluginInfos:
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   631
            self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "middle_visible" : False}
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   632
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   633
        self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   634
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   635
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   636
        
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   637
        leftwindowsizer = wx.FlexGridSizer(cols=1, rows=3)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   638
        leftwindowsizer.AddGrowableCol(0)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   639
        leftwindowsizer.AddGrowableRow(2)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   640
        leftwindow.SetSizer(leftwindowsizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   641
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   642
        leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   643
        leftbuttonmainsizer.AddGrowableCol(0)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   644
        leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) #|wx.TOP
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   645
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   646
        leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   647
        leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=5, flag=wx.GROW|wx.RIGHT)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   648
        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   649
        leftsizer = wx.BoxSizer(wx.VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   650
        leftbuttonsizer.AddSizer(leftsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   651
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   652
        rolesizer = wx.BoxSizer(wx.HORIZONTAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   653
        leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   654
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   655
        enablebutton_id = wx.NewId()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   656
        enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Disabled.png')),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   657
              name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   658
        enablebutton.SetToolTipString("Enable/Disable this plugin")
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   659
        make_genbitmaptogglebutton_flat(enablebutton)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   660
        enablebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Enabled.png')))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   661
        enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled())
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   662
        def toggleenablebutton(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   663
            res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle(), self.Log)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   664
            enablebutton.SetToggle(res)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   665
            event.Skip()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   666
        enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   667
        rolesizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   668
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   669
        roletext = wx.StaticText(leftwindow, -1)
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   670
        roletext.SetLabel(plugin.PlugHelp)
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   671
        rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   672
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   673
        plugin_IECChannel = plugin.BaseParams.getIEC_Channel()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   674
        
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   675
        iecsizer = wx.BoxSizer(wx.HORIZONTAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   676
        leftsizer.AddSizer(iecsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   677
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   678
        st = wx.StaticText(leftwindow, -1)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   679
        st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   680
        st.SetLabel(plugin.GetFullIEC_Channel())
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   681
        iecsizer.AddWindow(st, 0, border=0, flag=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   682
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   683
        updownsizer = wx.BoxSizer(wx.VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   684
        iecsizer.AddSizer(updownsizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   685
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   686
        if plugin_IECChannel > 0:
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   687
            ieccdownbutton_id = wx.NewId()
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   688
            ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCDown.png')),
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   689
                  name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0),
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   690
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   691
            ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   692
            updownsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_LEFT)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   693
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   694
        ieccupbutton_id = wx.NewId()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   695
        ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCUp.png')),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   696
              name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   697
              size=wx.Size(16, 16), style=wx.NO_BORDER)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   698
        ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel + 1), id=ieccupbutton_id)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   699
        updownsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_LEFT)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   700
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   701
        adddeletesizer = wx.BoxSizer(wx.VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   702
        iecsizer.AddSizer(adddeletesizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   703
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   704
        deletebutton_id = wx.NewId()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   705
        deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Delete16x16.png')),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   706
              name='DeleteBusButton', parent=leftwindow, pos=wx.Point(0, 0),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   707
              size=wx.Size(16, 16), style=wx.NO_BORDER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   708
        deletebutton.SetToolTipString("Delete this plugin")
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   709
        deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   710
        adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   711
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   712
        if len(plugin.PlugChildsTypes) > 0:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   713
            addbutton_id = wx.NewId()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   714
            addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Add16x16.png')),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   715
                  name='AddBusButton', parent=leftwindow, pos=wx.Point(0, 0),
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   716
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   717
            addbutton.SetToolTipString("Add a sub plugin")
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   718
            addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   719
            adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   720
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   721
        if len(self.PluginInfos[plugin]["children"]) > 0:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   722
            expandbutton_id = wx.NewId()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   723
            expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'plus.png')),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   724
                  name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   725
                  size=wx.Size(13, 13), style=wx.NO_BORDER)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   726
            expandbutton.labelDelta = 0
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   727
            expandbutton.SetBezelWidth(0)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   728
            expandbutton.SetUseFocusIndicator(False)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   729
            expandbutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'minus.png')))
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   730
            expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   731
            
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   732
            def togglebutton(event):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   733
                if expandbutton.GetToggle():
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   734
                    self.ExpandPlugin(plugin)
89
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 88
diff changeset
   735
                else:
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   736
                    self.CollapsePlugin(plugin)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   737
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   738
                self.PLCConfigMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   739
                self.RefreshScrollBars()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   740
                event.Skip()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   741
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   742
            leftbuttonsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   743
        
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   744
        tc_id = wx.NewId()
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   745
        tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 35), style=wx.NO_BORDER)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   746
        tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   747
        tc.SetValue(plugin.MandatoryParams[1].getName())
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   748
        tc.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   749
        leftbuttonsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   750
       
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   751
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   752
        leftminimizebutton_id = wx.NewId()
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   753
        leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'ShowVars.png')),
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   754
              name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0),
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   755
              size=wx.Size(24, 24), style=wx.NO_BORDER)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   756
        make_genbitmaptogglebutton_flat(leftminimizebutton)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   757
        leftminimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'HideVars.png')))
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   758
        leftminimizebutton.SetToggle(self.PluginInfos[plugin]["left_visible"])
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   759
        def toggleleftwindow(event):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   760
            if leftminimizebutton.GetToggle():
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   761
                leftwindowsizer.Show(1)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   762
            else:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   763
                leftwindowsizer.Hide(1)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   764
            self.PluginInfos[plugin]["left_visible"] = leftminimizebutton.GetToggle()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   765
            self.PLCConfigMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   766
            self.RefreshScrollBars()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   767
            event.Skip()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   768
        leftminimizebutton.Bind(wx.EVT_BUTTON, toggleleftwindow, id=leftminimizebutton_id)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   769
        leftbuttonmainsizer.AddWindow(leftminimizebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   770
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   771
        locations = plugin.GetLocations()
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   772
        lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, max(1, min(len(locations), 4)) * 25), style=wx.NO_BORDER)
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   773
        for location in locations:
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   774
            lb.Append(location["NAME"].replace("__", "%").replace("_", "."))
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   775
        if not self.PluginInfos[plugin]["left_visible"]:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   776
            lb.Hide()
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   777
        self.PluginInfos[plugin]["variable_list"] = lb
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   778
        leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   779
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   780
        middlewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   781
        middlewindow.SetBackgroundColour(bkgdclr)
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   782
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   783
        self.PluginTreeSizer.AddWindow(middlewindow, 0, border=0, flag=wx.GROW)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   784
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   785
        middlewindowmainsizer = wx.BoxSizer(wx.VERTICAL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   786
        middlewindow.SetSizer(middlewindowmainsizer)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   787
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   788
        middlewindowsizer = wx.FlexGridSizer(cols=2, rows=1)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   789
        middlewindowsizer.AddGrowableCol(1)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   790
        middlewindowsizer.AddGrowableRow(0)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   791
        middlewindowmainsizer.AddSizer(middlewindowsizer, 0, border=8, flag=wx.TOP|wx.GROW)
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   792
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   793
        msizer = self.GenerateMethodButtonSizer(plugin, middlewindow, not self.PluginInfos[plugin]["middle_visible"])
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   794
        middlewindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   795
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   796
        middleparamssizer = wx.BoxSizer(wx.HORIZONTAL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   797
        middlewindowsizer.AddSizer(middleparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   798
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   799
        paramswindow = wx.Panel(middlewindow, -1, size=wx.Size(-1, -1))
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   800
        paramswindow.SetBackgroundColour(bkgdclr)
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   801
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   802
        psizer = wx.BoxSizer(wx.HORIZONTAL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   803
        paramswindow.SetSizer(psizer)
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   804
        self.PluginInfos[plugin]["params"] = paramswindow
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   805
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   806
        middleparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   807
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   808
        plugin_infos = plugin.GetParamsAttributes()
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   809
        self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   810
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   811
        if not self.PluginInfos[plugin]["middle_visible"]:
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   812
            paramswindow.Hide()
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   813
        
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   814
        middleminimizebutton_id = wx.NewId()
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   815
        middleminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=middleminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')),
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   816
              name='MinimizeButton', parent=middlewindow, pos=wx.Point(0, 0),
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   817
              size=wx.Size(24, 24), style=wx.NO_BORDER)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   818
        make_genbitmaptogglebutton_flat(middleminimizebutton)
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   819
        middleminimizebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Minimize.png')))
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   820
        middleminimizebutton.SetToggle(self.PluginInfos[plugin]["middle_visible"])
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   821
        middleparamssizer.AddWindow(middleminimizebutton, 0, border=5, flag=wx.ALL)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   822
        
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   823
#        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   824
#        rightwindow.SetBackgroundColour(wx.Colour(240,240,240))
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   825
#        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   826
#        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   827
#        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   828
#        rightsizer = wx.BoxSizer(wx.VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   829
#        rightwindow.SetSizer(rightsizer)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   830
#        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   831
#        rightmainsizer = wx.BoxSizer(wx.VERTICAL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   832
#        rightsizer.AddSizer(rightmainsizer, 0, border=5, flag=wx.ALL)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   833
#        
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   834
#        if len(plugin.PlugChildsTypes) > 0:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   835
#            addsizer = self.GenerateAddButtonSizer(plugin, rightwindow)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   836
#            rightmainsizer.AddSizer(addsizer, 0, border=4, flag=wx.TOP)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   837
#        else:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   838
#            addsizer = None
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   839
            
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   840
        def togglemiddlerightwindow(event):
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   841
            if middleminimizebutton.GetToggle():
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   842
                middleparamssizer.Show(0)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   843
                msizer.SetCols(1)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   844
#                if addsizer is not None:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   845
#                    addsizer.SetCols(1)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   846
            else:
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   847
                middleparamssizer.Hide(0)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   848
                msizer.SetCols(len(plugin.PluginMethods))
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   849
#                if addsizer is not None:
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   850
#                    addsizer.SetCols(len(plugin.PlugChildsTypes))
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   851
            self.PluginInfos[plugin]["middle_visible"] = middleminimizebutton.GetToggle()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   852
            self.PLCConfigMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   853
            self.RefreshScrollBars()
84
8bc2669828e9 Plugin Tree Drawing bug hacked
lbessard
parents: 83
diff changeset
   854
            event.Skip()
99
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   855
        middleminimizebutton.Bind(wx.EVT_BUTTON, togglemiddlerightwindow, id=middleminimizebutton_id)
e5e9cb0f027f Beremiz layout improved
lbessard
parents: 98
diff changeset
   856
        
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   857
        self.PluginInfos[plugin]["left"] = leftwindow
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   858
        self.PluginInfos[plugin]["middle"] = middlewindow
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   859
#        self.PluginInfos[plugin]["right"] = rightwindow
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   860
        for child in self.PluginInfos[plugin]["children"]:
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   861
            self.GenerateTreeBranch(child)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   862
            if not self.PluginInfos[child]["expanded"]:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   863
                self.CollapsePlugin(child)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   864
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   865
    def RefreshVariableLists(self):
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   866
        for plugin, infos in self.PluginInfos.items():
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   867
            locations = plugin.GetLocations()
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   868
            infos["variable_list"].SetSize(wx.Size(-1, max(1, min(len(locations), 4)) * 25))
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   869
            infos["variable_list"].Clear()
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   870
            for location in locations:
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   871
                infos["variable_list"].Append(location["NAME"].replace("__", "%").replace("_", "."))
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   872
        self.PLCConfigMainSizer.Layout()
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   873
        self.RefreshScrollBars()
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   874
        
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   875
    def RefreshAll(self):
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   876
        self.RefreshPLCParams()
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   877
        self.RefreshPluginTree()
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   878
        
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   879
    def GetItemChannelChangedFunction(self, plugin, value):
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   880
        def OnPluginTreeItemChannelChanged(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   881
            res = self.SetPluginParamsAttribute(plugin, "BaseParams.IEC_Channel", value, self.Log)
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   882
            event.Skip()
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   883
        return OnPluginTreeItemChannelChanged
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   884
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   885
    def _GetAddPluginFunction(self, name, plugin):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   886
        def OnPluginMenu(event):
98
d359f0e7a97c Beremiz layout improved
lbessard
parents: 97
diff changeset
   887
            wx.CallAfter(self.AddPlugin, name, plugin)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   888
            event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   889
        return OnPluginMenu
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   890
    
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   891
    def Gen_AddPluginMenu(self, plugin):
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   892
        def AddPluginMenu(event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   893
            main_menu = wx.Menu(title='')
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   894
            if len(plugin.PlugChildsTypes) > 0:
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   895
                for name, XSDClass, help in plugin.PlugChildsTypes:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
   896
                    new_id = wx.NewId()
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   897
                    main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text="Append "+help)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   898
                    self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   899
            self.PopupMenuXY(main_menu)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   900
            event.Skip()
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   901
        return AddPluginMenu
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   902
    
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   903
    def GetButtonCallBackFunction(self, plugin, method):
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   904
        """ Generate the callbackfunc for a given plugin method"""
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   905
        def OnButtonClick(event):
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   906
            # Disable button to prevent re-entrant call 
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   907
            event.GetEventObject().Disable()
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   908
            # Call
105
434aed8dc58d Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents: 103
diff changeset
   909
            getattr(plugin,method)(self.Log)
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   910
            # Re-enable button 
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   911
            event.GetEventObject().Enable()
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 109
diff changeset
   912
            # Trigger refresh on Idle
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
   913
            wx.CallAfter(self.RefreshAll)
21
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   914
            event.Skip()
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   915
        return OnButtonClick
bded6d31365c Adding buttons for plugins
lbessard
parents: 20
diff changeset
   916
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   917
    def GetChoiceCallBackFunction(self, choicectrl, plugin, path):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   918
        def OnChoiceChanged(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   919
            res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection(), self.Log)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   920
            choicectrl.SetStringSelection(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   921
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   922
        return OnChoiceChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   923
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   924
    def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   925
        def OnChoiceContentChanged(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   926
            res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection(), self.Log)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   927
            if wx.VERSION < (2, 8, 0):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   928
                self.ParamsPanel.Freeze()
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   929
                choicectrl.SetStringSelection(res)
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   930
                infos = self.PluginRoot.GetParamsAttributes(path)
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   931
                staticbox = staticboxsizer.GetStaticBox()
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   932
                staticbox.SetLabel("%(name)s - %(value)s"%infos)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   933
                self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   934
                self.ParamsPanelMainSizer.Layout()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   935
                self.ParamsPanel.Thaw()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   936
                self.ParamsPanel.Refresh()
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   937
            else:
129
ec54cd416528 Bug with Target Type modification fixed
lbessard
parents: 127
diff changeset
   938
                wx.CallAfter(self.RefreshAll)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   939
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   940
        return OnChoiceContentChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   941
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   942
    def GetTextCtrlCallBackFunction(self, textctrl, plugin, path):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   943
        def OnTextCtrlChanged(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   944
            res = self.SetPluginParamsAttribute(plugin, path, textctrl.GetValue(), self.Log)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   945
            textctrl.SetValue(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   946
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   947
        return OnTextCtrlChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   948
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   949
    def GetCheckBoxCallBackFunction(self, chkbx, plugin, path):
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   950
        def OnCheckBoxChanged(event):
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
   951
            res = self.SetPluginParamsAttribute(plugin, path, chkbx.IsChecked(), self.Log)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   952
            chkbx.SetValue(res)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   953
            event.Skip()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   954
        return OnCheckBoxChanged
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   955
    
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   956
    def ClearSizer(self, sizer):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   957
        staticboxes = []
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   958
        for item in sizer.GetChildren():
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   959
            if item.IsSizer():
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   960
                item_sizer = item.GetSizer()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   961
                self.ClearSizer(item_sizer)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   962
                if isinstance(item_sizer, wx.StaticBoxSizer):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   963
                    staticboxes.append(item_sizer.GetStaticBox())
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   964
        sizer.Clear(True)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   965
        for staticbox in staticboxes:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   966
            staticbox.Destroy()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   967
                
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   968
    def RefreshSizerElement(self, parent, sizer, plugin, elements, path, clean = True):
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
   969
        if clean:
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   970
            if wx.VERSION < (2, 8, 0):
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   971
                self.ClearSizer(sizer)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   972
            else:
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
   973
                sizer.Clear(True)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   974
        first = True
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   975
        for element_infos in elements:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   976
            if path:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   977
                element_path = "%s.%s"%(path, element_infos["name"])
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   978
            else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   979
                element_path = element_infos["name"]
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   980
            if isinstance(element_infos["type"], types.ListType):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   981
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   982
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   983
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   984
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   985
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   986
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   987
                    name="%s_bitmap"%element_infos["name"], parent=parent,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   988
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
   989
                boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   990
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   991
                    name="%s_label"%element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   992
                    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
   993
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   994
                id = wx.NewId()
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
   995
                choicectrl = wx.Choice(id=id, name=element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   996
                    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
   997
                boxsizer.AddWindow(choicectrl, 0, border=0, flag=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   998
                choicectrl.Append("")
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
   999
                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
  1000
                    for choice, xsdclass in element_infos["type"]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1001
                        choicectrl.Append(choice)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1002
                    staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1003
                        name='%s_staticbox'%element_infos["name"], parent=parent,
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1004
                        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
  1005
                    staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1006
                    sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1007
                    self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1008
                    callback = self.GetChoiceContentCallBackFunction(choicectrl, staticboxsizer, plugin, element_path)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1009
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1010
                    for choice in element_infos["type"]:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1011
                        choicectrl.Append(choice)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1012
                    callback = self.GetChoiceCallBackFunction(choicectrl, plugin, element_path)
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
  1013
                if element_infos["value"]:
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
  1014
                    choicectrl.SetStringSelection(element_infos["value"])
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
  1015
                choicectrl.Bind(wx.EVT_CHOICE, callback, id=id)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1016
            elif isinstance(element_infos["type"], types.DictType):
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1017
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1018
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1019
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1020
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1021
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1022
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1023
                    name="%s_bitmap"%element_infos["name"], parent=parent,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1024
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1025
                boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1026
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1027
                    name="%s_label"%element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1028
                    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
  1029
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1030
                id = wx.NewId()
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1031
                scmin = -(2**31)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1032
                scmax = 2**31-1
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1033
                if "min" in element_infos["type"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1034
                    scmin = element_infos["type"]["min"]
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1035
                if "max" in element_infos["type"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1036
                    scmax = element_infos["type"]["max"]
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1037
                spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1038
                    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
  1039
                spinctrl.SetRange(scmin,scmax)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1040
                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
  1041
                spinctrl.SetValue(element_infos["value"])
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1042
                spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1043
            elif element_infos["type"] == "element":
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1044
                staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1045
                    name='%s_staticbox'%element_infos["name"], parent=parent,
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1046
                    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
  1047
                staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1048
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1049
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1050
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1051
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1052
                self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1053
            else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1054
                boxsizer = wx.BoxSizer(wx.HORIZONTAL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1055
                if first:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1056
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1057
                else:
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1058
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1059
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1060
                    name="%s_bitmap"%element_infos["name"], parent=parent,
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1061
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1062
                boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1063
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1064
                statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1065
                    name="%s_label"%element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1066
                    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
  1067
                boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1068
                id = wx.NewId()
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1069
                if element_infos["type"] == "boolean":
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1070
                    checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1071
                        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
  1072
                    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
  1073
                    checkbox.SetValue(element_infos["value"])
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1074
                    checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1075
                elif element_infos["type"] in ["unsignedLong", "long","integer"]:
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1076
                    if element_infos["type"].startswith("unsigned"):
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1077
                        scmin = 0
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1078
                    else:
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1079
                        scmin = -(2**31)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
  1080
                    scmax = 2**31-1
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1081
                    spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1082
                        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
  1083
                    spinctrl.SetRange(scmin, scmax)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1084
                    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
  1085
                    spinctrl.SetValue(element_infos["value"])
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1086
                    spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1087
                else:
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1088
                    textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, 
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
  1089
                        pos=wx.Point(0, 0), size=wx.Size(150, 25), style=0)#wx.TE_PROCESS_ENTER)
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1090
                    boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1091
                    textctrl.SetValue(str(element_infos["value"]))
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1092
                    textctrl.Bind(wx.EVT_KILL_FOCUS, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
19
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1093
            first = False
73257cea38bd Adding Plugin params visualization with basic controls
lbessard
parents: 18
diff changeset
  1094
    
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1095
    def OnNewProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1096
        defaultpath = self.PluginRoot.GetProjectPath()
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 21
diff changeset
  1097
        if not defaultpath:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1098
            defaultpath = os.getcwd()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
  1099
        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
  1100
        if dialog.ShowModal() == wx.ID_OK:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1101
            projectpath = dialog.GetPath()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1102
            dialog.Destroy()
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1103
            res = self.PluginRoot.NewProject(projectpath)
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1104
            if not res :
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1105
                self.RefreshPLCParams()
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1106
                self.RefreshPluginTree()
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1107
                self.RefreshMainMenu()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1108
            else:
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1109
                message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1110
                message.ShowModal()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1111
                message.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1112
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1113
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1114
    def OnOpenProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1115
        defaultpath = self.PluginRoot.GetProjectPath()
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1116
        if not defaultpath:
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1117
            defaultpath = os.getcwd()
4
e9d061c23e83 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 3
diff changeset
  1118
        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
  1119
        if dialog.ShowModal() == wx.ID_OK:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1120
            projectpath = dialog.GetPath()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1121
            if os.path.isdir(projectpath):
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
  1122
                result = self.PluginRoot.LoadProject(projectpath, self.Log)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1123
                if not result:
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1124
                    self.RefreshPLCParams()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1125
                    self.RefreshPluginTree()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1126
                    self.RefreshMainMenu()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1127
                else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1128
                    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
  1129
                    message.ShowModal()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1130
                    message.Destroy()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1131
            else:
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1132
                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
  1133
                message.ShowModal()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1134
                message.Destroy()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1135
            dialog.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1136
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1137
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1138
    def OnCloseProjectMenu(self, event):
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1139
        self.PluginInfos = {}
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1140
        self.RefreshPLCParams()
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1141
        self.RefreshPluginTree()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1142
        self.RefreshMainMenu()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1143
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1144
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1145
    def OnSaveProjectMenu(self, event):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1146
        if self.PluginRoot.HasProjectOpened():
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1147
            self.PluginRoot.SaveProject()
118
185d0d371ea4 Refuse close if PLC running.
etisserant
parents: 117
diff changeset
  1148
            self.RefreshAll()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1149
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1150
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1151
    def OnPropertiesMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1152
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1153
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1154
    def OnQuitMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1155
        self.Close()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1156
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1157
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1158
    def OnEditPLCMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1159
        self.EditPLC()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1160
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1161
    
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1162
    def OnAddMenu(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1163
        self.AddPlugin()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1164
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1165
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1166
    def OnDeleteMenu(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1167
        self.DeletePlugin()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1168
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1169
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
  1170
    def OnBuildMenu(self, event):
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 19
diff changeset
  1171
        #self.BuildAutom()
1
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
  1172
        event.Skip()
6e9f24fd1b98 Adding Build Method for PLC program generating
lbessard
parents: 0
diff changeset
  1173
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1174
    def OnSimulateMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1175
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1176
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1177
    def OnRunMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1178
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1179
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1180
    def OnSaveLogMenu(self, event):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1181
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1182
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1183
    def OnBeremizMenu(self, event):
126
034979cb02b0 add use of docutils for pdf
greg
parents: 124
diff changeset
  1184
        open_pdf(os.path.join(CWD, "doc", "manual_beremiz.pdf"))
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1185
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1186
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1187
    def OnAboutMenu(self, event):
134
517db40c30b7 docutils is now used for displaying pdf and html
greg
parents: 133
diff changeset
  1188
        OpenHtmlFrame(self,"About Beremiz", os.path.join(CWD, "doc","about.html"), wx.Size(550, 500))
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1189
        event.Skip()
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1190
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1191
    def OnAddButton(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1192
        PluginType = self.PluginChilds.GetStringSelection()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1193
        if PluginType != "":
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1194
            self.AddPlugin(PluginType)
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1195
        event.Skip()
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1196
    
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1197
    def OnDeleteButton(self, event):
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1198
        self.DeletePlugin()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1199
        event.Skip()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1200
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1201
    def GetAddButtonFunction(self, plugin, window):
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1202
        def AddButtonFunction(event):
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1203
            if plugin and len(plugin.PlugChildsTypes) > 0:
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1204
                plugin_menu = wx.Menu(title='')
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1205
                for name, XSDClass, help in plugin.PlugChildsTypes:
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1206
                    new_id = wx.NewId()
106
9810689febb0 Added plugins creation helpstrings, changed GUI layout (more compact), solved staticbitmap issues on win32, re-designed some icons...
etisserant
parents: 105
diff changeset
  1207
                    plugin_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name)
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1208
                    self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
87
4de868955ee4 Bug on ToolBar and AddButton Menu popup fixed
lbessard
parents: 84
diff changeset
  1209
                window_pos = window.GetPosition()
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1210
                wx.CallAfter(self.PLCConfig.PopupMenu, plugin_menu)
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1211
            event.Skip()
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1212
        return AddButtonFunction
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1213
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1214
    def GetDeleteButtonFunction(self, plugin):
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1215
        def DeleteButtonFunction(event):
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1216
            wx.CallAfter(self.DeletePlugin, plugin)
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1217
            event.Skip()
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1218
        return DeleteButtonFunction
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 76
diff changeset
  1219
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1220
    def AddPlugin(self, PluginType, plugin):
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1221
        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
  1222
        if dialog.ShowModal() == wx.ID_OK:
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1223
            PluginName = dialog.GetValue()
28
848ce4b1f9e4 Disabled unused run/edit menu, fixed some event/refresh machanisms
etisserant
parents: 25
diff changeset
  1224
            plugin.PlugAddChild(PluginName, PluginType, self.Log)
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 13
diff changeset
  1225
            self.RefreshPluginTree()
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1226
        dialog.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1227
    
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1228
    def DeletePlugin(self, plugin):
72
dc107daa2135 Bug on LeftPanelSizer with Windows fixed
lbessard
parents: 71
diff changeset
  1229
        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
  1230
        if dialog.ShowModal() == wx.ID_YES:
97
9c6fdf60ad2e Beremiz layout changed
lbessard
parents: 94
diff changeset
  1231
            self.PluginInfos.pop(plugin)
50
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
  1232
            plugin.PlugRemove()
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
  1233
            del plugin
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
  1234
            self.RefreshPluginTree()
447b7706a5b6 Added plugin deletion
etisserant
parents: 49
diff changeset
  1235
        dialog.Destroy()
7
e20fa7257d41 Added stdout/stderr separation limitation and coloration
etisserant
parents: 6
diff changeset
  1236
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1237
#-------------------------------------------------------------------------------
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1238
#                               Exception Handler
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1239
#-------------------------------------------------------------------------------
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1240
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1241
Max_Traceback_List_Size = 20
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1242
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1243
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1244
    trcbck_lst = []
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1245
    for i,line in enumerate(traceback.extract_tb(e_tb)):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1246
        trcbck = " " + str(i+1) + ". "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1247
        if line[0].find(os.getcwd()) == -1:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1248
            trcbck += "file : " + str(line[0]) + ",   "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1249
        else:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1250
            trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1251
        trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1252
        trcbck_lst.append(trcbck)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1253
        
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1254
    # Allow clicking....
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1255
    cap = wx.Window_GetCapture()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1256
    if cap:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1257
        cap.ReleaseMouse()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1258
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1259
    dlg = wx.SingleChoiceDialog(None, 
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1260
        """
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1261
An unhandled exception (bug) occured. Bug report saved at :
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1262
(%s)
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1263
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1264
Please be kind enough to send this file to:
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1265
bugs_beremiz@lolitech.fr
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1266
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1267
You should now restart Beremiz.
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1268
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1269
Traceback:
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1270
""" % bug_report_path +
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1271
        str(e_type) + " : " + str(e_value), 
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1272
        "Error",
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1273
        trcbck_lst)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1274
    try:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1275
        res = (dlg.ShowModal() == wx.ID_OK)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1276
    finally:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1277
        dlg.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1278
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1279
    return res
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1280
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1281
def Display_Error_Dialog(e_value):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1282
    message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1283
    message.ShowModal()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1284
    message.Destroy()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1285
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1286
def get_last_traceback(tb):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1287
    while tb.tb_next:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1288
        tb = tb.tb_next
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1289
    return tb
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1290
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1291
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1292
def format_namespace(d, indent='    '):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1293
    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
  1294
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1295
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1296
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1297
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
  1298
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1299
    
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1300
    def handle_exception(e_type, e_value, e_traceback):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1301
        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
  1302
        last_tb = get_last_traceback(e_traceback)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1303
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1304
        if str(e_value).startswith("!!!"):
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1305
            Display_Error_Dialog(e_value)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1306
        elif ex not in ignored_exceptions:
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1307
            date = time.ctime()
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1308
            bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt"
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1309
            result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1310
            if result:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1311
                ignored_exceptions.append(ex)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1312
                info = {
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1313
                    'app-title' : wx.GetApp().GetAppName(), # app_title
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1314
                    'app-version' : app_version,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1315
                    'wx-version' : wx.VERSION_STRING,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1316
                    'wx-platform' : wx.Platform,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1317
                    'python-version' : platform.python_version(), #sys.version.split()[0],
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1318
                    'platform' : platform.platform(),
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1319
                    'e-type' : e_type,
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1320
                    'e-value' : e_value,
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1321
                    'date' : date,
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1322
                    'cwd' : os.getcwd(),
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1323
                    }
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1324
                if e_traceback:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1325
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1326
                    last_tb = get_last_traceback(e_traceback)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1327
                    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
  1328
                    info['locals'] = format_namespace(exception_locals)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1329
                    if 'self' in exception_locals:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1330
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1331
                
109
f27ca37b6e7a Added enable/disable of plugin method buttons. Fixed alpha graying problem with disabled buttons. Updated debug dialog message with bug report path
etisserant
parents: 106
diff changeset
  1332
                output = open(bug_report_path,'w')
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1333
                lst = info.keys()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1334
                lst.sort()
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1335
                for a in lst:
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1336
                    output.write(a+":\n"+str(info[a])+"\n\n")
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1337
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1338
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1339
    sys.excepthook = handle_exception
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1340
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1341
if __name__ == '__main__':
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1342
    # Install a exception handle for bug reports
5
9565bb5facf7 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 4
diff changeset
  1343
    AddExceptHook(os.getcwd(),__version__)
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1344
    
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
  1345
    frame = Beremiz(None, projectOpen)
103
05b58747ca5d fix bzr.ico -> icon for windows installer
greg
parents: 102
diff changeset
  1346
    frame.Show()
133
d85b937cdac3 change splash.Hide() with splash.Close()
greg
parents: 129
diff changeset
  1347
    splash.Close()
117
32099ee16154 Added splash screen. Moved icons to /images
etisserant
parents: 116
diff changeset
  1348
0
215982c73cd6 First Beremiz commit
lbessard
parents:
diff changeset
  1349
    app.MainLoop()