editors/ConfTreeNodeEditor.py
author Laurent Bessard
Wed, 08 May 2013 18:33:49 +0200
changeset 1095 a73fde048749
parent 1059 50246061d5c6
child 1105 f0e5b475a074
permissions -rw-r--r--
Move C_ext file for merging with py_ext
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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
     8
from EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
     9
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
    10
from IDEFrame import TITLE, FILEMENU, PROJECTTREE, PAGETITLES
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
    11
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
    12
from controls import TextCtrlAutoComplete
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
    13
from dialogs import BrowseValuesLibraryDialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 781
diff changeset
    14
from util.BitmapLibrary import GetBitmap
738
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
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
    32
WINDOW_COLOUR = wx.Colour(240, 240, 240)
738
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
        
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   127
        wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   128
                 GetBitmap(bitmapname),
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   129
                 pos, size,
413946c04c87 refactoring
laurent
parents:
diff changeset
   130
                 style,
413946c04c87 refactoring
laurent
parents:
diff changeset
   131
                 name)
413946c04c87 refactoring
laurent
parents:
diff changeset
   132
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   133
    def OnPaint(self, event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   134
        dc = wx.PaintDC(self)
413946c04c87 refactoring
laurent
parents:
diff changeset
   135
        colour = self.GetParent().GetBackgroundColour()
413946c04c87 refactoring
laurent
parents:
diff changeset
   136
        dc.SetPen(wx.Pen(colour))
413946c04c87 refactoring
laurent
parents:
diff changeset
   137
        dc.SetBrush(wx.Brush(colour ))
413946c04c87 refactoring
laurent
parents:
diff changeset
   138
        dc.DrawRectangle(0, 0, *dc.GetSizeTuple())
413946c04c87 refactoring
laurent
parents:
diff changeset
   139
        if self._bitmap:
413946c04c87 refactoring
laurent
parents:
diff changeset
   140
            dc.DrawBitmap(self._bitmap, 0, 0, True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   141
413946c04c87 refactoring
laurent
parents:
diff changeset
   142
class ConfTreeNodeEditor(EditorPanel):
413946c04c87 refactoring
laurent
parents:
diff changeset
   143
    
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   144
    SHOW_BASE_PARAMS = True
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   145
    SHOW_PARAMS = True
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   146
    CONFNODEEDITOR_TABS = []
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   147
    
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   148
    def _init_Editor(self, parent):
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   149
        tabs_num = len(self.CONFNODEEDITOR_TABS)
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   150
        if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   151
            tabs_num += 1
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   152
            
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   153
        if tabs_num > 1 or self.SHOW_BASE_PARAMS:
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   154
            self.Editor = wx.Panel(parent, 
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   155
                style=wx.SUNKEN_BORDER|wx.SP_3D)
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   156
            self.Editor.SetBackgroundColour(WINDOW_COLOUR)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   157
            
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   158
            self.MainSizer = wx.BoxSizer(wx.VERTICAL)
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   159
            
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   160
            if self.SHOW_BASE_PARAMS:
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   161
                baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   162
                self.MainSizer.AddSizer(baseparamseditor_sizer, border=5, 
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   163
                      flag=wx.GROW|wx.ALL)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   164
                
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   165
                self.FullIECChannel = wx.StaticText(self.Editor, -1)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   166
                self.FullIECChannel.SetFont(
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   167
                    wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, 
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   168
                            wx.BOLD, faceName = faces["helv"]))
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   169
                baseparamseditor_sizer.AddWindow(self.FullIECChannel, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   170
                      flag=wx.ALIGN_CENTER_VERTICAL)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   171
                
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   172
                updownsizer = wx.BoxSizer(wx.VERTICAL)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   173
                baseparamseditor_sizer.AddSizer(updownsizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   174
                      flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   175
                
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   176
                self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.Editor, 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   177
                      bitmap=GetBitmap('IECCDown'), size=wx.Size(16, 16), style=wx.NO_BORDER)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   178
                self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   179
                      self.IECCUpButton)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   180
                updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   181
                
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   182
                self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.Editor, 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   183
                      bitmap=GetBitmap('IECCUp'), size=wx.Size(16, 16), style=wx.NO_BORDER)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   184
                self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   185
                      self.IECCDownButton)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   186
                updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   187
                
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   188
                self.ConfNodeName = wx.TextCtrl(self.Editor, 
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   189
                      size=wx.Size(150, 25), style=wx.NO_BORDER)
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   190
                self.ConfNodeName.SetFont(
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   191
                    wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, 
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   192
                            wx.BOLD, faceName = faces["helv"]))
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   193
                self.ConfNodeName.Bind(wx.EVT_TEXT, 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   194
                      self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   195
                      self.ConfNodeName)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   196
                baseparamseditor_sizer.AddWindow(self.ConfNodeName, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   197
                      flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   198
                
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   199
                buttons_sizer = self.GenerateMethodButtonSizer()
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   200
                baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   201
            
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   202
            if tabs_num > 1:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   203
                self.ConfNodeNoteBook = wx.Notebook(self.Editor)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   204
                parent = self.ConfNodeNoteBook
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   205
                self.MainSizer.AddWindow(self.ConfNodeNoteBook, 1, flag=wx.GROW)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   206
            else:
1059
50246061d5c6 Fixed new ConfTreeNodeEditor layout on Windows
Laurent Bessard
parents: 1055
diff changeset
   207
                parent = self.Editor
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   208
                self.ConfNodeNoteBook = None
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   209
            
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   210
            self.Editor.SetSizer(self.MainSizer)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   211
        else:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   212
            self.ConfNodeNoteBook = None
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   213
            self.Editor = None
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   214
        
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   215
        for title, create_func_name in self.CONFNODEEDITOR_TABS:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   216
            editor = getattr(self, create_func_name)(parent)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   217
            if self.ConfNodeNoteBook is not None:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   218
                self.ConfNodeNoteBook.AddPage(editor, title)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   219
            elif self.SHOW_BASE_PARAMS:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   220
                self.MainSizer.AddWindow(editor, 1, flag=wx.GROW)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   221
            else:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   222
                self.Editor = editor
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   223
        
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   224
        if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   225
            
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   226
            panel_style = wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL
1059
50246061d5c6 Fixed new ConfTreeNodeEditor layout on Windows
Laurent Bessard
parents: 1055
diff changeset
   227
            if self.ConfNodeNoteBook is None and parent != self.Editor:
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   228
                panel_style |= wx.SUNKEN_BORDER
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   229
            self.ParamsEditor = wx.ScrolledWindow(parent, 
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   230
                  style=panel_style)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   231
            self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   232
            self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   233
            self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   234
            
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   235
            # Variable allowing disabling of ParamsEditor scroll when Popup shown 
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   236
            self.ScrollingEnabled = True
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   237
            
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   238
            self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   239
            self.ParamsEditorSizer.AddGrowableCol(0)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   240
            self.ParamsEditorSizer.AddGrowableRow(0)
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   241
            self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   242
            
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   243
            self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   244
            self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   245
                  flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
775
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   246
            
172be32a2482 Adding support for hiding node base params controls if needed
laurent
parents: 767
diff changeset
   247
            self.RefreshConfNodeParamsSizer()
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   248
        
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   249
            if self.ConfNodeNoteBook is not None:
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   250
                self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config"))
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   251
            elif self.SHOW_BASE_PARAMS:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   252
                self.MainSizer.AddWindow(self.ParamsEditor, 1, flag=wx.GROW)
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   253
            else:
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 846
diff changeset
   254
                self.Editor = self.ParamsEditor
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   255
        else:
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   256
            self.ParamsEditor = None
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   257
    
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   258
    def __init__(self, parent, controler, window, tagname=""):
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   259
        EditorPanel.__init__(self, parent, tagname, window, controler)
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   260
        
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   261
        icon_name = self.Controler.GetIconName()
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   262
        if icon_name is not None:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   263
            self.SetIcon(GetBitmap(icon_name))
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   264
        else:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   265
            self.SetIcon(GetBitmap("Extension"))
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   266
        
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   267
    def __del__(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   268
        self.Controler.OnCloseEditor(self)
413946c04c87 refactoring
laurent
parents:
diff changeset
   269
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   270
    def GetTagName(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   271
        return self.Controler.CTNFullName()
413946c04c87 refactoring
laurent
parents:
diff changeset
   272
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   273
    def GetTitle(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   274
        fullname = self.Controler.CTNFullName()
413946c04c87 refactoring
laurent
parents:
diff changeset
   275
        if self.Controler.CTNTestModified():
413946c04c87 refactoring
laurent
parents:
diff changeset
   276
            return "~%s~" % fullname
413946c04c87 refactoring
laurent
parents:
diff changeset
   277
        return fullname
413946c04c87 refactoring
laurent
parents:
diff changeset
   278
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   279
    def HasNoModel(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   280
        return False
413946c04c87 refactoring
laurent
parents:
diff changeset
   281
    
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   282
    def GetBufferState(self):
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   283
        return False, False
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   284
    
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   285
    def Undo(self):
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   286
        pass
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   287
    
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   288
    def Redo(self):
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   289
        pass
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 738
diff changeset
   290
    
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   291
    def RefreshView(self):
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   292
        EditorPanel.RefreshView(self)
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   293
        if self.SHOW_BASE_PARAMS:
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   294
            self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   295
            self.RefreshIECChannelControlsState()
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   296
        if self.ParamsEditor is not None:
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 751
diff changeset
   297
            self.RefreshConfNodeParamsSizer()
840
980863738cf6 Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents: 814
diff changeset
   298
            self.RefreshScrollbars()
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   299
    
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   300
    def EnableScrolling(self, enable):
413946c04c87 refactoring
laurent
parents:
diff changeset
   301
        self.ScrollingEnabled = enable
413946c04c87 refactoring
laurent
parents:
diff changeset
   302
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   303
    def RefreshIECChannelControlsState(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   304
        self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel())
413946c04c87 refactoring
laurent
parents:
diff changeset
   305
        self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0)
1059
50246061d5c6 Fixed new ConfTreeNodeEditor layout on Windows
Laurent Bessard
parents: 1055
diff changeset
   306
        self.MainSizer.Layout()
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   307
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   308
    def RefreshConfNodeParamsSizer(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   309
        self.Freeze()
413946c04c87 refactoring
laurent
parents:
diff changeset
   310
        self.ConfNodeParamsSizer.Clear(True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   311
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   312
        confnode_infos = self.Controler.GetParamsAttributes()
413946c04c87 refactoring
laurent
parents:
diff changeset
   313
        if len(confnode_infos) > 0:
413946c04c87 refactoring
laurent
parents:
diff changeset
   314
            self.GenerateSizerElements(self.ConfNodeParamsSizer, confnode_infos, None, False)
413946c04c87 refactoring
laurent
parents:
diff changeset
   315
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   316
        self.ParamsEditorSizer.Layout()
413946c04c87 refactoring
laurent
parents:
diff changeset
   317
        self.Thaw()
413946c04c87 refactoring
laurent
parents:
diff changeset
   318
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   319
    def GenerateMethodButtonSizer(self):
413946c04c87 refactoring
laurent
parents:
diff changeset
   320
        normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   321
        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
   322
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   323
        msizer = wx.BoxSizer(wx.HORIZONTAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   324
        
413946c04c87 refactoring
laurent
parents:
diff changeset
   325
        for confnode_method in self.Controler.ConfNodeMethods:
413946c04c87 refactoring
laurent
parents:
diff changeset
   326
            if "method" in confnode_method and confnode_method.get("shown",True):
1055
da483f620668 Fixed ConfTreeNodeEditor layout
Laurent Bessard
parents: 920
diff changeset
   327
                button = GenBitmapTextButton(self.Editor,
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   328
                    bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")), 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   329
                    label=confnode_method["name"], style=wx.NO_BORDER)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   330
                button.SetFont(normal_bt_font)
413946c04c87 refactoring
laurent
parents:
diff changeset
   331
                button.SetToolTipString(confnode_method["tooltip"])
767
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   332
                if confnode_method.get("push", False):
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   333
                    button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True))
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   334
                else:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   335
                    button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), button)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   336
                # a fancy underline on mouseover
413946c04c87 refactoring
laurent
parents:
diff changeset
   337
                def setFontStyle(b, s):
413946c04c87 refactoring
laurent
parents:
diff changeset
   338
                    def fn(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   339
                        b.SetFont(s)
413946c04c87 refactoring
laurent
parents:
diff changeset
   340
                        b.Refresh()
413946c04c87 refactoring
laurent
parents:
diff changeset
   341
                        event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   342
                    return fn
413946c04c87 refactoring
laurent
parents:
diff changeset
   343
                button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font))
413946c04c87 refactoring
laurent
parents:
diff changeset
   344
                button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font))
