This is still at the ugly hack stage!
however it does work.
In order to wrap the gnome-db components into a complete module
I need to be able to interface with pygtk, in this sample I have had
resort to using ctypes to interface with gtk (theres no way to create
a pygtk widget from existing gtk ID)
I also need to look at using the "official" gda module too!
If anyone more knowledgeable about the internals of pygtk could
help out here I'd be most grateful
C
#!/usr/bin/python
import ctypes
import ctypes.util
import sys
def quitapp(w):
sys.exit(0)
gda=ctypes.CDLL(ctypes.util.find_library("gda-3.0"))
gdb=ctypes.CDLL(ctypes.util.find_library("gnomedb-3.0"))
gtk=ctypes.CDLL(ctypes.util.find_library("gtk-x11-2.0"))
gl=ctypes.CDLL(ctypes.util.find_library("glib-2.0"))
#print gl
#sys.exit(0)
GDA_CONNECTION_OPTIONS_DONT_SHARE=2
GDA_COMMAND_TYPE_SQL=0
GDA_COMMAND_OPTION_STOP_ON_ERRORS=2
GTK_WINDOW_TOPLEVEL=0
gdb.gnome_db_init("pyLibgnomedbTest", "1.0", None, None)
logindlg = gdb.gnome_db_login_dialog_new ("Select the Data Source to connect to")
if not gdb.gnome_db_login_dialog_run(logindlg):
print "Login cancelled!"
sys.exit(-10)
error_ptr = ctypes.POINTER(ctypes.c_int)() # TODO define error pointer properly
client = gda.gda_client_new()
cnc = gda.gda_client_open_connection (client,
gdb.gnome_db_login_dialog_get_dsn(logindlg),
gdb.gnome_db_login_dialog_get_username(logindlg),
gdb.gnome_db_login_dialog_get_password(logindlg),
GDA_CONNECTION_OPTIONS_DONT_SHARE,
ctypes.byref(error_ptr))
if not cnc:
print "could not connect"
sys.exit(-20)
gtk.gtk_widget_destroy(logindlg)
# TODO hmm how do I use an id from gnome db with pygtk....
sql=ctypes.create_string_buffer('select * from customers')
command = gda.gda_command_new (sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS)
data_model = gda.gda_connection_execute_select_command (cnc, command, None, ctypes.byref(error_ptr))
if not data_model:
print "could not get data_model for sql"
# TODO define error structure so error can be displayed
sys.exit(-30)
window = gtk.gtk_window_new(GTK_WINDOW_TOPLEVEL)
grid = gdb.gnome_db_grid_new(data_model)
gtk.g_object_unref(data_model)
gtk.gtk_container_add(window, grid)
gtk.gtk_window_set_default_size(window, 400, 300);
QUITFUNC = ctypes.CFUNCTYPE(ctypes.c_int,ctypes.c_int) # 2 not 1 - TODO find out wtf is going on !
quit_func = QUITFUNC(quitapp)
gtk.g_signal_connect_data(window, "destroy", quit_func, None);
gtk.gtk_widget_show_all (window)
gtk.gtk_main();
gda.gda_connection_close (cnc);
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/