ConfTreeNodeEditor.py
author Edouard Tisserant
Mon, 21 May 2012 16:40:57 +0200
changeset 740 cee825fbe9b3
parent 738 413946c04c87
child 742 41a4a560406c
child 743 4645a3a398ad
permissions -rw-r--r--
fixed exception when launching discovery dialog without network
738
413946c04c87 refactoring
laurent
parents:
diff changeset
     1
413946c04c87 refactoring
laurent
parents:
diff changeset
     2
import os
413946c04c87 refactoring
laurent
parents:
diff changeset
     3
import types
413946c04c87 refactoring
laurent
parents:
diff changeset
     4
413946c04c87 refactoring
laurent
parents:
diff changeset
     5
import wx
413946c04c87 refactoring
laurent
parents:
diff changeset
     6
import wx.lib.buttons
413946c04c87 refactoring
laurent
parents:
diff changeset
     7
413946c04c87 refactoring
laurent
parents:
diff changeset
     8
from controls import EditorPanel
413946c04c87 refactoring
laurent
parents:
diff changeset
     9
413946c04c87 refactoring
laurent
parents:
diff changeset
    10
from PLCOpenEditor import TITLE, FILEMENU, PROJECTTREE, PAGETITLES
413946c04c87 refactoring
laurent
parents:
diff changeset
    11
413946c04c87 refactoring
laurent
parents:
diff changeset
    12
from util import opjimg
413946c04c87 refactoring
laurent
parents:
diff changeset
    13
from util.TextCtrlAutoComplete import TextCtrlAutoComplete
413946c04c87 refactoring
laurent
parents:
diff changeset
    14
from util.BrowseValuesLibraryDialog import BrowseValuesLibraryDialog
413946c04c87 refactoring
laurent
parents:
diff changeset
    15
413946c04c87 refactoring
laurent
parents:
diff changeset
    16
if wx.Platform == '__WXMSW__':
413946c04c87 refactoring
laurent
parents:
diff changeset
    17
    faces = { 'times': 'Times New Roman',
413946c04c87 refactoring
laurent
parents:
diff changeset
    18
              'mono' : 'Courier New',
413946c04c87 refactoring
laurent
parents:
diff changeset
    19
              'helv' : 'Arial',
413946c04c87 refactoring
laurent
parents:
diff changeset
    20
              'other': 'Comic Sans MS',
413946c04c87 refactoring
laurent
parents:
diff changeset
    21
              'size' : 16,
413946c04c87 refactoring
laurent
parents:
diff changeset
    22
             }
413946c04c87 refactoring
laurent
parents:
diff changeset
    23
else:
413946c04c87 refactoring
laurent
parents:
diff changeset
    24
    faces = { 'times': 'Times',
413946c04c87 refactoring
laurent
parents:
diff changeset
    25
              'mono' : 'Courier',
413946c04c87 refactoring
laurent
parents:
diff changeset
    26
              'helv' : 'Helvetica',
413946c04c87 refactoring
laurent
parents:
diff changeset
    27
              'other': 'new century schoolbook',
413946c04c87 refactoring
laurent
parents:
diff changeset
    28
              'size' : 18,
413946c04c87 refactoring
laurent
parents:
diff changeset
    29
             }
413946c04c87 refactoring
laurent
parents:
diff changeset
    30
413946c04c87 refactoring
laurent
parents:
diff changeset
    31
SCROLLBAR_UNIT = 10
413946c04c87 refactoring
laurent
parents:
diff changeset
    32
WINDOW_COLOUR = wx.Colour(240,240,240)        
413946c04c87 refactoring
laurent
parents:
diff changeset
    33
413946c04c87 refactoring
laurent
parents:
diff changeset
    34
CWD = os.path.split(os.path.realpath(__file__))[0]
413946c04c87 refactoring
laurent
parents:
diff changeset
    35
413946c04c87 refactoring
laurent
parents:
diff changeset
    36
def Bpath(*args):
413946c04c87 refactoring
laurent
parents:
diff changeset
    37
    return os.path.join(CWD,*args)
413946c04c87 refactoring
laurent
parents:
diff changeset
    38
413946c04c87 refactoring
laurent
parents:
diff changeset
    39
# Some helpers to tweak GenBitmapTextButtons
413946c04c87 refactoring
laurent
parents:
diff changeset
    40
# TODO: declare customized classes instead.
413946c04c87 refactoring
laurent
parents:
diff changeset
    41
gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID)
413946c04c87 refactoring
laurent
parents:
diff changeset
    42
gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,))
413946c04c87 refactoring
laurent
parents:
diff changeset
    43
413946c04c87 refactoring
laurent
parents:
diff changeset
    44
def make_genbitmaptogglebutton_flat(button):
413946c04c87 refactoring
laurent
parents:
diff changeset
    45
    button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button)
413946c04c87 refactoring
laurent
parents:
diff changeset
    46
    button.labelDelta = 0
413946c04c87 refactoring
laurent
parents:
diff changeset
    47
    button.SetBezelWidth(0)
