diff --git a/plugins/component_table/__init__.py b/plugins/component_table/__init__.py index b5da952..1abe136 100644 --- a/plugins/component_table/__init__.py +++ b/plugins/component_table/__init__.py @@ -1,6 +1,7 @@ import pcbnew import wx import wx.lib.mixins.listctrl as listmix +import traceback COLUMNS = ['Designation', 'Value', 'Library', 'Package', 'Sheet'] @@ -15,7 +16,7 @@ class Sortable_Component_List(wx.ListCtrl, listmix.ColumnSorterMixin): col_widths = [100, 120, 160, 200, 200] for i, (col, w) in enumerate(zip(COLUMNS, col_widths)): self.InsertColumn(i, col, width=w) - self.item_data_map = {} + self.itemDataMap = {} listmix.ColumnSorterMixin.__init__(self, len(COLUMNS)) def GetListCtrl(self): @@ -23,13 +24,13 @@ class Sortable_Component_List(wx.ListCtrl, listmix.ColumnSorterMixin): def populate(self, rows): self.DeleteAllItems() - self.item_data_map = {} + self.itemDataMap = {} for idx, row in enumerate(rows): item = self.InsertItem(idx, row[0]) for col, val in enumerate(row[1:], start=1): self.SetItem(idx, col, val) self.SetItemData(idx, idx) - self.item_data_map[idx] = row + self.itemDataMap[idx] = row class Component_Table_Dialog(wx.Dialog): @@ -60,17 +61,9 @@ class Component_Table_Dialog(wx.Dialog): def _get_sheet(fp): try: - props = fp.GetProperties() - for key in ('Sheetname', 'Sheet', 'sheet'): - val = props.get(key, '') - if val: - return val - except Exception: - pass - try: - path = str(fp.GetPath()) - if path and path != '/': - return path + name = fp.GetSheetname() + if name: + return name except Exception: pass return '-' @@ -85,6 +78,23 @@ class Component_Table_Action(pcbnew.ActionPlugin): self.icon_file_name = '' def Run(self): + try: + self._run() + except Exception: + msg = traceback.format_exc() + dlg = wx.Dialog(None, title='Component Table — Error', size=(600, 350)) + sizer = wx.BoxSizer(wx.VERTICAL) + txt = wx.TextCtrl(dlg, value=msg, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL) + txt.SetFont(wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) + sizer.Add(txt, 1, wx.EXPAND | wx.ALL, 6) + btn = wx.Button(dlg, wx.ID_CLOSE, 'Close') + btn.Bind(wx.EVT_BUTTON, lambda e: dlg.Close()) + sizer.Add(btn, 0, wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, 8) + dlg.SetSizer(sizer) + dlg.ShowModal() + dlg.Destroy() + + def _run(self): board = pcbnew.GetBoard() components = [] diff --git a/plugins/component_table/__pycache__/__init__.cpython-314.pyc b/plugins/component_table/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..8604311 Binary files /dev/null and b/plugins/component_table/__pycache__/__init__.cpython-314.pyc differ