summaryrefslogtreecommitdiff
path: root/doc/source/sample_code/index.rst
blob: 15bd4c70d498dda27c323ad1d0bf2095645a3fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
.. _sample-code:

Sample Code
===========

All sample codes can be downloaded as a zip file: |sample_code_archive|.

.. |sample_code_archive| archive:: ../../../examples/
   :filename: silx_examples.zip
   :basedir: silx_examples
   :filter: *.py *.png

:mod:`silx.gui` sample code
+++++++++++++++++++++++++++

:mod:`silx.gui.icons`
.....................

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`icons.py <../../../examples/icons.py>`
     - .. image:: img/icons.png
         :width: 150px
     - Display icons and animated icons provided by silx.

:mod:`silx.gui.data` and :mod:`silx.gui.hdf5`
.............................................

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`customHdf5TreeModel.py <../../../examples/customHdf5TreeModel.py>`
     - .. image:: img/customHdf5TreeModel.png
         :width: 150px
     - Qt Hdf5 widget examples
   * - :download:`customDataView.py <../../../examples/customDataView.py>`
     - .. image:: img/customDataView.png
         :width: 150px
     - Qt data view example
   * - :download:`hdf5widget.py <../../../examples/hdf5widget.py>`
     - .. image:: img/hdf5widget.png
         :width: 150px
     - Qt Hdf5 widget examples

:mod:`silx.gui.dialog`
......................

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`fileDialog.py <../../../examples/fileDialog.py>`
     - .. image:: img/fileDialog.png
         :width: 150px
     - Example for the use of the ImageFileDialog.
   * - :download:`colormapDialog.py <../../../examples/colormapDialog.py>`
     - .. image:: img/colormapDialog.png
         :width: 150px
     - This script shows the features of a :mod:`~silx.gui.dialog.ColormapDialog`.

:mod:`silx.gui.widgets`
.......................

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`periodicTable.py <../../../examples/periodicTable.py>`
     - .. image:: img/periodicTable.png
         :width: 150px
         :align: center
     - This script is a simple example of how to use the periodic table widgets,
       select elements and connect signals.
   * - :download:`simplewidget.py <../../../examples/simplewidget.py>`
     - .. image:: img/simplewidget.png
         :width: 150px
     - This script shows a gallery of simple widgets provided by silx.

       It shows the following widgets:

       - :class:`~silx.gui.widgets.WaitingPushButton`:
         A button with a progress-like waiting animated icon.

:mod:`silx.gui.plot` sample code
++++++++++++++++++++++++++++++++

Widgets
.......

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`imageview.py <../../../examples/imageview.py>`
     - .. image:: img/imageview.png
         :width: 150px
     - Example to show the use of :mod:`~silx.gui.plot.ImageView` widget.

       It can be used to open an EDF or TIFF file from the shell command line.

       To view an image file with the current installed silx library:
       ``python examples/imageview.py <file to open>``
       To get help:
       ``python examples/imageview.py -h``
   * - :download:`stackView.py <../../../examples/stackView.py>`
     - .. image:: img/stackView.png
         :width: 150px
     - This script is a simple example to illustrate how to use the
       :mod:`~silx.gui.plot.StackView` widget.
   * - :download:`scatterview.py <../../../examples/scatterview.py>`
     - .. image:: img/scatterview.png
         :width: 150px
     - Example to show the use of :class:`~silx.gui.plot.ScatterView.ScatterView` widget
   * - :download:`compareImages.py <../../../examples/compareImages.py>`
     - .. image:: img/compareImages.png
          :width: 150px
     - usage: compareImages.py [-h] [--debug] [--testdata] [--use-opengl-plot]
                               [files [files ...]]

       Example demonstrating the use of the widget CompareImages

       positional arguments:
         files              Image data to compare (HDF5 file with path, EDF files,
                            JPEG/PNG image files). Data from HDF5 files can be
                            accessed using dataset path and slicing as an URL:
                            silx:../my_file.h5?path=/entry/data&slice=10 EDF file
                            frames also can can be accessed using URL:
                            fabio:../my_file.edf?slice=10 Using URL in command like
                            usually have to be quoted: "URL".

       optional arguments:
         -h, --help         show this help message and exit
         --debug            Set logging system in debug mode
         --testdata         Use synthetic images to test the application
         --use-opengl-plot  Use OpenGL for plots (instead of matplotlib)
   * - :download:`imageStack.py <../../../examples/imageStack.py>`
     - .. image:: img/imageStack.png
         :width: 150px
     - Simple example for using the ImageStack.

       In this example we want to display images from different source: .h5, .edf
       and .npy files.

       To do so we simple reimplement the thread managing the loading of data.


