You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
5 years ago
|
"""
|
||
|
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 voronoiview_ui.py file.
|
||
|
"""
|
||
|
|
||
|
from voronoiview.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
|
||
|
point_side = str_point.split("|")[0] # First element is the point
|
||
|
point_side = point_side.strip()
|
||
|
elems = point_side.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()
|