Re: Treeviews: changing the color of column headers

2015-06-13 Thread Daniel Kasak
I've done this in Gtk2. I don't have my laptop and old code handy
right now, but from memory:

- create a label
- set_markup() on the label, and set your colour(s) in there
- use TreeViewColumn.set_widget() to override the default label

If you can't get it working, post again and I'll go and dig out the
old ( perl ) code that I used.

Dan

On Sun, Jun 14, 2015 at 7:55 AM, Stefan Salewski m...@ssalewski.de wrote:
 On Sat, 2015-06-13 at 20:43 +0200, Stefan Salewski wrote:
 On Tue, 2015-06-09 at 08:54 +0200, Juan L. Freniche wrote:
  I am trying to change the color of the column headers of a treeview,
  with no sucess at all.

 It is funny that currently many people try to change default colors of
 GTK widgets. Of course generally that is not a good idea -- common sense
 is to give users their default styles. Of course, for special
 applications that may be OK. For tree view headers, I can remember that
 I tried to chance something style related, and it worked after I added a
 custom label widget as header text. See

 http://www.daa.com.au/pipermail/pygtk/2009-February/016601.html

  Try using a custom widget for the header using
  TreeViewColumn.set_widget()


 Sorry, have not been able to get it working with GTK2. I tried to put a
 label in a column header and change the color of the label with
 gtk_widget_modify_bg(label, GTK_STATE_NORMAL, color). But it seems to
 have no effect. Maybe it would work for GTK3, there we have
 gtk_widget_override_color().


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


Tracking Gtk2 error messages

2015-06-13 Thread Ian Chapman

Hi All,

How do I determine which widget is the cause of errors such as this?

Gtk-CRITICAL **: IA__gtk_widget_grab_default: assertion 
'gtk_widget_get_can_default (widget)' failed


I'm using perl-gtk2 and gtkbuilder. It gives a line number but that's 
simply where I'm adding the xml file...


i.e. $builder-add_from_file ($filename))

which isn't particularly useful. Thanks.

--
Ian Chapman.
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Changing background of TextView makes selection invisible

2015-06-13 Thread Stefan Salewski
On Sat, 2015-06-13 at 11:03 +0100, Kasper Peeters wrote:
 I am trying to make the background colour of all TextViews white,

Have you followed this page:

https://developer.gnome.org/gtk3/stable/TextWidget.html


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


Re: Treeviews: changing the color of column headers

2015-06-13 Thread Juan L. Freniche

More info:
I copy a small program (derived from some other program found in the 
treeview tutorial) and the Makefile. All things that I tried didn't 
change the background of the header treeview colum.

What is missing or wrong?

- the program -
#include gtk/gtk.h

enum
{
  COL_FIRST = 0,
  NUM_COLS
} ;

static GtkTreeModel *create_and_fill_model (void)
{
  GtkTreeStore  *treestore;
  GtkTreeItertoplevel;

  treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);

  gtk_tree_store_append(treestore, toplevel, NULL);
  gtk_tree_store_set(treestore, toplevel, COL_FIRST, some text, -1);

  gtk_tree_store_append(treestore, toplevel, NULL);
  gtk_tree_store_set(treestore, toplevel, COL_FIRST, more text, -1);

  return GTK_TREE_MODEL(treestore);
}

void set_header (GtkTreeViewColumn *col, char *title)
{ GtkWidget *lab;

  lab = gtk_label_new (title);
  gtk_tree_view_column_set_widget (col, lab);
  gtk_widget_show (lab);
}

void set_color (GtkWidget *w, GdkColor color)
{ /* none work */
  gtk_widget_modify_bg   (w, GTK_STATE_NORMAL,  color);
  gtk_widget_modify_base (w, GTK_STATE_NORMAL,  color);
  gtk_widget_modify_bg   (w, GTK_STATE_ACTIVE,  color);
  gtk_widget_modify_base (w, GTK_STATE_ACTIVE,  color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_bg   (w, GTK_STATE_SELECTED,color);
  gtk_widget_modify_base (w, GTK_STATE_SELECTED,color);
  gtk_widget_modify_bg   (w, GTK_STATE_INSENSITIVE, color);
  gtk_widget_modify_base (w, GTK_STATE_INSENSITIVE, color);
}

void set_color_header (GtkTreeView *view)
{
  GtkTreeViewColumn *col;
  GtkWidget *w;
  GdkColor  color;
  gboolean  res;

  res = gdk_color_parse (red, color);
  if (res == 0) return;
  col = gtk_tree_view_get_column (view, COL_FIRST);

  w = gtk_tree_view_column_get_widget (col); /* the label */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the alignment */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the hbox */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the button */
  set_color (w, color); /* NOK */
}

static GtkWidget *create_view_and_model (void)
{
  GtkTreeViewColumn   *col;
  GtkCellRenderer *renderer;
  GtkWidget   *view;
  GtkTreeModel*model;

  view = gtk_tree_view_new();

  col = gtk_tree_view_column_new();
  set_header (col, First Column);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, text, COL_FIRST);
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);

  /* set_color_header(GTK_TREE_VIEW(view));  NOK */

  model = create_and_fill_model();

  gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);

  g_object_unref(model);

  return view;
}

