2222from plotpy .widgets .colormap .widget import ColorMapWidget , CustomQwtLinearColormap
2323
2424
25+ class ColorPickDataSet (DataSet ):
26+ """Dataset with the field used to edit a color stop."""
27+
28+ _position_locked = False
29+
30+ position = (
31+ FloatItem (
32+ _ ("Relative position" ),
33+ min = 0.0 ,
34+ max = 1.0 ,
35+ help = _ ("Must be a value between 0.0 and 1.0." ),
36+ )
37+ .set_prop ("display" , format = "%.2f" )
38+ .set_prop ("display" , active = NotProp (GetAttrProp ("_position_locked" )))
39+ )
40+ hex_color = ColorItem (
41+ "Pick color" , help = "Pick a color to use for the selected cursor."
42+ )
43+
44+ def lock_position (self , lock = True ) -> None :
45+ """Used to lock the position of the cursor value.
46+
47+ Args:
48+ lock: True if value must be locked. Defaults to True.
49+ """
50+ self ._position_locked = lock
51+
52+ def is_position_locked (self ):
53+ """Returns True if the position is locked.
54+
55+ Returns:
56+ True if position is locked, False otherwise.
57+ """
58+ return self ._position_locked
59+
60+ def set_position (self , position : float ) -> None :
61+ """Set a new position for the cursor. Value is rounded to 2 decimals.
62+
63+ Args:
64+ position: new position to set
65+ """
66+ self .position = round (position , 2 )
67+
68+ def get_position (self ) -> float :
69+ """Return the current position of the cursor.
70+
71+ Returns:
72+ float value of the cursor position
73+ """
74+ return self .position # type: ignore
75+
76+ def set_color (self , hex_color : str ):
77+ """Set a new hex color for the cursor.
78+
79+ Args:
80+ hex_color: str hex color to set (e.g. "#FF0000" for red)
81+ """
82+ self .hex_color = hex_color
83+
84+ def get_hex_color (self ) -> str :
85+ """Return the current str hex color of the cursor.
86+
87+ Returns:
88+ str hex color of the cursor (e.g. "#FF0000" for red)
89+ """
90+ return self .hex_color # type: ignore
91+
92+
2593class ColorMapEditor (QW .QWidget ):
2694 """Widget that allows a user to edit a colormap by changing its color stops (
2795 add/delete/move/change color). Right click on the colorbar or slider to add or
@@ -41,73 +109,6 @@ class ColorMapEditor(QW.QWidget):
41109 Defaults to None.
42110 """
43111
44- class ColorPickDataSet (DataSet ):
45- """Dataset with the field used to edit a color stop."""
46-
47- _position_locked = False
48-
49- position = (
50- FloatItem (
51- _ ("Relative position" ),
52- min = 0.0 ,
53- max = 1.0 ,
54- help = _ ("Must be a value between 0.0 and 1.0." ),
55- )
56- .set_prop ("display" , format = "%.2f" )
57- .set_prop ("display" , active = NotProp (GetAttrProp ("_position_locked" )))
58- )
59- hex_color = ColorItem (
60- "Pick color" , help = "Pick a color to use for the selected cursor."
61- )
62-
63- def lock_position (self , lock = True ) -> None :
64- """Used to lock the position of the cursor value.
65-
66- Args:
67- lock: True if value must be locked. Defaults to True.
68- """
69- self ._position_locked = lock
70-
71- def is_position_locked (self ):
72- """Returns True if the position is locked.
73-
74- Returns:
75- True if position is locked, False otherwise.
76- """
77- return self ._position_locked
78-
79- def set_position (self , position : float ) -> None :
80- """Set a new position for the cursor. Value is rounded to 2 decimals.
81-
82- Args:
83- position: new position to set
84- """
85- self .position = round (position , 2 )
86-
87- def get_position (self ) -> float :
88- """Return the current position of the cursor.
89-
90- Returns:
91- float value of the cursor position
92- """
93- return self .position # type: ignore
94-
95- def set_color (self , hex_color : str ):
96- """Set a new hex color for the cursor.
97-
98- Args:
99- hex_color: str hex color to set (e.g. "#FF0000" for red)
100- """
101- self .hex_color = hex_color
102-
103- def get_hex_color (self ) -> str :
104- """Return the current str hex color of the cursor.
105-
106- Returns:
107- str hex color of the cursor (e.g. "#FF0000" for red)
108- """
109- return self .hex_color # type: ignore
110-
111112 def __init__ (
112113 self ,
113114 parent : QW .QWidget | None ,
@@ -127,7 +128,7 @@ def __init__(
127128
128129 self .tabs = QW .QTabWidget ()
129130
130- self .datasets : list [DataSetEditGroupBox [ColorMapEditor . ColorPickDataSet ]] = []
131+ self .datasets : list [DataSetEditGroupBox [ColorPickDataSet ]] = []
131132
132133 self .setup_tabs ()
133134 self .tabs .setCurrentIndex (0 )
@@ -209,13 +210,8 @@ def new_tab(self, index: int, handle_pos: float) -> None:
209210 handle_pos: relative value to set in the tab (new handle current position)
210211 """
211212 title = ""
212- # title.setPixmap(pixmap)
213213
214- dw = DataSetEditGroupBox (
215- QW .QLabel (title , self ),
216- self .ColorPickDataSet ,
217- # comment=_("Edit color point."),
218- )
214+ dw = DataSetEditGroupBox (QW .QLabel (title , self ), ColorPickDataSet )
219215 dw .dataset .set_position (handle_pos )
220216
221217 hex_color = self .colormap_widget .get_hex_color (index )
@@ -295,3 +291,4 @@ def update_current_dataset(self):
295291 relative_pos = self .colormap_widget .get_handles_tuple ()[current_index ]
296292 current_dataset_grp .dataset .set_position (relative_pos )
297293 current_dataset_grp .get ()
294+ current_dataset_grp .get ()
0 commit comments