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

feat: frozen models #31

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/app_model/registries/_menus_reg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from __future__ import annotations

from typing import Callable, Dict, Final, Iterator, List, Optional, Sequence, Set, Tuple
from typing import (
Any,
Callable,
Dict,
Final,
Iterator,
List,
Optional,
Sequence,
Set,
Tuple,
)

from psygnal import Signal

Expand Down Expand Up @@ -39,7 +50,11 @@ def append_menu_items(
menu_list = self._menu_items.setdefault(menu_id, [])
menu_list.append(item)
changed_ids.add(menu_id)
disposers.append(lambda: menu_list.remove(item))

def _remove(lst: list = menu_list, _item: Any = item) -> None:
lst.remove(_item)

disposers.append(_remove)

def _dispose() -> None:
for disposer in disposers:
Expand Down
12 changes: 7 additions & 5 deletions src/app_model/registries/_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ def _register_action_obj(
# keybinding
for keyb in action.keybindings or ():
if action.enablement is not None:
_keyb = keyb.copy()
if _keyb.when is None:
_keyb.when = action.enablement
else:
_keyb.when = action.enablement | _keyb.when
kwargs = keyb.dict()
kwargs["when"] = (
action.enablement
if keyb.when is None
else action.enablement | keyb.when
)
_keyb = type(keyb)(**kwargs)
else:
_keyb = keyb
if _d := app.keybindings.register_keybinding_rule(action.id, _keyb):
Expand Down
1 change: 1 addition & 0 deletions src/app_model/types/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ class _StrictModel(BaseModel):

class Config:
extra = Extra.forbid
frozen = True