:class:`silx.gui.plot.actions.PlotAction`
.........................................

Sample code that adds buttons to the toolbar of a silx plot widget.

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`plotClearAction.py <../../../examples/plotClearAction.py>`
     - .. image:: img/plotClearAction.png
         :width: 150px
     - This script shows how to create a minimalistic
       :class:`~silx.gui.plot.actions.PlotAction` that clear the plot.

       This illustrates how to add more buttons in a plot widget toolbar.
   * - :download:`shiftPlotAction.py <../../../examples/shiftPlotAction.py>`
     - .. image:: img/shiftPlotAction.png
         :width: 150px
     - This script is a simple (trivial) example of how to create a :class:`~silx.gui.plot.PlotWindow`,
       create a custom :class:`~silx.gui.plot.actions.PlotAction` and add it to the toolbar.

       The action simply shifts the selected curve up by 1 unit by adding 1 to each
       value of y.
   * - :download:`fftPlotAction.py <../../../examples/fftPlotAction.py>`,
       :download:`fft.png <../../../examples/fft.png>`
     - .. image:: img/fftPlotAction.png
         :width: 150px
     - This script is a simple example of how to create a :class:`~silx.gui.plot.PlotWindow`
       with a custom :class:`~silx.gui.plot.actions.PlotAction` added to the toolbar.

       The action computes the FFT of all curves and plots their amplitude spectrum.
       It also performs the reverse transform.

       This example illustrates:
          - how to create a checkable action
          - how to store user info with a curve in a PlotWindow
          - how to modify the graph title and axes labels
          - how to add your own icon as a PNG file

       See shiftPlotAction.py for a simpler example with more basic comments.

Add features to :class:`~silx.gui.plot.PlotWidget`
..................................................

Sample code that adds specific tools or functions to :class:`~silx.gui.plot.PlotWidget`.

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`plotWidget.py <../../../examples/plotWidget.py>`
     - .. image:: img/plotWidget.png
         :width: 150px
     - This script shows how to create a custom window around a PlotWidget.

       It subclasses :class:`QMainWindow`, uses a :class:`~silx.gui.plot.PlotWidget`
       as its central widget and adds toolbars and a colorbar by using pluggable widgets:

       - :class:`~silx.gui.plot.PlotWidget` from :mod:`silx.gui.plot`
       - QToolBar from :mod:`silx.gui.plot.tools`
       - QAction from :mod:`silx.gui.plot.actions`
       - QToolButton from :mod:`silx.gui.plot.PlotToolButtons`
       - :class:`silx.gui.plot.ColorBar.ColorBarWidget`
   * - :download:`plotItemsSelector.py <../../../examples/plotItemsSelector.py>`
     - .. image:: img/plotItemsSelector.png
         :width: 150px
     - This example illustrates how to use a :class:`ItemsSelectionDialog` widget
       associated with a :class:`~silx.gui.plot.PlotWidget`
   * - :download:`plotInteractiveImageROI.py <../../../examples/plotInteractiveImageROI.py>`
     - .. image:: img/plotInteractiveImageROI.png
         :width: 150px
     - This script illustrates image ROI selection in a :class:`~silx.gui.plot.PlotWidget`

       It uses :class:`~silx.gui.plot.tools.roi.RegionOfInterestManager` and
       :class:`~silx.gui.plot.tools.roi.RegionOfInterestTableWidget` to handle the
       interactive selection and to display the list of selected ROIs.
   * - :download:`printPreview.py <../../../examples/printPreview.py>`
     - .. image:: img/printPreview.png
         :width: 150px
     - This script illustrates how to add a print preview tool button to any plot
       widget inheriting :class:`~silx.gui.plot.PlotWidget`.

       Three plot widgets are instantiated. One of them uses a standalone
       :class:`~silx.gui.plot.PrintPreviewToolButton.PrintPreviewToolButton`,
       while the other two use a
       :class:`~silx.gui.plot.PrintPreviewToolButton.SingletonPrintPreviewToolButton`
       which allows them to send their content to the same print preview page.
   * - :download:`scatterMask.py <../../../examples/scatterMask.py>`
     - .. image:: img/scatterMask.png
         :width: 150px
     - This example demonstrates how to use ScatterMaskToolsWidget
       and NamedScatterAlphaSlider with a PlotWidget.
   * - :download:`plotCurveLegendWidget.py <../../../examples/plotCurveLegendWidget.py>`
     - .. image:: img/plotCurveLegendWidget.png
         :width: 150px
     - This example illustrates the use of :class:`CurveLegendsWidget`.

       :class:`CurveLegendsWidget` display curves style and legend currently visible
       in a :class:`~silx.gui.plot.PlotWidget`
   * - :download:`plotStats.py <../../../examples/plotStats.py>`
     - .. image:: img/plotStats.png
         :width: 150px
     - This script is a simple example of how to add your own statistic to a
       :class:`~silx.gui.plot.statsWidget.StatsWidget` from customs
       :class:`~silx.gui.plot.stats.Stats` and display it.

       On this example we will:

          - show sum of values for each type
          - compute curve integrals (only for 'curve').
          - compute center of mass for all possible items

       .. note:: for now the possible types manged by the Stats are ('curve', 'image',
                 'scatter' and 'histogram')
   * - :download:`plotProfile.py <../../../examples/plotProfile.py>`
     - .. image:: img/plotProfile.png
         :width: 150px
     - Example illustrating the different profile tools.


