static VALUE rb_gimp_rgb_list_names (VALUE self) { const gchar **names; GimpRGB *colors; gint num = gimp_rgb_list_names(&names, &colors); int i; volatile VALUE rbnames = rb_ary_new(); for(i=0; i<num; i++) rb_ary_push(rbnames, rb_str_new2(names[i])); volatile VALUE rbcolors = rb_ary_new(); for(i=0; i<num; i++) rb_ary_push(rbcolors, GimpRGB2rb(&colors[i])); g_free(names); g_free(colors); return rb_ary_new3(2, rbnames, rbcolors); }
static PyObject * pygimp_rgb_list_names(PyObject *self) { int num_names, i; const char **names; GimpRGB *colors; PyObject *dict, *color; num_names = gimp_rgb_list_names(&names, &colors); dict = PyDict_New(); if (!dict) goto cleanup; for (i = 0; i < num_names; i++) { color = pygimp_rgb_new(&colors[i]); if (!color) goto bail; if (PyDict_SetItemString(dict, names[i], color) < 0) { Py_DECREF(color); goto bail; } Py_DECREF(color); } goto cleanup; bail: Py_DECREF(dict); dict = NULL; cleanup: g_free(names); g_free(colors); return dict; }
static void gimp_color_hex_entry_init (GimpColorHexEntry *entry) { GtkEntryCompletion *completion; GtkCellRenderer *cell; GtkListStore *store; GimpRGB *colors; const gchar **names; gint num_colors; gint i; /* GtkEntry's minimum size is way too large, set a reasonable one * for our use case */ gtk_entry_set_width_chars (GTK_ENTRY (entry), 8); gimp_rgba_set (&entry->color, 0.0, 0.0, 0.0, 1.0); store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GIMP_TYPE_RGB); num_colors = gimp_rgb_list_names (&names, &colors); for (i = 0; i < num_colors; i++) { GtkTreeIter iter; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLUMN_NAME, names[i], COLUMN_COLOR, colors + i, -1); } g_free (colors); g_free (names); completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, "model", store, NULL); g_object_unref (store); cell = gimp_cell_renderer_color_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "color", COLUMN_COLOR, NULL); gtk_entry_completion_set_text_column (completion, COLUMN_NAME); gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); gtk_entry_set_text (GTK_ENTRY (entry), "000000"); g_signal_connect (entry, "focus-out-event", G_CALLBACK (gimp_color_hex_entry_events), NULL); g_signal_connect (entry, "key-press-event", G_CALLBACK (gimp_color_hex_entry_events), NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (gimp_color_hex_entry_matched), entry); }