| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
|
| 25 |
import logging |
| 26 |
|
| 27 |
import sys |
| 28 |
import time |
| 29 |
|
| 30 |
from .Qt import QtWidgets |
| 31 |
from .windows import PlotterWindow |
| 32 |
from ..thread import StoppableThread |
| 33 |
|
| 34 |
log = logging.getLogger(__name__) |
| 35 |
log.addHandler(logging.NullHandler()) |
| 36 |
|
| 37 |
|
| 38 |
class Plotter(StoppableThread): |
| 39 |
""" Plotter dynamically plots data from a file through the Results object. |
| 40 |
|
| 41 |
.. seealso:: |
| 42 |
|
| 43 |
Tutorial :ref:`tutorial-plotterwindow` |
| 44 |
A tutorial and example on using the Plotter and PlotterWindow. |
| 45 |
""" |
| 46 |
|
| 47 |
def __init__(self, results, refresh_time=0.1, linewidth=1): |
| 48 |
super().__init__() |
| 49 |
self.results = results |
| 50 |
self.refresh_time = refresh_time |
| 51 |
self.linewidth = linewidth |
| 52 |
|
| 53 |
def run(self): |
| 54 |
app = QtWidgets.QApplication(sys.argv) |
| 55 |
window = PlotterWindow(self, refresh_time=self.refresh_time, linewidth=self.linewidth) |
| 56 |
self.setup_plot(window.plot) |
| 57 |
app.aboutToQuit.connect(window.quit) |
| 58 |
window.show() |
| 59 |
app.exec() |
| 60 |
|
| 61 |
def setup_plot(self, plot): |
| 62 |
""" |
| 63 |
This method does nothing by default, but can be overridden by the child |
| 64 |
class in order to set up custom options for the plot window, via its |
| 65 |
PlotItem_. |
| 66 |
|
| 67 |
:param plot: This window's PlotItem_ instance. |
| 68 |
|
| 69 |
.. _PlotItem: https://pyqtgraph.readthedocs.io/en/latest/graphicsItems/plotitem.html |
| 70 |
""" |
| 71 |
pass |
| 72 |
|
| 73 |
def wait_for_close(self, check_time=0.1): |
| 74 |
while not self.should_stop(): |
| 75 |
time.sleep(check_time) |