GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 23, 2014 7:30 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: how do i create a button that pops-up alreadt existing textf
PostPosted: Fri Dec 16, 2011 6:58 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
i already have a collection of several textfiles and the callback that can list the files. what i want to know is what kind of button to popup a separate box (_with_ a CLOSE button) that displays what is in the file.

FWIW, I have searched for hours and not finding what i want. can anybody help me?

gary kline

PS i don't think i'll need to mess with scrolling, at least not at first. there is one example of GTK_TEXT(text) that refuses to compile!! ...


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Tue Dec 20, 2011 11:06 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I think you want to create your own GtkDialog. Add a GtkScrolledWindow to that, and then a GtkTextView into that.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Tue Dec 20, 2011 11:48 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Micah Carrick wrote:
I think you want to create your own GtkDialog. Add a GtkScrolledWindow to that, and then a GtkTextView into that.



i probably will need the scrolled window eventually; for now i'm thinking of doing an fopen on "/etc/crontab" or the like.

are there any examples of the above?


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Wed Dec 21, 2011 12:01 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Well, this is pretty old, but, here is an example of executing a command into a GtkTextView: Execute command into a GtkTextView (C and Libglade)

These days you would use GtkBuilder instead of libglade, the the concepts of using the GtkTextView are the same.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Wed Dec 28, 2011 9:47 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Well, the long/short of it is that someone showed me how to do it. Adding buttons was like the way you add them anywhere; the text was something else... Way over my head. but i have a new question that i've had for several days now:

How do i get an error or other message in a small window that pops up? the only way you can clear the message window is to hit "Enter". [[ i have found examples, but the code seems too involved for something that should be in a gtk library.

Example:

if (access (filename, F_OK) != 0)
{
printf("ERR: no access to %s\n", filename)'
}

how would i put that error in a popup?


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Thu Dec 29, 2011 4:03 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Well, I don't have any C code off hand, but I usually create a function in my project called 'error_dialog' which shows a simple error message. Something like this (may have typos... I haven't used C in while, I didn't test this, and I've had a couple beers):

Code:
void error_dialog(GtkWindow *parent, const gchar *title, const gchar *message)
{
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new (parent,
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
                                     GTK_MESSAGE_ERROR,
                                     GTK_BUTTONS_OK,
                                     message);
    gtk_window_set_title(GTK_WINDOW(dialog), title);
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
}


And then you would call it like:

Code:
if (some_thing_is_wrong)
{
    error_dialog(window, "Error", "You just messed up buddy! I hope you're happy.");
}

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Thu Dec 29, 2011 6:49 am 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
i can't understand exactly, for which error you want to display message. But it seems you want to display the error message if the file is not accessible. For that try, g_file_get_contents.


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Thu Dec 29, 2011 8:53 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Micah Carrick wrote:
Well, I don't have any C code off hand, but I usually create a function in my project called 'error_dialog' which shows a simple error message. Something like this (may have typos... I haven't used C in while, I didn't test this, and I've had a couple beers):

Code:
void error_dialog(GtkWindow *parent, const gchar *title, const gchar *message)
{
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new (parent,
                                     GTK_DIALOG_DESTROY_WITH_PARENT,
                                     GTK_MESSAGE_ERROR,
                                     GTK_BUTTONS_OK,
                                     message);
    gtk_window_set_title(GTK_WINDOW(dialog), title);
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
}


And then you would call it like:

Code:
if (some_thing_is_wrong)
{
    error_dialog(window, "Error", "You just messed up buddy! I hope you're happy.");
}


i am restoring things after accidentally kicking the power button on my desktop case.... i back things up nightly and RCS saves me too, so *whew*

your eroor_dialog snippet looks exactly what i want. i have a similar program that opens similar popups, but with everything dumped into one gtk src it's a bit hard to walk thru the code and make sense out of it.

in other words:: thanks!


Top
 Profile  
 
 Post subject: Re: how do i create a button that pops-up alreadt existing t
PostPosted: Thu Dec 29, 2011 9:22 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
abhijangda wrote:
i can't understand exactly, for which error you want to display message. But it seems you want to display the error message if the file is not accessible. For that try, g_file_get_contents.



it can be one of N general errors. i'm thinking of the case where the user has created a textfil, but the file is zero-length. in other words, events that may be rare but need to be thought about now.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


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