Re: Combobox disable item

2017-06-23 Thread Eric Cashon via gtk-app-devel-list

 
Add an extra column to your list and use that to set your "sensitive" property 
for the row. 

Eric


/*
gcc -Wall combo_filter2.c -o combo_filter2 `pkg-config --cflags --libs 
gtk+-3.0`
Tested on GTK3.18 and Ubuntu16.04
*/
#include

static void combo2_changed(GtkComboBox *combo2, gpointer data)
  {
gint combo_row=gtk_combo_box_get_active(combo2);
if(combo_row==1)
  {
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(data), , "1");
gtk_list_store_set(GTK_LIST_STORE(data), , 1, FALSE, -1);
  }
else
  {
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(data), , "1");
gtk_list_store_set(GTK_LIST_STORE(data), , 1, TRUE, -1);
  }
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Filter2");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Scandvb", 1, TRUE, -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "DVB module", 1, TRUE, -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "DVDb5-Scan", 1, TRUE, -1);
gtk_list_store_append(store, );

GtkCellRenderer *renderer=gtk_cell_renderer_text_new();

GtkWidget *combo1=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
gtk_widget_set_hexpand(combo1, TRUE);
gtk_widget_set_vexpand(combo1, TRUE);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1), 
GTK_CELL_RENDERER(renderer), "text", 0, "sensitive", 1, NULL);

GtkWidget *combo2=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show All");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Disable DVB 
module");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
gtk_widget_set_hexpand(combo2, TRUE);
gtk_widget_set_vexpand(combo2, TRUE);
g_signal_connect(combo2, "changed", G_CALLBACK(combo2_changed), store);

g_object_unref(G_OBJECT(store));

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Combobox disable item

2017-06-23 Thread Mike Martin
I am trying to make entries "greyed-out" ie: disabled, rather than hidden


eg the Combobox model contains ('Scandvb','DVB module','DVDb5-Scan')
There is another comboox with a configuration file chosen

I want to be able to make one or more of the entries unselectable if
prerequites are not available or the wrong type of config file is selected,
but still show the option as a prompt

thanks

On 22 June 2017 at 21:09,  wrote:

>
>
> Hi Mike,
>
> What part of the combo box are you trying to disable? If you want to
> filter rows or columns you can set up a tree model filter to do so. Maybe
> something like the following?
>
> Eric
>
>
> /*
> gcc -Wall combo_filter1.c -o combo_filter1 `pkg-config --cflags --libs
> gtk+-3.0`
> Tested on GTK3.18 and Ubuntu16.04
> */
> #include
> #include
>
> static gint combo_row=0;
>
> static void change_combo(GtkComboBox *combo2, gpointer *data)
>   {
> combo_row=gtk_combo_box_get_active(combo2);
> gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(data[1]));
> gtk_combo_box_set_active(GTK_COMBO_BOX(data[0]), 0);
>   }
> static gboolean show_rgb(GtkTreeModel *model, GtkTreeIter *iter, gpointer
> data)
>   {
> gchar *string=gtk_tree_model_get_string_from_iter(model, iter);
> gint row=atoi(string);
> g_free(string);
>
> if(combo_row==1&<3)
>   {
> g_print("Combo1 Don't Show %i\n", row);
> return FALSE;
>   }
> else
>   {
> g_print("Combo1 Show %i\n", row);
> return TRUE;
>   }
>   }
> int main(int argc, char *argv[])
>   {
> gtk_init(, );
>
> GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
> gtk_window_set_title(GTK_WINDOW(window), "Combo Filter");
> gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
> gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
> g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
>
> GtkTreeIter iter;
> GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Yellow", -1);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Purple", -1);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Cyan", -1);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Red", -1);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Green", -1);
> gtk_list_store_append(store, );
> gtk_list_store_set(store, , 0, "Blue", -1);
>
> GtkTreeModel *model=gtk_tree_model_filter_new(GTK_TREE_MODEL(store),
> NULL);
> gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), (
> GtkTreeModelFilterVisibleFunc)show_rgb, NULL, NULL);
>
> GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
>
> GtkWidget *combo1=gtk_combo_box_new_with_model(model);
> gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
> gtk_widget_set_hexpand(combo1, TRUE);
> gtk_widget_set_vexpand(combo1, TRUE);
> gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
> gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1),
> GTK_CELL_RENDERER(renderer), "text", 0, NULL);
>
> GtkWidget *combo2=gtk_combo_box_text_new();
> gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show
> All");
> gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Show
> RGB");
> gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
> gtk_widget_set_hexpand(combo2, TRUE);
> gtk_widget_set_vexpand(combo2, TRUE);
> gpointer data[]={combo1, model};
> g_signal_connect(combo2, "changed", G_CALLBACK(change_combo), data);
>
> g_object_unref(G_OBJECT(store));
>
> GtkWidget *grid=gtk_grid_new();
> gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
> gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
> gtk_container_add(GTK_CONTAINER(window), grid);
>
> gtk_widget_show_all(window);
> gtk_main();
> return 0;
>   }
>
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Combobox disable item

2017-06-22 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Mike,

What part of the combo box are you trying to disable? If you want to filter 
rows or columns you can set up a tree model filter to do so. Maybe something 
like the following?

Eric


/*
gcc -Wall combo_filter1.c -o combo_filter1 `pkg-config --cflags --libs 
gtk+-3.0`
Tested on GTK3.18 and Ubuntu16.04
*/
#include
#include

static gint combo_row=0;

static void change_combo(GtkComboBox *combo2, gpointer *data)
  {
combo_row=gtk_combo_box_get_active(combo2);
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(data[1]));
gtk_combo_box_set_active(GTK_COMBO_BOX(data[0]), 0);
  }
static gboolean show_rgb(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
  {
gchar *string=gtk_tree_model_get_string_from_iter(model, iter);
gint row=atoi(string);
g_free(string);

if(combo_row==1&<3)
  {
g_print("Combo1 Don't Show %i\n", row);
return FALSE;
  }
else
  { 
g_print("Combo1 Show %i\n", row);
return TRUE;
  }
  }
int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Combo Filter");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Yellow", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Purple", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Cyan", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Red", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Green", -1);
gtk_list_store_append(store, );
gtk_list_store_set(store, , 0, "Blue", -1);

GtkTreeModel *model=gtk_tree_model_filter_new(GTK_TREE_MODEL(store), NULL);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), 
(GtkTreeModelFilterVisibleFunc)show_rgb, NULL, NULL);  

GtkCellRenderer *renderer=gtk_cell_renderer_text_new();

GtkWidget *combo1=gtk_combo_box_new_with_model(model);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
gtk_widget_set_hexpand(combo1, TRUE);
gtk_widget_set_vexpand(combo1, TRUE);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1), 
GTK_CELL_RENDERER(renderer), "text", 0, NULL);

GtkWidget *combo2=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show All");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Show RGB");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
gtk_widget_set_hexpand(combo2, TRUE);
gtk_widget_set_vexpand(combo2, TRUE);
gpointer data[]={combo1, model};
g_signal_connect(combo2, "changed", G_CALLBACK(change_combo), data);

g_object_unref(G_OBJECT(store));

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);
gtk_main();
return 0;   
  }



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Combobox disable item

2017-06-22 Thread Mike Martin
Hi

Is it possible to disable an item in a combobox?

I cant find anything about this, set_sensitive only seems to apply to
either cell-renderer or widget

thanks

Mike
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list