evil-mad / axidraw

Software for the AxiDraw drawing machine
GNU General Public License v2.0
430 stars 130 forks source link

Callbacks for different stages #164

Open marcrleonard opened 1 year ago

marcrleonard commented 1 year ago

Hello! Been working with the python library and it's been really great to work with! Much better than the wrapper I wrote :-)

As I was working with the library I realized that it may be helpful to register callback functions for different stages of the plotting process. The one that specifically came to mind was for 'layer complete'. This would, for instance, allow you to group colors or thickness in layers and when the layer has completed plotting, you could write some code to execute. This is more powerful (and synchronous) than than the pause mechanism. It could look something like this:

from pyaxidraw import axidraw

def my_callback(*args, **kwargs):
    print("Layer has completed...")
    sleep(5)
    # Do some other helpful things like make a request or alert the user

ad = axidraw.AxiDraw()
ad.plot_setup("file.svg")
ad.callbacks.layer_complete=my_callback,
ad.plot_run()

Let me know what you think! I bet there are a dozen of these that could be helpful to interrupt/resume plots.

oskay commented 1 year ago

Interesting idea. Can you give some examples of ways in which this would be better than plotting in layers mode?