Fix ColumnSorterMixin attribute name and sheet detection
Use itemDataMap (required by wx mixin) instead of item_data_map, and use fp.GetSheetname() instead of GetProperties() lookup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import pcbnew
|
import pcbnew
|
||||||
import wx
|
import wx
|
||||||
import wx.lib.mixins.listctrl as listmix
|
import wx.lib.mixins.listctrl as listmix
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
COLUMNS = ['Designation', 'Value', 'Library', 'Package', 'Sheet']
|
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]
|
col_widths = [100, 120, 160, 200, 200]
|
||||||
for i, (col, w) in enumerate(zip(COLUMNS, col_widths)):
|
for i, (col, w) in enumerate(zip(COLUMNS, col_widths)):
|
||||||
self.InsertColumn(i, col, width=w)
|
self.InsertColumn(i, col, width=w)
|
||||||
self.item_data_map = {}
|
self.itemDataMap = {}
|
||||||
listmix.ColumnSorterMixin.__init__(self, len(COLUMNS))
|
listmix.ColumnSorterMixin.__init__(self, len(COLUMNS))
|
||||||
|
|
||||||
def GetListCtrl(self):
|
def GetListCtrl(self):
|
||||||
@@ -23,13 +24,13 @@ class Sortable_Component_List(wx.ListCtrl, listmix.ColumnSorterMixin):
|
|||||||
|
|
||||||
def populate(self, rows):
|
def populate(self, rows):
|
||||||
self.DeleteAllItems()
|
self.DeleteAllItems()
|
||||||
self.item_data_map = {}
|
self.itemDataMap = {}
|
||||||
for idx, row in enumerate(rows):
|
for idx, row in enumerate(rows):
|
||||||
item = self.InsertItem(idx, row[0])
|
item = self.InsertItem(idx, row[0])
|
||||||
for col, val in enumerate(row[1:], start=1):
|
for col, val in enumerate(row[1:], start=1):
|
||||||
self.SetItem(idx, col, val)
|
self.SetItem(idx, col, val)
|
||||||
self.SetItemData(idx, idx)
|
self.SetItemData(idx, idx)
|
||||||
self.item_data_map[idx] = row
|
self.itemDataMap[idx] = row
|
||||||
|
|
||||||
|
|
||||||
class Component_Table_Dialog(wx.Dialog):
|
class Component_Table_Dialog(wx.Dialog):
|
||||||
@@ -60,17 +61,9 @@ class Component_Table_Dialog(wx.Dialog):
|
|||||||
|
|
||||||
def _get_sheet(fp):
|
def _get_sheet(fp):
|
||||||
try:
|
try:
|
||||||
props = fp.GetProperties()
|
name = fp.GetSheetname()
|
||||||
for key in ('Sheetname', 'Sheet', 'sheet'):
|
if name:
|
||||||
val = props.get(key, '')
|
return name
|
||||||
if val:
|
|
||||||
return val
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
path = str(fp.GetPath())
|
|
||||||
if path and path != '/':
|
|
||||||
return path
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return '-'
|
return '-'
|
||||||
@@ -85,6 +78,23 @@ class Component_Table_Action(pcbnew.ActionPlugin):
|
|||||||
self.icon_file_name = ''
|
self.icon_file_name = ''
|
||||||
|
|
||||||
def Run(self):
|
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()
|
board = pcbnew.GetBoard()
|
||||||
components = []
|
components = []
|
||||||
|
|
||||||
|
|||||||
BIN
plugins/component_table/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
plugins/component_table/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user