1. Henning Schröder
  2. embeddedpyqt

Source

embeddedpyqt / experimental / test.py

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ctypes
import sip



def cfunc(func, *args, **kwargs):
	ptr = func(*args)
	result_type = kwargs.pop("type", QObject)
	if kwargs:
		raise TypeError("Unknown keyword argument(s): %r" % kwargs)
	return sip.wrapinstance(int(ptr), result_type)


def new(pyqtwrapper, class_name, *args, **properties):
	cls = cfunc(pyqtwrapper.metaObjectByName, class_name, type=QMetaObject)
	obj = cls.newInstance(*args)
	obj.pyqtConfigure(**properties)
	return obj



class QtLibWrapper(object):
	
	def __init__(self, filename):
		self._lib = ctypes.cdll.LoadLibrary(filename)
		self._instance = cfunc(self._lib.init)

	
	def __getattr__(self, name):
		cls = lambda *args, **properties: new(self._instance, name, **properties)
		return cls






app = QApplication(sys.argv)

qtlib = QtLibWrapper("./libhelloworld.so.1.0.0")
Hello = qtlib.Hello

hello = Hello(text="foo, bar")
hello.show()
app.exec_()