Skip to content

Commit

Permalink
fix: Align with latest pqthreads version
Browse files Browse the repository at this point in the history
Signed-off-by: Sietze van Buuren <[email protected]>
  • Loading branch information
swvanbuuren committed Aug 17, 2024
1 parent d52221e commit da98f7e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import mlpyqtgraph as mpg


@mpg.plottero(antialiasing=True)
@mpg.plotter(antialiasing=True)
def main():
""" Examples with surface plots """
extent = 10
Expand Down
54 changes: 14 additions & 40 deletions mlpyqtgraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
used as interface
"""

from pqthreads import decorator
from mlpyqtgraph import windows
from mlpyqtgraph import axes
from mlpyqtgraph import workers
Expand All @@ -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)
4 changes: 2 additions & 2 deletions mlpyqtgraph/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mlpyqtgraph/ml_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -17,15 +17,15 @@ 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


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
Expand Down
4 changes: 2 additions & 2 deletions mlpyqtgraph/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mlpyqtgraph/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da98f7e

Please sign in to comment.