Skip to content
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
1 change: 0 additions & 1 deletion construct_editor/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
3 changes: 2 additions & 1 deletion construct_editor/core/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from typing import Callable, Generic, TypeVar

from typing_extensions import ParamSpec
Expand Down
3 changes: 2 additions & 1 deletion construct_editor/core/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import abc
import typing as t

Expand Down
35 changes: 17 additions & 18 deletions construct_editor/core/construct_editor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import abc
Expand All @@ -19,7 +18,7 @@ def __init__(self, construct: cs.Construct[t.Any, t.Any], model: ConstructEditor
self.change_construct(construct)

self.on_entry_selected: CallbackList[
["entries.EntryConstruct"]
[entries.EntryConstruct]
] = CallbackList()
self.on_root_obj_changed: CallbackList[[t.Any]] = CallbackList()

Expand Down Expand Up @@ -56,15 +55,15 @@ def show_status(self, path_info: str, bytes_info: str):
"""

@abc.abstractmethod
def get_selected_entry(self) -> "entries.EntryConstruct | None":
def get_selected_entry(self) -> entries.EntryConstruct | None:
"""
Get the currently selected entry (or None if nothing is selected).

This has to be implemented by the derived class.
"""

@abc.abstractmethod
def select_entry(self, entry: "entries.EntryConstruct") -> None:
def select_entry(self, entry: entries.EntryConstruct) -> None:
"""
Select an entry programmatically.

Expand All @@ -87,21 +86,21 @@ def _get_from_clipboard(self) -> str | None:
This has to be implemented by the derived class.
"""

def copy_entry_value_to_clipboard(self, entry: "entries.EntryConstruct"):
def copy_entry_value_to_clipboard(self, entry: entries.EntryConstruct):
"""
Copy the value of the entry to the clipboard.
"""
copy_txt = entry.obj_str
self._put_to_clipboard(copy_txt)

def copy_entry_path_to_clipboard(self, entry: "entries.EntryConstruct"):
def copy_entry_path_to_clipboard(self, entry: entries.EntryConstruct):
"""
Copy the path of the entry to the clipboard.
"""
copy_txt = entries.create_path_str(entry.path)
self._put_to_clipboard(copy_txt)

def paste_entry_value_from_clipboard(self, entry: "entries.EntryConstruct"):
def paste_entry_value_from_clipboard(self, entry: entries.EntryConstruct):
"""
Paste the value of the entry from the clipboard.
"""
Expand Down Expand Up @@ -182,14 +181,14 @@ def build(self, **contextkw: t.Any) -> bytes:
return binary

@abc.abstractmethod
def expand_entry(self, entry: "entries.EntryConstruct"):
def expand_entry(self, entry: entries.EntryConstruct):
"""
Expand an entry.

This has to be implemented by the derived class.
"""

def expand_children(self, entry: "entries.EntryConstruct"):
def expand_children(self, entry: entries.EntryConstruct):
"""
Expand all children of an entry recursively including the entry itself.
"""
Expand All @@ -212,7 +211,7 @@ def expand_level(self, level: int):
Expand all Entries to Level ... (0=root level)
"""

def dvc_expand(entry: "entries.EntryConstruct", current_level: int):
def dvc_expand(entry: entries.EntryConstruct, current_level: int):
subentries = entry.subentries
if subentries is None:
return
Expand All @@ -227,14 +226,14 @@ def dvc_expand(entry: "entries.EntryConstruct", current_level: int):
dvc_expand(self._model.root_entry, 1)

@abc.abstractmethod
def collapse_entry(self, entry: "entries.EntryConstruct"):
def collapse_entry(self, entry: entries.EntryConstruct):
"""
Collapse an entry.

This has to be implemented by the derived class.
"""

def collapse_children(self, entry: "entries.EntryConstruct"):
def collapse_children(self, entry: entries.EntryConstruct):
"""
Collapse all children of an entry recursively including the entry itself.
"""
Expand All @@ -252,7 +251,7 @@ def collapse_all(self):
if self._model.root_entry:
self.collapse_children(self._model.root_entry)

def restore_expansion_from_model(self, entry: "entries.EntryConstruct"):
def restore_expansion_from_model(self, entry: entries.EntryConstruct):
"""
Restore the expansion state from the model recursively.

Expand All @@ -277,7 +276,7 @@ def restore_expansion_from_model(self, entry: "entries.EntryConstruct"):
for subentry in subentries:
self.restore_expansion_from_model(subentry)

def enable_list_view(self, entry: "entries.EntryConstruct"):
def enable_list_view(self, entry: entries.EntryConstruct):
"""
Enable the list view for an entry.
"""
Expand All @@ -292,7 +291,7 @@ def enable_list_view(self, entry: "entries.EntryConstruct"):
self.collapse_children(entry)
self.expand_entry(entry)

def disable_list_view(self, entry: "entries.EntryConstruct"):
def disable_list_view(self, entry: entries.EntryConstruct):
"""
Disable the list view for an entry.
"""
Expand All @@ -302,7 +301,7 @@ def disable_list_view(self, entry: "entries.EntryConstruct"):
self._model.list_viewed_entries.remove(entry)
self.reload()

def is_list_view_enabled(self, entry: "entries.EntryConstruct") -> bool:
def is_list_view_enabled(self, entry: entries.EntryConstruct) -> bool:
"""
Check if an entry is shown in a list view.
"""
Expand Down Expand Up @@ -362,7 +361,7 @@ def _get_list_viewed_column_count(self):
return column_count

def _get_list_viewed_column_names(
self, selected_entry: "entries.EntryConstruct"
self, selected_entry: entries.EntryConstruct
) -> t.List[str]:
"""
Get the names of all list viewed columns.
Expand All @@ -381,7 +380,7 @@ def _get_list_viewed_column_names(
column_names.append(entries.create_path_str(column_path))
return column_names

def _refresh_status_bar(self, entry: "entries.EntryConstruct | None") -> None:
def _refresh_status_bar(self, entry: entries.EntryConstruct | None) -> None:
if entry is None:
self.show_status("", "")
return
Expand Down
11 changes: 6 additions & 5 deletions construct_editor/core/context_menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import abc
import dataclasses
import typing as t
Expand Down Expand Up @@ -54,7 +55,7 @@ class RadioGroupMenuItems:
@dataclasses.dataclass
class SubmenuItem:
label: str
subitems: t.List["MenuItem"]
subitems: t.List[MenuItem]


MenuItem = ButtonMenuItem | SeparatorMenuItem | CheckboxMenuItem | RadioGroupMenuItems | SubmenuItem
Expand All @@ -63,9 +64,9 @@ class SubmenuItem:
class ContextMenu:
def __init__(
self,
parent: "construct_editor.ConstructEditor",
model: "ConstructEditorModel",
entry: t.Optional["entries.EntryConstruct"],
parent: construct_editor.ConstructEditor,
model: ConstructEditorModel,
entry: entries.EntryConstruct | None,
):
self.parent = parent
self.model = model
Expand Down
23 changes: 11 additions & 12 deletions construct_editor/core/custom.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import enum
import typing as t

Expand All @@ -9,7 +11,7 @@


def add_custom_transparent_subconstruct(
subconstruct: t.Type["cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]"],
subconstruct: t.Type[cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]],
):
"""
Add compatibility of an custom `cs.Subconstruct` to the construct-editor.
Expand All @@ -19,7 +21,7 @@ def add_custom_transparent_subconstruct(


def add_custom_tunnel(
tunnel: t.Type["cs.Tunnel[t.Any, t.Any]"],
tunnel: t.Type[cs.Tunnel[t.Any, t.Any]],
type_str: str,
):
"""
Expand All @@ -29,9 +31,9 @@ def add_custom_tunnel(
class EntryTunnel(entries.EntrySubconstruct):
def __init__(
self,
model: "model.ConstructEditorModel",
parent: t.Optional["entries.EntryConstruct"],
construct: "cs.Compressed[t.Any, t.Any]",
model: model.ConstructEditorModel,
parent: entries.EntryConstruct | None,
construct: cs.Compressed[t.Any, t.Any],
name: entries.NameType,
docs: str,
):
Expand All @@ -51,10 +53,7 @@ class AdapterObjEditorType(enum.Enum):


def add_custom_adapter(
adapter: t.Union[
t.Type["cs.Adapter[t.Any,t.Any,t.Any, t.Any]"], # for cs.Adapter
"cs.Adapter[t.Any,t.Any,t.Any, t.Any]", # for cs.ExprAdapter
],
adapter: t.Type[cs.Adapter[t.Any, t.Any, t.Any, t.Any]] | cs.Adapter[t.Any, t.Any, t.Any, t.Any],
type_str: str,
obj_editor_type: AdapterObjEditorType,
):
Expand All @@ -65,9 +64,9 @@ def add_custom_adapter(
class EntryAdapter(entries.EntryConstruct):
def __init__(
self,
model: "model.ConstructEditorModel",
parent: t.Optional["entries.EntryConstruct"],
construct: "cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]",
model: model.ConstructEditorModel,
parent: entries.EntryConstruct | None,
construct: cs.Subconstruct[t.Any, t.Any, t.Any, t.Any],
name: entries.NameType,
docs: str,
):
Expand Down
Loading