mnesarco / MarzWorkbench

FreeCAD Workbench for guitar design
GNU General Public License v3.0
82 stars 19 forks source link

Allow list to contain other items. #24

Closed xxxajk closed 1 year ago

xxxajk commented 1 year ago

Useful for appending/modifying an existing list.

xxxajk commented 1 year ago

An example from our past discussion as per use.

def areInside(points, face, checkface, boollist=[]):
        q=list(more_itertools.zip_offset(boollist, points,offsets=(0, 0), longest=True, fillvalue=True))
        tasks = [Task.execute(isInside, p, face, checkface) if x else p for x, p in q]
        return Task.joinAll(tasks)

This allows me to send a bool list, which decides if I want to execute (if True in the list) or keep the current value.

Other tricks are also possible. I'm sure you could find a few things that this would help your project with.

mnesarco commented 1 year ago

You are not passing a list of tasks but a list on arbitrary objects. It will make the API a mess. Why not just having a one-line function in your code:

def resolve_pending_tasks(data):
  return [j.get() if isinstance(j, Task) else j for j in data]
xxxajk commented 1 year ago

Yeah, just fixed the logic... jumped the gun a bit. Still it's useful!

mnesarco commented 1 year ago

@xxxajk Thank you for your contribution. But as this does not solve or improve anything related with this project, I am closing this issue. The threading module is an internal implementation detail, it is not by anyway a public API designed to be used as a general purpose library. Anyway you can use it as whatever you want if it is useful, but it is out of the scope of this specific project. Maybe I will move that to FreeCAD_Utils, in that case it would be different because that is a general purpose library. Or even better, I thing this threading module will be a good addition to fcscript that is much much more general purpose library.

BTW, as you are working with freecad macros, you can take a look a it:

xxxajk commented 1 year ago

Just thought I'd share something that would be useful, no big deal :-)