5

I want some application to look like widget inside my Python application.

That's all. I dont need any interaction between them. I'm interested in solutions in any GUI toolkit for both windows and x windows.

It would be nice to have a solution with Tkinter but it's not crucial.

1
  • I think it's highly platform dependent. Please give more details. Commented Jun 17, 2009 at 23:07

2 Answers 2

5

Using GTK on X windows (i.e. Linux, FreeBSD, Solaris), you can use the XEMBED protocol to embed widgets using gtk.Socket. Unfortunately, the application that you're launching has to explicitly support it so that you can tell it to embed itself. Some applications don't support this. Notably, I can't find a way to do it with Firefox.

Nonetheless, here's a sample program that will run either an X terminal or an Emacs session inside a GTK window:

import os
import gtk
from gtk import Socket, Button, Window, VBox, HBox

w = Window()
e = Button("Emacs")
x = Button("XTerm")
s = Socket()
v = VBox()
h = HBox()
w.add(v)
v.add(s)
h.add(e)
h.add(x)
v.pack_start(h, expand=False)

def runemacs(btn):
    x.set_sensitive(False); e.set_sensitive(False)
    os.spawnlp(os.P_NOWAIT, "emacs", 
        "emacs", "--parent-id", str(s.get_id()))

def runxterm(btn):
    x.set_sensitive(False); e.set_sensitive(False)
    os.spawnlp(os.P_NOWAIT, "xterm",
        "xterm", "-into", str(s.get_id()))

e.connect('clicked', runemacs)
x.connect('clicked', runxterm)
w.show_all()
gtk.main()
Sign up to request clarification or add additional context in comments.

3 Comments

Do you happen to know why embeded xterm doesn't receive keyboard events?
@MeanEYE, may be a matter of focus?
@Hibou57 oh, I solved this problem long time ago. :) Thanks for the effort. What I did was object.child_focus(gtk.DIR_TAB_FORWARD), object being the socket.
0

Not enough reputation to comment on Glyphs answer. To make xterm work, in addition to the comments above one needs to also add

XTerm*allowSendEvents: True 

to ~/.Xresources. (and perhaps reload those, with xrdb -load ~/.Xresources)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.