GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 4:08 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How-to move Close button to the right?
PostPosted: Fri Feb 10, 2012 11:49 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
guys, the following callback _does_ work when i choose Help -> How_to_Use, but because of the frame the close button is across the bottom. I would like it to be a small botton in the lower right just like the Authors help -> contributors button you clued in in on. I did borrow this from a "display_text" callback that helps the user search for and locate prev or last text files. If I could adopt the same button-placement code as last time; otherwise, would someone help me get the [Close] button in the lower right?
Code:
/*
*  the following callback reads in ~/.VBC/.Instructions.txt that tells how to
*  use VBC.  [[ May need/WANT to divide to explain "Display Textfile" (?)]]
*/
void
show_instructions_cb (void)
{

#define INSTRUCT ".Instructions.txt"
  GtkWidget *window, *view, *vbox, *separator;
  GtkWidget *close;
  GtkWidget *frame;
  GtkTextBuffer *buffer;
  GtkTextIter iter;
  FILE *infile;
  gchar file_buff[MAXCHAT];
  gchar instruction[32];
  gint nchars;

  /*
     set up file to be read into frame
   */
  sprintf (instruction, "%s%s", vhome, INSTRUCT);       /* name of instructions file
                                                         */
  printf ("DEBUG: show_file: instruction = [%s]\n", instruction);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
//--gtk_window_set_title(GTK_WINDOW(window), "Groat");
  gtk_window_set_title (GTK_WINDOW (window), "Instructions");
/* this tells the window manager the smallest size
* good idea to set this, else the UI can start to look goofy
*/
  gtk_widget_set_usize (window, 200, 200);
  gtk_container_set_border_width (GTK_CONTAINER (window), 8);
/* adding a frame around the vbox to make things look better */
  frame = gtk_frame_new ("MAYBE Help-1 {or 2 or 3}" ");
  gtk_container_add (GTK_CONTAINER (window), frame);
/* at this point we have:
* window with a frame inside it ( a frame is a container )
*/

  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
/* now we added a vbox container, to our frame*/

  view = gtk_text_view_new ();
  gtk_container_set_border_width (GTK_CONTAINER (view), 6);
  gtk_container_add (GTK_CONTAINER (vbox), view);
/* added the text view to the vbox */

  separator = gtk_hseparator_new ();
  gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);
/* using box packing allows automatic sizing, good idea for
* a seperator (let gtk figure it out)
* so now we packed a seperator below our text view */
  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);

  close = gtk_button_new_with_label (" Close window ");

  gtk_box_pack_end (GTK_BOX (hbox), close, TRUE, TRUE, FALSE);

/* fetch the buffer from the text view and get offset 0 */
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);

/* pull in data from instructions file and insert starting at iter */
  chdir (vhome);
  infile = fopen (instruction, " r ");
  if (infile)
    {
      while (1)
        {
          nchars = fread (file_buff, 1, MAXCHAT, infile);
          gtk_text_buffer_insert (buffer, &iter, file_buff, nchars);
          if (nchars < MAXCHAT)
            break;
        }
      fclose (infile);
    }
  else
    g_print (" \ nERROR ! could not open % s \ n ", instruction);

/* no reason to type out all that crap of showing each widget
* with this example */

  gtk_signal_connect (GTK_OBJECT (close), " button_press_event ",
                      (GtkSignalFunc) remove_text_window, window);

  gtk_widget_show_all (window);
  return;
}


Top
 Profile  
 
 Post subject: Re: How-to move Close button to the right?
PostPosted: Sat Feb 11, 2012 9:17 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I would suggest using GtkHButtonBox instead of GtkHBox for placing buttons at the bottom of the dialog. You can then use gtk_button_box_set_layout() function to position your button.

Alternatively (since you have only one button), you can replace GtkHBox in your code with GtkAlignment, make it right aligned, force it to shrink it's child and place a button inside.


And while I'm at it, where did you learn to use GTK+? Your code contains some really old constructs that have been deprecated for almost a decade now (gtk_signal_connect() for example). You should really update your knowledge sources, since your code doesn't even compile anymore on GTK+-3.0.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: How-to move Close button to the right?
PostPosted: Sat Feb 11, 2012 8:22 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
You are getting big buttons because you have set the expand and fill flags for your button which will make it expand to fill the whole hbox.


Top
 Profile  
 
 Post subject: Re: How-to move Close button to the right?
PostPosted: Sat Feb 11, 2012 8:47 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
tadeboro wrote:
Hi.

I would suggest using GtkHButtonBox instead of GtkHBox for placing buttons at the bottom of the dialog. You can then use gtk_button_box_set_layout() function to position your button.

Alternatively (since you have only one button), you can replace GtkHBox in your code with GtkAlignment, make it right aligned, force it to shrink it's child and place a button inside.


And while I'm at it, where did you learn to use GTK+? Your code contains some really old constructs that have been deprecated for almost a decade now (gtk_signal_connect() for example). You should really update your knowledge sources, since your code doesn't even compile anymore on GTK+-3.0.

Cheers,
Tadej


someone commented on several points that you mentioned and i did alter things such as gtk_signal_connect -> g_signal_connect() and others, newer constructs. i have been teaching myself gtk from existing snippets online. unfortunately, as you note, this can//HAS caused trouble.

after i posted this function i added the
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
that you suggested and it blew up. i tried it again just now and it worked, [??]! i fifured that the "frame" container might mess things up. After i pasted in the changed the first time and the application didn't work, i figured i was right. Now, it works. Hm:: ghosts!? ...Anyway,

thanks much,

gary

PS: I'LL post some pix on my thought.org domain.

...


Top
 Profile  
 
 Post subject: Re: How-to move Close button to the right?
PostPosted: Sun Feb 12, 2012 8:17 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
guys,

My ad-hoc URL for my voice-by-computer tool is at http://www.thought.org/vbc/ I am pretty sure that some of the folks on this site are missing; please drop a few words to me at kline@thought.org to correct this!

again, thanks for the help,

gary


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group