Ipython Qt Console
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Ipython Qt Console
I just wanted to ask if someone already has experimented to replace the console of freecad with an ipython qt console? Any ideas what has to be changed to get this working? https://ipython.org/ipython-doc/2/inter ... nsole.html Or isn't this possible?
Another cool thing would be to connect an ipython-notebook to freecad. This would provide some really great possibilities to work with freecad. (mathematica style inputs, inline plots, ....)
Another cool thing would be to connect an ipython-notebook to freecad. This would provide some really great possibilities to work with freecad. (mathematica style inputs, inline plots, ....)
Re: Ipython Qt Console
This definitely crossed my mind, especially the notebook integration. But more on the side on howto show freecad visualisation in the notebook (and then of course also the QT console) via javascript. Would be awesome to have, as this would enable a better working in other scientific contexts. But I never even tried it, just one of the many things that come from time to time into my mind. Would be nice to investigate this
Re: Ipython Qt Console
A few weeks ago I downloaded a Python package including ipython and I got it working on Windows.
Re: Ipython Qt Console
So using ipython inside freecad should work?wmayer wrote:A few weeks ago I downloaded a Python package including ipython and I got it working on Windows.
I tried to start ipython from the console but it has some problems with stdin.
Code: Select all
>>> from IPython import embed
>>> embed()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/IPython/terminal/embed.py", line 290, in embed
shell = InteractiveShellEmbed.instance(**kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/config/configurable.py", line 354, in instance
inst = cls(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/embed.py", line 92, in __init__
display_banner=display_banner
File "/usr/lib/python2.7/dist-packages/IPython/terminal/interactiveshell.py", line 328, in __init__
**kwargs
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 483, in __init__
self.init_readline()
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 1884, in init_readline
self.refill_readline_hist()
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 1893, in refill_readline_hist
stdin_encoding = sys.stdin.encoding or "utf-8"
Re: Ipython Qt Console
Yes, I was able to import the FreeCAD module and played a bit with creating documents and adding objects. You have to search for ipython in the forum to get this topic.So using ipython inside freecad should work?
Re: Ipython Qt Console
here is a link to the topic I think Werner is referring to.wmayer wrote:Yes, I was able to import the FreeCAD module and played a bit with creating documents and adding objects. You have to search for ipython in the forum to get this topic.So using ipython inside freecad should work?
viewtopic.php?f=22&t=13620
Re: Ipython Qt Console
Thanks. I tried this but the gui doesn't show up. There is also no error/crash. The output is this:
Is it possible to use the ipython console after start of freecad gui?
Code: Select all
>>>import sys
>>>sys.path.append("/usr/lib/freecad/lib")
>>>import FreeCAD, FreeCADGui
>>>from PySide import QtGui
>>>app = QtGui.QApplication(sys.argv)
>>>FreeCADGui.showMainWindow()
FreeCAD 0.16, Libs: 0.16R6397 (Git)
testMain window restored
Show main window
Toolbars restored
Re: Ipython Qt Console
When starting freecad from ipython the gui is always locked (grey). Using some code for embedding ipython I got a working console inside of freecad. Maybe something similar can be done with a notebook?
Code: Select all
from PySide import QtGui
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.qt.inprocess import QtInProcessKernelManager
import FreeCAD as App
import FreeCADGui as Gui
def put_ipy(parent):
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel = kernel_manager.kernel
kernel.gui = 'qt'
kernel_client = kernel_manager.client()
kernel_client.start_channels()
kernel_client.namespace = parent
def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
layout = QtGui.QVBoxLayout(parent)
widget = RichIPythonWidget(parent=parent)
layout.addWidget(widget)
widget.kernel_manager = kernel_manager
widget.kernel_client = kernel_client
widget.exit_requested.connect(stop)
ipython_widget = widget
ipython_widget.show()
kernel.shell.push({'widget':widget,'kernel':kernel, 'parent':parent})
kernel.shell.push({'App':App,'Gui':Gui})
return {'widget':widget,'kernel':kernel}
put_ipy(None)
Re: Ipython Qt Console
So here is a solution to start freecad from an ipython-qtconsole and ipython notebook. The trick was to place a %gui qt at the first line. Then the gui shows up. This is the code I have used now:
After starting freecad from the notebook, it is possible to show this notebook directly as a browser window in freecad, but I don't know if this is useful.
With the normal ipython console I still get some errors:
Code: Select all
%gui qt
import sys
sys.path.append("/usr/lib/freecad/lib")
import FreeCADGui
FreeCADGui.showMainWindow()
With the normal ipython console I still get some errors:
Code: Select all
Importing PySide disabled by IPython, which has
already imported an Incompatible QT Binding: pyqtv1
Re: Ipython Qt Console
With some help of jupyter people I have made a small kernel, based on a ipython-kernel which starts FreeCAD at launch. If you want to try you need jupyter, clone this repo and run (The freecadkernel.py file should be available to the import system of python. So palce it anywhere where python can find it) After starting a new notebook there should be the possibility to start a new FreeCAD kernel.
This cell based input is very useful for learning modules and trying new stuff. Also the auto-complete system seems a bit more advanced. The notebook also allows in-line plotting, showing svg's, display latex... .
Code: Select all
jupyter kernelspec install <path_to_FreeCAD_kernel_directory>
This cell based input is very useful for learning modules and trying new stuff. Also the auto-complete system seems a bit more advanced. The notebook also allows in-line plotting, showing svg's, display latex... .