413946c04c87 refactoring
laurent
parents:
diff changeset
    48
    button.SetUseFocusIndicator(False)
413946c04c87 refactoring
laurent
parents:
diff changeset
    49
413946c04c87 refactoring
laurent
parents:
diff changeset
    50
# Patch wx.lib.imageutils so that gray is supported on alpha images
413946c04c87 refactoring
laurent
parents:
diff changeset
    51
import wx.lib.imageutils
413946c04c87 refactoring
laurent
parents:
diff changeset
    52
from wx.lib.imageutils import grayOut as old_grayOut
413946c04c87 refactoring
laurent
parents:
diff changeset
    53
def grayOut(anImage):
413946c04c87 refactoring
laurent
parents:
diff changeset
    54
    if anImage.HasAlpha():
413946c04c87 refactoring
laurent
parents:
diff changeset
    55
        AlphaData = anImage.GetAlphaData()
413946c04c87 refactoring
laurent
parents:
diff changeset
    56
    else :
413946c04c87 refactoring
laurent
parents:
diff changeset
    57
        AlphaData = None
413946c04c87 refactoring
laurent
parents:
diff changeset
    58
413946c04c87 refactoring
laurent
parents:
diff changeset
    59
    old_grayOut(anImage)
413946c04c87 refactoring
laurent
parents:
diff changeset
    60
413946c04c87 refactoring
laurent
parents:
diff changeset
    61
    if AlphaData is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
    62
        anImage.SetAlphaData(AlphaData)
413946c04c87 refactoring
laurent
parents:
diff changeset
    63
413946c04c87 refactoring
laurent
parents:
diff changeset
    64
wx.lib.imageutils.grayOut = grayOut
413946c04c87 refactoring
laurent
parents:
diff changeset
    65
413946c04c87 refactoring
laurent
parents:
diff changeset
    66
