dialogs/BrowseLocationsDialog.py
author Laurent Bessard
Fri, 08 Jun 2012 12:36:24 +0200
changeset 707 e850bc674852
parent 681 c141dad94ff4
child 714 131ea7f237b9
permissions -rw-r--r--
Fix bug in SetProjectProperties function when asking to not buffering project
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     1
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     2
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     3
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     4
#See COPYING file for copyrights details.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     5
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     6
#This library is free software; you can redistribute it and/or
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     7
#modify it under the terms of the GNU General Public
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     8
#License as published by the Free Software Foundation; either
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     9
#version 2.1 of the License, or (at your option) any later version.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    10
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    11
#This library is distributed in the hope that it will be useful,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    12
#but WITHOUT ANY WARRANTY; without even the implied warranty of
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    13
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    14
#General Public License for more details.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    15
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    16
#You should have received a copy of the GNU General Public
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    17
#License along with this library; if not, write to the Free Software
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    18
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    19
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    20
import os
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    21
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    22
import wx
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    23
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    24
from plcopen.structures import LOCATIONDATATYPES
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
    25
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    26
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    27
CWD = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    28
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    29
def GetDirChoiceOptions():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    30
    _ = lambda x : x
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    31
    return [(_("All"), [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    32
            (_("Input"), [LOCATION_VAR_INPUT]), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    33
            (_("Output"), [LOCATION_VAR_OUTPUT]), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    34
            (_("Memory"), [LOCATION_VAR_MEMORY])]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    35
DIRCHOICE_OPTIONS_FILTER = dict([(_(option), filter) for option, filter in GetDirChoiceOptions()])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    36
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    37
# turn LOCATIONDATATYPES inside-out
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    38
LOCATION_SIZES = {}
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    39
for size, types in LOCATIONDATATYPES.iteritems():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    40
    for type in types:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    41
        LOCATION_SIZES[type] = size
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    42
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    43
[ID_BROWSELOCATIONSDIALOG, ID_BROWSELOCATIONSDIALOGLOCATIONSTREE, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    44
 ID_BROWSELOCATIONSDIALOGDIRCHOICE, ID_BROWSELOCATIONSDIALOGSTATICTEXT1, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    45
 ID_BROWSELOCATIONSDIALOGSTATICTEXT2, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    46
] = [wx.NewId() for _init_ctrls in range(5)]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    47
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    48
class BrowseLocationsDialog(wx.Dialog):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    49
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    50
    if wx.VERSION < (2, 6, 0):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    51
        def Bind(self, event, function, id = None):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    52
            if id is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    53
                event(self, id, function)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    54
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    55
                event(self, function)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    56
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    57
    def _init_coll_MainSizer_Items(self, parent):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    58
        parent.AddWindow(self.staticText1, 0, border=20, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    59
        parent.AddWindow(self.LocationsTree, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.GROW)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    60
        parent.AddSizer(self.ButtonGridSizer, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    61
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    62
    def _init_coll_MainSizer_Growables(self, parent):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    63
        parent.AddGrowableCol(0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    64
        parent.AddGrowableRow(1)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    65
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    66
    def _init_coll_ButtonGridSizer_Items(self, parent):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    67
        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    68
        parent.AddWindow(self.DirChoice, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    69
        parent.AddSizer(self.ButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    70
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    71
    def _init_coll_ButtonGridSizer_Growables(self, parent):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    72
        parent.AddGrowableCol(2)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    73
        parent.AddGrowableRow(0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    74
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    75
    def _init_sizers(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    76
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    77
        self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=5, rows=1, vgap=0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    78
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    79
        self._init_coll_MainSizer_Items(self.MainSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    80
        self._init_coll_MainSizer_Growables(self.MainSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    81
        self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    82
        self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    83
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    84
        self.SetSizer(self.MainSizer)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    85
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    86
    def _init_ctrls(self, prnt):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    87
        wx.Dialog.__init__(self, id=ID_BROWSELOCATIONSDIALOG, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    88
              name='BrowseLocationsDialog', parent=prnt,  
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    89
              size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    90
              title=_('Browse Locations'))
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    91
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    92
        self.staticText1 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT1,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    93
              label=_('Locations available:'), name='staticText1', parent=self,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    94
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    95
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    96
        if wx.Platform == '__WXMSW__':
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    97
            treestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    98
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    99
            treestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   100
        self.LocationsTree = wx.TreeCtrl(id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   101
              name='LocationsTree', parent=self, pos=wx.Point(0, 0),
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   102
              size=wx.Size(0, 0), style=treestyle)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   103
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnLocationsTreeItemActivated, 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   104
                  id=ID_BROWSELOCATIONSDIALOGLOCATIONSTREE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   105
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   106
        self.staticText2 = wx.StaticText(id=ID_BROWSELOCATIONSDIALOGSTATICTEXT2,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   107
              label=_('Direction:'), name='staticText2', parent=self,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   108
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   109
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   110
        self.DirChoice = wx.ComboBox(id=ID_BROWSELOCATIONSDIALOGDIRCHOICE,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   111
              name='DirChoice', parent=self, pos=wx.Point(0, 0),
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   112
              size=wx.DefaultSize, style=wx.CB_READONLY)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   113
        self.Bind(wx.EVT_COMBOBOX, self.OnDirChoice, id=ID_BROWSELOCATIONSDIALOGDIRCHOICE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   114
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   115
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   116
        if wx.VERSION >= (2, 5, 0):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   117
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   118
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   119
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   120
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   121
        self._init_sizers()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   122
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   123
    def __init__(self, parent, var_type, locations):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   124
        self._init_ctrls(parent)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   125
        self.VarType = var_type
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   126
        self.Locations = locations
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   127
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   128
        # Define Tree item icon list
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   129
        self.TreeImageList = wx.ImageList(16, 16)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   130
        self.TreeImageDict = {}
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   131
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   132
        # Icons for items
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   133
        for imgname, itemtype in [
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
   134
            ("CONFIGURATION", LOCATION_CONFNODE), 
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   135
            ("RESOURCE",      LOCATION_MODULE), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   136
            ("PROGRAM",       LOCATION_GROUP), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   137
            ("VAR_INPUT",     LOCATION_VAR_INPUT), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   138
            ("VAR_OUTPUT",    LOCATION_VAR_OUTPUT), 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   139
            ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   140
            self.TreeImageDict[itemtype]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%imgname)))
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   141
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   142
        # Assign icon list to TreeCtrls
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   143
        self.LocationsTree.SetImageList(self.TreeImageList)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   144
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   145
        # Set a options for the choice
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   146
        for option, filter in GetDirChoiceOptions():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   147
            self.DirChoice.Append(_(option))
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   148
        self.DirChoice.SetStringSelection(_("All"))
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   149
        self.RefreshFilter()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   150
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   151
        self.RefreshLocationsTree()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   152
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   153
    def RefreshFilter(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   154
        self.Filter = DIRCHOICE_OPTIONS_FILTER[self.DirChoice.GetStringSelection()]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   155
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   156
    def RefreshLocationsTree(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   157
        root = self.LocationsTree.GetRootItem()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   158
        if not root.IsOk():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   159
            if wx.Platform == '__WXMSW__':
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
   160
                root = self.LocationsTree.AddRoot(_('ConfNodes'))
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   161
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   162
                root = self.LocationsTree.AddRoot("")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   163
        self.GenerateLocationsTreeBranch(root, self.Locations)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   164
        self.LocationsTree.Expand(root)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   165
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   166
    def GenerateLocationsTreeBranch(self, root, locations):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   167
        to_delete = []
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   168
        if wx.VERSION >= (2, 6, 0):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   169
            item, root_cookie = self.LocationsTree.GetFirstChild(root)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   170
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   171
            item, root_cookie = self.LocationsTree.GetFirstChild(root, 0)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   172
        for loc_infos in locations:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   173
            infos = loc_infos.copy()
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
   174
            if infos["type"] in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP] or\
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   175
               infos["type"] in self.Filter and (infos["IEC_type"] == self.VarType or
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   176
               infos["IEC_type"] is None and LOCATION_SIZES[self.VarType] == infos["size"]):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   177
                children = [child for child in infos.pop("children")]
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   178
                if not item.IsOk():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   179
                    item = self.LocationsTree.AppendItem(root, infos["name"])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   180
                    if wx.Platform != '__WXMSW__':
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   181
                        item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   182
                else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   183
                    self.LocationsTree.SetItemText(item, infos["name"])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   184
                self.LocationsTree.SetPyData(item, infos)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   185
                self.LocationsTree.SetItemImage(item, self.TreeImageDict[infos["type"]])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   186
                self.GenerateLocationsTreeBranch(item, children)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   187
                item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   188
        while item.IsOk():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   189
            to_delete.append(item)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   190
            item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   191
        for item in to_delete:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   192
            self.LocationsTree.Delete(item)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   193
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   194
    def OnLocationsTreeItemActivated(self, event):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   195
        infos = self.LocationsTree.GetPyData(event.GetItem())
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
   196
        if infos["type"] not in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP]:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   197
            wx.CallAfter(self.EndModal, wx.ID_OK)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   198
        event.Skip()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   199
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   200
    def OnDirChoice(self, event):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   201
        self.RefreshFilter()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   202
        self.RefreshLocationsTree()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   203
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   204
    def GetValues(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   205
        selected = self.LocationsTree.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   206
        return self.LocationsTree.GetPyData(selected)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   207
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   208
    def OnOK(self, event):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   209
        selected = self.LocationsTree.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   210
        var_infos = None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   211
        if selected.IsOk():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   212
            var_infos = self.LocationsTree.GetPyData(selected)
681
c141dad94ff4 beremiz 'plugins' refactoring to 'confnode'
Edouard Tisserant
parents: 586
diff changeset
   213
        if var_infos is None or var_infos["type"] in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP]:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   214
            message = wx.MessageDialog(self, _("A location must be selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   215
            message.ShowModal()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   216
            message.Destroy()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   217
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   218
            self.EndModal(wx.ID_OK)