int main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *view;

  gtk_init(argc, argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  g_signal_connect(window, delete_event, gtk_main_quit, NULL); /* 
dirty */


  view = create_view_and_model();
  /*  set_color_header(GTK_TREE_VIEW(view)); NOK */

  gtk_container_add(GTK_CONTAINER(window), view);

  gtk_widget_show_all(window);

  set_color_header(GTK_TREE_VIEW(view)); /* NOK */

  gtk_main();

  return 0;
}
 the Makefile ---

CC = gcc

CFLAGS = -g -O0 `pkg-config --cflags gtk+-2.0`

all: treeview-demo

treeview-demo: main.o
gcc -o treeview-demo main.o `pkg-config --libs gtk+-2.0` -mwindows

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


Changing background of TextView makes selection invisible

2015-06-13 Thread Kasper Peeters
I am trying to make the background colour of all TextViews white, using
something along the lines of (this is gtkmm, but the problem is the same
in pure gtk):

  Glib::ustring data = GtkTextView { background: white; };
  auto css = Gtk::CssProvider::create();
  css-load_from_data(data);
  auto screen = Gdk::Screen::get_default();
  
Gtk::StyleContext::add_provider_for_screen(screen,css,GTK_STYLE_PROVIDER_PRIORITY_USER);

This does make the background white, but it also makes the colour used
for selection highlight white. As a result, I can't see anymore what I
am selecting.

A different colour leads to the same result: the highlight colour
becomes the same as the background colour, and hence the selection
becomes invisible. The same also happens when using the
override_background_color(..) function of the widget.

Is this a bug? (this is with gtk-3.10.8). Or am I doing something wrong?
Thanks!

Cheers,
Kasper
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Treeviews: changing the color of column headers

2015-06-13 Thread Stefan Salewski
On Tue, 2015-06-09 at 08:54 +0200, Juan L. Freniche wrote:
 I am trying to change the color of the column headers of a treeview, 
 with no sucess at all.

It is funny that currently many people try to change default colors of
GTK widgets. Of course generally that is not a good idea -- common sense
is to give users their default styles. Of course, for special
applications that may be OK. For tree view headers, I can remember that
I tried to chance something style related, and it worked after I added a
custom label widget as header text. See

http://www.daa.com.au/pipermail/pygtk/2009-February/016601.html

 Try using a custom widget for the header using 
 TreeViewColumn.set_widget()

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


GTK TreeView change the column header color

2015-06-13 Thread Juan L. Freniche
I am trying to change the color of the column headers of a treeview, 
with no sucess at all. I followed the way indicated in an old post in 
Nov. 2003:


I tried:
for each column in the treeview:
when defining the column, set_widget (col, label)
now show the widget (i.e., the label).
Then  show the treeview.
And now:
for each column in the treeview:
get_widget (col)
get_parent // the alignment
get_parent // the hbox
get_parent // the button
modify bg (button, state normal, some gdk color) // tried 
also with modify base

Result: nothing, header columns blank

I also tried in the rc file (still using gtk 2.xx):
style TreeHeaderStyle
 {
  bg[NORMAL] = blue  # tried also with base
 }
widget_class *.GtkTreeView.GtkButton style : highest TreeHeaderStyle

Result: nothing, header columns still blank

The global gtkrc is the default one and my particular gtkrc is
# Auto-written by gtk2_prefs. Do not edit.
gtk-theme-name = Nimbus
style user-font
{
font_name=Sans 10
}
widget_class * style user-font

I change the theme to several others and no success.
I know that some years ago the same question was made, I followed the 
recommendations given there. No success.


I would appreciate any help. Thanks.
Ah, in Win32.