413946c04c87 refactoring
laurent
parents:
diff changeset
   345
                #hack to force size to mini
413946c04c87 refactoring
laurent
parents:
diff changeset
   346
                if not confnode_method.get("enabled",True):
413946c04c87 refactoring
laurent
parents:
diff changeset
   347
                    button.Disable()
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   348
                msizer.AddWindow(button, flag=wx.ALIGN_CENTER)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   349
        return msizer
413946c04c87 refactoring
laurent
parents:
diff changeset
   350
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   351
    def GenerateSizerElements(self, sizer, elements, path, clean = True):
413946c04c87 refactoring
laurent
parents:
diff changeset
   352
        if clean:
413946c04c87 refactoring
laurent
parents:
diff changeset
   353
            sizer.Clear(True)
413946c04c87 refactoring
laurent
parents:
diff changeset
   354
        first = True
413946c04c87 refactoring
laurent
parents:
diff changeset
   355
        for element_infos in elements:
413946c04c87 refactoring
laurent
parents:
diff changeset
   356
            if path:
413946c04c87 refactoring
laurent
parents:
diff changeset
   357
                element_path = "%s.%s"%(path, element_infos["name"])
413946c04c87 refactoring
laurent
parents:
diff changeset
   358
            else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   359
                element_path = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   360
            if element_infos["type"] == "element":
