分类: C/C++
2007-03-22 21:52:16
static gboolean
_etc_main_win_add_trans(gpointer data)
{
PyObject *args = data;
if (PyTuple_Size(args) != lv_columns)
return FALSE;
GtkWidget *listview;
GtkTreeModel *model;
GtkTreeIter iter;
int i;
GValue value;
PyObject *obj;
listview = GTK_WIDGET(g_object_get_data(G_OBJECT(main_window), "trans_list"));
model = gtk_tree_view_get_model(GTK_TREE_VIEW(listview));
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
for (i = 0; i < lv_columns; ++i) {
memset(&value, 0, sizeof(value));
g_value_init(&value, lv_types[i]);
obj = PyTuple_GetItem(args, i);
switch(lv_types[i]) {
case G_TYPE_INT:
if (PyInt_Check(obj))
g_value_set_int(&value, PyInt_AsLong(obj));
break;
case G_TYPE_LONG:
if (PyLong_Check(obj))
g_value_set_long(&value, PyLong_AsLong(obj));
break;
case G_TYPE_UINT:
if (PyLong_Check(obj))
g_value_set_uint(&value, PyLong_AsUnsignedLong(obj));
break;
case G_TYPE_ULONG:
if (PyLong_Check(obj))
g_value_set_ulong(&value, PyLong_AsUnsignedLong(obj));
break;
case G_TYPE_FLOAT:
if (PyFloat_Check(obj))
g_value_set_float(&value, PyFloat_AsDouble(obj));
break;
case G_TYPE_DOUBLE:
if (PyFloat_Check(obj))
g_value_set_double(&value, PyFloat_AsDouble(obj));
break;
default:
if (PyString_Check(obj))
g_value_set_string(&value, PyString_AsString(obj));
break;
}
gtk_list_store_set_value(GTK_LIST_STORE(model), &iter, i, &value);
}
//Py_XDECREF(args);
return FALSE;
}
void
etc_main_win_add_trans(PyObject *args)
{
//Py_INCREF(args);
g_idle_add(_etc_main_win_add_trans, args);
}