need help getting this right
- From: Gary Kline <kline thought org>
- To: GTK Devel List <gtk-app-devel-list gnome org>
- Subject: need help getting this right
- Date: Sat, 25 Feb 2012 15:28:34 -0800
i'll append ~130 lines of C and gtk v2.0 or later. i found this
online in a much busier [and complex] example. for several days,
on and off, i messed around trying to get two independent horizontal
bars. i would guess that in total, i hacked away around 17-23
hours. this morning i threw everything away and started from
*scratch*. after about two hours of using EXtreme care, i got to
horizontal bars to work.
(by the way, this is for part of my menu-items "Options" dropdown.
i FINALLY found the program i had been looking for. Gespeaker. i
thought: Oh great; that's got all i need. BUUUT: Bzzt: it is is
python and i'm still learning that. )
what i need help w with is mostly =one=- thing: give the numbers more
=room=. only "0" and "100" are clear. the rest are displayed as if
torn [??]; i would like lots of vertical space between my three or
four horizontal bars. i've tried the 'separator' bar. no joy, at
least AFAICT.
thanks much in advance,
gary
--
Gary Kline kline thought org http://www.thought.org Public Service Unix
Voice By Computer (for Universal Access): http:/www.thought.org/vbc
The 8.57a release of Jottings: http://jottings.thought.org
Twenty-five years of service to the Unix community.
==================
#include <stdio.h>
#include <gtk/gtk.h>
GtkWidget *hscale, *hscale7;
void
scale_set_default_values (GtkScale *scale)
{
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_CONTINUOUS);
gtk_scale_set_digits (scale, 1);
gtk_scale_set_value_pos (scale, GTK_POS_TOP);
gtk_scale_set_draw_value (scale, TRUE);
}
/*
* creates the sample window
*/
void
create_range_controls (void)
{
GtkWidget *window;
GtkWidget *box1, *box2, *box3;
GtkWidget *button, *buttonbox;
GtkWidget *scrollbar, *scrollbar7;
GtkObject *adj1, *adj7;
/*
Standard window-creating stuff
*/
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_window_set_title (GTK_WINDOW (window), "two horiz bars");
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
box2 = gtk_hbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
/*
value, lower, upper, step_increment, page_increment, page_size
*/
/*
Note that the page_size value only makes a difference for
* scrollbar widgets, and the highest value you'll get is actually
* (upper - page_size).
*/
adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
box3 = gtk_vbox_new (FALSE, 10);
gtk_box_pack_start (GTK_BOX (box2), box3, TRUE, TRUE, 0);
gtk_widget_show (box3);
/* Reuse the same adjustment BAR-1*/
hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 30);
scale_set_default_values (GTK_SCALE (hscale));
gtk_box_pack_start (GTK_BOX (box3), hscale, TRUE, TRUE, 0);
gtk_widget_show (hscale);
/**** BAR-2 ****/
hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, 30);
scale_set_default_values (GTK_SCALE (hscale7));
gtk_box_pack_start (GTK_BOX (box3), hscale7, TRUE, TRUE, 0);
gtk_widget_show (hscale7);
/* Reuse the same adjustment again */
scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj1));
scrollbar7 = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj7));
/*
Notice how this causes the scales to always be updated
* continuously when the scrollbar is moved
*/
gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
gtk_box_pack_start (GTK_BOX (box3), scrollbar, TRUE, TRUE, 0);
gtk_widget_show (scrollbar);
gtk_range_set_update_policy (GTK_RANGE (scrollbar7), GTK_UPDATE_CONTINUOUS);
gtk_box_pack_start (GTK_BOX (box3), scrollbar7, TRUE, TRUE, 0);
gtk_widget_show (scrollbar7);
box2 = gtk_hbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
/**** END of horizontal bar stuff ****/
buttonbox = gtk_vbox_new (FALSE, 10); // WAS "box2" reused
gtk_container_set_border_width (GTK_CONTAINER (buttonbox), 10);
/**** "box1" below, so this button fits into the overall Window ****/
gtk_box_pack_start (GTK_BOX (box1), buttonbox, FALSE, TRUE, 0);
gtk_widget_show (buttonbox);
button = gtk_button_new_with_label ("Quit");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_box_pack_start (GTK_BOX (buttonbox), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_widget_show (window);
}
int
main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
create_range_controls (); // Handles windows and h-bars
gtk_main ();
return (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]