Can you debug freecad macros/python workbenches in VSCode? If so, can you give me any hints on how to do it?
Embedding KTextEditor in FreeCAD
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
- adrianinsaval
- Veteran
- Posts: 5551
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Embedding KTextEditor in FreeCAD
I started collecting all I discovered about scripting in hopes to make a sort of handbook.
I have a bunch of collected notes the includes everything I've figured out about configuring vscode in the appendices of this document: https://github.com/macdroid53/FreeCADScripting .
It will allow debugging (single stepping, etc.).
I have a bunch of collected notes the includes everything I've figured out about configuring vscode in the appendices of this document: https://github.com/macdroid53/FreeCADScripting .
It will allow debugging (single stepping, etc.).
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Embedding KTextEditor in FreeCAD
I went on a rabbit hole when I tried to make an external workbench in c++. Apparently it is discouraged to do that and it would be better to try to use python. So then I tried to use Shiboken to generate python bindings from c++. I couldn't find that many tutorials/examples of how to use Shiboken so it was hard to make it work. But from looking at the Shiboken documentation, a KDAB tutorial, and the FreeCAD source code I was able to get something working. So it is possible to embed KTextEditor in FreeCAD without having to make changes to the source code or adding more dependencies. I organized the code as a python package so the c++ code containing KTextEditor can be build and installed as a normal python package:
Then it can be used by FreeCAD by importing the python module and running this script:
And this should show the text editor:
However, it still can't open python/macro files. So I think the next step is in working on this.
Also, does someone have more resources on how to use Shiboken?
Code: Select all
python setup.py install --user
Code: Select all
from PySide import QtGui
from Editor.KEditor import KEditorView
def getMainWindow():
toplevel = QtGui.QApplication.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
mw = getMainWindow()
mdi=mw.findChild(QtGui.QMdiArea)
sub=mdi.addSubWindow(KEditorView())
sub.show()
mw.update()
Also, does someone have more resources on how to use Shiboken?
Re: Embedding KTextEditor in FreeCAD
Lol, just came across this on the wiki Developing_FreeCAD_with_KDevelop I got excited but very anticlimactic
Can't find much of anything on the wiki about italonso_jamm wrote: ↑Sat Jul 17, 2021 8:05 pm Also, does someone have more resources on how to use Shiboken?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Embedding KTextEditor in FreeCAD
I made a workbench using the python bindings for KTextEditor so now it can be used to edit python/macro files (or any other text file):
So far, the workbench have 3 commands:
So far, the workbench have 3 commands:
- Open file: Opens a QFileDialog which can be used to select a text file to edit.
- Configure: Opens a configuration dialog for KTextEditor. The editor already provides the configuration dialog so it was easy to add it. Also, it seems that KTextEditor handles the saving/loading of configuration settings so I didn't have to do much to include the configuration dialog.
- Open macro: Opens a QFileDialog on the macro folder in order to open and edit a macro file.
- HakanSeven12
- Veteran
- Posts: 1481
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Embedding KTextEditor in FreeCAD
Much better than standard editor good job
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: Embedding KTextEditor in FreeCAD
Awesome news. Is it ready for the Addon Manager yet?
What are the prerequisites (https://github.com/Alonso-JAMM/FreeCAD_ ... r/issues/4) ?
What are the prerequisites (https://github.com/Alonso-JAMM/FreeCAD_ ... r/issues/4) ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Embedding KTextEditor in FreeCAD
Thanks!Kunda1 wrote: ↑Sun Jul 25, 2021 10:47 pm Awesome news. Is it ready for the Addon Manager yet?
What are the prerequisites (https://github.com/Alonso-JAMM/FreeCAD_ ... r/issues/4) ?
I am not sure if it is ready for the Addon Manager because I don't know what are the requisites to be added. The prerequisites for building the python bindings are the same than for building FreeCAD from source plus the KTextEditor package which is provided by many Linux distributions. So, getting the required libraries to build the python bindings should be as hard as getting the libraries required to build FreeCAD from source.
The cmake files need a little bit more work in order to be sure they will work on other systems (right now I have hard-coded the include directory for PySide2).
Also, windows users won't be able to use the workbench since the cmake files only work with Linux and I don't know how to make them work in windows.
- kkremitzki
- Veteran
- Posts: 2515
- Joined: Thu Mar 03, 2016 9:52 pm
- Location: Illinois
Re: Embedding KTextEditor in FreeCAD
Very cool, I've long thought there is potential in pulling in KDE dependencies to enhance FreeCAD's UI/UX. Even if it isn't feasible to deploy it as a C++-based workbench, it would still be worthwhile IMO to try a "KDE-enhanced" distribution of FreeCAD, à la Realthunder's "fork". In terms of packaging, for Linux at least adding KDE deps wouldn't be any difficulty since KDE is already well-packaged on that platform. For Windows I know there is quite a bit of effort in improving things there, for example they recently put the Kate text editor in the Windows Store and of course Kdenlive as well is quite popular there. I'm not sure what the situation would be for Mac or Conda.
In principle, though, it makes a lot of sense. FreeCAD is already a Qt application, and the KDE Frameworks website describes them as "a set of 83 add-on libraries for programming with Qt."
In principle, though, it makes a lot of sense. FreeCAD is already a Qt application, and the KDE Frameworks website describes them as "a set of 83 add-on libraries for programming with Qt."
Re: Embedding KTextEditor in FreeCAD
+1
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs