Skip to content

Commit

Permalink
Merge pull request #1 from swvanbuuren/pqthreads-support
Browse files Browse the repository at this point in the history
Pqthreads support
  • Loading branch information
swvanbuuren authored Jun 30, 2024
2 parents 14b4970 + 0822832 commit b1a6828
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 679 deletions.
3 changes: 2 additions & 1 deletion examples/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mlpyqtgraph as mpg


@mpg.plotter
def main():
""" Advanced mlpyqtgraph example """
plot_args = {'width': 2}
Expand All @@ -22,4 +23,4 @@ def main():
mpg.gca().grid = True

if __name__ == '__main__':
mpg.GUIController(worker=main)
main()
3 changes: 2 additions & 1 deletion examples/minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import mlpyqtgraph as mpg


@mpg.plotter
def main():
""" Minimal mlpyqtgraph example """
mpg.plot(range(5), (1, 3, 2, 0, 5))


if __name__ == '__main__':
mpg.GUIController(worker=main)
main()
27 changes: 0 additions & 27 deletions examples/subplot.py

This file was deleted.

3 changes: 2 additions & 1 deletion examples/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mlpyqtgraph as mpg


@mpg.plottero(antialiasing=True)
def main():
""" Examples with surface plots """
extent = 10
Expand All @@ -29,4 +30,4 @@ def main():


if __name__ == '__main__':
mpg.GUIController(worker=main, antialiasing=True)
main()
49 changes: 47 additions & 2 deletions mlpyqtgraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,53 @@
used as interface
"""

from mlpyqtgraph import windows
from mlpyqtgraph import axes
from mlpyqtgraph import workers
from mlpyqtgraph import config_options as config


from . import ml_functions
from .ml_functions import *

from . import controllers
from .controllers import GUIController

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
36 changes: 23 additions & 13 deletions mlpyqtgraph/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@


import math
import pyqtgraph.Qt.QtCore as QtCore
from pyqtgraph.Qt import QtCore
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import pyqtgraph.functions as fn
import OpenGL.GL as ogl
import numpy as np

import mlpyqtgraph.config_options as config
import mlpyqtgraph.colors as colors
from mlpyqtgraph import colors


class RootException(Exception):
Expand All @@ -23,18 +23,9 @@ class InvalidAxis(RootException):
""" Exception raised for invalid axes """


def factory(*args, **kwargs):
""" Factory for creating 2D or 3D Axis objects """
axis_type = kwargs.pop('axis_type')
if axis_type == '2D':
return Axis2D(*args, **kwargs)
if axis_type == '3D':
return Axis3D(*args, **kwargs)
raise InvalidAxis(f'Invalid Axis Type: {axis_type}. Should be either 2D or 3D')


class Axis2D(pg.PlotItem):
""" Axis for plots in a given figure layout """
axis_type = '2D'
pen_styles = {'-': QtCore.Qt.SolidLine,
'--': QtCore.Qt.DashLine,
':': QtCore.Qt.DotLine,
Expand All @@ -43,7 +34,8 @@ class Axis2D(pg.PlotItem):
line_colors = colors_defs.get_line_colors()
scale_box_line_color = colors_defs.get_scale_box_colors(part='line')
scale_box_fill_color = colors_defs.get_scale_box_colors(part='fill')
def __init__(self, index, parent=None, **kwargs):
def __init__(self, index, **kwargs):
parent = kwargs.pop('parent', None)
super().__init__(parent=parent, **kwargs)
self.index = index
self.setup()
Expand Down Expand Up @@ -276,9 +268,13 @@ def get_ticks(self, axis):
ticks.extend(values)
return sorted(ticks)

def delete(self):
""" Closes the axis """


class Axis3D(gl.GLViewWidget):
""" 3D axis """
axis_type = '3D'

glOption = {
ogl.GL_DEPTH_TEST: True,
Expand Down Expand Up @@ -390,3 +386,17 @@ def add_single_grid_line(self, x, y, z):
""" Plots a single grid line for given coordinates """
points = np.column_stack((x, y, z))
self.addItem(gl.GLLinePlotItem(pos=points, **self.default_line_options))

def delete(self):
""" Closes the axis """


class Axis:
""" General Axis class, creates either 2D or 3D axis """
def __new__(cls, *args, **kwargs):
axis_type = kwargs.pop('axis_type', '2D')
if axis_type == '2D':
return Axis2D(*args, **kwargs)
if axis_type == '3D':
return Axis3D(*args, **kwargs)
raise InvalidAxis(f'Invalid Axis Type: {axis_type}. Should be either 2D or 3D')
176 changes: 0 additions & 176 deletions mlpyqtgraph/controllers.py

This file was deleted.

Loading

0 comments on commit b1a6828

Please sign in to comment.