LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2009, 02:31 PM   #1
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Rep: Reputation: 17
Adding GtkWidgets to GtkFrame in C


Hi guys, I'm writing my own poker timer program to use when my friends come over to play poker all night at my house. We play cash and tournaments.

I have a simple layout that I modeled after several poker timers I saw on Google Images. Anyways. I can't seem to find any example or tutorial or anything on my book or online about how to add widgets like buttons, labels and boxes to a frame.

My program will have 3 frames (3x1) and each will have boxes to hold buttons and labels and combo boxes. At the bottom of the program I will have 3 more buttons outside the frames in a 1x3 box to control the flow of the program.

Any help or reference would be appreciated, I'm teaching myself Gtk+ from "Beginning Linux Programming" and "Foundations of Gtk+ Development"

Also, this is not a homework problem, if anybody would like to collaborate I would be very happy to share what I have and it would be my first project so I'm very excited about getting this app to work.

Thanks in advance.
 
Old 04-23-2009, 02:59 PM   #2
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Original Poster
Rep: Reputation: 17
Hey guys, I figured out how to add the widgets to the frames. Apparently, you just add them to the frame as if it were a GtkContainer. But now the frame labels are not showing up.

Also, I can't find anything on how to make text on buttons big, like the font and the style (bold, italic or underline).

Thanks in advance.
 
Old 04-23-2009, 04:07 PM   #3
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Original Poster
Rep: Reputation: 17
This is what I have so far, and it compiles with no problems (using -g -Wall and -pedantic). But I get segmentation fault when I try to initialize my boxes:

Code:
#include <gtk/gtk.h>
#include <stdio.h>

void closeApp(GtkWidget *window, gpointer data)
{
  gtk_main_quit();
}

int main(int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *hbox1, *hbox2, *hbox3, *hbox4;
  GtkWidget *vbox1, *vbox2, *vbox3, *vbox4, *vbox5, *vbox6, *vbox7;
  GtkWidget *button_time, *button_start, *button_rewind, *button_forward;
  GtkWidget *label_sb_title, *label_bb_title, *label_ante_title;
  GtkWidget *label_sb, *label_bb, *label_ante;
  GtkWidget *label_game_type, *label_blind_profile;
  GtkWidget *combo_game_type, *combo_blind_profile;
  GtkWidget *frame_round, *frame_time_remaining, *frame_settings, *frame_buttons;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Poker Timer");
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 500);
  g_signal_connect(GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (closeApp), NULL);

  button_start = gtk_button_new_with_label("Start Timer");
  button_time = gtk_button_new_with_label("00:00");
  button_rewind = gtk_button_new_with_label("Rewind 1 Blind");
  button_forward = gtk_button_new_with_label("Forward 1 Blind");

  label_sb_title = gtk_label_new("Small Blind");
  label_bb_title = gtk_label_new("Big Blind");
  label_ante_title = gtk_label_new("Ante");
  label_sb = gtk_label_new("25");
  label_bb = gtk_label_new("50");
  label_ante = gtk_label_new("0");
  label_game_type = gtk_label_new("Game Type");
  label_blind_profile = gtk_label_new("Blind Profiles");

  combo_game_type = gtk_combo_box_new_text();
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_game_type), "Tournament");
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_game_type), "Cash - Coins");
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_game_type), "Cash - Bills");

  combo_blind_profile = gtk_combo_box_new_text();
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_blind_profile), "Tournament: 25 / 50");
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_blind_profile), "Cash: $0.01 / $0.02");
  gtk_combo_box_append_text(GTK_COMBO_BOX(combo_blind_profile), "Cash: $1.00 / $2.00");

  frame_round = gtk_frame_new("Round: 1");
  frame_time_remaining = gtk_frame_new("Time Remaining");
  frame_settings = gtk_frame_new("Settings");
  
  gtk_frame_set_shadow_type(GTK_FRAME(frame_round), GTK_SHADOW_IN);
  gtk_frame_set_shadow_type(GTK_FRAME(frame_time_remaining), GTK_SHADOW_OUT);
  gtk_frame_set_shadow_type(GTK_FRAME(frame_settings), GTK_SHADOW_IN);
  gtk_frame_set_shadow_type(GTK_FRAME(frame_buttons), GTK_SHADOW_IN);

  vbox1 = gtk_vbox_new(TRUE, 10);
  vbox2 = gtk_vbox_new(TRUE, 10);
  vbox3 = gtk_vbox_new(TRUE, 10);
  vbox4 = gtk_vbox_new(TRUE, 10);
  vbox5 = gtk_vbox_new(TRUE, 10);
  vbox6 = gtk_vbox_new(TRUE, 10);
  vbox7 = gtk_vbox_new(TRUE, 10);
  
  hbox1 = gtk_hbox_new(TRUE, 10);
  hbox2 = gtk_hbox_new(TRUE, 10);
  hbox3 = gtk_hbox_new(TRUE, 10);
  hbox4 = gtk_hbox_new(TRUE, 10);
  
  gtk_box_pack_start(GTK_BOX(vbox1), label_sb_title, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox1), label_sb, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox2), label_bb_title, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox2), label_bb, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox3), label_ante_title, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox3), label_ante, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox1), vbox1, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox1), vbox2, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox1), vbox3, TRUE, FALSE, 10);
  gtk_container_add(GTK_CONTAINER(frame_round), hbox1);

  gtk_box_pack_start(GTK_BOX(hbox2), button_time, TRUE, TRUE, 10);
  gtk_container_add(GTK_CONTAINER(frame_time_remaining), hbox2);

  gtk_box_pack_start(GTK_BOX(vbox4), label_game_type, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox4), label_blind_profile, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox5), combo_game_type, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox5), combo_blind_profile, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox3), vbox4, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox3), vbox5, TRUE, FALSE, 10);
  gtk_container_add(GTK_CONTAINER(frame_settings), hbox3);
  
  gtk_box_pack_start(GTK_BOX(hbox4), button_start, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox4), button_rewind, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(hbox4), button_forward, TRUE, FALSE, 10);
  gtk_container_add(GTK_CONTAINER(frame_buttons), hbox4);
  
  gtk_box_pack_start(GTK_BOX(vbox7), frame_round, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox7), frame_time_remaining, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox7), frame_settings, TRUE, FALSE, 10);
  gtk_box_pack_start(GTK_BOX(vbox7), frame_buttons, TRUE, FALSE, 10);
  gtk_container_add(GTK_CONTAINER(window), vbox7);
  gtk_widget_show_all(window);
  gtk_main ();
	
  return 0;
}
I get segmentation fault at the line:

Code:
  vbox1 = gtk_vbox_new(TRUE, 10);
Can't see why this is a problem, because the program was compiling and running fine before, all I did was add the frames into a final box and add the box to the window before showing and now its not running.
 
Old 04-23-2009, 04:49 PM   #4
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Original Poster
Rep: Reputation: 17
Never mind, the problem was before the box initialization, I had forgotten to initialize the last frame. Now my code works, and I'm going to start implementing the actions for the buttons and combo boxes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding HD Flab0y352 Linux - General 3 08-13-2007 02:25 AM
Adding more SWAP after adding memory marc1978 Linux - General 6 03-19-2006 07:13 PM
Creating array of GTKWidgets - is this possible? woodywellhung Programming 1 05-05-2004 03:44 PM
adding a second hd pld Linux - Hardware 2 07-31-2003 03:09 AM
ip adding help ranger12002 Linux - General 3 07-01-2003 10:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration