Design Pattern Examples
Overview of object-oriented design patterns
handlerchain_message_class.py
Go to the documentation of this file.
8
9from enum import Enum
10
11
12class MessageType(Enum):
13
16 Close = 0,
17
18
19 ButtonDown = 1,
20
21
22 ButtonUp = 2
23
24
25#========================================================================
26#========================================================================
27#========================================================================
28
29
30
34
35
41 def __init__(self, x : int, y : int) -> None:
42 self.X = x
43 self.Y = y
44
45
49
50
54 def ToString(self) -> str:
55 return "x={0:2},y={1:2}".format(self.X, self.Y)
56
57
58
59#========================================================================
60#========================================================================
61#========================================================================
62
63
64
66class Message:
67
68
75 def __init__(self, type : MessageType, position : MessagePosition) -> None:
76 self.MessageType = type
77 self.Position = position
78
79
86
87
88
92 def ToString(self) -> str:
93 messageTypeAsString = ""
94 match (self.MessageType):
95 case MessageType.Close:
96 messageTypeAsString = "Close"
97
98 case MessageType.ButtonDown:
99 messageTypeAsString = "ButtonDown"
100
101 case MessageType.ButtonUp:
102 messageTypeAsString = "ButtonUp"
103
104 case _:
105 messageTypeAsString = "Unknown message type"
106
107 return "{0} at ({1})".format(messageTypeAsString, self.Position.ToString())
108
None __init__(self, MessageType type, MessagePosition position)
Constructor.
MessageType
Value from the MessageType enumeration indicating the type of this message.
Position of the message in global coordinates (same scope of coordinates as windows).