413946c04c87 refactoring
laurent
parents:
diff changeset
   361
                label = element_infos["name"]
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   362
                staticbox = wx.StaticBox(self.ParamsEditor, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   363
                      label=_(label), size=wx.Size(10, 0))
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   364
                staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
413946c04c87 refactoring
laurent
parents:
diff changeset
   365
                if first:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   366
                    sizer.AddSizer(staticboxsizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   367
                          flag=wx.GROW|wx.TOP|wx.BOTTOM)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   368
                else:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   369
                    sizer.AddSizer(staticboxsizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   370
                          flag=wx.GROW|wx.BOTTOM)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   371
                self.GenerateSizerElements(staticboxsizer, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   372
                                           element_infos["children"], 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   373
                                           element_path)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   374
            else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   375
                boxsizer = wx.FlexGridSizer(cols=3, rows=1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   376
                boxsizer.AddGrowableCol(1)
413946c04c87 refactoring
laurent
parents:
diff changeset
   377
                if first:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   378
                    sizer.AddSizer(boxsizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   379
                          flag=wx.GROW|wx.ALL)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   380
                else:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   381
                    sizer.AddSizer(boxsizer, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   382
                          flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   383
                
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   384
                staticbitmap = GenStaticBitmap(ID=-1, bitmapname=element_infos["name"],
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   385
                    name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor,
413946c04c87 refactoring
laurent
parents:
diff changeset
   386
                    pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   387
                boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   388
                
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   389
                statictext = wx.StaticText(self.ParamsEditor, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   390
                      label="%s:"%_(element_infos["name"]))
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   391
                boxsizer.AddWindow(statictext, border=5, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   392
                      flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   393
                
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   394
                if isinstance(element_infos["type"], types.ListType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   395
                    if isinstance(element_infos["value"], types.TupleType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   396
                        browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   397
                        boxsizer.AddSizer(browse_boxsizer)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   398
                        
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   399
                        textctrl = wx.TextCtrl(self.ParamsEditor, 
846
26836e421e19 Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents: 844
diff changeset
   400
                              size=wx.Size(275, -1), style=wx.TE_READONLY)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   401
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   402
                            textctrl.SetValue(element_infos["value"][0])
413946c04c87 refactoring
laurent
parents:
diff changeset
   403
                            value_infos = element_infos["value"][1]
413946c04c87 refactoring
laurent
parents:
diff changeset
   404
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   405
                            value_infos = None
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   406
                        browse_boxsizer.AddWindow(textctrl)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   407
                        
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   408
                        button = wx.Button(self.ParamsEditor, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   409
                              label="...", size=wx.Size(25, 25))
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   410
                        browse_boxsizer.AddWindow(button)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   411
                        button.Bind(wx.EVT_BUTTON, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   412
                                    self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], 
413946c04c87 refactoring
laurent
parents:
diff changeset
   413
                                                                   value_infos, element_path), 
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   414
                                    button)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   415
                    else:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   416
                        combobox = wx.ComboBox(self.ParamsEditor, 
846
26836e421e19 Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents: 844
diff changeset
   417
                              size=wx.Size(300, -1), style=wx.CB_READONLY)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   418
                        boxsizer.AddWindow(combobox)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   419
                        
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   420
                        if element_infos["use"] == "optional":
413946c04c87 refactoring
laurent
parents:
diff changeset
   421
                            combobox.Append("")
413946c04c87 refactoring
laurent
parents:
diff changeset
   422
                        if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   423
                            for choice, xsdclass in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   424
                                combobox.Append(choice)
413946c04c87 refactoring
laurent
parents:
diff changeset
   425
                            name = element_infos["name"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   426
                            value = element_infos["value"]
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   427
                        
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   428
                            staticbox = wx.StaticBox(self.ParamsEditor, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   429
                                  label="%s - %s"%(_(name), _(value)), size=wx.Size(10, 0))
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   430
                            staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   431
                            sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW|wx.BOTTOM)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   432
                            self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   433
                            callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   434
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   435
                            for choice in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   436
                                combobox.Append(choice)
413946c04c87 refactoring
laurent
parents:
diff changeset
   437
                            callback = self.GetChoiceCallBackFunction(combobox, element_path)
413946c04c87 refactoring
laurent
parents:
diff changeset
   438
                        if element_infos["value"] is None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   439
                            combobox.SetStringSelection("")
413946c04c87 refactoring
laurent
parents:
diff changeset
   440
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   441
                            combobox.SetStringSelection(element_infos["value"])
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   442
                        combobox.Bind(wx.EVT_COMBOBOX, callback, combobox)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   443
                
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   444
                elif isinstance(element_infos["type"], types.DictType):
413946c04c87 refactoring
laurent
parents:
diff changeset
   445
                    scmin = -(2**31)
413946c04c87 refactoring
laurent
parents:
diff changeset
   446
                    scmax = 2**31-1
413946c04c87 refactoring
laurent
parents:
diff changeset
   447
                    if "min" in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   448
                        scmin = element_infos["type"]["min"]
413946c04c87 refactoring
laurent
parents:
diff changeset
   449
                    if "max" in element_infos["type"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   450
                        scmax = element_infos["type"]["max"]
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   451
                    spinctrl = wx.SpinCtrl(self.ParamsEditor, 
846
26836e421e19 Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents: 844
diff changeset
   452
                          size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   453
                    spinctrl.SetRange(scmin, scmax)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   454
                    boxsizer.AddWindow(spinctrl)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   455
                    if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   456
                        spinctrl.SetValue(element_infos["value"])
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   457
                    spinctrl.Bind(wx.EVT_SPINCTRL, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   458
                                  self.GetTextCtrlCallBackFunction(spinctrl, element_path),
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   459
                                  spinctrl)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   460
                
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   461
                else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   462
                    if element_infos["type"] == "boolean":
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   463
                        checkbox = wx.CheckBox(self.ParamsEditor, size=wx.Size(17, 25))
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   464
                        boxsizer.AddWindow(checkbox)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   465
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   466
                            checkbox.SetValue(element_infos["value"])
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   467
                        checkbox.Bind(wx.EVT_CHECKBOX, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   468
                                      self.GetCheckBoxCallBackFunction(checkbox, element_path), 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   469
                                      checkbox)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   470
                    
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   471
                    elif element_infos["type"] in ["unsignedLong", "long","integer"]:
413946c04c87 refactoring
laurent
parents:
diff changeset
   472
                        if element_infos["type"].startswith("unsigned"):
413946c04c87 refactoring
laurent
parents:
diff changeset
   473
                            scmin = 0
413946c04c87 refactoring
laurent
parents:
diff changeset
   474
                        else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   475
                            scmin = -(2**31)
413946c04c87 refactoring
laurent
parents:
diff changeset
   476
                        scmax = 2**31-1
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   477
                        spinctrl = wx.SpinCtrl(self.ParamsEditor, 
846
26836e421e19 Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents: 844
diff changeset
   478
                              size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   479
                        spinctrl.SetRange(scmin, scmax)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   480
                        boxsizer.AddWindow(spinctrl)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   481
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   482
                            spinctrl.SetValue(element_infos["value"])
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   483
                        spinctrl.Bind(wx.EVT_SPINCTRL, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   484
                                      self.GetTextCtrlCallBackFunction(spinctrl, element_path), 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   485
                                      spinctrl)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   486
                    
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   487
                    else:
413946c04c87 refactoring
laurent
parents:
diff changeset
   488
                        choices = self.ParentWindow.GetConfigEntry(element_path, [""])
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   489
                        textctrl = TextCtrlAutoComplete(name=element_infos["name"], 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   490
                                                        parent=self.ParamsEditor, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   491
                                                        appframe=self, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   492
                                                        choices=choices, 
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   493
                                                        element_path=element_path,
846
26836e421e19 Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents: 844
diff changeset
   494
                                                        size=wx.Size(300, -1))
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   495
                        
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 775
diff changeset
   496
                        boxsizer.AddWindow(textctrl)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   497
                        if element_infos["value"] is not None:
413946c04c87 refactoring
laurent
parents:
diff changeset
   498
                            textctrl.ChangeValue(str(element_infos["value"]))
413946c04c87 refactoring
laurent
parents:
diff changeset
   499
                        textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path))
413946c04c87 refactoring
laurent
parents:
diff changeset
   500
            first = False
413946c04c87 refactoring
laurent
parents:
diff changeset
   501
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   502
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   503
    def GetItemChannelChangedFunction(self, dir):
413946c04c87 refactoring
laurent
parents:
diff changeset
   504
        def OnConfNodeTreeItemChannelChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   505
            confnode_IECChannel = self.Controler.BaseParams.getIEC_Channel()
413946c04c87 refactoring
laurent
parents:
diff changeset
   506
            res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir)
413946c04c87 refactoring
laurent
parents:
diff changeset
   507
            wx.CallAfter(self.RefreshIECChannelControlsState)
413946c04c87 refactoring
laurent
parents:
diff changeset
   508
            wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE)
413946c04c87 refactoring
laurent
parents:
diff changeset
   509
            wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
413946c04c87 refactoring
laurent
parents:
diff changeset
   510
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   511
        return OnConfNodeTreeItemChannelChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   512
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   513
    def SetConfNodeParamsAttribute(self, *args, **kwargs):
413946c04c87 refactoring
laurent
parents:
diff changeset
   514
        res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs)
413946c04c87 refactoring
laurent
parents:
diff changeset
   515
        if StructChanged:
413946c04c87 refactoring
laurent
parents:
diff changeset
   516
            wx.CallAfter(self.RefreshConfNodeParamsSizer)
413946c04c87 refactoring
laurent
parents:
diff changeset
   517
        wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU)
413946c04c87 refactoring
laurent
parents:
diff changeset
   518
        return res
413946c04c87 refactoring
laurent
parents:
diff changeset
   519
    
767
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   520
    def GetButtonCallBackFunction(self, method, push=False):
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   521
        """ Generate the callbackfunc for a given confnode method"""
413946c04c87 refactoring
laurent
parents:
diff changeset
   522
        def OnButtonClick(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   523
            # Disable button to prevent re-entrant call 
413946c04c87 refactoring
laurent
parents:
diff changeset
   524
            event.GetEventObject().Disable()
413946c04c87 refactoring
laurent
parents:
diff changeset
   525
            # Call
413946c04c87 refactoring
laurent
parents:
diff changeset
   526
            getattr(self.Controler,method)()
413946c04c87 refactoring
laurent
parents:
diff changeset
   527
            # Re-enable button 
413946c04c87 refactoring
laurent
parents:
diff changeset
   528
            event.GetEventObject().Enable()
413946c04c87 refactoring
laurent
parents:
diff changeset
   529
            
767
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   530
            if not push:
36e823a90d94 Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents: 762
diff changeset
   531
                event.Skip()
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   532
        return OnButtonClick
413946c04c87 refactoring
laurent
parents:
diff changeset
   533
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   534
    def GetChoiceCallBackFunction(self, choicectrl, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   535
        def OnChoiceChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   536
            res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection())
413946c04c87 refactoring
laurent
parents:
diff changeset
   537
            choicectrl.SetStringSelection(res)
413946c04c87 refactoring
laurent
parents:
diff changeset
   538
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   539
        return OnChoiceChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   540
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   541
    def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   542
        def OnChoiceContentChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   543
            res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection())
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   544
            wx.CallAfter(self.RefreshConfNodeParamsSizer)
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   545
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   546
        return OnChoiceContentChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   547
    
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   548
    def GetTextCtrlCallBackFunction(self, textctrl, path, refresh=False):
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   549
        def OnTextCtrlChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   550
            res = self.SetConfNodeParamsAttribute(path, textctrl.GetValue())
413946c04c87 refactoring
laurent
parents:
diff changeset
   551
            if res != textctrl.GetValue():
844
ec9e6ef49878 Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents: 840
diff changeset
   552
                if isinstance(textctrl, wx.SpinCtrl):
ec9e6ef49878 Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents: 840
diff changeset
   553
                    textctrl.SetValue(res)
ec9e6ef49878 Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents: 840
diff changeset
   554
                else:
ec9e6ef49878 Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents: 840
diff changeset
   555
                    textctrl.ChangeValue(res)
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   556
            if refresh:
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   557
                wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES)
