Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: add component count selector in "component search" section #483

Open
cr1tbit opened this issue Jun 15, 2024 · 0 comments
Open

Idea: add component count selector in "component search" section #483

cr1tbit opened this issue Jun 15, 2024 · 0 comments

Comments

@cr1tbit
Copy link

cr1tbit commented Jun 15, 2024

Nuff said - Price column is a mess :) #382

I messed a bit with code, and wrote a simple PoC. I hardcoded element count to "30" for now:

image

Instead of hardcoding element count, an additional field could be added to the menu at the top, with target component count. Near it, a simple switch for toggling this feature should be present too.

As mentioned in linked issue, JLC API is not stable, so this feature should handle all parsing faults as gracefully as possible, and fallback to the default view on any error.

Another annoying issue I tried to deal here is "description" field, which is arguably even messier. I tried to highlight the searched phrase, to improve glance value when selecting component.

The scenario i'm trying to deal with: looking for "100n" component with "0402" package - when I'm obviously looking for a capacitor, I get "100nH 0402" choke listed.

This challenge however defeated me - I don't know if it's even possible to print bold text using wx component used here (and how portable such feature would be). For now i wrap keyword in ||double pipes||, but this doesn't really look useful at all.

Here's the snippet I made - obviously requiring a lot more sanitation before being prod-ready:

    self.populate_part_list(result, search_duration, self.keyword.GetValue())
    [...]

    def populate_part_list(self, parts, search_duration, keyword):
        """Populate the list with the result of the search."""

        target_count = 30
        search_duration_text = (
            f"{search_duration:.2f}s"
            if search_duration > 1
            else f"{search_duration * 1000.0:.0f}ms"
        )
        self.part_list.DeleteAllItems()
        if parts is None:
            return
        count = len(parts)
        if count >= 1000:
            self.result_count.SetLabel(
                f"{count} Results (limited) in {search_duration_text}"
            )
        else:
            self.result_count.SetLabel(f"{count} Results in {search_duration_text}")
        for p in parts:
            item = [str(c) for c in p]
            # Munge price to be more readable
            pricecol = 8 # Must match order in library.py search function
            descriptioncol = 7
            price = []
            try:
                for t in item[pricecol].split(","):
                    qty, p = t.split(":")

                    qty_low, qty_high = qty.split("-")

                    qty_low_f = float(qty_low)
                    try:
                        qty_high_f = float(qty_high)
                    except ValueError:
                        qty_high_f = float("inf")

                    if (target_count >= qty_low_f) and (target_count < qty_high_f):
                        p = float(p)
                        if p < 1.0:
                            price.append(f"{qty}: {p * 100:.2f}c")
                        else:
                            price.append(f"{qty}: ${p:.2f}")
                        self.logger.warning(f"${p:.2f}")                    

                    # if p < 1.0:
                    #     price.append(f"{qty}: {p * 100:.2f}c")
                    # else:
                    #     price.append(f"{qty}: ${p:.2f}")
                item[pricecol] = ", ".join(price)
            except ValueError:
                self.logger.warning("unable to parse price %s", item[pricecol])
            
            item[descriptioncol] = item[descriptioncol].replace(keyword, f"||{keyword}||")
            self.part_list.AppendItem(item)

Please tell me if it's something worth being merged-in, I could finish this and make an PR sometime in the future.

Bonus question - is it even remotely possible for kicad addon to utilize some other GUI-rendering framework? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant