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!
Re: Embedding KTextEditor in FreeCAD
Great!!!
At some point in the future it would be awesome to make a short guide on how to add other editors
At some point in the future it would be awesome to make a short guide on how to add other editors
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
Hopefully the interface I made to add custom editors works on other editors than KTextEditor. The interface is in src/Gui/CustomEditor.h. There are all the functions used through FreeCAD to open text files, to debug macros, and to get the undo/redo history of the editor. So most of all the changes required to embed new editors should be done on src/Gui/CustomEditor.cpp
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Embedding KTextEditor in FreeCAD
Hello, I just pushed a new commit that adds support to execute macro scripts when they are being edited with KTextEditor.
Re: Embedding KTextEditor in FreeCAD
A very general way is to get the window ID of any GUI application and then embed it e.g. as an mdi view into FreeCAD. So, this will also work for text editors of other DE or OS but it may feel like a foreign body as it doesn't use any of the functions (Open, Save, Undo, Redo, ...) of its host application.At some point in the future it would be awesome to make a short guide on how to add other editors
The steps are:
- Start the external editor with QProcess. The path to it can be saved in the preferences.
- Using the process id retrieve the window id. For Windows there exist some API functions but I don't know how exactly to do this on other platforms. At least on Linux you can get the window id manually with the tool xwininfo
See also: https://stackoverflow.com/questions/450 ... k-properly - Once you know the window id you can embed the application with
Code: Select all
from PySide2 import QtWidgets from PySide2 import QtGui winid = 0x4800003 # for example win = QtGui.QWindow.fromWinId(winid) win.show() widget = QtWidgets.QWidget() cont = QtWidgets.QWidget.createWindowContainer(win, widget) mw = Gui.getMainWindow() mdi = mw.findChild(QtWidgets.QMdiArea) mdi.addSubWindow(cont) cont.show()
https://www.linux-magazin.de/ausgaben/2 ... nd-und-qt/
Re: Embedding KTextEditor in FreeCAD
I can use ktexeditor in free ad main oficial branch?
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Embedding KTextEditor in FreeCAD
The last couple weeks I have been using KTextEditor as my default text editor in FreeCAD to try to caught as many problems as possible. And I have found several problems that make it annoying to use KTextEditor. The most annoying problems are related to shortcuts being ambiguous. The ambiguous shortcuts happen because KTextEditor comes with several actions with shortcuts that FreeCAD uses for its commands.
I found a way to remove the shortcuts of some of the actions of KTextEditor and use FreeCAD's commands instead. This only works for the standard actions that are the same in FreeCAD and in KTextEditor (like Copy, Paste, Save, etc). I am not sure how to solve this problem for actions that are different in FreeCAD and KTextEditor that have the same shortcut. For example, in KTextEditor Ctrl+D by default comments the line or the selected text. However, if I have an object selected in the Tree view while I am editing a macro file and I hit Ctrl+D I will get an ambiguous shortcut warning because KTextEditor has the comment action activated and FreeCAD has the display properties of the selected object activated.
Some other problems that are less annoying are:
1. So far there is no a preferences page to configure.
2. There is no auto-completion of FreeCAD's functions.
3. There is no LSP integration.
4. There is no a context menu
I will work on fixing the shortcuts of actions that are the same for FreeCAD and KTextEditor to remove most of the ambiguous shortcut warnings since they are the most annoying.
I found a way to remove the shortcuts of some of the actions of KTextEditor and use FreeCAD's commands instead. This only works for the standard actions that are the same in FreeCAD and in KTextEditor (like Copy, Paste, Save, etc). I am not sure how to solve this problem for actions that are different in FreeCAD and KTextEditor that have the same shortcut. For example, in KTextEditor Ctrl+D by default comments the line or the selected text. However, if I have an object selected in the Tree view while I am editing a macro file and I hit Ctrl+D I will get an ambiguous shortcut warning because KTextEditor has the comment action activated and FreeCAD has the display properties of the selected object activated.
Some other problems that are less annoying are:
1. So far there is no a preferences page to configure.
2. There is no auto-completion of FreeCAD's functions.
3. There is no LSP integration.
4. There is no a context menu
I will work on fixing the shortcuts of actions that are the same for FreeCAD and KTextEditor to remove most of the ambiguous shortcut warnings since they are the most annoying.
Re: Embedding KTextEditor in FreeCAD
Thanks for the update! This is important work you're doing @alonso_jamm
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
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Embedding KTextEditor in FreeCAD
time to make this happen?
yorik wrote: ↑Sat Oct 15, 2011 8:50 pm Oh.. I was going to propose to rename FreeCad to FreeKad...