I am attaching a small program derived from an example in the treeview 
tutorial

- the program -
#include gtk/gtk.h

enum
{
  COL_FIRST = 0,
  NUM_COLS
} ;

static GtkTreeModel *create_and_fill_model (void)
{
  GtkTreeStore  *treestore;
  GtkTreeItertoplevel;

  treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);

  gtk_tree_store_append(treestore, toplevel, NULL);
  gtk_tree_store_set(treestore, toplevel, COL_FIRST, some text, -1);

  gtk_tree_store_append(treestore, toplevel, NULL);
  gtk_tree_store_set(treestore, toplevel, COL_FIRST, more text, -1);

  return GTK_TREE_MODEL(treestore);
}

void set_header (GtkTreeViewColumn *col, char *title)
{ GtkWidget *lab;

  lab = gtk_label_new (title);
  gtk_tree_view_column_set_widget (col, lab);
  gtk_widget_show (lab);
}

void set_color (GtkWidget *w, GdkColor color)
{ /* none work */
  gtk_widget_modify_bg   (w, GTK_STATE_NORMAL,  color);
  gtk_widget_modify_base (w, GTK_STATE_NORMAL,  color);
  gtk_widget_modify_bg   (w, GTK_STATE_ACTIVE,  color);
  gtk_widget_modify_base (w, GTK_STATE_ACTIVE,  color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,color);
  gtk_widget_modify_bg   (w, GTK_STATE_SELECTED,color);
  gtk_widget_modify_base (w, GTK_STATE_SELECTED,color);
  gtk_widget_modify_bg   (w, GTK_STATE_INSENSITIVE, color);
  gtk_widget_modify_base (w, GTK_STATE_INSENSITIVE, color);
}

void set_color_header (GtkTreeView *view)
{
  GtkTreeViewColumn *col;
  GtkWidget *w;
  GdkColor  color;
  gboolean  res;

  res = gdk_color_parse (red, color);
  if (res == 0) return;
  col = gtk_tree_view_get_column (view, COL_FIRST);

  w = gtk_tree_view_column_get_widget (col); /* the label */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the alignment */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the hbox */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the button */
  set_color (w, color); /* NOK */
}

static GtkWidget *create_view_and_model (void)
{
  GtkTreeViewColumn   *col;
  GtkCellRenderer *renderer;
  GtkWidget   *view;
  GtkTreeModel*model;

  view = gtk_tree_view_new();

  col = gtk_tree_view_column_new();
  set_header (col, First Column);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, text, COL_FIRST);
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);

  /* set_color_header(GTK_TREE_VIEW(view));  NOK */

  model = create_and_fill_model();

  gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);

  g_object_unref(model);

  return view;
}

int main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *view;

  gtk_init(argc, argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  g_signal_connect(window, delete_event, gtk_main_quit, NULL); /* 
dirty */


  view = create_view_and_model();
  /*  set_color_header(GTK_TREE_VIEW(view)); NOK */

  gtk_container_add(GTK_CONTAINER(window), view);

  gtk_widget_show_all(window);

  set_color_header(GTK_TREE_VIEW(view)); /* NOK */

  gtk_main();

  return 0;
}
 the Makefile ---

CC = gcc

CFLAGS = -g -O0 `pkg-config --cflags gtk+-2.0`

all: treeview-demo

treeview-demo: main.o
   

Re: Treeviews: changing the color of column headers

2015-06-13 Thread Stefan Salewski
On Sat, 2015-06-13 at 20:43 +0200, Stefan Salewski wrote:
 On Tue, 2015-06-09 at 08:54 +0200, Juan L. Freniche wrote:
  I am trying to change the color of the column headers of a treeview, 
  with no sucess at all.
 
 It is funny that currently many people try to change default colors of
 GTK widgets. Of course generally that is not a good idea -- common sense
 is to give users their default styles. Of course, for special
 applications that may be OK. For tree view headers, I can remember that
 I tried to chance something style related, and it worked after I added a
 custom label widget as header text. See
 
 http://www.daa.com.au/pipermail/pygtk/2009-February/016601.html
 
  Try using a custom widget for the header using 
  TreeViewColumn.set_widget()
 

Sorry, have not been able to get it working with GTK2. I tried to put a
label in a column header and change the color of the label with
gtk_widget_modify_bg(label, GTK_STATE_NORMAL, color). But it seems to
have no effect. Maybe it would work for GTK3, there we have
gtk_widget_override_color().


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