11from .handlerchain_message_class
import MessageType, Message, MessagePosition
12from .handlerchain_class
import IMessageHandler, HandlerChain
30 def __init__(self, x : int, y : int, width : int, height : int) ->
None:
31 width = max([width, WindowRectangle.MINIMUM_WIDTH])
32 height = max([height, WindowRectangle.MINIMUM_HEIGHT])
57 if point.X >= self.
Left and point.X < self.
Right and \
58 point.Y >= self.
Top and point.Y < self.
Bottom:
69 return "x1={0:2}, y1={1:2}, x2={2:2}, y2={3:2}".format(
112 return self.
_closeBox.PointInside(position)
132 def __init__(self, windowId : int, title : str, x : int, y : int, width : int, height : int, handlerChain : HandlerChain) ->
None:
138 MessageWindow.CLOSE_WIDTH,
139 MessageWindow.CLOSE_HEIGHT)
144 MessageType.ButtonDown : MessageWindowHandlers._HandleButtonDownMessage,
145 MessageType.ButtonUp : MessageWindowHandlers._HandleButtonUpMessage,
146 MessageType.Close : MessageWindowHandlers._HandleCloseMessage
192 messageProcessed =
False
195 messageProcessed = handler(self, message)
196 return messageProcessed;
204 return "[id={0:2}] \"{1}\" ({2}), selected={3}".format(
250 def CreateWindow(title : str, x : int, y : int, width : int, height : int, handlerChain : HandlerChain) -> MessageWindow:
251 window =
MessageWindow(MessageWindowFactory._nextWindowId, title, x, y,
252 width, height, handlerChain)
253 MessageWindowFactory._nextWindowId += 1
256 handlerChain.AddHandler(window)
298 messageProcessed =
False
300 if window._PointInWindow(message.Position):
301 if not window._selected:
302 window._selected =
True
303 print(
" --> Button Down in \"{0}\", window selected".format(window._title))
306 window._selected =
False
307 print(
" --> Button Down not in \"{0}\", window deselected".format(window._title))
309 return messageProcessed
322 messageProcessed =
False
324 if window._PointInWindow(message.Position):
328 messageProcessed =
True
329 if window._PointInCloseBox(message.Position):
330 print(
" --> Button Up in \"{0}\" close box, sending Close message".format(window._title))
331 window._handlerChain.SendMessage(
Message(MessageType.Close, message.Position))
333 print(
" --> Button Up in \"{0}\", no further action taken".format(window._title))
335 return messageProcessed
348 messageProcessed =
False
350 print(
" --> Close in \"{0}\", removing window from handler chain".format(window._title))
354 messageProcessed =
True
355 window._handlerChain.RemoveHandler(window)
356 window._selected =
False
358 print(
" --> Close seen in \"{0}\" but this window is not selected, ignoring".format(window._title))
360 return messageProcessed
Represents a handler in a chain of handlers.
int ID(self)
Property getter for the ID of the window: value = o.ID.
Represents a message sent to the windows.
Represents a class factory for instances of the MessageWindow class.
MessageWindow CreateWindow(str title, int x, int y, int width, int height, HandlerChain handlerChain)
Creates an instance of the MessageWindow class with the specified attributes and adds the new instanc...
Contains the various message handlers that operate on MessageWindow class instances.
bool _HandleButtonDownMessage(MessageWindow window, Message message)
Helper method to handle the ButtonDown message.
bool _HandleCloseMessage(MessageWindow window, Message message)
Helper method to handle the Close message.
bool _HandleButtonUpMessage(MessageWindow window, Message message)
Helper method to handle the ButtonUp message.
Represents a rectangular region that can handle messages directed to that region.
bool ProcessMessage(self, Message message)
Processes a message.
str ToString(self)
Convert this handler to a string.
bool _PointInWindow(self, MessagePosition position)
Determine if the specified point is in this MessageWindow's region.
_selected
Whether this window has been selected (a button click occurred within the window).
def _PointInCloseBox(self, MessagePosition position)
Determine if the specified point is in this MessageWindow's "close" region.
_windowId
Unique ID of this window.
_title
Title/Name of this window.
_messageHandlers
Maps a message type to a handler method of type MessageHandler.
_closeBox
Position of the close window within the window box, although the coordinates are also global coordina...
_windowBox
Position of this window in global coordinates.
int ID(self)
Property getter for the ID of the message handler: value = o.ID
None __init__(self, int windowId, str title, int x, int y, int width, int height, HandlerChain handlerChain)
Constructor.
_handlerChain
The HandlerChain to which this window belongs (as an IMessageHandler object).
Represents a rectangular region, with upper left and lower right coordinates.
str ToString(self)
Convert this rectangle to a string.
Right
X position of the lower right corner of the window rectangle.
bool PointInside(self, MessagePosition point)
Determine if the given point is in the rectangle.
None __init__(self, int x, int y, int width, int height)
Top
Y position of the upper left corner of the window rectangle.
Bottom
Y position of the lower right corner of the window rectangle.
Left
X position of the upper left corner of the window rectangle.