diff --git a/icons/mdi-earth.png b/icons/mdi-earth.png new file mode 100644 index 0000000..e8442a9 Binary files /dev/null and b/icons/mdi-earth.png differ diff --git a/partdetails.py b/partdetails.py index f30f2e8..265d452 100644 --- a/partdetails.py +++ b/partdetails.py @@ -32,6 +32,7 @@ def __init__(self, parent, part): self.datasheet_path = Path(self.parent.project_path) / "datasheets" self.lcsc_api = LCSC_API() self.pdfurl = "" + self.pageurl = "" self.picture = None # --------------------------------------------------------------------- @@ -99,8 +100,18 @@ def __init__(self, parent, part): 0, ) + self.openpage_button = wx.Button( + self, + wx.ID_ANY, + "Open LCSC page", + wx.DefaultPosition, + wx.DefaultSize, + 0, + ) + self.savepdf_button.Bind(wx.EVT_BUTTON, self.savepdf) self.openpdf_button.Bind(wx.EVT_BUTTON, self.openpdf) + self.openpage_button.Bind(wx.EVT_BUTTON, self.openpage) self.savepdf_button.SetBitmap( loadBitmapScaled( @@ -118,6 +129,14 @@ def __init__(self, parent, part): ) self.openpdf_button.SetBitmapMargins((2, 0)) + self.openpage_button.SetBitmap( + loadBitmapScaled( + "mdi-earth.png", + self.parent.scale_factor, + ) + ) + self.openpage_button.SetBitmapMargins((2, 0)) + # --------------------------------------------------------------------- # ------------------------ Layout and Sizers -------------------------- # --------------------------------------------------------------------- @@ -127,6 +146,9 @@ def __init__(self, parent, part): right_side_layout.AddStretchSpacer(50) right_side_layout.Add(self.savepdf_button, 5, wx.LEFT | wx.RIGHT | wx.EXPAND, 5) right_side_layout.Add(self.openpdf_button, 5, wx.LEFT | wx.RIGHT | wx.EXPAND, 5) + right_side_layout.Add( + self.openpage_button, 5, wx.LEFT | wx.RIGHT | wx.EXPAND, 5 + ) layout = wx.BoxSizer(wx.HORIZONTAL) layout.Add(self.data_list, 30, wx.ALL | wx.EXPAND, 5) layout.Add(right_side_layout, 10, wx.ALL | wx.EXPAND, 5) @@ -166,6 +188,11 @@ def openpdf(self, *_): self.logger.info("opening %s", str(self.pdfurl)) webbrowser.open(str(self.pdfurl)) + def openpage(self, *_): + """Open the linked LCSC page for the part on button click.""" + self.logger.info("opening LCSC page for %s", str(self.part)) + webbrowser.open(str(self.pageurl)) + def get_scaled_bitmap(self, url, width, height): """Download a picture from a URL and convert it into a wx Bitmap.""" io_bytes = self.lcsc_api.download_bitmap(url) @@ -263,6 +290,7 @@ def get_part_data(self): ) ) self.pdfurl = result["data"].get("data", {}).get("dataManualUrl") + self.pageurl = result["data"].get("data", {}).get("lcscGoodsUrl") def report_part_data_fetch_error(self, reason): """Spawn a message box with an erro message if the fetch fails."""