Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed external window in GUI (Python + Glade + Gtk3)

I started to build a GUI with Glade, python and Gtk3 libraries. I want to try to view an external window linking it inside a container in my GUI. Is it possible? Which is the best container object to do this?

I started to search but easy methods in Gtk2 (like here) can't be used any more in Gtk3.

I found a very interesting post here which allow me to set the right ID of the target window but I'm still confused on how to show it inside my GUI.

I unsucessfully tried to change a bit these tutorials with cairo.

My piece of code so far ( I want to display the window with ID = 0x360000b in the map_area container and I have to use the "self." handles structure). Temporarily the map_area container is a Drawingarea.

# if condition occurs    
    Gdk.Window.process_all_updates()
    win_id = 0x360000b # from xwininfo command
    root_win = GdkX11.X11Display.get_default()
    win = GdkX11.X11Window.foreign_new_for_display(root_win, win_id)
    width = win.get_width()
    height = win.get_height()   
    self.map_area = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)               
    pixbuf = Gdk.pixbuf_get_from_window(win, 0, 0, width, height)
    cr = cairo.Context(self.map_area)   
    Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0)
    cr.paint()

Can anyone help me? Thank you in advance!

like image 413
marcoresk Avatar asked Aug 14 '16 18:08

marcoresk


1 Answers

It sounds like you want to be a window manager. Have a look at the answers to questions about how to write a window manager, such as this one:

Creating a window manager for Linux

or this one:

Building a Window Manager

Good luck!

like image 172
Bill Gribble Avatar answered Nov 03 '22 13:11

Bill Gribble