spearfire
spearfire

Reputation: 677

change gtk.Paned handle size

gtk.Paned contains a style property called 'handle-size' which i assume will change the size of the handle, it's read only, so how do i change it?(in PyGtk)

Upvotes: 4

Views: 1916

Answers (3)

DarkTrick
DarkTrick

Reputation: 3499

FYI: handle-size is deprecated since GTK 3.20

You can change the handle size via CSS:

paned separator{
  background-size:40px;
  min-height: 40px;
}

C Code

I can't provide Python code, but for reference I'll post C code.

void
_paned_change_handle_size(GtkWidget *widget)
{
  GtkStyleContext * context = gtk_widget_get_style_context (widget);

  GtkCssProvider * css = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (css,
                                   "paned separator{"
                                   "background-size:40px;"
                                   "min-height: 40px;"
                                   "}",
                                   -1,NULL);


  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER(css), 
                      GTK_STYLE_PROVIDER_PRIORITY_USER);
}

Upvotes: 1

ntd
ntd

Reputation: 7434

You can feed a custom resource file before starting your own application. In C (hopefully the translation to python is straightforward) that would be:

#include <gtk/gtk.h>

int
main(gint argc, gchar **argv)
{
    GtkWidget *window;
    GtkPaned  *paned;

    gtk_init(&argc, &argv);

    gtk_rc_parse_string("style 'my_style' {\n"
                        "    GtkPaned::handle-size = 200\n"
                        " }\n"
                        "widget '*' style 'my_style'");

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    paned = (GtkPaned *) gtk_hpaned_new();
    gtk_paned_add1(paned, gtk_label_new("left"));
    gtk_paned_add2(paned, gtk_label_new("right"));

    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(paned));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

Upvotes: 2

ptomato
ptomato

Reputation: 57910

From the documentation for gtk.Widget:

gtk.Widget introduces style properties - these are basically object properties that are stored not on the object, but in the style object associated to the widget. Style properties are set in resource files. This mechanism is used for configuring such things as the location of the scrollbar arrows through the theme, giving theme authors more control over the look of applications without the need to write a theme engine in C.

The general practice in GTK is not to set style properties from your program, but just use the standard UI widgets and let the user decide how they should look (by means of a desktop theme).

Upvotes: 3

Related Questions