controls/VariablePanel.py
branchpython3
changeset 3750 f62625418bff
parent 3660 0e41dbe6ddcd
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 
    27 from __future__ import division
    27 
    28 import re
    28 import re
    29 from builtins import str as text
    29 from builtins import str as text
    30 
    30 
    31 import wx
    31 import wx
    32 import wx.grid
    32 import wx.grid
    52 
    52 
    53 
    53 
    54 [
    54 [
    55     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
    55     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
    56     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
    56     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
    57 ] = range(10)
    57 ] = list(range(10))
    58 
    58 
    59 
    59 
    60 def GetVariableTableColnames(location):
    60 def GetVariableTableColnames(location):
    61     _ = NoTranslate
    61     _ = NoTranslate
    62     cols = ["#",
    62     cols = ["#",
   121         CustomTable.__init__(self, parent, data, colnames)
   121         CustomTable.__init__(self, parent, data, colnames)
   122         self.old_value = None
   122         self.old_value = None
   123         self.OPTIONS_DICT = dict([(_(option), option)
   123         self.OPTIONS_DICT = dict([(_(option), option)
   124                                   for option in GetOptions()])
   124                                   for option in GetOptions()])
   125         self.VARIABLE_CLASSES_DICT = dict([(_(_class), _class)
   125         self.VARIABLE_CLASSES_DICT = dict([(_(_class), _class)
   126                                            for _class in GetFilterChoiceTransfer().itervalues()])
   126                                            for _class in GetFilterChoiceTransfer().values()])
   127 
   127 
   128     def GetValueByName(self, row, colname):
   128     def GetValueByName(self, row, colname):
   129         if row < self.GetNumberRows():
   129         if row < self.GetNumberRows():
   130             return getattr(self.data[row], colname)
   130             return getattr(self.data[row], colname)
   131 
   131 
   198                     if colname == "Option":
   198                     if colname == "Option":
   199                         options = GetOptions(constant=var_class in ["Local", "External", "Global"],
   199                         options = GetOptions(constant=var_class in ["Local", "External", "Global"],
   200                                              retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   200                                              retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   201                                              non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   201                                              non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   202                         if len(options) > 1:
   202                         if len(options) > 1:
   203                             editor = wx.grid.GridCellChoiceEditor(map(_, options))
   203                             editor = wx.grid.GridCellChoiceEditor(list(map(_, options)))
   204                         else:
   204                         else:
   205                             grid.SetReadOnly(row, col, True)
   205                             grid.SetReadOnly(row, col, True)
   206                     elif col != 0 and self._GetRowEdit(row):
   206                     elif col != 0 and self._GetRowEdit(row):
   207                         grid.SetReadOnly(row, col, False)
   207                         grid.SetReadOnly(row, col, False)
   208                         if colname == "Name":
   208                         if colname == "Name":
   445 
   445 
   446     def __init__(self, parent, window, controler, element_type, debug=False):
   446     def __init__(self, parent, window, controler, element_type, debug=False):
   447         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   447         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   448 
   448 
   449         self.VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for
   449         self.VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for
   450                                            _class in GetFilterChoiceTransfer().iterkeys()])
   450                                            _class in GetFilterChoiceTransfer().keys()])
   451 
   451 
   452         self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
   452         self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
   453         self.MainSizer.AddGrowableCol(0)
   453         self.MainSizer.AddGrowableCol(0)
   454         self.MainSizer.AddGrowableRow(1)
   454         self.MainSizer.AddGrowableRow(1)
   455 
   455 
   579 
   579 
   580         for choice in self.FilterChoices:
   580         for choice in self.FilterChoices:
   581             self.ClassFilter.Append(_(choice))
   581             self.ClassFilter.Append(_(choice))
   582 
   582 
   583         reverse_transfer = {}
   583         reverse_transfer = {}
   584         for filter, choice in self.FilterChoiceTransfer.items():
   584         for filter, choice in list(self.FilterChoiceTransfer.items()):
   585             reverse_transfer[choice] = filter
   585             reverse_transfer[choice] = filter
   586         self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
   586         self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
   587         self.RefreshTypeList()
   587         self.RefreshTypeList()
   588 
   588 
   589         self.VariablesGrid.SetTable(self.Table)
   589         self.VariablesGrid.SetTable(self.Table)
   993         self.Table.ResetView(self.VariablesGrid)
   993         self.Table.ResetView(self.VariablesGrid)
   994         event.Skip()
   994         event.Skip()
   995 
   995 
   996     def AddVariableHighlight(self, infos, highlight_type):
   996     def AddVariableHighlight(self, infos, highlight_type):
   997         if isinstance(infos[0], tuple):
   997         if isinstance(infos[0], tuple):
   998             for i in xrange(*infos[0]):
   998             for i in range(*infos[0]):
   999                 self.Table.AddHighlight((i,) + infos[1:], highlight_type)
   999                 self.Table.AddHighlight((i,) + infos[1:], highlight_type)
  1000             cell_visible = infos[0][0]
  1000             cell_visible = infos[0][0]
  1001         else:
  1001         else:
  1002             self.Table.AddHighlight(infos, highlight_type)
  1002             self.Table.AddHighlight(infos, highlight_type)
  1003             cell_visible = infos[0]
  1003             cell_visible = infos[0]
  1005         self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
  1005         self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
  1006         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1006         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1007 
  1007 
  1008     def RemoveVariableHighlight(self, infos, highlight_type):
  1008     def RemoveVariableHighlight(self, infos, highlight_type):
  1009         if isinstance(infos[0], tuple):
  1009         if isinstance(infos[0], tuple):
  1010             for i in xrange(*infos[0]):
  1010             for i in range(*infos[0]):
  1011                 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
  1011                 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
  1012         else:
  1012         else:
  1013             self.Table.RemoveHighlight(infos, highlight_type)
  1013             self.Table.RemoveHighlight(infos, highlight_type)
  1014         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1014         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1015 
  1015