Skip to content

Commit

Permalink
Merge pull request #221 from sparkmicro/1.0.x
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
eeintech authored Apr 30, 2024
2 parents d1a59de + 46dbb1f commit 1718d06
Show file tree
Hide file tree
Showing 12 changed files with 1,090 additions and 387 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ jobs:
- name: Install dependencies
run: |
sudo apt install sqlite3
pip install -U invoke coveralls
pip install -U pip invoke coveralls
- name: InvenTree setup
run: |
git clone https://github.com/inventree/InvenTree/
mkdir InvenTree/static
cp tests/files/inventree_default_db.sqlite3 InvenTree/
cd InvenTree/ && git switch stable && invoke install && invoke migrate && cd -
cd InvenTree/ && git switch 0.14.x && invoke install && invoke migrate && cd -
- name: Ki-nTree setup
run: |
invoke install
Expand All @@ -93,7 +93,7 @@ jobs:
export len_log=$(cat gui.log | wc -l)
[[ ${len_log} -eq 0 ]] && true || false
- name: Setup Digi-Key token
if: github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree'
if: ${{ github.ref == 'refs/heads/main' || github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree' }}
run: |
git clone https://[email protected]/eeintech/digikey-token.git
cd digikey-token/
Expand All @@ -108,7 +108,7 @@ jobs:
echo -e "Digi-Key Token: $dk_token\n"
cd ..
- name: Run tests
if: github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree'
if: ${{ github.ref == 'refs/heads/main' || github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree' }}
run: |
invoke test -e 1
env:
Expand All @@ -119,7 +119,7 @@ jobs:
run: |
invoke test -e 0
- name: Coveralls
if: github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree'
if: ${{ github.ref == 'refs/heads/main' || github.event.pull_request.head.repo.full_name == 'sparkmicro/Ki-nTree' }}
run: |
coveralls --version
coveralls --service=github
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Note that each time you enable the "Add" permission to an object, InvenTree auto
d. It is also possible to sync the prices in InvenTree with the latest supplier prices. For this enable "Upload Pricing Data to InvenTree"
6. If your InvenTree server requires a IPN in a specific pattern make sure to adjust "Settings > InvenTree > Internal Part Number" to match it or adjust the servers pattern to the one yo set in Ki-nTree

> Note: All URLs should start with "http://" if they do not have a valid SSL certificate.
#### Get Digi-Key API token
<details>
Expand Down Expand Up @@ -204,12 +205,14 @@ Refer to [this file](https://github.com/sparkmicro/Ki-nTree/blob/main/kintree/co

Ki-nTree currently supports APIs for the following electronics suppliers: Digi-Key, Mouser, Element14, TME and LCSC.

1. In the main window, enter the part number and select the supplier in drop-down list, then click "CREATE". It will start by fetching part data using the supplier's API
1. In the main window, enter the part number and select the supplier in drop-down list, then click the "Submit" button (arrow). It will start by fetching part data using the supplier's API
2. In the case Digi-Key has been selected and the API token is not found or expired, a browser window will pop-up. To get a new token: [follow those steps](#get-digi-key-api-token)
3. Once the part data has been successfully fetched from the supplier's API, you will be prompted to add/confirm/edit the part information, followed by the `Category` and `Subcategory` to use for this part (Ki-nTree tries to match them automatically)
4. Then, you will be prompted with selecting the KiCad symbol library, the template and the footprint library to use for this part
5. It will take some time to complete the part creation in InvenTree and/or KiCad, once it finishes you'll be notified of the result
6. Finally, if the part was created or found in InvenTree, your browser will automatically open a new tab with the part information
3. Once the part data has been successfully fetched from the supplier's API, you can review the part information in the different fields and edit them, if needed.
4. Then, go to the Inventree tabl to pick the `Category` and `Subcategory` to use for this part
5. If you desire to add this part to KiCad, click the KiCad tab and select the KiCad symbol library, the template and the footprint library to use for this part
6. Finally, go to the Create tab and launch the part creation. It will take some time to complete the process in InvenTree and/or KiCad, once it finishes you'll be notified of the result

If the part was created or found in InvenTree, and if you have selected this option in the settings, your browser will automatically open and navigate to the new Inventree part page.

#### Kicad Templates

Expand Down Expand Up @@ -244,7 +247,7 @@ git clone https://github.com/sparkmicro/Ki-nTree
poetry install
Installing dependencies from lock file
...
Installing the current project: kintree (1.0.99)
Installing the current project: kintree (1.1.99)
```
> Note: the version is not accurate (placeholder only)

Expand All @@ -263,11 +266,11 @@ $ python -m kintree_gui
1. Make sure you followed the previous installation steps, then run:
``` bash
$ poetry build
Building kintree (1.0.99)
Building kintree (1.1.99)
- Building sdist
- Built kintree-1.0.99.tar.gz
- Built kintree-1.1.99.tar.gz
- Building wheel
- Built kintree-1.0.99-py3-none-any.whl
- Built kintree-1.1.99-py3-none-any.whl
```
2. Exit the virtual environment (`Ctrl + D` on Linux; you can also close the
terminal and reopen it in the same folder).
Expand All @@ -276,7 +279,7 @@ Building kintree (1.0.99)
step. For example:

```bash
pip install dist/kintree-1.0.99-py3-none-any.whl
pip install dist/kintree-1.1.99-py3-none-any.whl
```

3. You can now start Ki-nTree by typing `kintree` in the terminal, provided
Expand Down
6 changes: 4 additions & 2 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def translate_form_to_inventree(part_info: dict, category_tree: list, is_custom=
inventree_part['pricing'] = part_info.get('pricing', {})
inventree_part['currency'] = part_info.get('currency', 'USD')

parameters = part_info.get('parameters', {})

# Load parameters map
if category_tree:
parameter_map = config_interface.load_category_parameters(
Expand All @@ -335,7 +337,7 @@ def translate_form_to_inventree(part_info: dict, category_tree: list, is_custom=
parameter_value = part_tools.clean_parameter_value(
category=category_tree[0],
name=supplier_param,
value=part_info['parameters'][supplier_param],
value=parameters[supplier_param],
)
inventree_part['parameters'][inventree_param] = parameter_value
except KeyError:
Expand All @@ -354,7 +356,7 @@ def translate_form_to_inventree(part_info: dict, category_tree: list, is_custom=

# Check for extra parameters which weren't mapped
parameters_unmapped = []
for search_param in part_info['parameters'].keys():
for search_param in parameters.keys():
if search_param not in parameter_map.keys():
parameters_unmapped.append(search_param)

Expand Down
28 changes: 12 additions & 16 deletions kintree/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@ def kintree_gui(page: ft.Page):
'''Ki-nTree GUI'''
# Init
init_gui(page)
# Views
# Create main views
part_view = PartSearchView(page)
inventree_view = InventreeView(page)
kicad_view = KicadView(page)
create_view = CreateView(page)
# Settings
# Create settings views
user_settings_view = UserSettingsView(page)
supplier_settings_view = SupplierSettingsView(page)
inventree_settings_view = InvenTreeSettingsView(page)
kicad_settings_view = KiCadSettingsView(page)

# Routing
def route_change(route):
# print(f'\n--> Routing to {route.route}')
if '/main' in page.route:
if '/main' in page.route or page.route == '/':
page.views.clear()
if 'part' in page.route:
if 'part' in page.route or page.route == '/':
page.views.append(part_view)
if 'inventree' in page.route:
page.views.append(inventree_view)
Expand All @@ -71,22 +72,19 @@ def route_change(route):
elif '/settings' in page.route:
if '/settings' in page.views[-1].route:
page.views.pop()
if page.route == user_settings_view.route:
if 'user' in page.route:
page.views.append(user_settings_view)
elif page.route == supplier_settings_view.route:
elif 'supplier' in page.route:
page.views.append(supplier_settings_view)
elif page.route == inventree_settings_view.route:
elif 'inventree' in page.route:
page.views.append(inventree_settings_view)
elif page.route == kicad_settings_view.route:
elif 'kicad' in page.route:
page.views.append(kicad_settings_view)
else:
page.views.append(user_settings_view)
else:
page.views.append(part_view)

page.update()

def view_pop(e):
def view_pop(view):
'''Pop setting view'''
page.views.pop()
top_view = page.views[-1]
Expand All @@ -101,10 +99,8 @@ def view_pop(e):
update_page=True,
timeout=0.3,
)
if 'part' in top_view.route:
part_view.partial_update()
elif 'inventree' in top_view.route:
inventree_view.partial_update()
if '/main/part' in top_view.route or '/main/inventree' in top_view.route:
top_view.partial_update()

page.on_route_change = route_change
page.on_view_pop = view_pop
Expand Down
25 changes: 12 additions & 13 deletions kintree/gui/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ def update_theme(page: ft.Page, mode='light', transition=False, compact=True):
class CommonView(ft.View):
'''Common view to all GUI views'''

page = None
_page = None
navigation_rail = None
NAV_BAR_INDEX = None
title = None
column = None
fields = None
Expand All @@ -90,7 +89,7 @@ class CommonView(ft.View):

def __init__(self, page: ft.Page, appbar: ft.AppBar, navigation_rail: ft.NavigationRail):
# Store page pointer
self.page = page
self._page = page

# Init view
super().__init__(route=self.route, appbar=appbar)
Expand All @@ -103,7 +102,7 @@ def build_column(self):
# Empty column (to be set inside the children views)
self.column = ft.Column()

def _build(self):
def build(self):
# Build column
if not self.column:
self.build_column()
Expand Down Expand Up @@ -164,15 +163,15 @@ def show_dialog(
if snackbar:
self.build_snackbar(d_type, message)
if isinstance(self.dialog, ft.SnackBar):
self.page.snack_bar = self.dialog
self.page.snack_bar.open = True
self._page.snack_bar = self.dialog
self._page.snack_bar.open = True
elif isinstance(self.dialog, ft.Banner):
self.page.banner = self.dialog
self.page.banner.open = open
self._page.banner = self.dialog
self._page.banner.open = open
elif isinstance(self.dialog, ft.AlertDialog):
self.page.dialog = self.dialog
self.page.dialog.open = open
self.page.update()
self._page.dialog = self.dialog
self._page.dialog.open = open
self._page.update()


class SwitchWithRefs(ft.Switch):
Expand Down Expand Up @@ -433,7 +432,7 @@ def header_click(self, e):
self.shevron.rotate = pi / 2 if self.shevron.rotate == 0 else 0
self.update()

def _build(self):
def build(self):
title_row = ft.Row()
if self.icon is not None:
title_row.controls.append(self.icon)
Expand Down Expand Up @@ -476,7 +475,7 @@ def __init__(
def item_click(self, _):
pass

def _build(self):
def build(self):
row = ft.Row()
if self.icon is not None:
row.controls.append(self.icon)
Expand Down
Loading

0 comments on commit 1718d06

Please sign in to comment.