Re: Gtk3 custom theme parsing



On Thu, 02 Aug 2012 18:33:16 +0200
Torsten Schoenfeld <kaffeetisch gmx de> wrote:

On 02.08.2012 17:57, zentara wrote:
GtkCssProvider *provider = gtk_css_provider_new ();

   gtk_css_provider_load_from_data (
     provider,
     "GtkButton {font: Monospace 10; background-color: rgba(0%, 76%, 0%, 0.6);}",
     -1, NULL);

  my $p = Gtk3::CssProvider->new;
  $p->load_from_data ("GtkButton {font: Monospace 10; background-color: 
rgba(0%, 76%, 0%, 0.6);}", -1);
  say $p->to_string;

Unfortuantely, due to an annotation error in gtk+ itself, this doesn't 
currently work.  See <https://bugzilla.gnome.org/show_bug.cgi?id=646859>.

As a workaround, use

  $p->load_from_data ([map ord, split //, "GtkButton {font: Monospace 
10; background-color: rgba(0%, 76%, 0%, 0.6);}"]);
_______________________________________________

Hi, 
thanks for that. 

 With it, my script runs error free, but the desired theme elements
are not overridden.

From googling, it looks like I need the Perl equivalent of 

 GdkDisplay *display = gdk_display_get_default ();
GdkScreen *screen = gdk_display_get_default_screen (display);

gtk_style_context_add_provider_for_screen (screen,
                                           GTK_STYLE_PROVIDER (provider),
                                           GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

g_object_unref (provider);

But even in the c code which uses this, it only works if there
is no theme linked to ./config/gtk-3.0

Somehow the priorities are not working right.

I can only really test with c code right now, as I try to figure
out the syntax. The following c code only works correctly
if there is no link to a Gtk3 theme. If a theme is linked in,
only the large red cursor and font is changed, but not the background color.

Any ideas on how I should proceed?

0m,
zentara

The c code:

/*  Compile With:
*   gcc -Wall -o cursor2 `pkg-config --cflags --libs gtk+-3.0` cursor2.c

*/
#include <gtk/gtk.h>

int main (int argc, char* argv[])
{
GtkWidget *window;
GtkWidget *tview;
GtkTextBuffer *tbuf;

gtk_init(&argc, &argv);

/*-------- CSS 
------------------------------------------------------------------------------------------------------------------------------------------*/

GtkCssProvider *provider = gtk_css_provider_new ();

gtk_css_provider_load_from_data (provider,
                                 "GtkTextView {\n"
                                 "color: blue;\n"
                                 "font: Serif 38;\n"
                                 "background-color: yellow;\n"
                                 "-GtkWidget-cursor-color: red;\n"
                                 "}\n"
                                 "GtkTextView:selected {\n"
                                 "background-color: black;\n"
                                 "color: green;\n"
                                 "}\n", -1, NULL);

GdkDisplay *display = gdk_display_get_default ();
GdkScreen *screen = gdk_display_get_default_screen (display);

gtk_style_context_add_provider_for_screen (screen,
                                           GTK_STYLE_PROVIDER (provider),
                                           GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

g_object_unref (provider);
/*--------------------------------------------------------------------------------------------------------------------------------------------------*/

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 250);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
                         G_CALLBACK(gtk_main_quit), NULL);

tbuf = gtk_text_buffer_new(NULL);
tview = gtk_text_view_new_with_buffer (tbuf);
gtk_container_add(GTK_CONTAINER(window), tview);

gtk_widget_show_all(window);
gtk_main();
return 0;
}


























[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]