Portál AbcLinuxu, 5. května 2025 04:54
Zdravim, potrebuji na win platforme vnorit do GUI okno internet exploreru pomoci PyGTK. Nasel jsem existujici DLL knihovnu GtkIEEmbed (http://live.gnome.org/GtkIEEmbed), ktera by mela pomoci funkce gtk_ie_embed_new() vytvorit objekt typu gtk.Widget. Volam tuto funkci pres ctypes (nemam s ni zatim zadne zkusenosti), ale nefunguje mi to - funkce vraci jen hodnotu INT, nedari se mi ji zmenit ani pomoci restype... Budu velmi vdecny za nejake nakopnuti...
Prozatim experimentuju s timhle:
import gtk
from ctypes import *
class TinyIE:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
gtkie = cdll.LoadLibrary("libgtkieembed-0.dll")
gtkie.gtk_ie_embed_new.restype = gtk.Widget
self.ie = gtkie.gtk_ie_embed_new()
self.window.add(self.ie)
self.window.show_all()
if __name__ == '__main__':
TinyIE()
gtk.main()
Člověk musí napřed položit dotaz, aby pak konečně o něco zakopl na webu :))
Funkční kód:
import ctypes
from ctypes import *
import gtk
import gobject
class _PyGObject_Functions(ctypes.Structure):
_fields_ = [
('register_class',
ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p,
ctypes.c_int, ctypes.py_object,
ctypes.py_object)),
('register_wrapper',
ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.py_object)),
('register_sinkfunc',
ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)),
('lookupclass',
ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_int)),
('newgobj',
ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)),
]
class PyGObjectCAPI(object):
def __init__(self):
addr = ctypes.pythonapi.PyCObject_AsVoidPtr(
ctypes.py_object(gobject._PyGObject_API))
self._api = _PyGObject_Functions.from_address(addr)
def pygobject_new(self, addr):
return self._api.newgobj(addr)
class TinyIE:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
gtkie = CDLL("libgtkieembed-0.dll")
capi = PyGObjectCAPI()
self.ie = capi.pygobject_new(gtkie.gtk_ie_embed_new())
self.window.add(self.ie)
self.window.show_all()
contents = "<html><title>Hello world / html verze.</title><body><P><B>Hello</B> <i>world</i> <font color='red'>!</font></body></html>";
gtkie.gtk_ie_embed_load_html_from_string (hash(self.ie), contents);
if __name__ == '__main__':
TinyIE()
gtk.main()
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.