982 self.EthercatMasterEditor.Scroll(posx, posy) |
982 self.EthercatMasterEditor.Scroll(posx, posy) |
983 self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
983 self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
984 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
984 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
985 event.Skip() |
985 event.Skip() |
986 |
986 |
987 def GetModulesTableColnames(): |
|
988 _ = lambda x : x |
|
989 return [_("Name"), _("PDO alignment (bits)")] |
|
990 |
|
991 class LibraryEditorSizer(wx.FlexGridSizer): |
987 class LibraryEditorSizer(wx.FlexGridSizer): |
992 |
988 |
993 def __init__(self, parent, module_library, buttons): |
989 def __init__(self, parent, module_library, buttons): |
994 wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=4, vgap=5) |
990 wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=4, vgap=5) |
995 |
991 |
1049 self.ModulesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DCLICK, |
1045 self.ModulesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DCLICK, |
1050 self.OnModulesGridLeftDClick) |
1046 self.OnModulesGridLeftDClick) |
1051 self.AddWindow(self.ModulesGrid, border=10, |
1047 self.AddWindow(self.ModulesGrid, border=10, |
1052 flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1048 flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1053 |
1049 |
1054 for colname, colsize, colalign in zip(GetModulesTableColnames(), |
1050 for colname, colsize, colalign in zip( |
1055 [400, 150], |
1051 [_("Name")] + [param_infos["column_label"] |
1056 [wx.ALIGN_LEFT, wx.ALIGN_RIGHT]): |
1052 for param, param_infos in |
|
1053 self.ModuleLibrary.MODULES_EXTRA_PARAMS], |
|
1054 [400] + [150] * len(self.ModuleLibrary.MODULES_EXTRA_PARAMS), |
|
1055 [wx.ALIGN_LEFT] + [wx.ALIGN_RIGHT] * len(self.ModuleLibrary.MODULES_EXTRA_PARAMS)): |
1057 self.ModulesGrid.AddColumn(_(colname), colsize, colalign) |
1056 self.ModulesGrid.AddColumn(_(colname), colsize, colalign) |
1058 self.ModulesGrid.SetMainColumn(0) |
1057 self.ModulesGrid.SetMainColumn(0) |
1059 |
1058 |
1060 def GetPath(self): |
1059 def GetPath(self): |
1061 return self.ModuleLibrary.GetPath() |
1060 return self.ModuleLibrary.GetPath() |
1087 for module in modules: |
1086 for module in modules: |
1088 if no_more_items: |
1087 if no_more_items: |
1089 item = self.ModulesGrid.AppendItem(root, "") |
1088 item = self.ModulesGrid.AppendItem(root, "") |
1090 self.ModulesGrid.SetItemText(item, module["name"], 0) |
1089 self.ModulesGrid.SetItemText(item, module["name"], 0) |
1091 if module["infos"] is not None: |
1090 if module["infos"] is not None: |
1092 self.ModulesGrid.SetItemText(item, str(module["infos"]["alignment"]), 1) |
1091 for param_idx, (param, params_infos) in enumerate(self.ModuleLibrary.MODULES_EXTRA_PARAMS): |
|
1092 self.ModulesGrid.SetItemText(item, |
|
1093 str(module["infos"][param]), |
|
1094 param_idx + 1) |
1093 else: |
1095 else: |
1094 self.ModulesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY) |
1096 self.ModulesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY) |
1095 self.ModulesGrid.SetItemPyData(item, module["infos"]) |
1097 self.ModulesGrid.SetItemPyData(item, module["infos"]) |
1096 self.GenerateModulesGridBranch(item, module["children"], colnames) |
1098 self.GenerateModulesGridBranch(item, module["children"], colnames) |
1097 if not no_more_items: |
1099 if not no_more_items: |
1145 |
1147 |
1146 def OnModulesGridLeftDClick(self, event): |
1148 def OnModulesGridLeftDClick(self, event): |
1147 item, flags, col = self.ModulesGrid.HitTest(event.GetPosition()) |
1149 item, flags, col = self.ModulesGrid.HitTest(event.GetPosition()) |
1148 if item.IsOk(): |
1150 if item.IsOk(): |
1149 entry_infos = self.ModulesGrid.GetItemPyData(item) |
1151 entry_infos = self.ModulesGrid.GetItemPyData(item) |
1150 if entry_infos is not None and col == 1: |
1152 if entry_infos is not None and col > 0: |
|
1153 param, param_infos = self.ModuleLibrary.MODULES_EXTRA_PARAMS[col - 1] |
|
1154 column_label = param_infos["column_label"] |
|
1155 stripped_column_label = column_label.split('(')[0].strip() |
1151 dialog = wx.TextEntryDialog(self.ParentWindow, |
1156 dialog = wx.TextEntryDialog(self.ParentWindow, |
1152 _("Set PDO alignment (bits):"), |
1157 _("Set %s:") % column_label, |
1153 _("%s PDO alignment") % self.ModulesGrid.GetItemText(item), |
1158 self.ModulesGrid.GetItemText(item) + " " + stripped_column_label, |
1154 str(entry_infos["alignment"])) |
1159 str(entry_infos[param])) |
1155 |
1160 |
1156 if dialog.ShowModal() == wx.ID_OK: |
1161 if dialog.ShowModal() == wx.ID_OK: |
1157 try: |
1162 try: |
1158 self.ModuleLibrary.SetAlignment( |
1163 self.ModuleLibrary.SetModuleExtraParam( |
1159 entry_infos["vendor"], |
1164 entry_infos["vendor"], |
1160 entry_infos["product_code"], |
1165 entry_infos["product_code"], |
1161 entry_infos["revision_number"], |
1166 entry_infos["revision_number"], |
|
1167 param, |
1162 int(dialog.GetValue())) |
1168 int(dialog.GetValue())) |
1163 wx.CallAfter(self.RefreshModulesGrid) |
1169 wx.CallAfter(self.RefreshModulesGrid) |
1164 except ValueError: |
1170 except ValueError: |
1165 message = wx.MessageDialog(self, |
1171 message = wx.MessageDialog(self, |
1166 _("Module PDO alignment must be an integer!"), |
1172 _("Module %s must be an integer!") % stripped_column_label, |
1167 _("Error"), wx.OK|wx.ICON_ERROR) |
1173 _("Error"), wx.OK|wx.ICON_ERROR) |
1168 message.ShowModal() |
1174 message.ShowModal() |
1169 message.Destroy() |
1175 message.Destroy() |
1170 |
1176 |
1171 dialog.Destroy() |
1177 dialog.Destroy() |