Hey, put this into a file called fc.c,
Code:
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *filechooser;
GtkFileFilter *filter;
int resp;
gtk_init(&argc, &argv);
filechooser = gtk_file_chooser_dialog_new("Choose File", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT,
NULL);
filter = gtk_file_filter_new();
gtk_file_filter_add_pattern(filter, "*.hex");
gtk_file_filter_set_name(filter, "Hex Files (*.hex)");
gtk_file_chooser_add_filter(filechooser, filter);
if((resp = gtk_dialog_run(GTK_DIALOG(filechooser))) == GTK_RESPONSE_ACCEPT) {
printf("%s\n",
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser)));
}
gtk_widget_destroy(filechooser);
return (resp == GTK_RESPONSE_ACCEPT ? 0 : 1);
}
Then compile it w/
Code:
gcc fc.c -o fc `pkg-config --cflags --libs gtk+-2.0`
Now you have an executable called fc, run it,
It'll pop up a box, choose a file, it'll write the file name chosen to standard out, then return 0 if successful, 1 if they pressed cancel (Check w/ the bash var $?).
So,
file="`./fc`"
Also, this only let's you choose .hex files, but you can remove anything that says filter to get it to let you choose all, or you could just mess w/ it.
|