class GraphicType
An enumeration class that defines the types of graphics that can be generated in the system.
/tf/active/vicechatdev/e-ink-llm/graphics_generator.py
26 - 31
simple
Purpose
GraphicType is an Enum class that provides a standardized set of constants representing different categories of graphics that can be created. It serves as a type-safe way to specify and validate graphic types throughout the application, ensuring consistency when working with chart generation, diagram creation, illustrations, and sketches. This enum is typically used as a parameter in graphic generation functions or methods to determine the type of visual output to produce.
Source Code
class GraphicType(Enum):
"""Types of graphics that can be generated"""
CHART = "chart"
DIAGRAM = "diagram"
ILLUSTRATION = "illustration"
SKETCH = "sketch"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Enum | - |
Parameter Details
bases: Inherits from Enum base class, which provides enumeration functionality. No custom __init__ parameters are defined for this enum.
Return Value
Instantiating or accessing GraphicType members returns a GraphicType enum instance. Each member has a name (e.g., 'CHART') and a value (e.g., 'chart'). The value property returns the string representation of the graphic type.
Class Interface
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
CHART |
GraphicType | Represents chart-type graphics (value: 'chart') | class |
DIAGRAM |
GraphicType | Represents diagram-type graphics (value: 'diagram') | class |
ILLUSTRATION |
GraphicType | Represents illustration-type graphics (value: 'illustration') | class |
SKETCH |
GraphicType | Represents sketch-type graphics (value: 'sketch') | class |
Dependencies
enum
Required Imports
from enum import Enum
Usage Example
from enum import Enum
class GraphicType(Enum):
CHART = "chart"
DIAGRAM = "diagram"
ILLUSTRATION = "illustration"
SKETCH = "sketch"
# Access enum members
graphic_type = GraphicType.CHART
print(graphic_type) # GraphicType.CHART
print(graphic_type.value) # "chart"
print(graphic_type.name) # "CHART"
# Compare enum members
if graphic_type == GraphicType.CHART:
print("This is a chart type")
# Get enum by value
type_from_string = GraphicType("diagram")
print(type_from_string) # GraphicType.DIAGRAM
# Iterate over all types
for gtype in GraphicType:
print(f"{gtype.name}: {gtype.value}")
# Use in function signatures
def generate_graphic(graphic_type: GraphicType) -> None:
if graphic_type == GraphicType.CHART:
print("Generating chart...")
elif graphic_type == GraphicType.DIAGRAM:
print("Generating diagram...")
Best Practices
- Use GraphicType members directly (e.g., GraphicType.CHART) rather than string literals to ensure type safety
- When accepting graphic types as parameters, use type hints with GraphicType to enable IDE autocomplete and type checking
- Access the string value using the .value property when needed for serialization or API calls
- Use GraphicType(string_value) to convert string values back to enum members, which will raise ValueError if the string is invalid
- Enums are immutable and singleton - each member is instantiated only once
- Compare enum members using == or 'is' operators, both work correctly
- Use 'in' operator to check membership: if some_value in GraphicType._value2member_map_
- Iterate over all graphic types using: for gtype in GraphicType
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class AnalysisType 66.5% similar
-
class SectionType 62.3% similar
-
class GraphicSpec 59.8% similar
-
class GraphicsGenerator 59.2% similar
-
class CommentType 58.4% similar