class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
413946c04c87 refactoring
laurent
parents:
diff changeset
    67
    def _GetLabelSize(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
    68
        """ used internally """
413946c04c87 refactoring
laurent
parents:
diff changeset
    69
        w, h = self.GetTextExtent(self.GetLabel())
413946c04c87 refactoring
laurent
parents:
diff changeset
    70
        if not self.bmpLabel:
413946c04c87 refactoring
laurent
parents:
diff changeset
    71
            return w, h, False       # if there isn't a bitmap use the size of the text
413946c04c87 refactoring
laurent
parents:
diff changeset
    72
413946c04c87 refactoring
laurent
parents:
diff changeset
    73
        w_bmp = self.bmpLabel.GetWidth()+2
413946c04c87 refactoring
laurent
parents:
diff changeset
    74
        h_bmp = self.bmpLabel.GetHeight()+2
413946c04c87 refactoring
laurent
parents:
diff changeset
    75
        height = h + h_bmp
413946c04c87 refactoring
laurent
parents:
diff changeset
    76
        if w_bmp > w:
413946c04c87 refactoring
laurent
parents:
diff changeset
    77
            width = w_bmp
413946c04c87 refactoring
laurent
parents:
diff changeset
    78
        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
    79
            width = w
413946c04c87 refactoring
laurent
parents:
diff changeset
    80
        return width, height, False
413946c04c87 refactoring
laurent
parents:
diff changeset
    81
413946c04c87 refactoring
laurent
parents:
diff changeset
    82
    def DrawLabel(self, dc, width, height, dw=0, dy=0):
413946c04c87 refactoring
laurent
parents:
diff changeset
    83
        bmp = self.bmpLabel
413946c04c87 refactoring
laurent
parents:
diff changeset
    84
        if bmp != None:     # if the bitmap is used
413946c04c87 refactoring
laurent
parents:
diff changeset
    85
            if self.bmpDisabled and not self.IsEnabled():
413946c04c87 refactoring
laurent
parents:
diff changeset
    86
                bmp = self.bmpDisabled
413946c04c87 refactoring
laurent
parents:
diff changeset
    87
            if self.bmpFocus and self.hasFocus:
413946c04c87 refactoring
laurent
parents:
diff changeset
    88
                bmp = self.bmpFocus
413946c04c87 refactoring
laurent
parents:
diff changeset
    89
            if self.bmpSelected and not self.up:
413946c04c87 refactoring
laurent
parents:
diff changeset
    90
                bmp = self.bmpSelected
413946c04c87 refactoring
laurent
parents:
diff changeset
    91
            bw,bh = bmp.GetWidth(), bmp.GetHeight()
413946c04c87 refactoring
laurent
parents:
diff changeset
    92
            if not self.up:
413946c04c87 refactoring
laurent
parents:
diff changeset
    93
                dw = dy = self.labelDelta
413946c04c87 refactoring
laurent
parents:
diff changeset
    94
            hasMask = bmp.GetMask() != None
413946c04c87 refactoring
laurent
parents:
diff changeset
    95
        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
    96
            bw = bh = 0     # no bitmap -> size is zero
413946c04c87 refactoring
laurent
parents:
diff changeset
    97
413946c04c87 refactoring
laurent
parents:
diff changeset
    98
        dc.SetFont(self.GetFont())
413946c04c87 refactoring
laurent
parents:
diff changeset
    99
        if self.IsEnabled():
413946c04c87 refactoring
laurent
parents:
diff changeset
   100
            dc.SetTextForeground(self.GetForegroundColour())
413946c04c87 refactoring
laurent
parents:
diff changeset
   101
        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   102
            dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
413946c04c87 refactoring
laurent
parents:
diff changeset
   103
413946c04c87 refactoring
laurent
parents:
diff changeset
   104
        label = self.GetLabel()
413946c04c87 refactoring
laurent
parents:
diff changeset
   105
        tw, th = dc.GetTextExtent(label)        # size of text
413946c04c87 refactoring
laurent
parents:
diff changeset
   106
        if not self.up:
413946c04c87 refactoring
laurent
parents:
diff changeset
   107
            dw = dy = self.labelDelta
413946c04c87 refactoring
laurent
parents:
diff changeset
   108
413946c04c87 refactoring
laurent
parents:
diff changeset
   109
        pos_x = (width-bw)/2+dw      # adjust for bitmap and text to centre
413946c04c87 refactoring
laurent
parents:
diff changeset
   110
        pos_y = (height-bh-th)/2+dy
413946c04c87 refactoring
laurent
parents:
diff changeset
   111
        if bmp !=None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   112
            dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available
413946c04c87 refactoring
laurent
parents:
diff changeset
   113
            pos_x = (width-tw)/2+dw      # adjust for bitmap and text to centre
413946c04c87 refactoring
laurent
parents:
diff changeset
   114
            pos_y += bh + 2
413946c04c87 refactoring
laurent
parents:
diff changeset
   115
413946c04c87 refactoring
laurent
parents:
diff changeset
   116
        dc.DrawText(label, pos_x, pos_y)      # draw the text
413946c04c87 refactoring
laurent
parents:
diff changeset
   117
413946c04c87 refactoring
laurent
parents:
diff changeset
   118
413946c04c87 refactoring
laurent
parents:
diff changeset
   119
class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
413946c04c87 refactoring
laurent
parents:
diff changeset
   120
    """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   121
    and accept image name as __init__ parameter, fail silently if file do not exist"""
413946c04c87 refactoring
laurent
parents:
diff changeset
   122
    def __init__(self, parent, ID, bitmapname,
413946c04c87 refactoring
laurent
parents:
diff changeset
   123
                 pos = wx.DefaultPosition, size = wx.DefaultSize,
413946c04c87 refactoring
laurent
parents:
diff changeset
   124
                 style = 0,
413946c04c87 refactoring
laurent
parents:
diff changeset
   125
                 name = "genstatbmp"):
413946c04c87 refactoring
laurent
parents:
diff changeset
   126
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   127
        bitmappath = Bpath( "images", bitmapname)
413946c04c87 refactoring
laurent
parents:
diff changeset
   128
        if os.path.isfile(bitmappath):
413946c04c87 refactoring
laurent
parents:
diff changeset
   129
            bitmap = wx.Bitmap(bitmappath)
413946c04c87 refactoring
laurent
parents:
diff changeset
   130
        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   131
            bitmap = None
413946c04c87 refactoring
laurent
parents:
diff changeset
   132
        wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap,
413946c04c87 refactoring
laurent
parents:
diff changeset
   133
                 pos, size,
413946c04c87 refactoring
laurent
parents:
diff changeset
   134
                 style,
413946c04c87 refactoring
laurent
parents:
diff changeset
   135
                 name)
