LinuxQuestions.org
Visit Jeremy's Blog.
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-2006, 10:52 AM   #1
General
Member
 
Registered: Aug 2005
Distribution: Debian 7
Posts: 526

Rep: Reputation: 31
'dialog' app for GTK+2.0


I am writing a bash script that will bring up a "Open file" dialog displaying files with a *.hex ending. Once the file is chosen, the path of the file is sent to a variable, so that the bash script can perform some tasks on that given file.

I am wondering if there is a program, like the curses-based dialog app, that can display a GTK+2.0 file selection dialog. I found this application, but the file selection dialog that it uses doens't look anything like those in the rest of the GNOME desktop. I am not a programmer so I probably could not make a stand-alone program that does this.
 
Old 04-23-2006, 11:02 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Not really an answer but a suggestion - maybe Python can serve your purpose better for GUI purposes since it has many modules like pygtk, pyglade and so on which are easier to use.
 
Old 04-23-2006, 11:21 AM   #3
General
Member
 
Registered: Aug 2005
Distribution: Debian 7
Posts: 526

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Harishankar
Not really an answer but a suggestion - maybe Python can serve your purpose better for GUI purposes since it has many modules like pygtk, pyglade and so on which are easier to use.
Thanks! I will look into that.
 
Old 04-23-2006, 12:02 PM   #4
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
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,
Code:
./fc
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.
 
Old 04-23-2006, 12:05 PM   #5
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Well, that's one way, but then why not write the whole program in C?
 
Old 04-23-2006, 12:17 PM   #6
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Quote:
Well, that's one way, but then why not write the whole program in C?
Why? There's nothing wrong with combining languages to produce a more flexible program. Not to mention,

Quote:
Once the file is chosen, the path of the file is sent to a variable, so that the bash script can perform some tasks on that given file.
depending on what "some tasks" are, that could involve a helluva lot of C!!
 
Old 04-23-2006, 01:10 PM   #7
General
Member
 
Registered: Aug 2005
Distribution: Debian 7
Posts: 526

Original Poster
Rep: Reputation: 31
95se, that is exactly what I need. Thanks very much!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Dialog modal+GTK santhosh.linux Programming 1 02-20-2006 11:47 AM
GTK 2.0 problems in displaying dialog boxes stephenwalter Programming 1 01-20-2006 01:21 AM
GTK+ dialog: want to display buttons vertically in action area paulsm4 Programming 0 06-22-2005 06:46 PM
gtk app problem emg Linux - Software 3 04-30-2005 01:22 PM
gtk+ dialog, data check before close danxl Programming 1 10-11-2003 11:29 PM

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

All times are GMT -5. The time now is 01:25 AM.

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