413946c04c87 refactoring
laurent
parents:
diff changeset
   558
                wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
413946c04c87 refactoring
laurent
parents:
diff changeset
   559
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   560
        return OnTextCtrlChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   561
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   562
    def GetCheckBoxCallBackFunction(self, chkbx, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   563
        def OnCheckBoxChanged(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   564
            res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked())
413946c04c87 refactoring
laurent
parents:
diff changeset
   565
            chkbx.SetValue(res)
413946c04c87 refactoring
laurent
parents:
diff changeset
   566
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   567
        return OnCheckBoxChanged
413946c04c87 refactoring
laurent
parents:
diff changeset
   568
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   569
    def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path):
413946c04c87 refactoring
laurent
parents:
diff changeset
   570
        infos = [value_infos]
413946c04c87 refactoring
laurent
parents:
diff changeset
   571
        def OnBrowseButton(event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   572
            dialog = BrowseValuesLibraryDialog(self, name, library, infos[0])
413946c04c87 refactoring
laurent
parents:
diff changeset
   573
            if dialog.ShowModal() == wx.ID_OK:
413946c04c87 refactoring
laurent
parents:
diff changeset
   574
                value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos())
413946c04c87 refactoring
laurent
parents:
diff changeset
   575
                textctrl.ChangeValue(value)
