Skip to content

Commit

Permalink
Merge a78b14f into e7ad3a6
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Aug 3, 2023
2 parents e7ad3a6 + a78b14f commit 0b1bce7
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 347 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
[![Tests | Linting | Publishing](https://github.com/sparkmicro/Ki-nTree/actions/workflows/test_deploy.yaml/badge.svg)](https://github.com/sparkmicro/Ki-nTree/actions)
[![Coverage Status](https://coveralls.io/repos/github/sparkmicro/Ki-nTree/badge.svg?branch=main&service=github)](https://coveralls.io/github/sparkmicro/Ki-nTree?branch=main)

## :warning: InvenTree Compatibility
Ki-nTree currently only supports InvenTree `0.11` or older versions. InvenTree `0.12` introduced a new parameter template system which is not supported as of now, see https://github.com/sparkmicro/Ki-nTree/issues/165 for more details. The future versions of InvenTree (`0.13` and up) should be compatible with Ki-nTree again soon, and this page will be updated with the required InvenTree setup.

## :fast_forward: [Demo Video](https://youtu.be/YeWBqOCb4pw)

<img src="https://raw.githubusercontent.com/sparkmicro/Ki-nTree/main/images/doc/kintree_v1_example.png" width="auto" height="auto">
Expand Down
2 changes: 1 addition & 1 deletion kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def load_ipn_settings():
CONFIG_GENERAL = config_interface.load_file(CONFIG_GENERAL_PATH)
# Datasheets
DATASHEET_SAVE_ENABLED = CONFIG_GENERAL.get('DATASHEET_SAVE_ENABLED', False)
DATASHEET_SAVE_PATH = CONFIG_GENERAL.get('DATASHEET_SAVE_PATH', False)
DATASHEET_SAVE_PATH = CONFIG_GENERAL.get('DATASHEET_SAVE_PATH', '')
# Open Browser
AUTOMATIC_BROWSER_OPEN = CONFIG_GENERAL.get('AUTOMATIC_BROWSER_OPEN', False)
# Default Supplier
Expand Down
1 change: 1 addition & 0 deletions kintree/config/user/general.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DATASHEET_SAVE_ENABLED: false
DATASHEET_SAVE_PATH: null
DATASHEET_INVENTREE_ENABLED: false
AUTOMATIC_BROWSER_OPEN: true
INVENTREE_ENV: null
DEFAULT_SUPPLIER: Digi-Key
Expand Down
4 changes: 2 additions & 2 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def build_tree(tree, left_to_go, level) -> list:
last_entry = f' {category_tree(tree[-1])}{category_separator}'
except IndexError:
last_entry = ''
if type(left_to_go) == dict:
if isinstance(left_to_go, dict):
for key, value in left_to_go.items():
tree.append(f'{"-" * level}{last_entry}{key}')
build_tree(tree, value, level + 1)
elif type(left_to_go) == list:
elif isinstance(left_to_go, list):
# Supports legacy structure
for item in left_to_go:
tree.append(f'{"-" * level}{last_entry}{item}')
Expand Down
6 changes: 3 additions & 3 deletions kintree/gui/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ def show_dialog(
):
if snackbar:
self.build_snackbar(d_type, message)
if type(self.dialog) == ft.SnackBar:
if isinstance(self.dialog, ft.SnackBar):
self.page.snack_bar = self.dialog
self.page.snack_bar.open = True
elif type(self.dialog) == ft.Banner:
elif isinstance(self.dialog, ft.Banner):
self.page.banner = self.dialog
self.page.banner.open = open
elif type(self.dialog) == ft.AlertDialog:
elif isinstance(self.dialog, ft.AlertDialog):
self.page.dialog = self.dialog
self.page.dialog.open = open
self.page.update()
Expand Down
10 changes: 5 additions & 5 deletions kintree/gui/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def call_settings(self, e):

def reset_view(self, e, ignore=['enable'], hidden={}):
def reset_field(field):
if type(field) is ft.ProgressBar:
if isinstance(field, ft.ProgressBar):
field.value = 0
else:
field.value = None
field.update()

for name, field in self.fields.items():
if type(field) == dict:
if isinstance(field, dict):
for key, value in field.items():
value.disabled = True
reset_field(value)
Expand Down Expand Up @@ -588,7 +588,7 @@ def process_update(self, e, value=None):

def process_category(self, e=None, label=None, value=None):
parent_category = None
if type(self.fields['Category'].value) == str:
if isinstance(self.fields['Category'].value, str):
parent_category = inventree_interface.split_category_tree(self.fields['Category'].value)[0]
self.fields['IPN: Category Code'].options = self.get_code_options()
# Select category code corresponding to selected category
Expand Down Expand Up @@ -954,10 +954,10 @@ def build_column(self):
kicad_inputs = []
for name, field in self.fields.items():
# Update callbacks
if type(field) == ft.ElevatedButton:
if isinstance(field, ft.ElevatedButton):
field.on_click = self.check_snapeda
# Update options
elif type(field) == DropdownWithSearch:
elif isinstance(field, DropdownWithSearch):
field.label = name
if name == 'Symbol Library':
field.options = self.build_library_options(type='symbol')
Expand Down
36 changes: 16 additions & 20 deletions kintree/gui/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(self, page: ft.Page):
# Load setting fields
self.fields = {}
for field_name, field_data in SETTINGS.get(self.title, {}).items():
if type(field_data) == list and field_data[0] is not None:
if isinstance(field_data, list) and field_data[0] is not None:
self.fields[field_name] = field_data[1]
self.fields[field_name].value = self.settings[field_data[0]]

Expand Down Expand Up @@ -357,7 +357,7 @@ def init_column(self) -> ft.Column:
)

def update_field(self, name, field, column):
if type(field) == ft.TextField:
if isinstance(field, ft.TextField):
field_predefined = bool(field.width)
if not field_predefined:
field.label = name
Expand Down Expand Up @@ -386,7 +386,7 @@ def update_field(self, name, field, column):
ft.Row(height=GUI_PARAMS['textfield_space_after']),
]
)
elif type(field) == ft.Text:
elif isinstance(field, ft.Text):
field.value = name
field_row = ft.Row(
controls=[
Expand All @@ -395,7 +395,7 @@ def update_field(self, name, field, column):
)
column.controls.append(field_row)
column.controls.append(ft.Divider())
elif type(field) == ft.TextButton:
elif isinstance(field, ft.TextButton):
column.controls.append(
ft.ElevatedButton(
name,
Expand All @@ -405,12 +405,12 @@ def update_field(self, name, field, column):
on_click=lambda e, s=name: self.test_s(e, s=s)
),
)
elif type(field) == ft.Dropdown:
elif isinstance(field, ft.Dropdown):
field.on_change = lambda _: self.save()
column.controls.append(
field,
)
elif type(field) == ft.Switch or type(field) == SwitchWithRefs:
elif isinstance(field, ft.Switch) or isinstance(field, SwitchWithRefs):
if 'proxy' in name.lower():
field.on_change = lambda _: None
else:
Expand Down Expand Up @@ -499,11 +499,16 @@ class UserSettingsView(PathSettingsView):
'CACHE_VALID_DAYS': global_settings.CACHE_VALID_DAYS
},
}
settings_file = [
settings_file_list = [
global_settings.USER_CONFIG_FILE,
global_settings.CONFIG_GENERAL_PATH,
global_settings.CONFIG_SEARCH_API_PATH,
]

def save(self):
# Save all settings
for sf in self.settings_file_list:
super().save(settings_file=sf, show_dialog=True)

def increment_cache_value(self, inc):
field = SETTINGS[self.title]['CACHE_VALID_DAYS'][1]
Expand Down Expand Up @@ -542,26 +547,17 @@ def build_column(self):
self.column.controls.append(cache_row)
# Add cache row to switch refs
SETTINGS[self.title]['Enable Supplier Search Cache'][1].refs = [cache_row_ref]

setting_file1 = self.settings_file[1]
setting_file2 = self.settings_file[2]

for name, field in SETTINGS[self.title].items():
if field[0] in ['AUTOMATIC_BROWSER_OPEN', 'DATASHEET_SAVE_ENABLED', 'DATASHEET_SAVE_PATH', 'DATASHEET_INVENTREE_ENABLED']:
self.fields[name].on_change = lambda _: self.save(
settings_file=setting_file1,
show_dialog=False
)
self.fields[name].on_change = lambda _: self.save()
elif field[0] in ['CACHE_ENABLED', 'CACHE_VALID_DAYS']:
self.fields[name].on_change = lambda _: self.save(
settings_file=setting_file2,
show_dialog=False
)
self.settings_file = self.settings_file[0]
self.fields[name].on_change = lambda _: self.save()
self.settings_file = self.settings_file_list[0]

# Update datasheet ref
for idx, field in enumerate(self.column.controls):
if type(field) == SwitchWithRefs:
if isinstance(field, SwitchWithRefs):
if field.label == 'Save Datasheets to Local Folder':
datasheet_row_ref.current = self.column.controls[idx + 1]
SETTINGS[self.title]['Save Datasheets to Local Folder'][1].refs = [datasheet_row_ref]
Expand Down

0 comments on commit 0b1bce7

Please sign in to comment.