:class:`~silx.gui.plot.PlotWidget` features
...........................................

Sample code that illustrates some functionalities of :class:`~silx.gui.plot.PlotWidget`.

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`plotContextMenu.py <../../../examples/plotContextMenu.py>`
     - .. image:: img/plotContextMenu.png
         :width: 150px
     - This script illustrates the addition of a context menu to a
       :class:`~silx.gui.plot.PlotWidget`.

       This is done by adding a custom context menu to the plot area of PlotWidget:
       - set the context menu policy of the plot area to Qt.CustomContextMenu.
       - connect to the plot area customContextMenuRequested signal.

       The same method works with :class:`~silx.gui.plot.PlotWindow.PlotWindow`,
       :class:`~silx.gui.plot.PlotWindow.Plot1D` and
       :class:`~silx.gui.plot.PlotWindow.Plot2D` widgets as they
       inherit from :class:`~silx.gui.plot.PlotWidget`.

       For more information on context menus, see Qt documentation.
   * - :download:`plotLimits.py <../../../examples/plotLimits.py>`
     - .. image:: img/plotLimits.png
         :width: 150px
     - This script is an example to illustrate how to use axis synchronization
       tool.
   * - :download:`plotUpdateCurveFromThread.py <../../../examples/plotUpdateCurveFromThread.py>`
     - .. image:: img/plotUpdateCurveFromThread.png
         :width: 150px
     - This script illustrates the update of a :mod:`silx.gui.plot` widget from a thread.

       The problem is that plot and GUI methods should be called from the main thread.
       To safely update the plot from another thread, one need to execute the update
       asynchronously in the main thread.
       In this example, this is achieved with
       :func:`~silx.gui.utils.concurrent.submitToQtMainThread`.

       In this example a thread calls submitToQtMainThread to update the curve
       of a plot.
   * - :download:`plotUpdateImageFromThread.py <../../../examples/plotUpdateImageFromThread.py>`
     - .. image:: img/plotUpdateImageFromThread.png
         :width: 150px
     - This script illustrates the update of a :mod:`silx.gui.plot` widget from a thread.

       The problem is that plot and GUI methods should be called from the main thread.
       To safely update the plot from another thread, one need to execute the update
       asynchronously in the main thread.
       In this example, this is achieved with
       :func:`~silx.gui.utils.concurrent.submitToQtMainThread`.

       In this example a thread calls submitToQtMainThread to update the curve
       of a plot.
   * - :download:`syncaxis.py <../../../examples/syncaxis.py>`
     - .. image:: img/syncaxis.png
         :width: 150px
     - This script is an example to illustrate how to use axis synchronization
       tool.
   * - :download:`compositeline.py <../../../examples/compositeline.py>`
     - .. image:: img/compositeline.png
         :width: 150px
     - Example to show the use of markers to draw head and tail of lines.
   * - :download:`dropZones.py <../../../examples/dropZones.py>`
     - .. image:: img/dropZones.png
         :width: 150px
     - Example of drop zone supporting application/x-silx-uri.

       This example illustrates the support of drag&drop of silx URLs.
       It provides 2 URLs (corresponding to 2 datasets) that can be dragged to
       either a :class:`PlotWidget` or a QLable displaying the URL information.
   * - :download:`exampleBaseline.py <../../../examples/exampleBaseline.py>`
     - .. image:: img/exampleBaseline.png
         :width: 150px
     - This example illustrates some usage possible with the baseline parameter
   * - :download:`syncPlotLocation.py <../../../examples/syncPlotLocation.py>`
     - .. image:: img/syncPlotLocation.png
         :width: 150px
     - This script is an example to illustrate how to use axis synchronization
       tool.


