Beremiz.py
author greg
Fri, 23 Oct 2009 15:41:48 +0200
changeset 427 7ac746c07ff2
parent 426 3f285782ac9b
child 428 ea09f33ce717
permissions -rw-r--r--
Check ProjectPath write permission
Manage buildpath
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     1
#!/usr/bin/env python
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     2
# -*- coding: utf-8 -*-
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     3
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     6
#
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     8
#
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
     9
#See COPYING file for copyrights details.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    10
#
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    11
#This library is free software; you can redistribute it and/or
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    12
#modify it under the terms of the GNU General Public
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    13
#License as published by the Free Software Foundation; either
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    15
#
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    16
#This library is distributed in the hope that it will be useful,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    19
#General Public License for more details.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    20
#
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    21
#You should have received a copy of the GNU General Public
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    22
#License along with this library; if not, write to the Free Software
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    24
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    25
__version__ = "$Revision$"
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    26
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    27
import os, sys, getopt, wx
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    28
import tempfile
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    29
import shutil
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    30
import random
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    31
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    32
CWD = os.path.split(os.path.realpath(__file__))[0]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    33
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    34
def Bpath(*args):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    35
    return os.path.join(CWD,*args)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    36
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    37
if __name__ == '__main__':
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    38
    def usage():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    39
        print "\nUsage of Beremiz.py :"
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    40
        print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    41
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    42
    try:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    43
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    44
    except getopt.GetoptError:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    45
        # print help information and exit:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    46
        usage()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    47
        sys.exit(2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    48
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    49
    for o, a in opts:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    50
        if o in ("-h", "--help"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    51
            usage()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    52
            sys.exit()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    53
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    54
    if len(args) > 2:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    55
        usage()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    56
        sys.exit()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    57
    elif len(args) == 1:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    58
        projectOpen = args[0]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    59
        buildpath = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    60
    elif len(args) == 2:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    61
        projectOpen = args[0]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    62
        buildpath = args[1]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    63
    else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    64
        projectOpen = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    65
        buildpath = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    66
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    67
    app = wx.PySimpleApp()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    68
    app.SetAppName('beremiz')
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    69
    wx.InitAllImageHandlers()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    70
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    71
    bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    72
    splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    73
    wx.Yield()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    74
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    75
# Import module for internationalization
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    76
import gettext
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    77
import __builtin__
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    78
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    79
# Get folder containing translation files
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    80
localedir = os.path.join(CWD,"locale")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    81
# Get the default language
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    82
langid = wx.LANGUAGE_DEFAULT
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    83
# Define translation domain (name of translation files)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    84
domain = "Beremiz"
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    85
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    86
# Define locale for wx
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    87
loc = __builtin__.__dict__.get('loc', None)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    88
if loc is None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    89
    loc = wx.Locale(langid)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    90
    __builtin__.__dict__['loc'] = loc
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    91
# Define location for searching translation files
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    92
loc.AddCatalogLookupPathPrefix(localedir)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    93
# Define locale domain
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    94
loc.AddCatalog(domain)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    95
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    96
def unicode_translation(message):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    97
    return wx.GetTranslation(message).encode("utf-8")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    98
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
    99
if __name__ == '__main__':
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   100
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   101
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   102
#Quick hack to be able to find Beremiz IEC tools. Should be config params.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   103
base_folder = os.path.split(sys.path[0])[0]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   104
sys.path.append(base_folder)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   105
sys.path.append(os.path.join(base_folder, "plcopeneditor"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   106
sys.path.append(os.path.join(base_folder, "docutils"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   107
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   108
import wx.lib.buttons, wx.lib.statbmp
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   109
import TextCtrlAutoComplete, cPickle
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   110
import types, time, re, platform, time, traceback, commands
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   111
from plugger import PluginsRoot, MATIEC_ERROR_MODEL
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   112
from wxPopen import ProcessLogger
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   113
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   114
from docutils import *
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   115
from PLCOpenEditor import IDEFrame, Viewer, AppendMenu, TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   116
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   117
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   118
SCROLLBAR_UNIT = 10
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   119
WINDOW_COLOUR = wx.Colour(240,240,240)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   120
TITLE_COLOUR = wx.Colour(200,200,220)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   121
CHANGED_TITLE_COLOUR = wx.Colour(220,200,220)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   122
CHANGED_WINDOW_COLOUR = wx.Colour(255,240,240)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   123
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   124
if wx.Platform == '__WXMSW__':
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   125
    faces = { 'times': 'Times New Roman',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   126
              'mono' : 'Courier New',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   127
              'helv' : 'Arial',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   128
              'other': 'Comic Sans MS',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   129
              'size' : 16,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   130
             }
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   131
else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   132
    faces = { 'times': 'Times',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   133
              'mono' : 'Courier',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   134
              'helv' : 'Helvetica',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   135
              'other': 'new century schoolbook',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   136
              'size' : 18,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   137
             }
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   138
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   139
# Some helpers to tweak GenBitmapTextButtons
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   140
# TODO: declare customized classes instead.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   141
gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   142
gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   143
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   144
def make_genbitmaptogglebutton_flat(button):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   145
    button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   146
    button.labelDelta = 0
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   147
    button.SetBezelWidth(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   148
    button.SetUseFocusIndicator(False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   149
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   150
# Patch wx.lib.imageutils so that gray is supported on alpha images
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   151
import wx.lib.imageutils
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   152
from wx.lib.imageutils import grayOut as old_grayOut
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   153
def grayOut(anImage):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   154
    if anImage.HasAlpha():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   155
        AlphaData = anImage.GetAlphaData()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   156
    else :
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   157
        AlphaData = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   158
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   159
    old_grayOut(anImage)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   160
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   161
    if AlphaData is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   162
        anImage.SetAlphaData(AlphaData)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   163
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   164
wx.lib.imageutils.grayOut = grayOut
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   165
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   166
class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   167
    def _GetLabelSize(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   168
        """ used internally """
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   169
        w, h = self.GetTextExtent(self.GetLabel())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   170
        if not self.bmpLabel:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   171
            return w, h, False       # if there isn't a bitmap use the size of the text
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   172
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   173
        w_bmp = self.bmpLabel.GetWidth()+2
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   174
        h_bmp = self.bmpLabel.GetHeight()+2
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   175
        height = h + h_bmp
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   176
        if w_bmp > w:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   177
            width = w_bmp
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   178
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   179
            width = w
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   180
        return width, height, False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   181
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   182
    def DrawLabel(self, dc, width, height, dw=0, dy=0):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   183
        bmp = self.bmpLabel
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   184
        if bmp != None:     # if the bitmap is used
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   185
            if self.bmpDisabled and not self.IsEnabled():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   186
                bmp = self.bmpDisabled
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   187
            if self.bmpFocus and self.hasFocus:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   188
                bmp = self.bmpFocus
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   189
            if self.bmpSelected and not self.up:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   190
                bmp = self.bmpSelected
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   191
            bw,bh = bmp.GetWidth(), bmp.GetHeight()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   192
            if not self.up:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   193
                dw = dy = self.labelDelta
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   194
            hasMask = bmp.GetMask() != None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   195
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   196
            bw = bh = 0     # no bitmap -> size is zero
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   197
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   198
        dc.SetFont(self.GetFont())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   199
        if self.IsEnabled():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   200
            dc.SetTextForeground(self.GetForegroundColour())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   201
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   202
            dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   203
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   204
        label = self.GetLabel()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   205
        tw, th = dc.GetTextExtent(label)        # size of text
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   206
        if not self.up:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   207
            dw = dy = self.labelDelta
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   208
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   209
        pos_x = (width-bw)/2+dw      # adjust for bitmap and text to centre
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   210
        pos_y = (height-bh-th)/2+dy
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   211
        if bmp !=None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   212
            dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   213
            pos_x = (width-tw)/2+dw      # adjust for bitmap and text to centre
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   214
            pos_y += bh + 2
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   215
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   216
        dc.DrawText(label, pos_x, pos_y)      # draw the text
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   217
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   218
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   219
class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   220
    """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   221
    and accept image name as __init__ parameter, fail silently if file do not exist"""
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   222
    def __init__(self, parent, ID, bitmapname,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   223
                 pos = wx.DefaultPosition, size = wx.DefaultSize,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   224
                 style = 0,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   225
                 name = "genstatbmp"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   226
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   227
        bitmappath = Bpath( "images", bitmapname)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   228
        if os.path.isfile(bitmappath):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   229
            bitmap = wx.Bitmap(bitmappath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   230
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   231
            bitmap = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   232
        wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   233
                 pos, size,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   234
                 style,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   235
                 name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   236
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   237
    def OnPaint(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   238
        dc = wx.PaintDC(self)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   239
        colour = self.GetParent().GetBackgroundColour()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   240
        dc.SetPen(wx.Pen(colour))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   241
        dc.SetBrush(wx.Brush(colour ))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   242
        dc.DrawRectangle(0, 0, *dc.GetSizeTuple())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   243
        if self._bitmap:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   244
            dc.DrawBitmap(self._bitmap, 0, 0, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   245
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   246
                        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   247
class LogPseudoFile:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   248
    """ Base class for file like objects to facilitate StdOut for the Shell."""
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   249
    def __init__(self, output):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   250
        self.red_white = wx.TextAttr("RED", "WHITE")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   251
        self.red_yellow = wx.TextAttr("RED", "YELLOW")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   252
        self.black_white = wx.TextAttr("BLACK", "WHITE")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   253
        self.default_style = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   254
        self.output = output
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   255
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   256
    def write(self, s, style = None):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   257
        if style is None : style=self.black_white
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   258
        self.output.Freeze(); 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   259
        if self.default_style != style: 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   260
            self.output.SetDefaultStyle(style)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   261
            self.default_style = style
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   262
        self.output.AppendText(s)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   263
        self.output.ScrollLines(s.count('\n')+1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   264
        self.output.ShowPosition(self.output.GetLastPosition())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   265
        self.output.Thaw()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   266
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   267
    def write_warning(self, s):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   268
        self.write(s,self.red_white)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   269
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   270
    def write_error(self, s):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   271
        self.write(s,self.red_yellow)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   272
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   273
    def flush(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   274
        self.output.SetValue("")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   275
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   276
    def isatty(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   277
        return false
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   278
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   279
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   280
 ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   281
 ID_BEREMIZINSPECTOR] = [wx.NewId() for _init_ctrls in range(5)]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   282
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   283
[ID_BEREMIZRUNMENUBUILD, ID_BEREMIZRUNMENUSIMULATE, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   284
 ID_BEREMIZRUNMENURUN, ID_BEREMIZRUNMENUSAVELOG, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   285
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   286
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   287
class Beremiz(IDEFrame):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   288
	
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   289
    def _init_coll_FileMenu_Items(self, parent):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   290
        AppendMenu(parent, help='', id=wx.ID_NEW,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   291
              kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   292
        AppendMenu(parent, help='', id=wx.ID_OPEN,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   293
              kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   294
        AppendMenu(parent, help='', id=wx.ID_SAVE,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   295
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
   296
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
   297
              kind=wx.ITEM_NORMAL, text=_(u'Save as\tCTRL+S'))
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   298
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   299
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   300
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   301
              kind=wx.ITEM_NORMAL, text=_(u'Close Project'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   302
        parent.AppendSeparator()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   303
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   304
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   305
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   306
              kind=wx.ITEM_NORMAL, text=_(u'Preview'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   307
        AppendMenu(parent, help='', id=wx.ID_PRINT,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   308
              kind=wx.ITEM_NORMAL, text=_(u'Print'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   309
        parent.AppendSeparator()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   310
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   311
              kind=wx.ITEM_NORMAL, text=_(u'Properties'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   312
        parent.AppendSeparator()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   313
        AppendMenu(parent, help='', id=wx.ID_EXIT,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   314
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   315
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   316
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   317
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   318
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
   319
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   320
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   321
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   322
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   323
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   324
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   325
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   326
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   327
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   328
    def _init_coll_HelpMenu_Items(self, parent):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   329
        parent.Append(help='', id=wx.ID_HELP,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   330
              kind=wx.ITEM_NORMAL, text=_(u'Beremiz\tF1'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   331
        parent.Append(help='', id=wx.ID_ABOUT,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   332
              kind=wx.ITEM_NORMAL, text=_(u'About'))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   333
        self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   334
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   335
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   336
    def _init_coll_PLCConfigMainSizer_Items(self, parent):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   337
        parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   338
        parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   339
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   340
    def _init_coll_PLCConfigMainSizer_Growables(self, parent):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   341
        parent.AddGrowableCol(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   342
        parent.AddGrowableRow(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   343
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   344
    def _init_coll_PluginTreeSizer_Growables(self, parent):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   345
        parent.AddGrowableCol(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   346
        parent.AddGrowableCol(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   347
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   348
    def _init_beremiz_sizers(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   349
        self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   350
        self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   351
        #self.PluginTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   352
        self.PluginTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   353
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   354
        self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   355
        self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   356
        self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   357
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   358
        self.PLCConfig.SetSizer(self.PLCConfigMainSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   359
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   360
    def _init_ctrls(self, prnt):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   361
        IDEFrame._init_ctrls(self, prnt)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   362
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   363
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   364
        accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   365
        self.SetAcceleratorTable(accel)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   366
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   367
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   368
              name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   369
              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   370
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   371
        self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   372
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   373
        self.PLCConfig.Bind(wx.EVT_MOUSEWHEEL, self.OnPLCConfigScroll)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   374
        self.BottomNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   375
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   376
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   377
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   378
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   379
        self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   380
        self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   381
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   382
        self._init_beremiz_sizers()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   383
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   384
    def __init__(self, parent, projectOpen=None, buildpath=None, plugin_root=None, debug=True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   385
        IDEFrame.__init__(self, parent, debug)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   386
        self.Config = wx.ConfigBase.Get()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   387
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   388
        self.Log = LogPseudoFile(self.LogConsole)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   389
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   390
        self.local_runtime = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   391
        self.runtime_port = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   392
        self.local_runtime_tmpdir = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   393
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   394
        self.DisableEvents = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   395
        # Variable allowing disabling of PLCConfig scroll when Popup shown 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   396
        self.ScrollingEnabled = True
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   397
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   398
        self.PluginInfos = {}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   399
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   400
        if projectOpen is not None and os.path.isdir(projectOpen):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   401
            self.PluginRoot = PluginsRoot(self, self.Log)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   402
            self.Controler = self.PluginRoot
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   403
            result = self.PluginRoot.LoadProject(projectOpen, buildpath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   404
            if not result:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   405
                self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   406
                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   407
                self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   408
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   409
                self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   410
                self.ShowErrorMessage(result)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   411
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   412
            self.PluginRoot = plugin_root
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   413
            self.Controler = plugin_root
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   414
            if plugin_root is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   415
                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   416
                self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   417
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   418
        # Add beremiz's icon in top left corner of the frame
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   419
        self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   420
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   421
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   422
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   423
        self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   424
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   425
    def RefreshTitle(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   426
        name = _("Beremiz")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   427
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   428
            projectname = self.PluginRoot.GetProjectName()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   429
            if self.PluginRoot.PlugTestModified():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   430
                projectname = "~%s~" % projectname
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   431
            self.SetTitle("%s - %s" % (name, projectname))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   432
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   433
            self.SetTitle(name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   434
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   435
    def StartLocalRuntime(self, taskbaricon = True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   436
        if self.local_runtime is None or self.local_runtime.finished:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   437
            # create temporary directory for runtime working directory
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   438
            self.local_runtime_tmpdir = tempfile.mkdtemp()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   439
            # choose an arbitrary random port for runtime
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   440
            self.runtime_port = int(random.random() * 1000) + 61131
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   441
            # launch local runtime
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   442
            self.local_runtime = ProcessLogger(self.Log,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   443
                                               "\"%s\" \"%s\" -p %s -i localhost %s %s"%(sys.executable,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   444
                                                           Bpath("Beremiz_service.py"),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   445
                                                           self.runtime_port,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   446
                                                           {False : "-x 0", True :"-x 1"}[taskbaricon],
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   447
                                                           self.local_runtime_tmpdir),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   448
                                                           no_gui=False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   449
            self.local_runtime.spin(timeout=500, keyword = "working", kill_it = False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   450
        return self.runtime_port
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   451
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   452
    def KillLocalRuntime(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   453
        if self.local_runtime is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   454
            # shutdown local runtime
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   455
            self.local_runtime.kill(gently=False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   456
            # clear temp dir
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   457
            shutil.rmtree(self.local_runtime_tmpdir)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   458
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   459
    def OnOpenWidgetInspector(self, evt):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   460
        # Activate the widget inspection tool
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   461
        from wx.lib.inspection import InspectionTool
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   462
        if not InspectionTool().initialized:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   463
            InspectionTool().Init()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   464
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   465
        # Find a widget to be selected in the tree.  Use either the
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   466
        # one under the cursor, if any, or this frame.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   467
        wnd = wx.FindWindowAtPointer()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   468
        if not wnd:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   469
            wnd = self
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   470
        InspectionTool().Show(wnd, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   471
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   472
    def OnLogConsoleDClick(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   473
        wx.CallAfter(self.SearchLineForError)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   474
        event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   475
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   476
    def SearchLineForError(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   477
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   478
            text = self.LogConsole.GetRange(0, self.LogConsole.GetInsertionPoint())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   479
            line = self.LogConsole.GetLineText(len(text.splitlines()) - 1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   480
            result = MATIEC_ERROR_MODEL.match(line)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   481
            if result is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   482
                first_line, first_column, last_line, last_column, error = result.groups()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   483
                infos = self.PluginRoot.ShowError(self.Log,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   484
                                                  (int(first_line), int(first_column)), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   485
                                                  (int(last_line), int(last_column)))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   486
		
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   487
    def OnCloseFrame(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   488
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   489
            if self.PluginRoot.ProjectTestModified():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   490
                dialog = wx.MessageDialog(self,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   491
                                          _("Save changes ?"),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   492
                                          _("Close Application"), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   493
                                          wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   494
                answer = dialog.ShowModal()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   495
                dialog.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   496
                if answer == wx.ID_YES:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   497
                    self.PluginRoot.SaveProject()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   498
                    event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   499
                elif answer == wx.ID_NO:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   500
                    event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   501
                    return
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   502
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   503
                    event.Veto()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   504
                    return
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   505
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   506
        self.KillLocalRuntime()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   507
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   508
        event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   509
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   510
    def OnMoveWindow(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   511
        self.GetBestSize()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   512
        self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   513
        event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   514
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   515
    def EnableScrolling(self, enable):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   516
        self.ScrollingEnabled = enable
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   517
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   518
    def OnPLCConfigScroll(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   519
        if self.ScrollingEnabled:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   520
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   521
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   522
    def OnPanelLeftDown(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   523
        focused = self.FindFocus()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   524
        if isinstance(focused, TextCtrlAutoComplete.TextCtrlAutoComplete):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   525
            focused.DismissListBox()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   526
        event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   527
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   528
    def RefreshFileMenu(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   529
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   530
            selected = self.TabsOpened.GetSelection()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   531
            if selected >= 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   532
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   533
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   534
                graphic_viewer = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   535
            if self.TabsOpened.GetPageCount() > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   536
                self.FileMenu.Enable(wx.ID_CLOSE, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   537
                if graphic_viewer:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   538
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   539
                    self.FileMenu.Enable(wx.ID_PRINT, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   540
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   541
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   542
                    self.FileMenu.Enable(wx.ID_PRINT, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   543
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   544
                self.FileMenu.Enable(wx.ID_CLOSE, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   545
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   546
                self.FileMenu.Enable(wx.ID_PRINT, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   547
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   548
            self.FileMenu.Enable(wx.ID_SAVE, True)
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
   549
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   550
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   551
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   552
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   553
            self.FileMenu.Enable(wx.ID_CLOSE, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   554
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   555
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   556
            self.FileMenu.Enable(wx.ID_PRINT, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   557
            self.FileMenu.Enable(wx.ID_SAVE, False)
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
   558
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   559
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   560
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   561
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   562
    def RefreshScrollBars(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   563
        xstart, ystart = self.PLCConfig.GetViewStart()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   564
        window_size = self.PLCConfig.GetClientSize()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   565
        sizer = self.PLCConfig.GetSizer()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   566
        if sizer:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   567
            maxx, maxy = sizer.GetMinSize()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   568
            self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   569
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   570
                max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   571
                max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   572
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   573
    def RefreshPLCParams(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   574
        self.Freeze()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   575
        self.ClearSizer(self.PLCParamsSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   576
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   577
        if self.PluginRoot is not None:    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   578
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   579
            if self.PluginRoot.PlugTestModified():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   580
                bkgdclr = CHANGED_TITLE_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   581
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   582
                bkgdclr = TITLE_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   583
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   584
            if self.PluginRoot not in self.PluginInfos:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   585
                self.PluginInfos[self.PluginRoot] = {"right_visible" : False}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   586
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   587
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   588
            plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   589
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   590
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   591
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   592
            plcwindow.SetSizer(plcwindowsizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   593
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   594
            st = wx.StaticText(plcwindow, -1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   595
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   596
            st.SetLabel(self.PluginRoot.GetProjectName())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   597
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   598
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   599
            addbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   600
            addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   601
                  name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   602
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   603
            addbutton.SetToolTipString(_("Add a sub plugin"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   604
            addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   605
            plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   606
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   607
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   608
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   609
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   610
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   611
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   612
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   613
            msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   614
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   615
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   616
            paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   617
            paramswindow.SetBackgroundColour(TITLE_COLOUR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   618
            paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   619
            plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   620
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   621
            psizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   622
            paramswindow.SetSizer(psizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   623
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   624
            plugin_infos = self.PluginRoot.GetParamsAttributes()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   625
            self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   626
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   627
            if not self.PluginInfos[self.PluginRoot]["right_visible"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   628
                paramswindow.Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   629
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   630
            minimizebutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   631
            minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   632
                  name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   633
                  size=wx.Size(24, 24), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   634
            make_genbitmaptogglebutton_flat(minimizebutton)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   635
            minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   636
            minimizebutton.SetToggle(self.PluginInfos[self.PluginRoot]["right_visible"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   637
            plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   638
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   639
            def togglewindow(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   640
                if minimizebutton.GetToggle():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   641
                    paramswindow.Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   642
                    msizer.SetCols(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   643
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   644
                    paramswindow.Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   645
                    msizer.SetCols(len(self.PluginRoot.PluginMethods))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   646
                self.PluginInfos[self.PluginRoot]["right_visible"] = minimizebutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   647
                self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   648
                self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   649
                event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   650
            minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   651
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   652
            self.PluginInfos[self.PluginRoot]["main"] = plcwindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   653
            self.PluginInfos[self.PluginRoot]["params"] = paramswindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   654
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   655
        self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   656
        self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   657
        self.Thaw()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   658
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   659
    def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   660
        normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   661
        mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   662
        if horizontal:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   663
            msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   664
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   665
            msizer = wx.FlexGridSizer(cols=1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   666
        for plugin_method in plugin.PluginMethods:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   667
            if "method" in plugin_method and plugin_method.get("shown",True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   668
                id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   669
                label = plugin_method["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   670
                button = GenBitmapTextButton(id=id, parent=parent,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   671
                    bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   672
                    name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   673
                button.SetFont(normal_bt_font)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   674
                button.SetToolTipString(plugin_method["tooltip"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   675
                button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   676
                # a fancy underline on mouseover
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   677
                def setFontStyle(b, s):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   678
                    def fn(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   679
                        b.SetFont(s)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   680
                        b.Refresh()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   681
                        event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   682
                    return fn
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   683
                button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   684
                button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   685
                #hack to force size to mini
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   686
                if not plugin_method.get("enabled",True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   687
                    button.Disable()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   688
                msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   689
        return msizer
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   690
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   691
    def RefreshPluginTree(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   692
        self.Freeze()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   693
        self.ClearSizer(self.PluginTreeSizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   694
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   695
            for child in self.PluginRoot.IECSortedChilds():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   696
                self.GenerateTreeBranch(child)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   697
                if not self.PluginInfos[child]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   698
                    self.CollapsePlugin(child)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   699
        self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   700
        self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   701
        self.Thaw()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   702
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   703
    def SetPluginParamsAttribute(self, plugin, *args, **kwargs):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   704
        res, StructChanged = plugin.SetParamsAttribute(*args, **kwargs)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   705
        if StructChanged:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   706
            wx.CallAfter(self.RefreshPluginTree)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   707
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   708
            if plugin == self.PluginRoot:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   709
                bkgdclr = CHANGED_TITLE_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   710
                items = ["main", "params"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   711
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   712
                bkgdclr = CHANGED_WINDOW_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   713
                items = ["left", "right", "params"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   714
            for i in items:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   715
                self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   716
                self.PluginInfos[plugin][i].Refresh()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   717
        return res
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   718
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   719
    def ExpandPlugin(self, plugin, force = False):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   720
        for child in self.PluginInfos[plugin]["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   721
            self.PluginInfos[child]["left"].Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   722
            self.PluginInfos[child]["right"].Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   723
            if force or not self.PluginInfos[child]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   724
                self.ExpandPlugin(child, force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   725
                if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   726
                    self.PluginInfos[child]["expanded"] = True
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   727
        locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   728
        if locations_infos is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   729
            if force or locations_infos["root"]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   730
                self.ExpandLocation(locations_infos, "root", force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   731
                if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   732
                    locations_infos["root"]["expanded"] = True
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   733
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   734
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   735
    def CollapsePlugin(self, plugin, force = False):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   736
        for child in self.PluginInfos[plugin]["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   737
            self.PluginInfos[child]["left"].Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   738
            self.PluginInfos[child]["right"].Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   739
            self.CollapsePlugin(child, force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   740
            if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   741
                self.PluginInfos[child]["expanded"] = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   742
        locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   743
        if locations_infos is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   744
            self.CollapseLocation(locations_infos, "root", force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   745
            if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   746
                locations_infos["root"]["expanded"] = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   747
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   748
    def ExpandLocation(self, locations_infos, group, force = False):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   749
        for child in locations_infos[group]["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   750
            locations_infos[child]["left"].Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   751
            locations_infos[child]["right"].Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   752
            if force or locations_infos[child]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   753
                self.ExpandLocation(locations_infos, child, force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   754
                if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   755
                    locations_infos[child]["expanded"] = True
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   756
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   757
    def CollapseLocation(self, locations_infos, group, force = False):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   758
        for child in locations_infos[group]["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   759
            locations_infos[child]["left"].Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   760
            locations_infos[child]["right"].Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   761
            self.CollapseLocation(locations_infos, child, force)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   762
            if force:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   763
                locations_infos[child]["expanded"] = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   764
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   765
    def GenerateTreeBranch(self, plugin):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   766
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   767
        if plugin.PlugTestModified():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   768
            bkgdclr=CHANGED_WINDOW_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   769
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   770
            bkgdclr=WINDOW_COLOUR
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   771
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   772
        leftwindow.SetBackgroundColour(bkgdclr)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   773
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   774
        if not self.PluginInfos.has_key(plugin):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   775
            self.PluginInfos[plugin] = {"expanded" : False, "right_visible" : False}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   776
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   777
        self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   778
        plugin_locations = []
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   779
        if len(self.PluginInfos[plugin]["children"]) == 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   780
            plugin_locations = plugin.GetVariableLocationTree()["children"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   781
            if not self.PluginInfos[plugin].has_key("locations_infos"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   782
                self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   783
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   784
            self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   785
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   786
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   787
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   788
        leftwindowsizer = wx.FlexGridSizer(cols=1, rows=2)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   789
        leftwindowsizer.AddGrowableCol(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   790
        leftwindow.SetSizer(leftwindowsizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   791
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   792
        leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   793
        leftbuttonmainsizer.AddGrowableCol(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   794
        leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) #|wx.TOP
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   795
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   796
        leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   797
        leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=5, flag=wx.GROW|wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   798
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   799
        leftsizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   800
        leftbuttonsizer.AddSizer(leftsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   801
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   802
        rolesizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   803
        leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   804
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   805
        enablebutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   806
        enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   807
              name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   808
        enablebutton.SetToolTipString(_("Enable/Disable this plugin"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   809
        make_genbitmaptogglebutton_flat(enablebutton)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   810
        enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png')))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   811
        enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   812
        def toggleenablebutton(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   813
            res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   814
            enablebutton.SetToggle(res)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   815
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   816
        enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   817
        rolesizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   818
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   819
        roletext = wx.StaticText(leftwindow, -1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   820
        roletext.SetLabel(plugin.PlugHelp)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   821
        rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   822
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   823
        plugin_IECChannel = plugin.BaseParams.getIEC_Channel()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   824
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   825
        iecsizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   826
        leftsizer.AddSizer(iecsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   827
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   828
        st = wx.StaticText(leftwindow, -1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   829
        st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   830
        st.SetLabel(plugin.GetFullIEC_Channel())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   831
        iecsizer.AddWindow(st, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   832
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   833
        updownsizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   834
        iecsizer.AddSizer(updownsizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   835
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   836
        if plugin_IECChannel > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   837
            ieccdownbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   838
            ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCDown.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   839
                  name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   840
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   841
            ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   842
            updownsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_LEFT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   843
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   844
        ieccupbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   845
        ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCUp.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   846
              name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   847
              size=wx.Size(16, 16), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   848
        ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel + 1), id=ieccupbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   849
        updownsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_LEFT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   850
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   851
        adddeletesizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   852
        iecsizer.AddSizer(adddeletesizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   853
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   854
        deletebutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   855
        deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   856
              name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   857
              size=wx.Size(16, 16), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   858
        deletebutton.SetToolTipString(_("Delete this plugin"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   859
        deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   860
        adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   861
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   862
        if len(plugin.PlugChildsTypes) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   863
            addbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   864
            addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   865
                  name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   866
                  size=wx.Size(16, 16), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   867
            addbutton.SetToolTipString(_("Add a sub plugin"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   868
            addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   869
            adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   870
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   871
        expandbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   872
        expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   873
              name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   874
              size=wx.Size(13, 13), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   875
        expandbutton.labelDelta = 0
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   876
        expandbutton.SetBezelWidth(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   877
        expandbutton.SetUseFocusIndicator(False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   878
        expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   879
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   880
        if len(self.PluginInfos[plugin]["children"]) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   881
            expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   882
            def togglebutton(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   883
                if expandbutton.GetToggle():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   884
                    self.ExpandPlugin(plugin)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   885
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   886
                    self.CollapsePlugin(plugin)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   887
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   888
                self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   889
                self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   890
                event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   891
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   892
        elif len(plugin_locations) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   893
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   894
            expandbutton.SetToggle(locations_infos["root"]["expanded"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   895
            def togglebutton(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   896
                if expandbutton.GetToggle():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   897
                    self.ExpandLocation(locations_infos, "root")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   898
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   899
                    self.CollapseLocation(locations_infos, "root")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   900
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   901
                locations_infos["root"]["expanded"] = expandbutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   902
                self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   903
                self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   904
                event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   905
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   906
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   907
            expandbutton.Enable(False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   908
        iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   909
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   910
        tc_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   911
        tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 25), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   912
        tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   913
        tc.ChangeValue(plugin.MandatoryParams[1].getName())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   914
        tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   915
        iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   916
       
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   917
        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   918
        rightwindow.SetBackgroundColour(bkgdclr)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   919
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   920
        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   921
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   922
        rightwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   923
        rightwindow.SetSizer(rightwindowmainsizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   924
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   925
        rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   926
        rightwindowsizer.AddGrowableCol(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   927
        rightwindowsizer.AddGrowableRow(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   928
        rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=8, flag=wx.TOP|wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   929
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   930
        msizer = self.GenerateMethodButtonSizer(plugin, rightwindow, not self.PluginInfos[plugin]["right_visible"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   931
        rightwindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   932
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   933
        rightparamssizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   934
        rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   935
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   936
        paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   937
        paramswindow.SetBackgroundColour(bkgdclr)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   938
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   939
        psizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   940
        paramswindow.SetSizer(psizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   941
        self.PluginInfos[plugin]["params"] = paramswindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   942
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   943
        rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   944
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   945
        plugin_infos = plugin.GetParamsAttributes()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   946
        self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   947
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   948
        if not self.PluginInfos[plugin]["right_visible"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   949
            paramswindow.Hide()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   950
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   951
        rightminimizebutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   952
        rightminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=rightminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   953
              name='MinimizeButton', parent=rightwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   954
              size=wx.Size(24, 24), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   955
        make_genbitmaptogglebutton_flat(rightminimizebutton)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   956
        rightminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   957
        rightminimizebutton.SetToggle(self.PluginInfos[plugin]["right_visible"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   958
        rightparamssizer.AddWindow(rightminimizebutton, 0, border=5, flag=wx.ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   959
                    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   960
        def togglerightwindow(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   961
            if rightminimizebutton.GetToggle():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   962
                rightparamssizer.Show(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   963
                msizer.SetCols(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   964
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   965
                rightparamssizer.Hide(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   966
                msizer.SetCols(len(plugin.PluginMethods))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   967
            self.PluginInfos[plugin]["right_visible"] = rightminimizebutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   968
            self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   969
            self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   970
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   971
        rightminimizebutton.Bind(wx.EVT_BUTTON, togglerightwindow, id=rightminimizebutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   972
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   973
        self.PluginInfos[plugin]["left"] = leftwindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   974
        self.PluginInfos[plugin]["right"] = rightwindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   975
        for child in self.PluginInfos[plugin]["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   976
            self.GenerateTreeBranch(child)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   977
            if not self.PluginInfos[child]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   978
                self.CollapsePlugin(child)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   979
        if len(plugin_locations) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   980
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   981
            for location in plugin_locations:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   982
                locations_infos["root"]["children"].append("root.%s" % location["name"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   983
                self.GenerateLocationTreeBranch(locations_infos, "root", location)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   984
            if not locations_infos["root"]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   985
                self.CollapseLocation(locations_infos, "root")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   986
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   987
    LOCATION_BITMAP = {LOCATION_PLUGIN: "CONFIGURATION",
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   988
                       LOCATION_MODULE: "RESOURCE",
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   989
                       LOCATION_GROUP: "PROGRAM",
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   990
                       LOCATION_VAR_INPUT: "VAR_INPUT",
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   991
                       LOCATION_VAR_OUTPUT: "VAR_OUTPUT",
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   992
                       LOCATION_VAR_MEMORY: "VAR_LOCAL"}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   993
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   994
    def GenerateLocationTreeBranch(self, locations_infos, parent, location):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   995
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   996
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   997
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   998
        leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
   999
        leftwindow.SetSizer(leftwindowsizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1000
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1001
        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1002
        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1003
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1004
        location_name = "%s.%s" % (parent, location["name"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1005
        if not locations_infos.has_key(location_name):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1006
            locations_infos[location_name] = {"expanded" : False}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1007
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1008
        if location["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1009
            leftwindow.SetBackgroundColour(WINDOW_COLOUR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1010
            rightwindow.SetBackgroundColour(WINDOW_COLOUR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1011
                    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1012
            st = wx.StaticText(leftwindow, -1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1013
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1014
            st.SetLabel(location["location"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1015
            leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1016
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1017
            expandbutton_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1018
            expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1019
                  name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1020
                  size=wx.Size(13, 13), style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1021
            expandbutton.labelDelta = 0
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1022
            expandbutton.SetBezelWidth(0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1023
            expandbutton.SetUseFocusIndicator(False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1024
            expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1025
            expandbutton.SetToggle(locations_infos[location_name]["expanded"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1026
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1027
            if len(location["children"]) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1028
                def togglebutton(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1029
                    if expandbutton.GetToggle():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1030
                        self.ExpandLocation(locations_infos, location_name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1031
                    else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1032
                        self.CollapseLocation(locations_infos, location_name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1033
                    locations_infos[location_name]["expanded"] = expandbutton.GetToggle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1034
                    self.PLCConfigMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1035
                    self.RefreshScrollBars()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1036
                    event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1037
                expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1038
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1039
                expandbutton.Enable(False)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1040
            leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1041
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1042
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1043
            leftwindow.SetBackgroundColour(wx.WHITE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1044
            rightwindow.SetBackgroundColour(wx.WHITE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1045
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1046
            leftwindowsizer.Add(wx.Size(20, 16), 0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1047
            
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1048
        sb = wx.StaticBitmap(leftwindow, -1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1049
        sb.SetBitmap(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[location["type"]])))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1050
        leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1051
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1052
        st_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1053
        st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1054
        label = location["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1055
        if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1056
            label += " (%s)" % location["location"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1057
            infos = location.copy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1058
            infos.pop("children")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1059
            st.SetFont(wx.Font(faces["size"] * 0.5, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1060
            st.Bind(wx.EVT_LEFT_DOWN, self.GenerateLocationLeftDownFunction(infos))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1061
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1062
            st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1063
        st.SetLabel(label)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1064
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1065
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1066
        locations_infos[location_name]["left"] = leftwindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1067
        locations_infos[location_name]["right"] = rightwindow
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1068
        locations_infos[location_name]["children"] = []
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1069
        for child in location["children"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1070
            child_name = "%s.%s" % (location_name, child["name"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1071
            locations_infos[location_name]["children"].append(child_name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1072
            self.GenerateLocationTreeBranch(locations_infos, location_name, child)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1073
        if not locations_infos[location_name]["expanded"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1074
            self.CollapseLocation(locations_infos, location_name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1075
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1076
    def GenerateLocationLeftDownFunction(self, infos):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1077
        def OnLocationLeftDownFunction(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1078
            data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["name"], infos["description"])))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1079
            dragSource = wx.DropSource(self)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1080
            dragSource.SetData(data)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1081
            dragSource.DoDragDrop()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1082
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1083
        return OnLocationLeftDownFunction
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1084
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1085
    def RefreshAll(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1086
        self.RefreshPLCParams()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1087
        self.RefreshPluginTree()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1088
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1089
    def GetItemChannelChangedFunction(self, plugin, value):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1090
        def OnPluginTreeItemChannelChanged(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1091
            res = self.SetPluginParamsAttribute(plugin, "BaseParams.IEC_Channel", value)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1092
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1093
        return OnPluginTreeItemChannelChanged
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1094
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1095
    def _GetAddPluginFunction(self, name, plugin):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1096
        def OnPluginMenu(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1097
            wx.CallAfter(self.AddPlugin, name, plugin)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1098
        return OnPluginMenu
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1099
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1100
    def Gen_AddPluginMenu(self, plugin):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1101
        def AddPluginMenu(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1102
            main_menu = wx.Menu(title='')
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1103
            if len(plugin.PlugChildsTypes) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1104
                for name, XSDClass, help in plugin.PlugChildsTypes:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1105
                    new_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1106
                    main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1107
                    self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1108
            self.PopupMenuXY(main_menu)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1109
        return AddPluginMenu
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1110
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1111
    def GetButtonCallBackFunction(self, plugin, method):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1112
        """ Generate the callbackfunc for a given plugin method"""
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1113
        def OnButtonClick(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1114
            # Disable button to prevent re-entrant call 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1115
            event.GetEventObject().Disable()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1116
            # Call
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1117
            getattr(plugin,method)()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1118
            # Re-enable button 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1119
            event.GetEventObject().Enable()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1120
            # Trigger refresh on Idle
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1121
            wx.CallAfter(self.RefreshAll)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1122
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1123
        return OnButtonClick
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1124
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1125
    def GetChoiceCallBackFunction(self, choicectrl, plugin, path):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1126
        def OnChoiceChanged(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1127
            res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1128
            choicectrl.SetStringSelection(res)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1129
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1130
        return OnChoiceChanged
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1131
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1132
    def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1133
        def OnChoiceContentChanged(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1134
            res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1135
            if wx.VERSION < (2, 8, 0):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1136
                self.ParamsPanel.Freeze()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1137
                choicectrl.SetStringSelection(res)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1138
                infos = self.PluginRoot.GetParamsAttributes(path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1139
                staticbox = staticboxsizer.GetStaticBox()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1140
                staticbox.SetLabel("%(name)s - %(value)s"%infos)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1141
                self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1142
                self.ParamsPanelMainSizer.Layout()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1143
                self.ParamsPanel.Thaw()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1144
                self.ParamsPanel.Refresh()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1145
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1146
                wx.CallAfter(self.RefreshAll)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1147
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1148
        return OnChoiceContentChanged
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1149
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1150
    def GetTextCtrlCallBackFunction(self, textctrl, plugin, path):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1151
        def OnTextCtrlChanged(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1152
            res = self.SetPluginParamsAttribute(plugin, path, textctrl.GetValue())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1153
            if res != textctrl.GetValue():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1154
                textctrl.ChangeValue(res)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1155
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1156
        return OnTextCtrlChanged
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1157
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1158
    def GetCheckBoxCallBackFunction(self, chkbx, plugin, path):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1159
        def OnCheckBoxChanged(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1160
            res = self.SetPluginParamsAttribute(plugin, path, chkbx.IsChecked())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1161
            chkbx.SetValue(res)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1162
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1163
        return OnCheckBoxChanged
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1164
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1165
    def ClearSizer(self, sizer):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1166
        staticboxes = []
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1167
        for item in sizer.GetChildren():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1168
            if item.IsSizer():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1169
                item_sizer = item.GetSizer()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1170
                self.ClearSizer(item_sizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1171
                if isinstance(item_sizer, wx.StaticBoxSizer):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1172
                    staticboxes.append(item_sizer.GetStaticBox())
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1173
        sizer.Clear(True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1174
        for staticbox in staticboxes:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1175
            staticbox.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1176
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1177
    def RefreshSizerElement(self, parent, sizer, plugin, elements, path, clean = True):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1178
        if clean:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1179
            if wx.VERSION < (2, 8, 0):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1180
                self.ClearSizer(sizer)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1181
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1182
                sizer.Clear(True)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1183
        first = True
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1184
        for element_infos in elements:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1185
            if path:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1186
                element_path = "%s.%s"%(path, element_infos["name"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1187
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1188
                element_path = element_infos["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1189
            if element_infos["type"] == "element":
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1190
                label = element_infos["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1191
                staticbox = wx.StaticBox(id=-1, label=_(label), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1192
                    name='%s_staticbox'%element_infos["name"], parent=parent,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1193
                    pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1194
                staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1195
                if first:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1196
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1197
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1198
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1199
                self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1200
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1201
                boxsizer = wx.FlexGridSizer(cols=3, rows=1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1202
                boxsizer.AddGrowableCol(1)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1203
                if first:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1204
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1205
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1206
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1207
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1208
                    name="%s_bitmap"%element_infos["name"], parent=parent,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1209
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1210
                boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1211
                label = element_infos["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1212
                statictext = wx.StaticText(id=-1, label="%s:"%_(label), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1213
                    name="%s_label"%element_infos["name"], parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1214
                    pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1215
                boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1216
                id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1217
                if isinstance(element_infos["type"], types.ListType):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1218
                    combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1219
                        pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1220
                    boxsizer.AddWindow(combobox, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1221
                    if element_infos["use"] == "optional":
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1222
                        combobox.Append("")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1223
                    if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1224
                        for choice, xsdclass in element_infos["type"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1225
                            combobox.Append(choice)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1226
                        name = element_infos["name"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1227
                        value = element_infos["value"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1228
                        staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1229
                            name='%s_staticbox'%element_infos["name"], parent=parent,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1230
                            pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1231
                        staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1232
                        sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1233
                        self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1234
                        callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1235
                    else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1236
                        for choice in element_infos["type"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1237
                            combobox.Append(choice)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1238
                        callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1239
                    if element_infos["value"] is None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1240
                        combobox.SetStringSelection("")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1241
                    else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1242
                        combobox.SetStringSelection(element_infos["value"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1243
                    combobox.Bind(wx.EVT_COMBOBOX, callback, id=id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1244
                elif isinstance(element_infos["type"], types.DictType):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1245
                    scmin = -(2**31)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1246
                    scmax = 2**31-1
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1247
                    if "min" in element_infos["type"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1248
                        scmin = element_infos["type"]["min"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1249
                    if "max" in element_infos["type"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1250
                        scmax = element_infos["type"]["max"]
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1251
                    spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1252
                        pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1253
                    spinctrl.SetRange(scmin,scmax)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1254
                    boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1255
                    spinctrl.SetValue(element_infos["value"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1256
                    spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1257
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1258
                    if element_infos["type"] == "boolean":
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1259
                        checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1260
                            pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1261
                        boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1262
                        checkbox.SetValue(element_infos["value"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1263
                        checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1264
                    elif element_infos["type"] in ["unsignedLong", "long","integer"]:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1265
                        if element_infos["type"].startswith("unsigned"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1266
                            scmin = 0
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1267
                        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1268
                            scmin = -(2**31)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1269
                        scmax = 2**31-1
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1270
                        spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1271
                            pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1272
                        spinctrl.SetRange(scmin, scmax)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1273
                        boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1274
                        spinctrl.SetValue(element_infos["value"])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1275
                        spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1276
                    else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1277
                        choices = cPickle.loads(str(self.Config.Read(element_path, cPickle.dumps([""]))))                           
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1278
                        textctrl = TextCtrlAutoComplete.TextCtrlAutoComplete(id=id, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1279
                                                                     name=element_infos["name"], 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1280
                                                                     parent=parent, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1281
                                                                     appframe=self, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1282
                                                                     choices=choices, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1283
                                                                     element_path=element_path,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1284
                                                                     pos=wx.Point(0, 0), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1285
                                                                     size=wx.Size(300, 25), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1286
                                                                     style=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1287
                        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1288
                        boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1289
                        textctrl.ChangeValue(str(element_infos["value"]))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1290
                        textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1291
            first = False
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1292
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1293
    def ResetView(self):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1294
        IDEFrame.ResetView(self)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1295
        self.PluginInfos = {}
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1296
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1297
            self.PluginRoot.CloseProject()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1298
        self.PluginRoot = None
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1299
        self.Log.flush()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1300
        self.DebugVariablePanel.SetDataProducer(None)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1301
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1302
    def OnNewProjectMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1303
        if not self.Config.HasEntry("lastopenedfolder"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1304
            defaultpath = os.path.expanduser("~")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1305
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1306
            defaultpath = self.Config.Read("lastopenedfolder")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1307
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1308
        dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1309
        if dialog.ShowModal() == wx.ID_OK:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1310
            projectpath = dialog.GetPath()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1311
            dialog.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1312
            self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1313
            self.Config.Flush()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1314
            self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1315
            self.PluginRoot = PluginsRoot(self, self.Log)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1316
            self.Controler = self.PluginRoot
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1317
            result = self.PluginRoot.NewProject(projectpath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1318
            if not result:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1319
                self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1320
                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1321
                self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1322
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1323
                self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1324
                self.ShowErrorMessage(result)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1325
            self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1326
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1327
    def OnOpenProjectMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1328
        if not self.Config.HasEntry("lastopenedfolder"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1329
            defaultpath = os.path.expanduser("~")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1330
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1331
            defaultpath = self.Config.Read("lastopenedfolder")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1332
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1333
        dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1334
        if dialog.ShowModal() == wx.ID_OK:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1335
            projectpath = dialog.GetPath()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1336
            if os.path.isdir(projectpath):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1337
                self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1338
                self.Config.Flush()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1339
                self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1340
                self.PluginRoot = PluginsRoot(self, self.Log)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1341
                self.Controler = self.PluginRoot
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1342
                result = self.PluginRoot.LoadProject(projectpath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1343
                if not result:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1344
                    self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1345
                    self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1346
                    self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1347
                else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1348
                    self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1349
                    self.ShowErrorMessage(result)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1350
            else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1351
                self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1352
            self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1353
        dialog.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1354
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1355
    def OnCloseProjectMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1356
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1357
            if self.PluginRoot.ProjectTestModified():
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1358
                dialog = wx.MessageDialog(self,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1359
                                          _("Save changes ?"),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1360
                                          _("Close Application"), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1361
                                          wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1362
                answer = dialog.ShowModal()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1363
                dialog.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1364
                if answer == wx.ID_YES:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1365
                    self.PluginRoot.SaveProject()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1366
                elif answer == wx.ID_CANCEL:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1367
                    return
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1368
            self.ResetView()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1369
            self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1370
            self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1371
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1372
    def OnSaveProjectMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1373
        if self.PluginRoot is not None:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1374
            self.PluginRoot.SaveProject()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1375
            self.RefreshAll()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1376
            self.RefreshTitle()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1377
    
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1378
    def OnSaveProjectAsMenu(self, event):
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1379
        if self.PluginRoot is not None:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1380
            self.PluginRoot.SaveProjectAs()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1381
            self.RefreshAll()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1382
            self.RefreshTitle()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1383
        event.Skip()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1384
    
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1385
    def OnPropertiesMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1386
        self.ShowProperties()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1387
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1388
    def OnQuitMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1389
        self.Close()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1390
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1391
    def OnBeremizMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1392
        open_pdf(Bpath( "doc", "manual_beremiz.pdf"))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1393
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1394
    def OnAboutMenu(self, event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1395
        OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500))
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1396
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1397
    def GetAddButtonFunction(self, plugin, window):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1398
        def AddButtonFunction(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1399
            if plugin and len(plugin.PlugChildsTypes) > 0:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1400
                plugin_menu = wx.Menu(title='')
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1401
                for name, XSDClass, help in plugin.PlugChildsTypes:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1402
                    new_id = wx.NewId()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1403
                    plugin_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1404
                    self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1405
                window_pos = window.GetPosition()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1406
                wx.CallAfter(self.PLCConfig.PopupMenu, plugin_menu)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1407
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1408
        return AddButtonFunction
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1409
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1410
    def GetDeleteButtonFunction(self, plugin):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1411
        def DeleteButtonFunction(event):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1412
            wx.CallAfter(self.DeletePlugin, plugin)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1413
            event.Skip()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1414
        return DeleteButtonFunction
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1415
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1416
    def AddPlugin(self, PluginType, plugin):
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1417
        if self.PluginRoot.CheckProjectPathPerm():
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1418
            dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1419
            if dialog.ShowModal() == wx.ID_OK:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1420
                PluginName = dialog.GetValue()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1421
                plugin.PlugAddChild(PluginName, PluginType)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1422
                self.RefreshPluginTree()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1423
                self.PluginRoot.RefreshPluginsBlockLists()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1424
            dialog.Destroy()
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1425
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1426
    def DeletePlugin(self, plugin):
427
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1427
        if self.PluginRoot.CheckProjectPathPerm():
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1428
            dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1429
            if dialog.ShowModal() == wx.ID_YES:
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1430
                self.PluginInfos.pop(plugin)
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1431
                plugin.PlugRemove()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1432
                del plugin
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1433
                self.PluginRoot.RefreshPluginsBlockLists()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1434
                self.RefreshPluginTree()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1435
            dialog.Destroy()
7ac746c07ff2 Check ProjectPath write permission
greg
parents: 426
diff changeset
  1436
    
426
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1437
#-------------------------------------------------------------------------------
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1438
#                               Exception Handler
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1439
#-------------------------------------------------------------------------------
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1440
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1441
Max_Traceback_List_Size = 20
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1442
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1443
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1444
    trcbck_lst = []
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1445
    for i,line in enumerate(traceback.extract_tb(e_tb)):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1446
        trcbck = " " + str(i+1) + _(". ")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1447
        if line[0].find(os.getcwd()) == -1:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1448
            trcbck += _("file : ") + str(line[0]) + _(",   ")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1449
        else:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1450
            trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(",   ")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1451
        trcbck += _("line : ") + str(line[1]) + _(",   ") + _("function : ") + str(line[2])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1452
        trcbck_lst.append(trcbck)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1453
        
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1454
    # Allow clicking....
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1455
    cap = wx.Window_GetCapture()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1456
    if cap:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1457
        cap.ReleaseMouse()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1458
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1459
    dlg = wx.SingleChoiceDialog(None, 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1460
        _("""
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1461
An unhandled exception (bug) occured. Bug report saved at :
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1462
(%s)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1463
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1464
Please contact LOLITech at:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1465
+33 (0)3 29 57 60 42
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1466
or please be kind enough to send this file to:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1467
bugs_beremiz@lolitech.fr
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1468
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1469
You should now restart Beremiz.
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1470
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1471
Traceback:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1472
""") % bug_report_path +
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1473
        str(e_type) + " : " + str(e_value), 
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1474
        _("Error"),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1475
        trcbck_lst)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1476
    try:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1477
        res = (dlg.ShowModal() == wx.ID_OK)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1478
    finally:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1479
        dlg.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1480
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1481
    return res
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1482
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1483
def Display_Error_Dialog(e_value):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1484
    message = wxMessageDialog(None, str(e_value), _("Error"), wxOK|wxICON_ERROR)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1485
    message.ShowModal()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1486
    message.Destroy()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1487
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1488
def get_last_traceback(tb):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1489
    while tb.tb_next:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1490
        tb = tb.tb_next
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1491
    return tb
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1492
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1493
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1494
def format_namespace(d, indent='    '):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1495
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1496
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1497
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1498
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1499
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1500
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1501
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1502
    def handle_exception(e_type, e_value, e_traceback):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1503
        traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1504
        last_tb = get_last_traceback(e_traceback)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1505
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1506
        if str(e_value).startswith("!!!"):
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1507
            Display_Error_Dialog(e_value)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1508
        elif ex not in ignored_exceptions:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1509
            date = time.ctime()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1510
            bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt"
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1511
            result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1512
            if result:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1513
                ignored_exceptions.append(ex)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1514
                info = {
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1515
                    'app-title' : wx.GetApp().GetAppName(), # app_title
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1516
                    'app-version' : app_version,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1517
                    'wx-version' : wx.VERSION_STRING,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1518
                    'wx-platform' : wx.Platform,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1519
                    'python-version' : platform.python_version(), #sys.version.split()[0],
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1520
                    'platform' : platform.platform(),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1521
                    'e-type' : e_type,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1522
                    'e-value' : e_value,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1523
                    'date' : date,
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1524
                    'cwd' : os.getcwd(),
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1525
                    }
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1526
                if e_traceback:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1527
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1528
                    last_tb = get_last_traceback(e_traceback)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1529
                    exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1530
                    info['locals'] = format_namespace(exception_locals)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1531
                    if 'self' in exception_locals:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1532
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1533
                
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1534
                output = open(bug_report_path,'w')
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1535
                lst = info.keys()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1536
                lst.sort()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1537
                for a in lst:
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1538
                    output.write(a+":\n"+str(info[a])+"\n\n")
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1539
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1540
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1541
    sys.excepthook = handle_exception
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1542
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1543
if __name__ == '__main__':
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1544
    # Install a exception handle for bug reports
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1545
    AddExceptHook(os.getcwd(),__version__)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1546
    
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1547
    frame = Beremiz(None, projectOpen, buildpath)
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1548
    frame.Show()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1549
    splash.Close()
3f285782ac9b Bugs with TextCtrlAutoComplete on Windows fixed
laurent
parents: 422
diff changeset
  1550
    app.MainLoop()