GithubHelp home page GithubHelp logo

Comments (4)

wmvanvliet avatar wmvanvliet commented on July 22, 2024

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.

naquad avatar naquad commented on July 22, 2024

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.

wmvanvliet avatar wmvanvliet commented on July 22, 2024

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.

naquad avatar naquad commented on July 22, 2024

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.

image

from qtconsole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.