Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
silas
Posts: 17
Joined: Tue Jun 05, 2018 2:42 pm

Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby silas » Wed Jul 04, 2018 7:41 pm

Hello guys. Silas from Wikilab here (more about Wikilab here).

With our small team of beginners, we have sucessfully solved issue 0003499. Tomorrow we are going to make a pull request. Although it is a simple change (only three lines of code!) people got a bit scared with C++, which is not a problem for students that are just starting.

So we are thinking about making a more complex change, but in Python this time. So we have choose issue 0003393: Configuration wizard when launching FreeCAD for the first time. On the issue tracker the reporter sugests a window from LibreCAD, which I found interesting and a good starting point.

So, as a good starting point, our plan is to allow the user to chose the following options:

* Default unit
* GUI Language (fetchs a initial option from the system language)

And, later, we can implement other features the NormandC (a commenter) tells on the tracker.

Any tips about that?

Ah, I'd also like to ask you if you have some tip about a good starting point at the code so we can take a look at. We want to maximize Python and minimize C++. Anyway, we can deal with some C++, if necessary.

Thanks!
chrisb
Posts: 30846
Joined: Tue Mar 17, 2015 9:14 am

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby chrisb » Wed Jul 04, 2018 7:53 pm

Congratulations to your first FreeCAD contribution. Three lines of code is a good amount for a start. Simply double the number of lines on each contribution! You might have heard about the story of the invention of the chess game.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Posts: 9223
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby Kunda1 » Thu Jul 05, 2018 12:16 am

@silas :+1:
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Opus
Posts: 91
Joined: Wed Nov 08, 2017 5:36 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby Opus » Thu Jul 05, 2018 11:05 am

silas wrote:
Wed Jul 04, 2018 7:41 pm
So we are thinking about making a more complex change, but in Python this time. So we have choose issue 0003393: Configuration wizard when launching FreeCAD for the first time. On the issue tracker the reporter sugests a window from LibreCAD, which I found interesting and a good starting point.
Maybe you can look at BIM workbench, developped by Yorik: https://github.com/yorikvanhavre/BIM_Workbench

Video presentation where you could see the setup dialog (between 1'15'' and 3'00''):
phpBB [video]


[EDIT] BIM workbench topic for inspiration too: https://forum.freecadweb.org/viewtopic.php?f=9&t=27237
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby wandererfan » Thu Jul 05, 2018 12:30 pm

silas wrote:
Wed Jul 04, 2018 7:41 pm
Ah, I'd also like to ask you if you have some tip about a good starting point at the code so we can take a look at. We want to maximize Python and minimize C++. Anyway, we can deal with some C++, if necessary.
In Mod/Draft/Draft.py approximately line #117 2 functions will be helpful:
- def getParam(param,default=None): and
- def setParam(param,value):.
User avatar
yorik
Site Admin
Posts: 12148
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby yorik » Thu Jul 05, 2018 10:30 pm

Starting from a dialog similar to the librecad one seems a very good idea indeed.
This is pretty simple to do fully in python. I did one for BIM (that appears in the video), that is basically one ui file designed in qt designer (dialogSetup.ui) , and one python file:

https://github.com/yorikvanhavre/BIM_Wo ... imSetup.py

I think you can do something very similar...

In FreeCAD, Tools -> Edit parameters is very useful to know all the settings and their types.

To launch your screen at FreeCAD startup, when it's the first launch, you can implement a separate workbench, but it's much just to show a dialog, or I would suggest to hook it to the Mod/Tux module, which contains several other utilities that are run at FreeCAD startup.
User avatar
Kunda1
Posts: 9223
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby Kunda1 » Sun Jul 08, 2018 3:26 pm

Maybe the wizard could also ask user what type of mouse navigation methodology users perfer? Maybe a scrollbar just like in the taskbar ?
mouse-navigation.png
mouse-navigation.png (25.85 KiB) Viewed 1054 times
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
silas
Posts: 17
Joined: Tue Jun 05, 2018 2:42 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby silas » Fri Jul 27, 2018 11:26 am

Hello.

Although drawing the wizard UI and writing its related code are not difficult, we are stuck at where (and how to) show the window.

We have two choices:

1. Show it just after the splash screen gets closed (add these lines on lines 1838 of Gui/Application.cpp). Something like:

Code: Select all

if (firstTime) {
	WizardConfigDialog wizardDlg;
	wizardDlg.exec();
}
The exec() function blocks until the user closes the dialog.

2. Write a Python module.

We've made a very small prototype with [1] (C++ only) and it seems to work, but we would really like to implement it in Python, if possible. Looking at the documentation, we figured out a python module can be loaded with:

Code: Select all

Base::Interpreter().loadModule("WizardConfig");
And we create a directory within the Mod directory. We tested it and it works fine for arbitrary Python code (like creating a file) but when we try to create a window in our Python code (by creating a class that subclass QtGui.QDialog) we get the following error:

Code: Select all

QWidget: Must construct a QApplication before a QPaintDevice
zsh: abort (core dumped)  ./bin/FreeCAD
Python script cannot detect we have a QApplication at the Python side (that makes sense, since it would allow the Python interpreter to have full access of the hosting app). I am probably missing something.

We can probably implement that feature in Python in other manners that not a standalone window at the beginning of the application, but a standalone would be the "classic" way :-)

What you recommend? It is not a problem the WizardConfig window have to be done only in C++ at this level. We just would like to know :-)

Thanks!
User avatar
Kunda1
Posts: 9223
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby Kunda1 » Sun Jul 29, 2018 11:52 am

Hey Silas,
I hope some devs are able to address your questions. Thanks again for working on this. Also I'm going to link this thread with:
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
wmayer
Site Admin
Posts: 16874
Joined: Thu Feb 19, 2009 10:32 am

Re: Ideas for implementing 0003393: Configuration wizard when launching FreeCAD for the first time

Postby wmayer » Sun Jul 29, 2018 3:01 pm

And we create a directory within the Mod directory. We tested it and it works fine for arbitrary Python code (like creating a file) but when we try to create a window in our Python code (by creating a class that subclass QtGui.QDialog) we get the following error:
This simply means that you create that dialog too early. Before creating any kind of widget a QApplication must exist.

Could it be that you load it from the Init.py file of your application module? If yes then move it to the initGui.py file. If this is not the case you should explain the way how you invoke your Python module.