Comments (4)
The reason it doesn't get much attention is because it's just too difficult. Interactive widgets need a browser with javascript support. The QtConsole is based around a QTextEdit
that is a text widget with support for inline images, not a browser. Of course there is the QWebView
widget, but how would we go around embedding that inside a QTextEdit
? Perhaps there are solutions here I'm not aware of.
from qtconsole.
Yeah, I get that running not just a browser but a bunch of browsers is a pain.
I've been thinking about an ad-hoc hack for Matplotlib: X11 and Win64 both can do what's called a window embedding. The idea is to add a new matplotlib backend that would render something like MIME embed/window-id with the data = window id and QtConsole would just embed the window using QWidget.createWindowContainer. Actual interaction will be handled by the original process in the kernel. There are still quiet a few unknowns in this (Qt conflicts, potential visual glitches) and limitations (remote interaction will become ridiculously hard) but it is still better than nothing.
Embedding example.
Embedded:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QSlider, QVBoxLayout, QWidget
from PyQt5.QtCore import Qt
import ctypes
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Slider Example")
# Create a label to display the slider value
self.label = QLabel("Slider Value: 0", self)
self.label.setAlignment(Qt.AlignCenter)
# Create a horizontal slider
self.slider = QSlider(Qt.Horizontal, self)
self.slider.setMinimum(0)
self.slider.setMaximum(100)
self.slider.setValue(0)
self.slider.valueChanged.connect(self.update_label)
# Set up the layout
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.slider)
# Create a central widget and set the layout
central_widget = QWidget(self)
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
# Print the native window ID
window_id = int(self.winId())
print(f"WinID: {window_id}")
def update_label(self, value):
self.label.setText(f"Slider Value: {value}")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
An embedder:
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QWindow
class EmbedExternalWindow(QWidget):
def __init__(self, win_id):
super().__init__()
# Initialize layout
layout = QVBoxLayout()
self.setLayout(layout)
# Create a QWindow object from the external window ID
external_window = QWindow.fromWinId(win_id)
external_window.show()
external_widget = QWidget.createWindowContainer(external_window, self)
# Add the external window to the layout
layout.addWidget(external_widget)
# Window settings
self.setWindowTitle('Embed External Window')
self.setGeometry(100, 100, 400, 300) # Adjust size and position as needed
if __name__ == '__main__':
app = QApplication(sys.argv)
main_window = EmbedExternalWindow(int(sys.argv[1]))
main_window.show()
sys.exit(app.exec())
Start the embedded and execute the embedder with the argument = output of an embedded.
from qtconsole.
Embedding a window in another window is one thing. But can you embed into a TextEdit
widget? It all looks very complicated to me.
from qtconsole.
Well, a quick and dirty try demonstrates that it is possible. There are still quite a few questions regarding the widget geometry, placing, and so forth, but it is doable.
from qtconsole.
Related Issues (20)
- Catching Ctrl-Z and Ctrl-\
- Question: Removal of ipython_genutils HOT 1
- Values missing from console when running automatically
- AttributeError: 'QtInProcessChannel' object has no attribute 'closed' HOT 2
- How to access objects in my application follow the example qtconsole/examples/inprocess_qtconsole.py? HOT 2
- Qt bindings version outdated in documentation HOT 2
- Matplotlib Qt5Agg backend is given anonymous icon when used with qtconsole on macOS HOT 3
- Weird pytest error: 'CompletionHtml' object has no attribute '_text_edit' HOT 4
- Qtconsole quits when trying to drag in PyQt6 HOT 12
- Segmentation Fault on `jupyter qtconsole` HOT 10
- Stop using `IPythonLexer` from ` IPython.lib.lexers` HOT 3
- TypeError due to wrong spelling in keyword HOT 1
- compute_item_matrix() got an unexpected keyword argument 'displaywidth' HOT 1
- New tab causes crash for --existing kernels
- intersphinx warning HOT 1
- possibly removing `qtconsole` from jupyter metapackage HOT 2
- Horizontal scrolling not updated until wndow resize event HOT 3
- misspelled keyword arg in qtconsole.util.compute_item_matrix HOT 2
- Segfault on import running against Qt 6.7 on 64 bit Windows 11 w/ python 3.12 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtconsole.