diff --git a/examples/surface.py b/examples/surface.py index 4e5a9f2..cdd833f 100644 --- a/examples/surface.py +++ b/examples/surface.py @@ -6,7 +6,7 @@ import mlpyqtgraph as mpg -@mpg.plottero(antialiasing=True) +@mpg.plotter(antialiasing=True) def main(): """ Examples with surface plots """ extent = 10 diff --git a/mlpyqtgraph/__init__.py b/mlpyqtgraph/__init__.py index 053c09b..e92d206 100644 --- a/mlpyqtgraph/__init__.py +++ b/mlpyqtgraph/__init__.py @@ -3,6 +3,7 @@ used as interface """ +from pqthreads import decorator from mlpyqtgraph import windows from mlpyqtgraph import axes from mlpyqtgraph import workers @@ -15,43 +16,16 @@ __version__ = '0.1.0' -GUIAgency = controllers.GUIAgency -GUIAgency.add_agent('figure', windows.FigureWindow) -GUIAgency.add_agent('axis', axes.Axis) - - -def plotter(func): - """ Decorator for end user functions, adding figure functionality""" - def func_wrapper(*args, **kwargs): - """ Wrapper """ - gui_agency = GUIAgency(worker=func, *args, **kwargs) - gui_agency.worker_agency.add_container('figure', workers.FigureWorker) - gui_agency.worker_agency.add_container('axis', workers.AxisWorker) - gui_agency.kickoff() - return gui_agency.result - return func_wrapper - - -# Check out -# https://stackoverflow.com/questions/653368/how-to-create-a-decorator-that-can-be-used-either-with-or-without-parameters -# for more on decorators with and without input arguments... - -# The decorator stuff should really move the into the pqthreads package - -# What to do, if a decorators is used, but no plot commands are issued? - -def plottero(**options): - """ Decorator for end user functions, adding figure functionality""" - if len(options) > 0: - config.options.set_options(**options) - def wrap(func): - """ Wrapper """ - def func_wrapper(*args, **kwargs): - """ Wrapper """ - gui_agency = GUIAgency(worker=func, *args, **kwargs) - gui_agency.worker_agency.add_container('figure', workers.FigureWorker) - gui_agency.worker_agency.add_container('axis', workers.AxisWorker) - gui_agency.kickoff() - return gui_agency.result - return func_wrapper - return wrap +class OptionsDecoratorCore(decorator.DecoratorCore): + """ Decorator take also takes keyword arguments and sets them as config + options """ + + def __init__(self, **options): + super().__init__(**options) + if options: + config.options.set_options(**options) + + +OptionsDecoratorCore.add_agent('figure', windows.FigureWindow, workers.FigureWorker) +OptionsDecoratorCore.add_agent('axis',axes.Axis, workers.AxisWorker) +plotter = decorator.Decorator(OptionsDecoratorCore) diff --git a/mlpyqtgraph/axes.py b/mlpyqtgraph/axes.py index 822f540..7ca4ab5 100644 --- a/mlpyqtgraph/axes.py +++ b/mlpyqtgraph/axes.py @@ -350,14 +350,14 @@ def setup(self): def set_colormap(surface, colormap='CET-L10'): """ Assign colormap to surface using surface height """ heights = surface._z - normalized_heights = (heights - heights.min())/heights.ptp() + normalized_heights = (heights - heights.min())/np.ptp(heights) colors = pg.colormap.get(colormap).map(normalized_heights, mode='float') surface._meshdata.setFaceColors(colors) def set_projection_method(self, *coords, method='orthographic'): """ Sets the projection method, either perspective or orthographic """ #object_size = math.sqrt(sum([coord.ptp()**2.0 for coord in coords])) - object_size = (sum([coord.ptp()**3.0 for coord in coords]))**(1.0/3.0) + object_size = (sum([np.ptp(coord)**3.0 for coord in coords]))**(1.0/3.0) field_of_view = 60 if method == 'orthographic': field_of_view = 1 diff --git a/mlpyqtgraph/ml_functions.py b/mlpyqtgraph/ml_functions.py index 8a648fc..37f8f15 100644 --- a/mlpyqtgraph/ml_functions.py +++ b/mlpyqtgraph/ml_functions.py @@ -2,12 +2,12 @@ Matplotlib-like functions for easy figure and plot definitions """ -from pqthreads import controllers +from pqthreads import refs def figure(*args, **kwargs): """ Create, raise or modify FigureWorker objects """ - container = controllers.worker_refs.get('figure') + container = refs.worker.get('figure') if not args: return container.create(**kwargs) figure_worker = args[0] @@ -17,7 +17,7 @@ def figure(*args, **kwargs): def gcf(): """ Returns the current figure """ - container = controllers.worker_refs.get('figure') + container = refs.worker.get('figure') if container.current is None: figure() # make sure we always have a figure return container.current @@ -25,7 +25,7 @@ def gcf(): def gca(): """ Returns the current axis """ - container = controllers.worker_refs.get('axis') + container = refs.worker.get('axis') if container.current is None: figure() # make sure we always have a figure return container.current diff --git a/mlpyqtgraph/windows.py b/mlpyqtgraph/windows.py index 56f8328..7951940 100644 --- a/mlpyqtgraph/windows.py +++ b/mlpyqtgraph/windows.py @@ -7,7 +7,7 @@ from pyqtgraph.Qt import QtWidgets from pyqtgraph.Qt import QtCore import pyqtgraph as pg -from pqthreads import controllers +from pqthreads import refs pg.setConfigOption('background', 'w') @@ -84,7 +84,7 @@ def change_layout(self, layout_type='pg'): def add_axis(self, index): """ Adds an axis to the figure """ - axis = controllers.gui_refs.get('axis').items[index] + axis = refs.gui.get('axis').items[index] self.graphics_layout.addItem(axis) @property diff --git a/mlpyqtgraph/workers.py b/mlpyqtgraph/workers.py index 20a3a5a..9eb33ec 100644 --- a/mlpyqtgraph/workers.py +++ b/mlpyqtgraph/workers.py @@ -2,8 +2,8 @@ This modules defines all worker thread related classes and instances """ -from pqthreads import controllers from pqthreads import containers +from pqthreads import refs class AxisWorker(containers.WorkerItem): @@ -42,7 +42,7 @@ def create_axis(self, *args, **kwargs): """ Adds an axis to the figure worker """ if self.axis: return - axis_container = controllers.worker_refs.get('axis') + axis_container = refs.worker.get('axis') axis = axis_container.create(**kwargs) index = axis.index self.add_axis(index)