kembed-emacs /

Full commit
#!/usr/bin/env python
# encoding: utf-8

"""A test-program for embedding emacs in KDE."""

from PyQt4.QtGui import QX11EmbedContainer
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QProcess, SIGNAL, SLOT

from sys import argv, version_info

from optparse import OptionParser
parser = OptionParser(__doc__)
parser.add_option("--basic", help="use a basic display", action="store_true")
parser.add_option("--no-client", help="do not use emacsclient", action="store_true")
parser.add_option("--justprintid", help="just print the window Id so a program can attach from outside.", action="store_true")
opts, args = parser.parse_args()

if version_info > (2,7,0, 'final', 0): 
    from subprocess import check_output
    out = check_output(["emacs", "--version"])
    n = len("GNU Emacs ")
    vers = float(out[n:n+4])
    vers = None

app = QApplication(argv)

container = QX11EmbedContainer()
container.resize(670, 630)

if opts.justprintid:
    print container.winId()
    container.connect(container, SIGNAL("clientClosed()"), app.quit)
    container.connect(container, SIGNAL("error(QX11EmbedContainer::Error)"), app.quit)

process = QProcess(container)
args = ["--parent-id", str(container.winId())]
if opts.basic:
    args.extend(["-Q", "--basic-display"])

if vers >= 24 and not opts.basic and not opts.no_client: 
    process.start("emacsclient", args)
elif vers is None or vers >= 23.1: 
    process.start("emacs", args)
    print "You need at least emacs 23.1 for embedding emacs via XEmbed."
container.connect(container, SIGNAL("clientClosed()"), app.quit)
#container.connect(container, SIGNAL("clientIsEmbedded()"), container.resize_)
container.connect(container, SIGNAL("error(QX11EmbedContainer::Error)"), app.quit)
status = app.exec_()