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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## [UNRELEASED]
- Updated construct-typing dependency to v0.8.* and updated the DataClass definitions to reflect the breaking changes.
- Updated construct-typing dependency to v0.8.1+ and updated the DataClass definitions to reflect the breaking changes.
- Bumped minimum required Python version to 3.10 (previously: 3.8 which has reached end-of-life).
- Updated `typing_extensions` dependency to >=4.12.0 for Python 3.13 compatibility.
- Removed `version.py`, use `importlib.metadata` instead to get the version number.
- Fixed a bug where multiple instances of `WxConstructHexEditor` might share the same default dict, leading to potentially unexpected behavior.

-------------------------------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions construct_editor/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, max_commands: int) -> None:
self._max_commands = max_commands

self._history: t.List[Command] = []
self._current_command_idx: t.Optional[int] = None
self._current_command_idx: int | None = None

def can_undo(self) -> bool:
"""
Expand Down Expand Up @@ -131,7 +131,7 @@ def clear_commands(self):
self._history.clear()
self._current_command_idx = None

def get_current_command(self) -> t.Optional[Command]:
def get_current_command(self) -> Command | None:
"""
Returns the current command.
"""
Expand All @@ -140,7 +140,7 @@ def get_current_command(self) -> t.Optional[Command]:

return self._history[self._current_command_idx]

def get_next_command(self) -> t.Optional[Command]:
def get_next_command(self) -> Command | None:
"""
Returns the next command.
"""
Expand Down
18 changes: 10 additions & 8 deletions construct_editor/core/construct_editor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import abc
import typing as t

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


class ConstructEditor:
def __init__(self, construct: cs.Construct, model: ConstructEditorModel):
def __init__(self, construct: cs.Construct[t.Any, t.Any], model: ConstructEditorModel):
Comment thread
robin523790 marked this conversation as resolved.
self._model = model

self.change_construct(construct)
Expand All @@ -30,15 +32,15 @@ def reload(self):
"""

@abc.abstractmethod
def show_parse_error_message(self, msg: t.Optional[str], ex: t.Optional[Exception]):
def show_parse_error_message(self, msg: str | None, ex: Exception | None):
"""
Show an parse error message to the user.

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

@abc.abstractmethod
def show_build_error_message(self, msg: t.Optional[str], ex: t.Optional[Exception]):
def show_build_error_message(self, msg: str | None, ex: Exception | None):
"""
Show an build error message to the user.

Expand Down Expand Up @@ -78,7 +80,7 @@ def _put_to_clipboard(self, txt: str):
"""

@abc.abstractmethod
def _get_from_clipboard(self):
def _get_from_clipboard(self) -> str | None:
"""
Get text from the clipboard.

Expand Down Expand Up @@ -113,7 +115,7 @@ def paste_entry_value_from_clipboard(self, entry: "entries.EntryConstruct"):
# self.model.set_value(txt, entry, ConstructEditorColumn.Value)
# self.on_root_obj_changed.fire(self.root_obj)

def change_construct(self, constr: cs.Construct) -> None:
def change_construct(self, constr: cs.Construct[t.Any, t.Any]) -> None:
"""
Change the construct format, that is used for building/parsing.
"""
Expand Down Expand Up @@ -309,14 +311,14 @@ def is_list_view_enabled(self, entry: "entries.EntryConstruct") -> bool:
return False

@property
def construct(self) -> cs.Construct:
def construct(self) -> cs.Construct[t.Any, t.Any]:
"""
Construct that is used for displaying.
"""
return self._construct

@construct.setter
def construct(self, constr: cs.Construct):
def construct(self, constr: cs.Construct[t.Any, t.Any]):
self.change_construct(constr)

@property
Expand Down Expand Up @@ -379,7 +381,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: t.Optional["entries.EntryConstruct"]) -> None:
def _refresh_status_bar(self, entry: "entries.EntryConstruct | None") -> None:
if entry is None:
self.show_status("", "")
return
Expand Down
19 changes: 8 additions & 11 deletions construct_editor/core/context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import construct_editor.core.construct_editor as construct_editor
import construct_editor.core.entries as entries
from construct_editor.core.model import ConstructEditorModel, IntegerFormat
from construct_editor.core.model import (
ConstructEditorModel,
IntegerFormat,
)

COPY_LABEL = "Copy"
PASTE_LABEL = "Paste"
Expand All @@ -15,6 +18,7 @@
INTFORMAT_DEC_LABEL = "Dec"
INTFORMAT_HEX_LABEL = "Hex"


# #####################################################################################################################
# Context Menu ########################################################################################################
# #####################################################################################################################
Expand All @@ -26,15 +30,15 @@ class SeparatorMenuItem:
@dataclasses.dataclass
class ButtonMenuItem:
label: str
shortcut: t.Optional[str]
shortcut: str | None
enabled: bool
callback: t.Callable[[], None]


@dataclasses.dataclass
class CheckboxMenuItem:
label: str
shortcut: t.Optional[str]
shortcut: str | None
enabled: bool
checked: bool
callback: t.Callable[[bool], None]
Expand All @@ -53,13 +57,7 @@ class SubmenuItem:
subitems: t.List["MenuItem"]


MenuItem = t.Union[
ButtonMenuItem,
SeparatorMenuItem,
CheckboxMenuItem,
RadioGroupMenuItems,
SubmenuItem,
]
MenuItem = ButtonMenuItem | SeparatorMenuItem | CheckboxMenuItem | RadioGroupMenuItems | SubmenuItem


class ContextMenu:
Expand Down Expand Up @@ -161,7 +159,6 @@ def _init_intformat(self):
def _init_list_viewed_entries(self):
submenu = SubmenuItem("List Viewed Items", [])
for e in self.model.list_viewed_entries:

def on_remove_list_viewed_item(checked: bool):
self.parent.disable_list_view(e)

Expand Down
2 changes: 1 addition & 1 deletion construct_editor/core/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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 Down
Loading