forked from brickbots/PiFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Type, Any | ||
from PiFinder.composite_object import CompositeObject | ||
|
||
|
||
@dataclass | ||
class MenuItemDefinition: | ||
|
||
# The name of the menu item | ||
name: str = field(default="") | ||
menu_class: Type = field(default=object) | ||
stateful: bool = field(default=False) | ||
state: Any = field(default=None) | ||
preload: bool = field(default=False) | ||
select: str = field(default="") | ||
items: list = field(default_factory=list) | ||
objects: list[CompositeObject] = field(default_factory=list) | ||
label: str = field(default="") | ||
sorting: list[str] = field(default_factory=list) | ||
enabled: bool = field(default=True) | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, MenuItemDefinition): | ||
return NotImplemented | ||
return self.name == other.name and self.label == other.label | ||
|
||
def __hash__(self): | ||
return hash(self.name+self.label) | ||
|
||
@classmethod | ||
def from_dict(cls, d): | ||
return cls(**d) | ||
|
||
@property | ||
def display_name(self): | ||
""" | ||
Returns the display name for this object | ||
""" | ||
return f"{self.name}" |