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
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Plugin Loader

Postby NormandC » Sun Apr 26, 2015 10:20 pm

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
Site Admin
Posts: 12034
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Plugin Loader

Postby yorik » Mon Apr 27, 2015 3:45 am

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
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Plugin Loader

Postby NormandC » Mon Apr 27, 2015 3:46 am

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

Re: Plugin Loader

Postby microelly2 » Mon Apr 27, 2015 6:56 pm

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
Site Admin
Posts: 12034
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Plugin Loader

Postby yorik » Mon Apr 27, 2015 7:21 pm

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
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Postby microelly2 » Mon Apr 27, 2015 8:44 pm

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
Site Admin
Posts: 12034
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Plugin Loader

Postby yorik » Mon Apr 27, 2015 9:06 pm

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

Re: Plugin Loader

Postby microelly2 » Wed Apr 29, 2015 2:35 pm

]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 1700 times
User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Plugin Loader

Postby microelly2 » Wed May 06, 2015 3:02 pm

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 1670 times
User avatar
yorik
Site Admin
Posts: 12034
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Plugin Loader

Postby yorik » Wed May 06, 2015 3:38 pm

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