Skip to content

Commit 09b2355

Browse files
committed
Ready for V1.1.0 to pypi
Tested backwards compatibility with V1.0.0 demo, added comments to minimal and customised V1.1.0 demos
1 parent 35351aa commit 09b2355

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

demo_V1.0.0_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# for backwards compatibility with V1.0.0, this is the existing demo code
2+
3+
from xyz_canvas.canvas import define_points
4+
5+
6+
def on_complete(lines):
7+
print("Points created are:")
8+
for l in lines:
9+
print(l)
10+
11+
demo_3D_builder = define_points(on_complete_cb = on_complete,
12+
xlim =[0,10], ylim =[-20,30], zlim=[-3,5],
13+
xlabel="x", ylabel="y", zlabel="z")
14+
15+
# up to here....
16+
17+
# - Moved `plt.show()` out of `__init__` to allow users more control over plot display timing.
18+
# - Users now must call `.show()` explicitly when ready to display.
19+
20+
demo_3D_builder.plt.show()
21+
22+
# also note that on_complete_cb is no longer used, and 'lines' in the example above should have been 'points'

demo_minimal.py renamed to demo_V1.1.0_minimal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
# showing the plot
1111
demo.plt.show()
1212

13+
# note that this is so minimal that all it does is display;
14+
# the resulting points are not used here.
15+
1316
print("Demo finished ...")
1417

demo_with_customisation.py renamed to demo_V1.1.0_with_customisation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# callback examples
66

77
def on_click(canvas, xyz, pt_index):
8+
# add more of your own code here - xyz is the 3D point clicked, and
9+
# pt_index is None if there's no defined point associated, otherwise
10+
# it's the index (i.e. 'point number' of the points created
811
if (pt_index is not None):
912
print(f"Clicked on point {pt_index} at {canvas.points_xyz[pt_index]}")
1013
if(len(canvas.points_xyz) >3):
@@ -14,6 +17,9 @@ def on_click(canvas, xyz, pt_index):
1417
print(f"Clicked at {xyz}")
1518

1619
def on_move(canvas, xyz, selectable_pt_index, selected_pt_index):
20+
# add more of your own code here - xyz is the 3D point of the mouse pointer,
21+
# selectable_pt_index is the point index of points 'hovered over', or None
22+
# selected_pt_index is the point index of any point being 'carried', or None
1723
if (selectable_pt_index is not None):
1824
print(f"Moved to {xyz} near point {selectable_pt_index}" )
1925
if (selected_pt_index is not None):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "xyz_canvas"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
license = "MIT"
55

66
authors = [

xyz_canvas/canvas.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ def _interleave(ends):
3535

3636
class xyz_canvas:
3737

38-
def __init__(self,
39-
xlim =[0,1], ylim =[0,1], zlim=[0,1],
40-
xlabel="x", ylabel="y", zlabel="z",
41-
on_click_cb = None,
42-
on_move_cb = None
38+
def __init__(self, *args, xlim =[0,10], ylim =[-20,30], zlim=[-3,5],
39+
xlabel="x", ylabel="y", zlabel="z",
40+
on_click_cb = None, on_move_cb = None, **kwargs
4341
):
4442
self.plt = plt
4543
self.fig = plt.figure()
@@ -93,13 +91,6 @@ def redraw(self, showframe_xyz=None):
9391
x,y,z = xyz[0],xyz[1],xyz[2]
9492
self.ax.text(x,y,z,f" ({x:.3f}, {y:.3f}, {z:.3f})", size = 'small')
9593

96-
def on_button_press(self,action):
97-
if action == 'clear':
98-
self.init_canvas()
99-
elif action == 'save':
100-
self.on_complete_cb(self.points_xyz)
101-
elif action == 'exit':
102-
plt.close()
10394

10495
def on_pointer_click(self, xyz, ep_idx):
10596
# If we click whilst moving a point, drop it.
@@ -236,3 +227,18 @@ def _in_axes_range(self, p):
236227
y_in = self.ax.get_ylim()[0] <= p[1] <= self.ax.get_ylim()[1]
237228
z_in = self.ax.get_zlim()[0] <= p[2] <= self.ax.get_zlim()[1]
238229
return (x_in and y_in and z_in)
230+
231+
232+
233+
# Keep old name as an alias with deprecation warning
234+
class define_points(xyz_canvas):
235+
def __init__(self, *args, on_complete_cb=None, **kwargs):
236+
warnings.warn(
237+
"define_points is deprecated and will be removed in a future version. "
238+
"Please use NewClassName instead.",
239+
DeprecationWarning,
240+
stacklevel=2
241+
)
242+
if on_complete_cb is not None:
243+
warnings.warn("on_complete_cb is no longer used and will be ignored.", DeprecationWarning)
244+
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)