413946c04c87 refactoring
laurent
parents:
diff changeset
   576
                infos[0] = value_infos
413946c04c87 refactoring
laurent
parents:
diff changeset
   577
            dialog.Destroy()
413946c04c87 refactoring
laurent
parents:
diff changeset
   578
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   579
        return OnBrowseButton
413946c04c87 refactoring
laurent
parents:
diff changeset
   580
    
840
980863738cf6 Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents: 814
diff changeset
   581
    def RefreshScrollbars(self):
746
2e09777a40d3 Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents: 744
diff changeset
   582
        self.ParamsEditor.GetBestSize()
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   583
        xstart, ystart = self.ParamsEditor.GetViewStart()
413946c04c87 refactoring
laurent
parents:
diff changeset
   584
        window_size = self.ParamsEditor.GetClientSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   585
        maxx, maxy = self.ParamsEditorSizer.GetMinSize()
413946c04c87 refactoring
laurent
parents:
diff changeset
   586
        posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
413946c04c87 refactoring
laurent
parents:
diff changeset
   587
        posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
413946c04c87 refactoring
laurent
parents:
diff changeset
   588
        self.ParamsEditor.Scroll(posx, posy)
413946c04c87 refactoring
laurent
parents:
diff changeset
   589
        self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
413946c04c87 refactoring
laurent
parents:
diff changeset
   590
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
840
980863738cf6 Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents: 814
diff changeset
   591
    
980863738cf6 Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents: 814
diff changeset
   592
    def OnWindowResize(self, event):
980863738cf6 Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents: 814
diff changeset
   593
        self.RefreshScrollbars()
738
413946c04c87 refactoring
laurent
parents:
diff changeset
   594
        event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   595
    
413946c04c87 refactoring
laurent
parents:
diff changeset
   596
    def OnMouseWheel(self, event):
413946c04c87 refactoring
laurent
parents:
diff changeset
   597
        if self.ScrollingEnabled:
413946c04c87 refactoring
laurent
parents:
diff changeset
   598
            event.Skip()
413946c04c87 refactoring
laurent
parents:
diff changeset
   599