objdictgen/subindextable.py
changeset 584 e23359f62023
parent 580 2ae92a99ac10
child 585 d62424ba12bf
equal deleted inserted replaced
583:a2c74eca6bf2 584:e23359f62023
    35 def GetAccessList(write=True):
    35 def GetAccessList(write=True):
    36     _ = lambda x : x
    36     _ = lambda x : x
    37     if write:
    37     if write:
    38         return [_("Read Only"), _("Write Only"), _("Read/Write")]
    38         return [_("Read Only"), _("Write Only"), _("Read/Write")]
    39     return [_("Read Only"), _("Read/Write")]
    39     return [_("Read Only"), _("Read/Write")]
    40 AccessList = ",".join(GetAccessList())
    40 AccessList = ",".join(map(_, GetAccessList()))
    41 RAccessList = ",".join(GetAccessList(False))
    41 RAccessList = ",".join(map(_, GetAccessList(False)))
    42 ACCESS_LIST_DICT = dict([(_(access), access) for access in GetAccessList()])
    42 ACCESS_LIST_DICT = dict([(_(access), access) for access in GetAccessList()])
    43 
    43 
    44 def GetBoolList():
    44 def GetBoolList():
    45     _ = lambda x : x
    45     _ = lambda x : x
    46     return [_("True"), _("False")]
    46     return [_("True"), _("False")]
    47 BoolList = ",".join(GetBoolList())
    47 BoolList = ",".join(map(_, GetBoolList()))
    48 BOOL_LIST_DICT = dict([(_(bool), bool) for bool in GetBoolList()])
    48 BOOL_LIST_DICT = dict([(_(bool), bool) for bool in GetBoolList()])
    49 
    49 
    50 def GetOptionList():
    50 def GetOptionList():
    51     _ = lambda x : x
    51     _ = lambda x : x
    52     return [_("Yes"), _("No")]
    52     return [_("Yes"), _("No")]
    53 OptionList = ",".join(GetOptionList())
    53 OptionList = ",".join(map(_, GetOptionList()))
    54 OPTION_LIST_DICT = dict([(_(option), option) for option in GetOptionList()])
    54 OPTION_LIST_DICT = dict([(_(option), option) for option in GetOptionList()])
    55 
    55 
    56 [USER_TYPE, SDO_SERVER, SDO_CLIENT, 
    56 [USER_TYPE, SDO_SERVER, SDO_CLIENT, 
    57  PDO_TRANSMIT, PDO_RECEIVE, MAP_VARIABLE] = range(6)
    57  PDO_TRANSMIT, PDO_RECEIVE, MAP_VARIABLE] = range(6)
    58 
    58 
   135             return self.colnames[col]
   135             return self.colnames[col]
   136 
   136 
   137     def GetRowLabelValues(self, row, translate=True):
   137     def GetRowLabelValues(self, row, translate=True):
   138         return row
   138         return row
   139 
   139 
   140     def GetValue(self, row, col):
   140     def GetValue(self, row, col, translate=True):
   141         if row < self.GetNumberRows():
   141         if row < self.GetNumberRows():
   142             colname = self.GetColLabelValue(col, False)
   142             colname = self.GetColLabelValue(col, False)
   143             value = unicode(self.data[row].get(colname, ""))
   143             value = unicode(self.data[row].get(colname, ""))
   144             if self.editors[row][colname] in ["access", "raccess", "bool", "option"]:
   144             if translate and (colname == "access" or 
       
   145                               self.editors[row][colname] in ["bool", "option"] or
       
   146                               self.editors[row][colname] == "map" and value == "None"):
   145                 value = _(value)
   147                 value = _(value)
   146             return value
   148             return value
   147             
   149             
   148     def GetEditor(self, row, col):
   150     def GetEditor(self, row, col):
   149         if row < self.GetNumberRows():
   151         if row < self.GetNumberRows():
   153         return self.data[row].get(colname)
   155         return self.data[row].get(colname)
   154 
   156 
   155     def SetValue(self, row, col, value):
   157     def SetValue(self, row, col, value):
   156         if col < len(self.colnames):
   158         if col < len(self.colnames):
   157             colname = self.GetColLabelValue(col, False)
   159             colname = self.GetColLabelValue(col, False)
   158             if self.editors[row][colname] in ["access", "raccess"]:
   160             if colname == "access":
   159                 value = ACCESS_LIST_DICT[value]
   161                 value = ACCESS_LIST_DICT[value]
   160             elif self.editors[row][colname] == "bool":
   162             elif self.editors[row][colname] == "bool":
   161                 value = BOOL_LIST_DICT[value]
   163                 value = BOOL_LIST_DICT[value]
   162             elif self.editors[row][colname] == "option":
   164             elif self.editors[row][colname] == "option":
   163                 value = OPTION_LIST_DICT[value]
   165                 value = OPTION_LIST_DICT[value]
       
   166             elif self.editors[row][colname] == "map" and value == _("None"):
       
   167                 value = "None"
   164             self.data[row][colname] = value
   168             self.data[row][colname] = value
   165         
   169         
   166     def ResetView(self, grid):
   170     def ResetView(self, grid):
   167         """
   171         """
   168         (wx.grid.Grid) -> Reset the grid view.   Call this to
   172         (wx.grid.Grid) -> Reset the grid view.   Call this to
   677     def OnSubindexGridCellChange(self, event):
   681     def OnSubindexGridCellChange(self, event):
   678         if self.Editable:
   682         if self.Editable:
   679             index = self.Table.GetCurrentIndex()
   683             index = self.Table.GetCurrentIndex()
   680             subIndex = event.GetRow()
   684             subIndex = event.GetRow()
   681             col = event.GetCol()
   685             col = event.GetCol()
   682             name = self.Table.GetColLabelValue(col)
   686             name = self.Table.GetColLabelValue(col, False)
   683             value = self.Table.GetValue(subIndex, col)
   687             value = self.Table.GetValue(subIndex, col, False)
   684             editor = self.Table.GetEditor(subIndex, col)
   688             editor = self.Table.GetEditor(subIndex, col)
   685             self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
   689             self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
   686             self.ParentWindow.RefreshBufferState()
   690             self.ParentWindow.RefreshBufferState()
   687             wx.CallAfter(self.RefreshTable)
   691             wx.CallAfter(self.RefreshTable)
   688         event.Skip()
   692         event.Skip()