views:

338

answers:

4

I want my widget to look exactly like it does now, except to be smaller. It includes buttons, labels, text, images, etc. Is there any way to just say "scale this to be half the size", and have GTK do all the image processing, widget resizing, etc., necessary? If not, what's the easiest way to accomplish this?

+1  A: 

There is no built in way to do this. To do this, you'll have to consider what is "taking up space" in your ui, and how to reduce it.

If your UI is mostly text and images, you can use a smaller font size, then scale all images down by an appropriate percentage. The widget sizing will shrink automatically once the text and images that they are displaying shrinks (unless you've done Bad Things like hardcode heights/widths, use GtkFixed, etc).

The tricky part will be determining the relationship between font point size and image scale.

EDIT:

Here's a post about the pygtk syntax to change the font size.

anthony
Thanks for the tip. I haven't done Bad Things thankfully =). How can I shrink the font size?
Claudiu
+2  A: 

Change the theme from the user interface is not something that I recommend, but you can do it if you require it, using a custom gtkrc may help you to change the font and the way the buttons are drawed, mostly because of the xthickness and ythickness.

 import gtk
 file = "/path/to/the/gtkrc"
 gtk.rc_parse(file)
 gtk.rc_add_default_file(file)
 gtk.rc_reparse_all()

And the custom gtkrc may look like this:

gtk_color_scheme = "fg_color:#ECE9E9;bg_color:#ECE9E9;base_color:#FFFFFF;text_color:#000000;selected_bg_color:#008DD7;selected_fg_color:#FFFFFF;tooltip_bg_color:#000000;tooltip_fg_color:#F5F5B5"
style "theme-fixes" {

  fg[NORMAL]        = @fg_color
  fg[PRELIGHT]      = @fg_color
  fg[SELECTED]      = @selected_fg_color
  fg[ACTIVE]        = @fg_color
  fg[INSENSITIVE]   = darker (@bg_color)

  bg[NORMAL]        = @bg_color
  bg[PRELIGHT]      = shade (1.02, @bg_color)
  bg[SELECTED]      = @selected_bg_color
  bg[INSENSITIVE]   = @bg_color
  bg[ACTIVE]        = shade (0.9, @bg_color)

  base[NORMAL]      = @base_color
  base[PRELIGHT]    = shade (0.95, @bg_color)
  base[ACTIVE]      = shade (0.9, @selected_bg_color)
  base[SELECTED]    = @selected_bg_color
  base[INSENSITIVE] = @bg_color

  text[NORMAL]      = @text_color
  text[PRELIGHT]    = @text_color
  text[ACTIVE]      = @selected_fg_color
  text[SELECTED]    = @selected_fg_color
  text[INSENSITIVE] = darker (@bg_color)

  GtkTreeView::odd_row_color  = shade (0.929458256, @base_color)
  GtkTreeView::even_row_color = @base_color
  GtkTreeView::horizontal-separator = 12

      font_name = "Helvetica World 7"
 }
 class "*" style "theme-fixes"
markuz
i tried doing this and I changed text color to "FF0000" to see if it had any effect, but it didn't. do I have to set the theme somehow too from my app?
Claudiu
note that doing set_default_files caused the appearance to change
Claudiu
nm, i wasnt giving absolute paths. it seems to work (although this particular scheme looks ugly now.. and it seems text color isn't being black.. but ill figure it out)
Claudiu
just change this: fg_color:#ECE9E9 for this: fg_color:#000000. If you don't want to mess with colors just skip them
markuz
A: 

Having written a 100% scalable gtk app, what I did was limit myself to gdk_draw_line, and gdk_draw_rectangle, which were easy to then scale myself. Text was "done" via gdk_draw_line. (for certain low values of "done.") See: http://wordwarvi.sourceforge.net

Not that it helps you any, I'm guessing.

smcameron
nah I have a GUI app, not a game. wouldn't something like SDL be better for a game, btw? (or maybe i misunderstood what your program is exactly)
Claudiu
For that game probably not better, just different. I knew gtk, but not SDL, and all I needed to get the game up was the ability to draw lines. I'd be surprised if SDL's implementation of line drawing was better than gtk's -- they probably both just do xlib calls -- and I esp. didn't want any of the game-y hardware specific x-windows bypassing stuff that SDL might provide (IDK if it does or not) I wanted it to work with X like a "normal" program, though, and I knew gtk would get me that. Blender's interface is scalable, and it takes a similar approach -- custom rendered UI.
smcameron
+1  A: 

Resolution independence has been worked on by some gtk devs, and here is an update with a very big patch to introduce it into GTK. The patch is however a year old now and it is still unclear how/when/if it is going to be included: (screenshots at the end)

http://mail.gnome.org/archives/gtk-devel-list/2008-August/msg00044.html

kaizer.se
this would be great if i could get it to work - thanks for the lead!
Claudiu