""" Similar to the opengl_widget module, this module defines helper functions for the point_list_widget. It is named the same for convenience. The actual point_list_widget is defined in the clusterview_ui.py file. """ from clusterview2.point_manager import PointManager def _string_point_to_point(str_point): """ In the QListWidget points are stored as strings because of the way Qt has list items defined. @param str_point The string of the form (x, y) to convert. """ # 1. Split elems = str_point.split(",") # 2. Take elements "(x" and "y)" and remove their first and # last characters, respectively. Note that for y this # function expects there to be a space after the comma. x = elems[0][1:] y = elems[1][1:-1] return (int(x), int(y)) def item_click_handler(ctx, item): """ Handles an item becoming clicked in the list. This function is designed to be partially applied with the main_window context in order to be able to trigger an opengl_widget refresh. @param ctx The context. @param item The clicked item. """ point = _string_point_to_point(item.text()) # TODO: Super slow linear search, should write a find_point function # on the point_set in order to speed this up since PointSet # is backed by a set anyway. for p in PointManager.point_set.points: if p.x == point[0] and p.y == point[1]: p.select() else: p.unselect() ctx.opengl_widget.update()