Taylor Bockman
5 years ago
8 changed files with 118 additions and 81 deletions
@ -0,0 +1,52 @@
|
||||
""" |
||||
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 .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 (x, 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() |
@ -0,0 +1,7 @@
|
||||
class PointManager(): |
||||
""" |
||||
A state class that represents the absolute state of the |
||||
world in regards to points. |
||||
""" |
||||
|
||||
point_set = None |
Loading…
Reference in new issue