Plugin Loader

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Plugin Loader

Post by NormandC »

It would be really cool if the Macros on the wiki could be dynamically linked with their twin entry in the Github repo... But I doubt it could be done. Keeping them up to date will be a hassle.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Plugin Loader

Post by yorik »

Actually if the macros are hosted on a repo, I don't think one needs to see the whole code directly on the wiki... We could have a link instead...
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Plugin Loader

Post by NormandC »

Of course you're right. Doh! :D
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Post by microelly2 »

Here my idea how to manage Macros. I have checked into the repo this example for test and discussion
https://github.com/FreeCAD/FreeCAD-macr ... fafb23abe5

Every Macro has its own directory (example myMacroDir)
with at least one python File myMacro.py and a __init__.py to control imports
If there is no __init__.py and only one python file in the directory it will be created automaticly, but for special effects the macro texter can write his one initfile.

The master file myMacro.py must have a main() function, which executes the macro.
It can have a test() function to check the success of the install process.

Example

Code: Select all

#
# your copyright info here
#

import FreeCAD

#
# the macro should have a test method to check the success of the installation
#
def test():
	errorMsg="There are some errors: a, b, c"
	warnMsg="There are some warnings: d, e"
	infoMsg="There is a info: f"
	errors=3
	warns=2
	infos=1
	result=[errors,errorMsg,warns,warnMsg,infos,infoMsg]
	return result

#
# the macro should have a main method - the macro itself
#

def main():
	t=FreeCAD.ParamGet('User parameter:BaseApp/Preferences/Macro')
	mp=t.GetString("MacroPath")
	FreeCAD.Console.PrintMessage("\n"*4+"H E L L O   W O R L D,\n I'm myMacro.py located in "+ mp+ "/MyMacroDir" + "\n"*4)
In the Macrofolder there will be a Macro created by the plugin installer:
myMacroDir.FCMacro - this can be used from the Macro Menu

Code: Select all

#----------------------------------------------------
# generated by plugin installer
FreeCAD.Console.PrintMessage("\ntry Macro myMacroDir.MyMacro ...\n")
try:
	import myMacroDir
	reload(myMacroDir.myMacro)
	myMacroDir.myMacro.main()
	FreeCAD.Console.PrintMessage("\nmyMacroDir.MyMacro done\n")
except:
	FreeCAD.Console.PrintError("\nError Macro myMacroDir.MyMacro\n")
#----------------------------------------------------
It would be nice to have a releaselog file in the dir to get information about the development state of the macro.
this news information can be composed with the wiki-page in the pluginviewer for the enduser. Maybe that releaseinfo also can be obtained by the git log but no every body will have write access to the git and can write his log into the commit, so there is more freedom to write a private log.

I think there should not be big problems to convert the existing macros in this manner. But its still a suggestion and i'm hoping for feedback.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Plugin Loader

Post by yorik »

Hm this is cool, but I think it removes one of the main advantages of the macro: it simplicity. If we ask the user to do some heavier modification, we will have much less people ready or able to contribute with macros. And it adds more work to maintainers too, who need to check that things work, adapt existing macros, etc.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Post by microelly2 »

Okay, i unterstand. So we can handle macros two different ways .
One file macros simple stored in the root directory or a category subfolder and complex macros in a subfolder in the descibed way?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Plugin Loader

Post by yorik »

Yes that seems a good solution...
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Post by microelly2 »

]After some trouble with the menusystem I have found a way to bring up the plugininstaller automaticly on startup.
It will be available as dockwindow.

So now its time to classify the plugins

Simple macros start their life as one file.

If they become complex more over time files can be added: a library to store common function, some icons to beautify it.
If a macro has more then one file there should be the macrofilename MyMacro.FCMacro
and the same name for the directory to collect helper files (without the suffix).

python specific access control to the directory can be done by the __init__.py inside.
In this way macros can share libraries.

Macros are accessable through toolbars.

Behaviour of Macros:

1) silent: click and run without extra interaction
2) one starting dialog for configuration: example unfold box, replace part in assembly
3) always or longer time open: Work Feature

There are already addons which life in a dockwindow (but are not macros)

bolts
part library
drawing symbol library

I love the dockwindow because I can freely arrange all my windows and I often undock windows
to the other screen to get more space to the work area without loosing access to teh tools.

My idea is: long living dialogs should live as dockwindows.
Hide and show can be controlled by pluginloader menu.

The can be stored in the FreeCAD params and reactivated automaticly on freecad startup.

Workbenches can organize themselve, they have the ability to create menu, toolbars, contextmenues.
They only have to be installed/updated.

EDIT: picture replaced
Attachments
bn_652.png
bn_652.png (80.81 KiB) Viewed 2807 times
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Post by microelly2 »

This week I will finish macro substitution and platform depended switches in the configuration file:

Code: Select all


  defaulttest:
    status: ignore
    destdir:
      Linux: UserAppData/Mod/testdir
      Windows: c:/haha
    backup: UserHomePath/tmp/bak_
    icon: AppHomePath/Mod/plugins/icons/master.png

Next Step: I will prepare templates for the mostly used plugins. But I do not know them all. Community, please tell me what/whre are interesting !

Which workbenches do exist and are in use?

I found these (and will integrate them step by step)
http://www.freecadweb.org/wiki/index.ph ... d_projects
http://www.freecadweb.org/wiki/index.ph ... os_recipes

Which operating systems I have do support?

import platform
os=platform.system() --> Linux, Windows ???

current state:
Attachments
bn_653.png
bn_653.png (75.75 KiB) Viewed 2777 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Plugin Loader

Post by yorik »

This is becoming very impressive. Great job microelly!
I think you have all the most important ones already...
Post Reply