Skip to content

Commit

Permalink
Toggle BOM/POS without re-populate entire list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouni committed Jun 29, 2023
1 parent 2ddeed1 commit a3bb155
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
14 changes: 14 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from enum import IntEnum


class Column(IntEnum):
REFERENCE = 0
VALUE = 1
FOOTPRINT = 2
LCSC = 3
TYPE = 4
STOCK = 5
BOM = 6
POS = 7
ROTATION = 8
SIDE = 9
20 changes: 20 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re

import wx
import wx.dataview

PLUGIN_PATH = os.path.split(os.path.abspath(__file__))[0]

Expand Down Expand Up @@ -70,6 +71,25 @@ def loadIconScaled(filename, scale=1.0):
return wx.Icon(bmp)


def GetListIcon(value, scale_factor):
if value == 0:
return wx.dataview.DataViewIconText(
"",
loadIconScaled(
"mdi-check-color.png",
scale_factor,
),
)
else:
return wx.dataview.DataViewIconText(
"",
loadIconScaled(
"mdi-close-color.png",
scale_factor,
),
)


def natural_sort_collation(a, b):
"""Natural sort collation for use in sqlite."""
if a == b:
Expand Down
23 changes: 14 additions & 9 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
getVersion,
loadBitmapScaled,
loadIconScaled,
GetListIcon,
toggle_exclude_from_bom,
toggle_exclude_from_pos,
)
from .const import Column
from .library import Library, LibraryState
from .partdetails import PartDetailsDialog
from .partmapper import PartMapperManagerDialog
Expand Down Expand Up @@ -719,9 +721,12 @@ def toggle_bom_pos(self, e):
pos = toggle_exclude_from_pos(fp)
self.store.set_bom(ref, bom)
self.store.set_pos(ref, pos)
self.populate_footprint_list()
for row in selected_rows:
self.footprint_list.SelectRow(row)
self.footprint_list.SetValue(
GetListIcon(bom, self.scale_factor), row, Column.BOM
)
self.footprint_list.SetValue(
GetListIcon(pos, self.scale_factor), row, Column.POS
)

def toggle_bom(self, e):
"""Toggle the exclude from BOM attribute of a footprint."""
Expand All @@ -733,9 +738,9 @@ def toggle_bom(self, e):
fp = get_footprint_by_ref(GetBoard(), ref)[0]
bom = toggle_exclude_from_bom(fp)
self.store.set_bom(ref, bom)
self.populate_footprint_list()
for row in selected_rows:
self.footprint_list.SelectRow(row)
self.footprint_list.SetValue(
GetListIcon(bom, self.scale_factor), row, Column.BOM
)

def toggle_pos(self, e):
selected_rows = []
Expand All @@ -747,9 +752,9 @@ def toggle_pos(self, e):
fp = get_footprint_by_ref(GetBoard(), ref)[0]
pos = toggle_exclude_from_pos(fp)
self.store.set_pos(ref, pos)
self.populate_footprint_list()
for row in selected_rows:
self.footprint_list.SelectRow(row)
self.footprint_list.SetValue(
GetListIcon(pos, self.scale_factor), row, Column.POS
)

def remove_part(self, e):
"""Remove an assigned a LCSC Part number to a footprint."""
Expand Down

0 comments on commit a3bb155

Please sign in to comment.