from .mode import Mode from .opengl_widget import set_drawing_event def __handle_add_point(ctx, event): """ Event handler for the add point mode. Sets the drawing mode for the OpenGL Widget using `set_drawing_mode`, converts a point to our point representation, and adds it to the list. """ print("[ADD] GOT POINT: ({}, {})".format(event.x(), event.y())) set_drawing_event(event) ctx.update() # Convert to our point representation and add to list widget # Point representation is a class called Point with coordinates, # and attributes (currently always None) def __handle_edit_point(ctx, event): # TODO: This function and delete definitely need to make sure they are # on a point we have. # # Since points are unique consider a hashmap of points to make O(1) # lookups for addition and deletion. This list can be maintained here # in this module. It should be a dictionary - from point to # attributes in the case of algorithms that require points to have # weights or something. # # Should move the associated point in the list to the new location if # applicable. print("[EDIT] GOT POINT: ({}, {})".format(event.x(), event.y())) # Store old x, y from event set_drawing_event(event) ctx.update() # after this remove the point from the list def __handle_move_points(ctx, event): # TODO: Should move the associated points in the list to the new location. print("[MOVE] Pressed - NOTE NEED DRAG EVENT") # Store list of old points that are captured set_drawing_event(event) # Find and move all points from the old list to their new locations def __handle_delete_point(ctx, event): print("[DELETE] GOT POINT: ({}, {})".format(event.x(), event.y())) set_drawing_event(event) # Find the point from event and remove it from the list # Simple dispatcher to make it easy to dispatch the right mode # function when the OpenGL window is clicked. MODE_HANDLER_MAP = { Mode.OFF: lambda: None, Mode.ADD: __handle_add_point, Mode.EDIT: __handle_edit_point, Mode.MOVE: __handle_move_points, Mode.DELETE: __handle_delete_point }