LinuxQuestions.org
Help answer threads with 0 replies.
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 08-09-2012, 10:27 AM   #1
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Rep: Reputation: 17
simple opensuse gui to run shell scripts


Friends,

I have done some googling and see many suggestions but thought I would seek the wisdom of this forum.
My goal :
I have 4 shell scripts.
call them : play , stop , fast forward , rewind

these currently work if i call them[ ./stop etc...]

I would like a simple gui
a small rectangle with 4 buttons ( yes , play,stop etc ]

what might be the simplest way for a fellow to start
to have a window open w 4 buttons etc.

this is for open suse 11.1 -- 12.1 64 bit kde

thanks much
 
Old 08-09-2012, 11:36 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Not sure about a GUI, but you could easily create keyboard shortcuts to run them.
 
Old 08-09-2012, 12:13 PM   #3
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Original Poster
Rep: Reputation: 17
well i have them as alias in my .bashrc
but would like something the MacFanBoys can mash down on.
[ theyz love theyz mice ]
 
Old 08-09-2012, 09:38 PM   #4
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
I put this command line in a launcher in my desktop panel.
Code:
/usr/bin/xterm -bg black -fg white -geometry 6x3+1324+986 -e ~/bin/timer.sh
You might play around with this.


timer.sh looks like this.
Code:
#!/bin/bash
##
read time
sleep "$time"m;
/usr/bin/mplayer /usr/share/sounds/gnome/elkbugle.ogg;

Last edited by Dafydd; 08-09-2012 at 09:49 PM.
 
Old 08-10-2012, 12:45 AM   #5
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
Depends on what GUI toolkit you want to use. If your a C programmer and a *Nix user(Which you are), then use GTK2.xx. If your a C++ coder, QT maybe. I've heard its better than GTKMM(C++'s version of GTK). I use the GTK toolkit. Python has PyGTK and QT. But you get the point. There are lots of other toolkits out there as well. Just hit Google up.

Ill boot up my Arch box and whip up a GUI for you real quick with GTK.
 
Old 08-10-2012, 01:48 AM   #6
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
Here is a simple GUI using the GTK2.xx toolkit. I do not like version 3.

GUI CODE:
Code:
#include <gtk/gtk.h>

static void destroy_event(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}

static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
gtk_main_quit();
return FALSE;
}

static void play(GtkWidget *widget, GdkEvent *event, gpointer data ) {
execl("", "", "", (char *)NULL); // Call your play script and execute it
}

static void fast_fwd(GtkWidget *widget, GdkEvent *event, gpointer data ) {
execl("", "", "", (char *)NULL); // Call your fast_forward script and execute it
}

static void _rewind(GtkWidget *widget, GdkEvent *event, gpointer data ) {
execl("", "", "", (char *)NULL); // Call your rewind script and execute it
}

static void stop( GtkWidget *widget, GdkEvent *event, gpointer data ) {
execl("", "", "", (char *)NULL); // Call your stop script and execute it
}

//To compile append `pkg-config --cflags --libs gtk+-2.0`
int main(int argc, char *argv[]) {

GtkWidget *window;
GtkWidget *table;
GtkWidget *play_button;
GtkWidget *stop_button;
GtkWidget *rewind_button;
GtkWidget *ff_button;
GtkWidget *frame;

GtkWidget *play_image;
GtkWidget *stop_image;
GtkWidget *_rewind_image;
GtkWidget *ff_image;

GtkTooltips *tooltips;

GdkPixbuf *play_pixbuf;
GdkPixbuf *stop_pixbuf;
GdkPixbuf *ff_pixbuf;
GdkPixbuf *_rewind_pixbuf;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Media Control");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
gtk_widget_show(window);

table = gtk_table_new(10, 10, TRUE);
gtk_container_add(GTK_CONTAINER(window), table);
gtk_widget_show(table);

frame = gtk_frame_new(NULL);
gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 9, 1, 9);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
gtk_widget_show(frame);

play_button = gtk_button_new();
gtk_table_attach_defaults(GTK_TABLE(table), play_button, 2, 5, 5, 8);
gtk_widget_show(play_button);

tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, play_button, "Click to play music.", NULL);

stop_button = gtk_button_new();
gtk_table_attach_defaults(GTK_TABLE(table), stop_button, 5, 8, 5, 8);
gtk_widget_show(stop_button);

tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, stop_button, "Click to stop playback", NULL);

ff_button = gtk_button_new();
gtk_table_attach_defaults(GTK_TABLE(table), ff_button, 5, 8, 2, 5);
gtk_widget_show(ff_button);

tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, ff_button, "Click to fast forward music.", NULL);

rewind_button = gtk_button_new();
gtk_table_attach_defaults(GTK_TABLE(table), rewind_button, 2, 5, 2, 5);
gtk_widget_show(rewind_button);

tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, rewind_button, "Click to rewind music.", NULL);

  play_pixbuf = gdk_pixbuf_new_from_file("/path/to/play.png", NULL);
  play_image = gtk_image_new_from_pixbuf(play_pixbuf);
  gtk_container_add(GTK_CONTAINER(play_button), play_image);
  gtk_widget_show(play_image);

  stop_pixbuf = gdk_pixbuf_new_from_file("/path/to/stop.png", NULL);
  stop_image = gtk_image_new_from_pixbuf(stop_pixbuf);
  gtk_container_add(GTK_CONTAINER(stop_button), stop_image);
  gtk_widget_show(stop_image);

  _rewind_pixbuf = gdk_pixbuf_new_from_file("/path/to/rewind.png", NULL);
  _rewind_image = gtk_image_new_from_pixbuf(_rewind_pixbuf);
  gtk_container_add(GTK_CONTAINER(play_button), _rewind_image);
  gtk_widget_show(_rewind_image);

  ff_pixbuf = gdk_pixbuf_new_from_file("/path/to/fast_fwd.png", NULL);
  ff_image = gtk_image_new_from_pixbuf(ff_pixbuf);
  gtk_container_add(GTK_CONTAINER(ff_button), ff_image);
  gtk_widget_show(ff_image);

  g_signal_connect_swapped(G_OBJECT(window), "destroy-event",
      G_CALLBACK(destroy_event), NULL);

  g_signal_connect_swapped(G_OBJECT(window), "delete-event",
      G_CALLBACK(delete_event), NULL);

  g_signal_connect(play_button, "clicked",
      G_CALLBACK(play), (gpointer)"button");

  g_signal_connect_swapped(ff_button, "clicked",
      G_CALLBACK(fast_fwd), (gpointer)"button");

  g_signal_connect_swapped(stop_button, "clicked",
      G_CALLBACK(stop), (gpointer)"button");

  g_signal_connect_swapped(rewind_button, "clicked",
      G_CALLBACK(_rewind), (gpointer)"button");

gtk_main();

return 0;
}
Just edit the execl params to fit your scripts. The callback functions will execute your scripts when the corresponding buttons are pressed. The png images for the buttons have to be scaled down to fit inside the containers or it will enlarge the top level window. Or you could just use plain text for the buttons if you do not want to do all that work(Which really isnt much!). So instead of having a blue triangle for the play widget, you could display the word play inside instead. Up to you though.

You must have libgtk2.0-dev installed to get this code running. And to compile, append

`pkg-config --cflags --libs gtk+-2.0`

to the end of your CLI compilation args

Any questions feel free to ask.

Last edited by amboxer21; 08-10-2012 at 02:48 AM.
 
1 members found this post helpful.
Old 08-10-2012, 08:13 AM   #7
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Original Poster
Rep: Reputation: 17
Thanks Amboxer21

I will have to give this a try...
but that will not be til monday due to travel ..

thanks much
 
Old 08-10-2012, 08:26 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
How about dialog or zenity?
 
1 members found this post helpful.
Old 08-10-2012, 11:46 AM   #9
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Original Poster
Rep: Reputation: 17
yes both dialog & zenity are good ideas.
I have used dialog -- the good thing with it is -- no xorg
( or that is my understanding )
 
Old 08-10-2012, 12:14 PM   #10
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
Quote:
Originally Posted by zimbot View Post
Thanks Amboxer21

I will have to give this a try...
but that will not be til monday due to travel ..

thanks much
Seeing pixellany's response; I can't help but feel that my response was an overkill.

Last edited by amboxer21; 08-10-2012 at 12:15 PM.
 
Old 08-12-2012, 08:53 PM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I have used yad (the zenity fork) in the past with decent success writing scripts this such as this.

yad driven choices and program execution

with some tweaking, I bet this could be done handily.

Last edited by Habitual; 08-14-2012 at 08:30 AM.
 
Old 08-13-2012, 10:19 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Using yad...
See attachment

Last edited by Habitual; 06-26-2015 at 05:47 PM.
 
Old 08-13-2012, 11:12 AM   #13
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
Code:
bash-4.2# xmessage -buttons play,stop,ff,rew ":-)"
Click image for larger version

Name:	xmessage.png
Views:	27
Size:	4.7 KB
ID:	10358
 
1 members found this post helpful.
  


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
LXer: A GUI Progress Bar for Shell Scripts LXer Syndicated Linux News 0 12-11-2011 01:42 AM
Basic GUI (non-x) needed to run bash scripts AP81 Programming 8 02-09-2007 09:38 AM
How can I set scripts to run at startup? openSuSE 10.1 x86 iceportal SUSE / openSUSE 13 09-25-2006 10:29 AM
How do you run shell scripts? shadowdrums Slackware 5 05-15-2006 11:02 AM
How to? Run Shell scripts jmr0311 Mandriva 2 07-14-2004 09:24 PM

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

All times are GMT -5. The time now is 09:31 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