.. _plot3d-sample-code:

:mod:`silx.gui.plot3d` sample code
++++++++++++++++++++++++++++++++++

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`plot3dSceneWindow.py <../../../examples/plot3dSceneWindow.py>`
     - .. image:: img/plot3dSceneWindow.png
         :width: 150px
     - This script displays the different items of :class:`~silx.gui.plot3d.SceneWindow`.

       It shows the different visualizations of :class:`~silx.gui.plot3d.SceneWindow`
       and :class:`~silx.gui.plot3d.SceneWidget`.
       It illustrates the API to set those items.

       It features:

       - 2D images: data and RGBA images
       - 2D scatter data, displayed either as markers, wireframe or surface.
       - 3D scatter plot
       - 3D scalar field with iso-surface and cutting plane.
       - A clipping plane.
   * - :download:`plot3dUpdateScatterFromThread.py <../../../examples/plot3dUpdateScatterFromThread.py>`
     - .. image:: img/plot3dUpdateScatterFromThread.png
         :width: 150px
     - This script illustrates the update of a
       :class:`~silx.gui.plot3d.SceneWindow.SceneWindow` widget from a thread.

       The problem is that GUI methods should be called from the main thread.
       To safely update the scene from another thread, one need to execute the update
       asynchronously in the main thread.
       In this example, this is achieved with
       :func:`~silx.gui.utils.concurrent.submitToQtMainThread`.

       In this example a thread calls submitToQtMainThread to append data to a 3D scatter.
   * - :download:`plot3dContextMenu.py <../../../examples/plot3dContextMenu.py>`
     - .. image:: img/plot3dContextMenu.png
         :width: 150px
     - This script adds a context menu to a :class:`silx.gui.plot3d.ScalarFieldView`.

       This is done by adding a custom context menu to the :class:`Plot3DWidget`:

       - set the context menu policy to Qt.CustomContextMenu.
       - connect to the customContextMenuRequested signal.

       For more information on context menus, see Qt documentation.
   * - :download:`viewer3DVolume.py <../../../examples/viewer3DVolume.py>`
     - .. image:: img/viewer3DVolume.png
         :width: 150px
     - This script illustrates the use of :class:`silx.gui.plot3d.ScalarFieldView`.

       It loads a 3D scalar data set from a file and displays iso-surfaces and
       an interactive cutting plane.
       It can also be started without providing a file.


:mod:`silx.io` sample code
++++++++++++++++++++++++++

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`writetoh5.py <../../../examples/writetoh5.py>`
     -
     - This script is an example of how to use the :mod:`silx.io.convert` module.
       See the following tutorial for more information: :doc:`../Tutorials/convert`


:mod:`silx.image` sample code
+++++++++++++++++++++++++++++

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`findContours.py <../../../examples/findContours.py>`
     - .. image:: img/findContours.png
         :width: 150px
     - Find contours examples

       .. note:: This module has an optional dependency with sci-kit image library.
          You might need to install it if you don't already have it.

:mod:`silx.app` sample code
+++++++++++++++++++++++++++

.. list-table::
   :widths: 1 1 4
   :header-rows: 1

   * - Source
     - Screenshot
     - Description
   * - :download:`customSilxView.py <../../../examples/customSilxView.py>`
     - .. image:: img/customSilxView.png
         :width: 150px
     - Sample code illustrating how to custom silx view into another application.