Skip to content

Commit

Permalink
Add open lcsc page button to part details dialog (Bouni#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouni authored Oct 11, 2024
1 parent a39bf1d commit 35479b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Binary file added icons/mdi-earth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions partdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -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(
Expand All @@ -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 --------------------------
# ---------------------------------------------------------------------
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 35479b9

Please sign in to comment.