1
- from viscm .gui import *
2
- from viscm .bezierbuilder import *
3
1
import numpy as np
4
- import matplotlib as mpl
5
- from matplotlib .backends .qt_compat import QtGui , QtCore
6
- from matplotlib .backends .backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
7
2
8
- cms = {"viscm/examples/sample_linear.jscm" ,
9
- "viscm/examples/sample_diverging.jscm" ,
10
- "viscm/examples/sample_diverging_continuous.jscm" }
3
+ from viscm .bezierbuilder import json
4
+ from viscm .gui import Colormap , viscm_editor
5
+
6
+ cms = {
7
+ "viscm/examples/sample_linear.jscm" ,
8
+ "viscm/examples/sample_diverging.jscm" ,
9
+ "viscm/examples/sample_diverging_continuous.jscm" ,
10
+ }
11
11
12
12
13
13
def test_editor_loads_native ():
@@ -16,8 +16,13 @@ def test_editor_loads_native():
16
16
data = json .loads (f .read ())
17
17
cm = Colormap (None , "CatmulClark" , "CAM02-UCS" )
18
18
cm .load (k )
19
- viscm = viscm_editor (uniform_space = cm .uniform_space , cmtype = cm .cmtype , method = cm .method , ** cm .params )
20
- assert viscm .name == data ["name" ]
19
+ viscm = viscm_editor (
20
+ uniform_space = cm .uniform_space ,
21
+ cmtype = cm .cmtype ,
22
+ method = cm .method ,
23
+ ** cm .params ,
24
+ )
25
+ assert viscm .name == data ["name" ]
21
26
22
27
extensions = data ["extensions" ]["https://matplotlib.org/viscm" ]
23
28
xp , yp , fixed = viscm .control_point_model .get_control_points ()
@@ -26,7 +31,7 @@ def test_editor_loads_native():
26
31
assert len (extensions ["xp" ]) == len (xp )
27
32
assert len (extensions ["yp" ]) == len (yp )
28
33
assert len (xp ) == len (yp )
29
- for i in range (len (xp )):
34
+ for i in range (len (xp )):
30
35
assert extensions ["xp" ][i ] == xp [i ]
31
36
assert extensions ["yp" ][i ] == yp [i ]
32
37
assert extensions ["min_Jp" ] == viscm .min_Jp
@@ -35,19 +40,34 @@ def test_editor_loads_native():
35
40
assert extensions ["cmtype" ] == viscm .cmtype
36
41
37
42
colors = data ["colors" ]
38
- colors = [[int (c [i :i + 2 ], 16 ) / 256 for i in range (0 , 6 , 2 )] for c in [colors [i :i + 6 ] for i in range (0 , len (colors ), 6 )]]
43
+ colors = [
44
+ [int (c [i : i + 2 ], 16 ) / 256 for i in range (0 , 6 , 2 )]
45
+ for c in [colors [i : i + 6 ] for i in range (0 , len (colors ), 6 )]
46
+ ]
39
47
editor_colors = viscm .cmap_model .get_sRGB (num = 256 )[0 ].tolist ()
40
48
for i in range (len (colors )):
41
49
for z in range (3 ):
42
50
assert colors [i ][z ] == np .rint (editor_colors [i ][z ] / 256 )
43
51
52
+
53
+ # import matplotlib as mpl
54
+ # from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
55
+ # from matplotlib.backends.qt_compat import QtCore, QtGui
56
+ #
44
57
# def test_editor_add_point():
45
58
# # Testing linear
46
-
59
+ #
47
60
# fig = plt.figure()
48
61
# figure_canvas = FigureCanvas(fig)
49
- # linear = viscm_editor(min_Jp=40, max_Jp=60, xp=[-10, 10], yp=[0,0], figure=fig, cmtype="linear")
50
-
62
+ # linear = viscm_editor(
63
+ # min_Jp=40,
64
+ # max_Jp=60,
65
+ # xp=[-10, 10],
66
+ # yp=[0,0],
67
+ # figure=fig,
68
+ # cmtype="linear",
69
+ # )
70
+ #
51
71
# Jp, ap, bp = linear.cmap_model.get_Jpapbp(3)
52
72
# eJp, eap, ebp = [40, 50, 60], [-10, 0, 10], [0, 0, 0]
53
73
# for i in range(3):
@@ -61,12 +81,24 @@ def test_editor_loads_native():
61
81
# for i in range(3):
62
82
# for z in range(3):
63
83
# assert approxeq(rgb[i][z], ergb[i][z])
64
-
84
+
65
85
66
86
# # Testing adding a point to linear
67
87
# linear.bezier_builder.mode = "add"
68
- # qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
69
- # event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
88
+ # qtEvent = QtGui.QMouseEvent(
89
+ # QtCore.QEvent.MouseButtonPress,
90
+ # QtCore.QPoint(),
91
+ # QtCore.Qt.LeftButton,
92
+ # QtCore.Qt.LeftButton,
93
+ # QtCore.Qt.ShiftModifier,
94
+ # )
95
+ # event = mpl.backend_bases.MouseEvent(
96
+ # "button_press_event",
97
+ # figure_canvas,
98
+ # 0,
99
+ # 10,
100
+ # guiEvent=qtEvent,
101
+ # )
70
102
# event.xdata = 0
71
103
# event.ydata = 10
72
104
# event.inaxes = linear.bezier_builder.ax
@@ -87,8 +119,20 @@ def test_editor_loads_native():
87
119
88
120
# # Removing a point from linear
89
121
# linear.bezier_builder.mode = "remove"
90
- # qtEvent = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, QtCore.QPoint(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.ControlModifier)
91
- # event = mpl.backend_bases.MouseEvent("button_press_event", figure_canvas, 0, 10, guiEvent=qtEvent)
122
+ # qtEvent = QtGui.QMouseEvent(
123
+ # QtCore.QEvent.MouseButtonPress,
124
+ # QtCore.QPoint(),
125
+ # QtCore.Qt.LeftButton,
126
+ # QtCore.Qt.LeftButton,
127
+ # QtCore.Qt.ControlModifier,
128
+ # )
129
+ # event = mpl.backend_bases.MouseEvent(
130
+ # "button_press_event",
131
+ # figure_canvas,
132
+ # 0,
133
+ # 10,
134
+ # guiEvent=qtEvent,
135
+ # )
92
136
# event.xdata = 0
93
137
# event.ydata = 10
94
138
# event.inaxes = linear.bezier_builder.ax
@@ -102,7 +146,5 @@ def test_editor_loads_native():
102
146
# # print(linear.cmap_model.get_Jpapbp(3))
103
147
104
148
105
-
106
149
def approxeq (x , y , err = 0.0001 ):
107
150
return abs (y - x ) < err
108
-
0 commit comments