SplineEditor (hwx.gui)#

class SplineEditor(spline=None, command=None, interpolationMethod='akima', columnLabels=('X', 'Y'), **kwds)#

Bases: Frame

Compsite widget to edit a math.Spline

Contains:

  • A Table on the left to enter the X, Y values

  • A Plot on the left to visualize and drag the values

  • Buttons on the top of the table to add/insert/remove values and read/write csv

Like other widgets you can specify a command parameter that is a method that gets called when the spline changes.

Attribute Table#

Name

Type

interpolationMethod

property

interpolationNpts

property

spline

property

Method Table#

Name

Description

clearSelection (self)

Unselects all table rows and plot points.

createContents (self)

Creates the contents for the SplineEditor.

decorateContents (self)

Called when cells from the table are selected so we can disable the

deleteSelected (self)

Called if the user hits the <Del> key or clicks the delete button to

enableDragAndDrop (self, *widgets)

Enables dragging and dropping of csv file into the SplineEditor.

getSelectedRows (self)

Returns a list of indices of the selected rows.

layoutContents (self)

Creates the layout for the SplineEditor.

okToDrop (self, fname)

Returns if the file dropped is a csv file.

onDrop (self, fname)

Reads the csv file on drop.

onKeyPress (self, event)

onPlotSelected (self, points)

Called when user selects points in the plot to select the corresponding table rows.

onSplineModified (self, selectRow=None, fitPlot=’selected’)

Called when the the spline changes, that happens when:

onTableSelected (self, rows)

Called when user selects cells in the table to select the corresponding plot points.

readCsv (self, fname=None)

Reads spline data from a csv file.

selectRow (self, row)

Selects the table row and plot point for the specified row.

setSpline (self, spline, clearSelection=True, fitPlot=True)

Sets the specified spline in SplineEditor table and plot.

writeCsv (self, fname=None)

Writes a csv file containing the values.

Example

from hwx.gui import SplineEditor as se
splineEditor = se.SplineEditor()
show(splineEditor)
createContents()#

Creates the contents for the SplineEditor.

layoutContents()#

Creates the layout for the SplineEditor.

decorateContents()#

Called when cells from the table are selected so we can disable the the delete button if needed.

setSpline(spline, clearSelection=True, fitPlot=True)#

Sets the specified spline in SplineEditor table and plot.

Parameters:
  • spline (Spline) – The spline containing x/y values to be set.

  • clearSelection (bool) – Determines whether to remove selection from the SplineEditor.

  • fitPlot (bool) – Determines whether to fit the plot inside SplineEditor plot.

property spline#

The spline object.

property interpolationMethod#

The interpolation method.

property interpolationNpts#

The number of samples to generate.

getSelectedRows()#

Returns a list of indices of the selected rows.

selectRow(row)#

Selects the table row and plot point for the specified row.

Parameters:

row (Union[int, list]) – A single index of the table or list of indices.

clearSelection()#

Unselects all table rows and plot points.

onPlotSelected(points)#

Called when user selects points in the plot to select the corresponding table rows.

Parameters:

points (Union[Point, list[Point]]) – The selected from user points in the plot.

onTableSelected(rows)#

Called when user selects cells in the table to select the corresponding plot points.

Parameters:

rows (Union[int, list[int]]) – The selected row or list of row indices from the table.

onSplineModified(selectRow=None, fitPlot='selected')#

Called when the the spline changes, that happens when:

  • A table cell value was changed.

  • A plot point was modified (mouse up, not drag).

  • One of the buttons was clicked.

Parameters:
  • selectRow (int) – The row index to select the modified spline from the table.

  • fitPlot (str) – The points of the plot to fit.

onKeyPress(event)#

Emits when key is pressed

deleteSelected()#

Called if the user hits the <Del> key or clicks the delete button to delete the selected points.

readCsv(fname=None)#

Reads spline data from a csv file.

Parameters:

fname (str) – The CSV file path.

writeCsv(fname=None)#

Writes a csv file containing the values.

Parameters:

fname (str) – CSV file path.

enableDragAndDrop(*widgets)#

Enables dragging and dropping of csv file into the SplineEditor.

Parameters:

widgets (collection) – The widgets to be enabled drag and drop.

okToDrop(fname)#

Returns if the file dropped is a csv file.

Parameters:

fname (str) – CSV file path.

Returns:

True if the file to dropped is a csv file, otherwise False

Return type:

bool

onDrop(fname)#

Reads the csv file on drop.

Parameters:

fname (str) – CSV file path.