diff --git a/library.py b/library.py index 18374e03..0f925d0e 100644 --- a/library.py +++ b/library.py @@ -387,12 +387,12 @@ def get_part_details(self, lcsc: list) -> dict: con.row_factory = dict_factory cur = con.cursor() results = [] - query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type FROM parts WHERE parts MATCH ?''' + query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type, "Description" FROM parts WHERE parts MATCH ?''' # Use parameter binding to prevent SQL injection and handle the query more efficiently for number in lcsc: # Each number needs to be wrapped in double quotes for exact match in FTS5 - match_query = f'"LCSC Part:{number}"' + match_query = f'"lcsc:{number}"' cur.execute(query, (match_query,)) results.extend(cur.fetchall()) if results: diff --git a/mainwindow.py b/mainwindow.py index 7595e5a0..79e57b16 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -263,7 +263,7 @@ def __init__(self, parent, kicad_provider=KicadProvider()): "bom-pos.png", self.scale_factor, ), - "Toggle exclud from BOM and POS attribute", + "Toggle exclude from BOM and POS attribute", ) self.toggle_bom_button = self.right_toolbar.AddTool( @@ -382,7 +382,7 @@ def __init__(self, parent, kicad_provider=KicadProvider()): self.footprint = self.footprint_list.AppendTextColumn( "Footprint", mode=wx.dataview.DATAVIEW_CELL_INERT, - width=int(self.scale_factor * 300), + width=int(self.scale_factor * 150), align=wx.ALIGN_CENTER, flags=wx.dataview.DATAVIEW_COL_RESIZABLE, ) @@ -435,6 +435,13 @@ def __init__(self, parent, kicad_provider=KicadProvider()): align=wx.ALIGN_CENTER, flags=wx.dataview.DATAVIEW_COL_RESIZABLE, ) + self.description = self.footprint_list.AppendTextColumn( + "Description", + mode=wx.dataview.DATAVIEW_CELL_INERT, + width=int(self.scale_factor * 300), + align=wx.ALIGN_LEFT, + flags=wx.dataview.DATAVIEW_COL_RESIZABLE, + ) self.footprint_list.AppendTextColumn( "", mode=wx.dataview.DATAVIEW_CELL_INERT, @@ -607,6 +614,7 @@ def populate_footprint_list(self, *_): part["rotation"] = "" part["type"] = "" part["side"] = "" + part["description"] = "" parts.append(part) details = self.library.get_part_details(numbers) corrections = self.library.get_all_correction_data() @@ -615,7 +623,8 @@ def populate_footprint_list(self, *_): if details: part["type"] = details["type"] part["stock"] = details["stock"] - # First check if the part name mathes + part["description"] = details["description"] + # First check if the part name matches for regex, correction in corrections: if re.search(regex, str(part["reference"])): part["rotation"] = str(correction) @@ -639,6 +648,7 @@ def populate_footprint_list(self, *_): part["exclude_from_pos"], part["rotation"], part["side"], + part["description"], "", ] ) diff --git a/schematicexport.py b/schematicexport.py index 506843a6..e7063180 100644 --- a/schematicexport.py +++ b/schematicexport.py @@ -200,6 +200,7 @@ def _update_schematic8(self, path): lastLcsc = "" newLcsc = "" lastRef = "" + property_name = self.parent.settings.get("schematic", {}).get("property_name", "LCSC") lines = [] newlines = [] @@ -224,7 +225,7 @@ def _update_schematic8(self, path): key = m.group(1) # self.logger.info("key %s", key) # found a LCSC property, so update it if needed - if key in {"LCSC", "LCSC_PN", "JLC_PN"}: + if key in {"LCSC", "LCSC_PN", "LCSC Part", "JLC_PN"}: value = m.group(2) lastLcsc = value if newLcsc not in (lastLcsc, ""): @@ -254,7 +255,7 @@ def _update_schematic8(self, path): if m3 and partSection: if lastLcsc == "" and newLcsc != "" and lastLoc != "": self.logger.info("added %s to %s", newLcsc, lastRef) - newTxt = f'\t\t(property "LCSC" "{newLcsc}"\n\t\t\t(at {lastLoc} 0)' + newTxt = f'\t\t(property "{property_name}" "{newLcsc}"\n\t\t\t(at {lastLoc} 0)' newlines.append(newTxt) newlines.append( "\t\t\t(effects\n\t\t\t\t(font\n\t\t\t\t\t(size 1.27 1.27)\n\t\t\t\t)\n\t\t\t\t(hide yes)" @@ -273,4 +274,4 @@ def _update_schematic8(self, path): with open(path, "w", encoding="utf-8") as f: for line in newlines: f.write(line + "\n") - self.logger.info("Added LCSC's to %s (maybe?)", path) + self.logger.info("Added \"%s\"'s to %s (maybe?)", property_name, path) diff --git a/settings.py b/settings.py index 5932934a..9171744c 100644 --- a/settings.py +++ b/settings.py @@ -232,6 +232,24 @@ def __init__(self, parent): lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_image, 10, wx.ALL | wx.EXPAND, 5) lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_setting, 100, wx.ALL | wx.EXPAND, 5) + ##### Property name used when updating schematics ##### + self.property_name_setting = wx.ComboBox( + self, + size=wx.DefaultSize, + choices=["LCSC", "LCSC_PN", "LCSC Part", "JLC_PN"], + value="LCSC", + name="schematic_property_name", + ) + self.property_name_setting.SetToolTip( + wx.ToolTip("The property name that will be used when updating schematics") + ) + self.property_name_setting.Bind(wx.EVT_COMBOBOX, self.update_settings) + self.property_name_label = wx.StaticText(self, label="Property name:") + + property_name_sizer = wx.BoxSizer() + property_name_sizer.Add(self.property_name_label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) + property_name_sizer.Add(self.property_name_setting, 0, wx.ALL | wx.EXPAND, 5) + # --------------------------------------------------------------------- # ---------------------- Main Layout Sizer ---------------------------- # --------------------------------------------------------------------- @@ -243,6 +261,7 @@ def __init__(self, parent): layout.Add(plot_references_sizer, 0, wx.ALL | wx.EXPAND, 5) layout.Add(lcsc_priority_sizer, 0, wx.ALL | wx.EXPAND, 5) layout.Add(lcsc_bom_cpl_sizer, 0, wx.ALL | wx.EXPAND, 5) + layout.Add(property_name_sizer, 0, wx.ALL | wx.EXPAND, 5) self.SetSizer(layout) self.Layout() self.Centre(wx.BOTH) @@ -355,6 +374,10 @@ def update_lcsc_bom_cpl(self, add): loadBitmapScaled("no_bom.png", self.parent.scale_factor, static=True) ) + def update_property_name(self, name): + """Update settings dialog according to the settings.""" + self.property_name_setting.SetValue(name) + def load_settings(self): """Load settings and set checkboxes accordingly.""" self.update_tented_vias( @@ -375,6 +398,9 @@ def load_settings(self): self.update_lcsc_bom_cpl( self.parent.settings.get("gerber", {}).get("lcsc_bom_cpl", True) ) + self.update_property_name( + self.parent.settings.get("schematic", {}).get("property_name", "LCSC") + ) def update_settings(self, event): """Update and persist a setting that was changed."""