413946c04c87 refactoring
laurent
parents:
diff changeset
   136
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   137
    def OnPaint(self, event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   138
        dc = wx.PaintDC(self)
413946c04c87 refactoring
laurent
parents:
diff changeset
   139
        colour = self.GetParent().GetBackgroundColour()
413946c04c87 refactoring
laurent
parents:
diff changeset
   140
        dc.SetPen(wx.Pen(colour))
413946c04c87 refactoring
laurent
parents:
diff changeset
   141
        dc.SetBrush(wx.Brush(colour ))
413946c04c87 refactoring
laurent
parents:
diff changeset
   142
        dc.DrawRectangle(0, 0, *dc.GetSizeTuple())
413946c04c87 refactoring
laurent
parents:
diff changeset
   143
        if self._bitmap:
413946c04c87 refactoring
laurent
parents:
diff changeset
   144
            dc.DrawBitmap(self._bitmap, 0, 0, True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   145
413946c04c87 refactoring
laurent
parents:
diff changeset
   146
class ConfTreeNodeEditor(EditorPanel):
413946c04c87 refactoring
laurent
parents:
diff changeset
   147
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   148
    HAS_BASE_PARAMS = True
413946c04c87 refactoring
laurent
parents:
diff changeset
   149
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   150
    def _init_ConfNodeEditor(self, prnt):
413946c04c87 refactoring
laurent
parents:
diff changeset
   151
        self.ConfNodeEditor = None
413946c04c87 refactoring
laurent
parents:
diff changeset
   152
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   153
    def _init_Editor(self, prnt):
413946c04c87 refactoring
laurent
parents:
diff changeset
   154
        self.Editor = wx.SplitterWindow(id=self.ID, name='EditorSplitter', parent=prnt,
413946c04c87 refactoring
laurent
parents:
diff changeset
   155
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER|wx.SP_3D)
413946c04c87 refactoring
laurent
parents:
diff changeset
   156
        self.SetNeedUpdating(True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   157
        self.SetMinimumPaneSize(1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   158
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   159
        self.ParamsEditor = wx.ScrolledWindow(self.Editor, -1, size=wx.Size(-1, -1),
413946c04c87 refactoring
laurent
parents:
diff changeset
   160
                        style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   161
        self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR)
413946c04c87 refactoring
laurent
parents:
diff changeset
   162
        self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize)
413946c04c87 refactoring
laurent
parents:
diff changeset
   163
        self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
413946c04c87 refactoring
laurent
parents:
diff changeset
   164
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   165
        # Variable allowing disabling of ParamsEditor scroll when Popup shown 
413946c04c87 refactoring
laurent
parents:
diff changeset
   166
        self.ScrollingEnabled = True
413946c04c87 refactoring
laurent
parents:
diff changeset
   167
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   168
        self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
413946c04c87 refactoring
laurent
parents:
diff changeset
   169
        self.ParamsEditorSizer.AddGrowableCol(0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   170
        self.ParamsEditorSizer.AddGrowableRow(1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   171
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   172
        self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
413946c04c87 refactoring
laurent
parents:
diff changeset
   173
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   174
        baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   175
        self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, 0, border=5, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   176
                                        flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP)
413946c04c87 refactoring
laurent
parents:
diff changeset
   177
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   178
        self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   179
        self.FullIECChannel.SetFont(
413946c04c87 refactoring
laurent
parents:
diff changeset
   180
            wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   181
                    wx.BOLD, faceName = faces["helv"]))
413946c04c87 refactoring
laurent
parents:
diff changeset
   182
        baseparamseditor_sizer.AddWindow(self.FullIECChannel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   183
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   184
        updownsizer = wx.BoxSizer(wx.VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   185
        baseparamseditor_sizer.AddSizer(updownsizer, 0, border=5, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   186
                                    flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   187
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   188
        ieccdownbutton_id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   189
        self.IECCDownButton = wx.lib.buttons.GenBitmapButton(
413946c04c87 refactoring
laurent
parents:
diff changeset
   190
              id=ieccdownbutton_id, bitmap=wx.Bitmap(opjimg('IECCDown')),
413946c04c87 refactoring
laurent
parents:
diff changeset
   191
              name='IECDownButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
413946c04c87 refactoring
laurent
parents:
diff changeset
   192
              size=wx.Size(16, 16), style=wx.NO_BORDER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   193
        self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   194
                                id=ieccdownbutton_id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   195
        updownsizer.AddWindow(self.IECCDownButton, 0, border=0, flag=wx.ALIGN_LEFT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   196
413946c04c87 refactoring
laurent
parents:
diff changeset
   197
        ieccupbutton_id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   198
        self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(
413946c04c87 refactoring
laurent
parents:
diff changeset
   199
              id=ieccupbutton_id, bitmap=wx.Bitmap(opjimg('IECCUp')),
413946c04c87 refactoring
laurent
parents:
diff changeset
   200
              name='IECUpButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
413946c04c87 refactoring
laurent
parents:
diff changeset
   201
              size=wx.Size(16, 16), style=wx.NO_BORDER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   202
        self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   203
                              id=ieccupbutton_id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   204
        updownsizer.AddWindow(self.IECCUpButton, 0, border=0, flag=wx.ALIGN_LEFT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   205
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   206
        self.RefreshIECChannelControlsState()
413946c04c87 refactoring
laurent
parents:
diff changeset
   207
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   208
        confnodename_id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   209
        self.ConfNodeName = wx.TextCtrl(
413946c04c87 refactoring
laurent
parents:
diff changeset
   210
              self.ParamsEditor, confnodename_id, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   211
              size=wx.Size(150, 25), style=wx.NO_BORDER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   212
        self.ConfNodeName.SetFont(
413946c04c87 refactoring
laurent
parents:
diff changeset
   213
            wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   214
                    wx.BOLD, faceName = faces["helv"]))
413946c04c87 refactoring
laurent
parents:
diff changeset
   215
        self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
413946c04c87 refactoring
laurent
parents:
diff changeset
   216
        self.ConfNodeName.Bind(wx.EVT_TEXT, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   217
            self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name"), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   218
            id=confnodename_id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   219
        baseparamseditor_sizer.AddWindow(self.ConfNodeName, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   220
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   221
        buttons_sizer = self.GenerateMethodButtonSizer()
413946c04c87 refactoring
laurent
parents:
diff changeset
   222
        baseparamseditor_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.ALIGN_CENTER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   223
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   224
        self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   225
        self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   226
                                        flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
413946c04c87 refactoring
laurent
parents:
diff changeset
   227
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   228
        self.RefreshConfNodeParamsSizer()
413946c04c87 refactoring
laurent
parents:
diff changeset
   229
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   230
        self._init_ConfNodeEditor(self.Editor)
413946c04c87 refactoring
laurent
parents:
diff changeset
   231
            
413946c04c87 refactoring
laurent
parents:
diff changeset
   232
        if self.ConfNodeEditor is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   233
            min_size = self.ParamsEditorSizer.GetMinSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   234
            self.Editor.SplitHorizontally(self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   235
                                   self.ConfNodeEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   236
                                   min(min_size.height, 200))
413946c04c87 refactoring
laurent
parents:
diff changeset
   237
        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   238
            self.Editor.Initialize(self.ParamsEditor)
413946c04c87 refactoring
laurent
parents:
diff changeset
   239
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   240
    def __init__(self, parent, tagname, controler, window):
413946c04c87 refactoring
laurent
parents:
diff changeset
   241
        EditorPanel.__init__(self, parent, tagname, window, controler)
413946c04c87 refactoring
laurent
parents:
diff changeset
   242
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   243
        self.SetIcon(wx.Bitmap(self.Controler.GetIconPath(), wx.BITMAP_TYPE_PNG))
413946c04c87 refactoring
laurent
parents:
diff changeset
   244
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   245
    def __del__(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   246
        self.Controler.OnCloseEditor(self)
413946c04c87 refactoring
laurent
parents:
diff changeset
   247
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   248
    def GetTagName(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   249
        return self.Controler.CTNFullName()
413946c04c87 refactoring
laurent
parents:
diff changeset
   250
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   251
    def GetTitle(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   252
        fullname = self.Controler.CTNFullName()
413946c04c87 refactoring
laurent
parents:
diff changeset
   253
        if self.Controler.CTNTestModified():
413946c04c87 refactoring
laurent
parents:
diff changeset
   254
            return "~%s~" % fullname
413946c04c87 refactoring
laurent
parents:
diff changeset
   255
        return fullname
413946c04c87 refactoring
laurent
parents:
diff changeset
   256
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   257
    def HasNoModel(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   258
        return False
413946c04c87 refactoring
laurent
parents:
diff changeset
   259
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   260
    def EnableScrolling(self, enable):
413946c04c87 refactoring
laurent
parents:
diff changeset
   261
        self.ScrollingEnabled = enable
413946c04c87 refactoring
laurent
parents:
diff changeset
   262
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   263
    def RefreshIECChannelControlsState(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   264
        self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel())
413946c04c87 refactoring
laurent
parents:
diff changeset
   265
        self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   266
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   267
    def RefreshConfNodeParamsSizer(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   268
        self.Freeze()
413946c04c87 refactoring
laurent
parents:
diff changeset
   269
        self.ConfNodeParamsSizer.Clear(True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   270
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   271
        confnode_infos = self.Controler.GetParamsAttributes()
413946c04c87 refactoring
laurent
parents:
diff changeset
   272
        if len(confnode_infos) > 0:
413946c04c87 refactoring
laurent
parents:
diff changeset
   273
            self.GenerateSizerElements(self.ConfNodeParamsSizer, confnode_infos, None, False)
413946c04c87 refactoring
laurent
parents:
diff changeset
   274
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   275
        self.ParamsEditorSizer.Layout()
413946c04c87 refactoring
laurent
parents:
diff changeset
   276
        self.Thaw()
413946c04c87 refactoring
laurent
parents:
diff changeset
   277
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   278
    def GenerateMethodButtonSizer(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   279
        normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   280
        mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   281
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   282
        msizer = wx.BoxSizer(wx.HORIZONTAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   283
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   284
        for confnode_method in self.Controler.ConfNodeMethods:
413946c04c87 refactoring
laurent
parents:
diff changeset
   285
            if "method" in confnode_method and confnode_method.get("shown",True):
413946c04c87 refactoring
laurent
parents:
diff changeset
   286
                id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   287
                label = confnode_method["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   288
                button = GenBitmapTextButton(id=id, parent=self.ParamsEditor,
413946c04c87 refactoring
laurent
parents:
diff changeset
   289
                    bitmap=wx.Bitmap(Bpath("images", "%s.png"%confnode_method.get("bitmap", "Unknown"))), label=label, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   290
                    name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   291
                button.SetFont(normal_bt_font)
413946c04c87 refactoring
laurent
parents:
diff changeset
   292
                button.SetToolTipString(confnode_method["tooltip"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   293
                button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), id=id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   294
                # a fancy underline on mouseover
413946c04c87 refactoring
laurent
parents:
diff changeset
   295
                def setFontStyle(b, s):
413946c04c87 refactoring
laurent
parents:
diff changeset
   296
                    def fn(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   297
                        b.SetFont(s)
413946c04c87 refactoring
laurent
parents:
diff changeset
   298
                        b.Refresh()
413946c04c87 refactoring
laurent
parents:
diff changeset
   299
                        event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   300
                    return fn
413946c04c87 refactoring
laurent
parents:
diff changeset
   301
                button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font))
413946c04c87 refactoring
laurent
parents:
diff changeset
   302
                button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font))
413946c04c87 refactoring
laurent
parents:
diff changeset
   303
                #hack to force size to mini
413946c04c87 refactoring
laurent
parents:
diff changeset
   304
                if not confnode_method.get("enabled",True):
413946c04c87 refactoring
laurent
parents:
diff changeset
   305
                    button.Disable()
413946c04c87 refactoring
laurent
parents:
diff changeset
   306
                msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER)
413946c04c87 refactoring
laurent
parents:
diff changeset
   307
        return msizer
413946c04c87 refactoring
laurent
parents:
diff changeset
   308
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   309
    def GenerateSizerElements(self, sizer, elements, path, clean = True):
413946c04c87 refactoring
laurent
parents:
diff changeset
   310
        if clean:
413946c04c87 refactoring
laurent
parents:
diff changeset
   311
            sizer.Clear(True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   312
        first = True
413946c04c87 refactoring
laurent
parents:
diff changeset
   313
        for element_infos in elements:
413946c04c87 refactoring
laurent
parents:
diff changeset
   314
            if path:
413946c04c87 refactoring
laurent
parents:
diff changeset
   315
                element_path = "%s.%s"%(path, element_infos["name"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   316
            else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   317
                element_path = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   318
            if element_infos["type"] == "element":
413946c04c87 refactoring
laurent
parents:
diff changeset
   319
                label = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   320
                staticbox = wx.StaticBox(id=-1, label=_(label), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   321
                    name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor,
413946c04c87 refactoring
laurent
parents:
diff changeset
   322
                    pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   323
                staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   324
                if first:
413946c04c87 refactoring
laurent
parents:
diff changeset
   325
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
413946c04c87 refactoring
laurent
parents:
diff changeset
   326
                else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   327
                    sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW)
413946c04c87 refactoring
laurent
parents:
diff changeset
   328
                self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   329
            else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   330
                boxsizer = wx.FlexGridSizer(cols=3, rows=1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   331
                boxsizer.AddGrowableCol(1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   332
                if first:
413946c04c87 refactoring
laurent
parents:
diff changeset
   333
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   334
                else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   335
                    sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
413946c04c87 refactoring
laurent
parents:
diff changeset
   336
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
413946c04c87 refactoring
laurent
parents:
diff changeset
   337
                    name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor,
413946c04c87 refactoring
laurent
parents:
diff changeset
   338
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   339
                boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   340
                label = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   341
                statictext = wx.StaticText(id=-1, label="%s:"%_(label), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   342
                    name="%s_label"%element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   343
                    pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   344
                boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   345
                id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   346
                if isinstance(element_infos["type"], types.ListType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   347
                    if isinstance(element_infos["value"], types.TupleType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   348
                        browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   349
                        boxsizer.AddSizer(browse_boxsizer, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   350
                        
413946c04c87 refactoring
laurent
parents:
diff changeset
   351
                        textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   352
                            pos=wx.Point(0, 0), size=wx.Size(275, 25), style=wx.TE_READONLY)
413946c04c87 refactoring
laurent
parents:
diff changeset
   353
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   354
                            textctrl.SetValue(element_infos["value"][0])
413946c04c87 refactoring
laurent
parents:
diff changeset
   355
                            value_infos = element_infos["value"][1]
413946c04c87 refactoring
laurent
parents:
diff changeset
   356
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   357
                            value_infos = None
413946c04c87 refactoring
laurent
parents:
diff changeset
   358
                        browse_boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   359
                        button_id = wx.NewId()
413946c04c87 refactoring
laurent
parents:
diff changeset
   360
                        button = wx.Button(id=button_id, name="browse_%s" % element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   361
                            label="...", pos=wx.Point(0, 0), size=wx.Size(25, 25))
413946c04c87 refactoring
laurent
parents:
diff changeset
   362
                        browse_boxsizer.AddWindow(button, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   363
                        button.Bind(wx.EVT_BUTTON, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   364
                                    self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], 
413946c04c87 refactoring
laurent
parents:
diff changeset
   365
                                                                   value_infos, element_path), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   366
                                    id=button_id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   367
                    else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   368
                        combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   369
                            pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY)
413946c04c87 refactoring
laurent
parents:
diff changeset
   370
                        boxsizer.AddWindow(combobox, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   371
                        if element_infos["use"] == "optional":
413946c04c87 refactoring
laurent
parents:
diff changeset
   372
                            combobox.Append("")
413946c04c87 refactoring
laurent
parents:
diff changeset
   373
                        if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   374
                            for choice, xsdclass in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   375
                                combobox.Append(choice)
413946c04c87 refactoring
laurent
parents:
diff changeset
   376
                            name = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   377
                            value = element_infos["value"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   378
                            staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   379
                                name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor,
413946c04c87 refactoring
laurent
parents:
diff changeset
   380
                                pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   381
                            staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   382
                            sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
413946c04c87 refactoring
laurent
parents:
diff changeset
   383
                            self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   384
                            callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   385
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   386
                            for choice in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   387
                                combobox.Append(choice)
413946c04c87 refactoring
laurent
parents:
diff changeset
   388
                            callback = self.GetChoiceCallBackFunction(combobox, element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   389
                        if element_infos["value"] is None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   390
                            combobox.SetStringSelection("")
413946c04c87 refactoring
laurent
parents:
diff changeset
   391
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   392
                            combobox.SetStringSelection(element_infos["value"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   393
                        combobox.Bind(wx.EVT_COMBOBOX, callback, id=id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   394
                elif isinstance(element_infos["type"], types.DictType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   395
                    scmin = -(2**31)
413946c04c87 refactoring
laurent
parents:
diff changeset
   396
                    scmax = 2**31-1
413946c04c87 refactoring
laurent
parents:
diff changeset
   397
                    if "min" in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   398
                        scmin = element_infos["type"]["min"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   399
                    if "max" in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   400
                        scmax = element_infos["type"]["max"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   401
                    spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   402
                        pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   403
                    spinctrl.SetRange(scmin,scmax)
413946c04c87 refactoring
laurent
parents:
diff changeset
   404
                    boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   405
                    if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   406
                        spinctrl.SetValue(element_infos["value"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   407
                    spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   408
                else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   409
                    if element_infos["type"] == "boolean":
413946c04c87 refactoring
laurent
parents:
diff changeset
   410
                        checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   411
                            pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   412
                        boxsizer.AddWindow(checkbox, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   413
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   414
                            checkbox.SetValue(element_infos["value"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   415
                        checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   416
                    elif element_infos["type"] in ["unsignedLong", "long","integer"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   417
                        if element_infos["type"].startswith("unsigned"):
413946c04c87 refactoring
laurent
parents:
diff changeset
   418
                            scmin = 0
413946c04c87 refactoring
laurent
parents:
diff changeset
   419
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   420
                            scmin = -(2**31)
413946c04c87 refactoring
laurent
parents:
diff changeset
   421
                        scmax = 2**31-1
413946c04c87 refactoring
laurent
parents:
diff changeset
   422
                        spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   423
                            pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
413946c04c87 refactoring
laurent
parents:
diff changeset
   424
                        spinctrl.SetRange(scmin, scmax)
413946c04c87 refactoring
laurent
parents:
diff changeset
   425
                        boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   426
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   427
                            spinctrl.SetValue(element_infos["value"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   428
                        spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
413946c04c87 refactoring
laurent
parents:
diff changeset
   429
                    else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   430
                        choices = self.ParentWindow.GetConfigEntry(element_path, [""])
413946c04c87 refactoring
laurent
parents:
diff changeset
   431
                        textctrl = TextCtrlAutoComplete(id=id, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   432
                                                                     name=element_infos["name"], 
413946c04c87 refactoring
laurent
parents:
diff changeset
   433
                                                                     parent=self.ParamsEditor, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   434
                                                                     appframe=self, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   435
                                                                     choices=choices, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   436
                                                                     element_path=element_path,
413946c04c87 refactoring
laurent
parents:
diff changeset
   437
                                                                     pos=wx.Point(0, 0), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   438
                                                                     size=wx.Size(300, 25), 
413946c04c87 refactoring
laurent
parents:
diff changeset
   439
                                                                     style=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   440
                        
413946c04c87 refactoring
laurent
parents:
diff changeset
   441
                        boxsizer.AddWindow(textctrl, 0, border=0, flag=0)
413946c04c87 refactoring
laurent
parents:
diff changeset
   442
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   443
                            textctrl.ChangeValue(str(element_infos["value"]))
413946c04c87 refactoring
laurent
parents:
diff changeset
   444
                        textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path))
413946c04c87 refactoring
laurent
parents:
diff changeset
   445
            first = False
413946c04c87 refactoring
laurent
parents:
diff changeset
   446
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   447
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   448
    def GetItemChannelChangedFunction(self, dir):
413946c04c87 refactoring
laurent
parents:
diff changeset
   449
        def OnConfNodeTreeItemChannelChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   450
            confnode_IECChannel = self.Controler.BaseParams.getIEC_Channel()
413946c04c87 refactoring
laurent
parents:
diff changeset
   451
            res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir)
413946c04c87 refactoring
laurent
parents:
diff changeset
   452
            wx.CallAfter(self.RefreshIECChannelControlsState)
413946c04c87 refactoring
laurent
parents:
diff changeset
   453
            wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE)
413946c04c87 refactoring
laurent
parents:
diff changeset
   454
            wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
413946c04c87 refactoring
laurent
parents:
diff changeset
   455
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   456
        return OnConfNodeTreeItemChannelChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   457
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   458
    def SetConfNodeParamsAttribute(self, *args, **kwargs):
413946c04c87 refactoring
laurent
parents:
diff changeset
   459
        res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs)
413946c04c87 refactoring
laurent
parents:
diff changeset
   460
        if StructChanged:
413946c04c87 refactoring
laurent
parents:
diff changeset
   461
            wx.CallAfter(self.RefreshConfNodeParamsSizer)
413946c04c87 refactoring
laurent
parents:
diff changeset
   462
        wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU)
413946c04c87 refactoring
laurent
parents:
diff changeset
   463
        return res
413946c04c87 refactoring
laurent
parents:
diff changeset
   464
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   465
    def GetButtonCallBackFunction(self, method):
413946c04c87 refactoring
laurent
parents:
diff changeset
   466
        """ Generate the callbackfunc for a given confnode method"""
413946c04c87 refactoring
laurent
parents:
diff changeset
   467
        def OnButtonClick(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   468
            # Disable button to prevent re-entrant call 
413946c04c87 refactoring
laurent
parents:
diff changeset
   469
            event.GetEventObject().Disable()
413946c04c87 refactoring
laurent
parents:
diff changeset
   470
            # Call
413946c04c87 refactoring
laurent
parents:
diff changeset
   471
            getattr(self.Controler,method)()
413946c04c87 refactoring
laurent
parents:
diff changeset
   472
            # Re-enable button 
413946c04c87 refactoring
laurent
parents:
diff changeset
   473
            event.GetEventObject().Enable()
413946c04c87 refactoring
laurent
parents:
diff changeset
   474
            
413946c04c87 refactoring
laurent
parents:
diff changeset
   475
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   476
        return OnButtonClick
413946c04c87 refactoring
laurent
parents:
diff changeset
   477
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   478
    def GetChoiceCallBackFunction(self, choicectrl, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   479
        def OnChoiceChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   480
            res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection())
413946c04c87 refactoring
laurent
parents:
diff changeset
   481
            choicectrl.SetStringSelection(res)
413946c04c87 refactoring
laurent
parents:
diff changeset
   482
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   483
        return OnChoiceChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   484
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   485
    def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   486
        def OnChoiceContentChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   487
            res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection())
413946c04c87 refactoring
laurent
parents:
diff changeset
   488
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   489
        return OnChoiceContentChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   490
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   491
    def GetTextCtrlCallBackFunction(self, textctrl, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   492
        def OnTextCtrlChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   493
            res = self.SetConfNodeParamsAttribute(path, textctrl.GetValue())
413946c04c87 refactoring
laurent
parents:
diff changeset
   494
            if res != textctrl.GetValue():
413946c04c87 refactoring
laurent
parents:
diff changeset
   495
                textctrl.ChangeValue(res)
413946c04c87 refactoring
laurent
parents:
diff changeset
   496
            if textctrl == self.ConfNodeName:
413946c04c87 refactoring
laurent
parents:
diff changeset
   497
                wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES)
413946c04c87 refactoring
laurent
parents:
diff changeset
   498
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
413946c04c87 refactoring
laurent
parents:
diff changeset
   499
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   500
        return OnTextCtrlChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   501
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   502
    def GetCheckBoxCallBackFunction(self, chkbx, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   503
        def OnCheckBoxChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   504
            res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked())
413946c04c87 refactoring
laurent
parents:
diff changeset
   505
            chkbx.SetValue(res)
413946c04c87 refactoring
laurent
parents:
diff changeset
   506
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   507
        return OnCheckBoxChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   508
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   509
    def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   510
        infos = [value_infos]
413946c04c87 refactoring
laurent
parents:
diff changeset
   511
        def OnBrowseButton(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   512
            dialog = BrowseValuesLibraryDialog(self, name, library, infos[0])
413946c04c87 refactoring
laurent
parents:
diff changeset
   513
            if dialog.ShowModal() == wx.ID_OK:
413946c04c87 refactoring
laurent
parents:
diff changeset
   514
                value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos())
413946c04c87 refactoring
laurent
parents:
diff changeset
   515
                textctrl.ChangeValue(value)
413946c04c87 refactoring
laurent
parents:
diff changeset
   516
                infos[0] = value_infos
413946c04c87 refactoring
laurent
parents:
diff changeset
   517
            dialog.Destroy()
413946c04c87 refactoring
laurent
parents:
diff changeset
   518
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   519
        return OnBrowseButton
413946c04c87 refactoring
laurent
parents:
diff changeset
   520
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   521
    def OnWindowResize(self, event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   522
        self.GetBestSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   523
        xstart, ystart = self.ParamsEditor.GetViewStart()
413946c04c87 refactoring
laurent
parents:
diff changeset
   524
        window_size = self.ParamsEditor.GetClientSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   525
        maxx, maxy = self.ParamsEditorSizer.GetMinSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   526
        posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
413946c04c87 refactoring
laurent
parents:
diff changeset
   527
        posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
413946c04c87 refactoring
laurent
parents:
diff changeset
   528
        self.ParamsEditor.Scroll(posx, posy)
413946c04c87 refactoring
laurent
parents:
diff changeset
   529
        self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   530
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
413946c04c87 refactoring
laurent
parents:
diff changeset
   531
        event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   532
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   533
    def OnMouseWheel(self, event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   534
        if self.ScrollingEnabled:
413946c04c87 refactoring
laurent
parents:
diff changeset
   535
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   536