Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 01 Nov 2014, 05:53
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog/Bash Application in System Task Bar
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Sat 08 Sep 2012, 15:06    Post subject:  GtkDialog/Bash Application in System Task Bar  

Hi,

i wonder if it is possible to have a Bash/GtkDialog Application sitting in the Task Bar as small icon -at the right side, just like the firewall icon- instead of having a big button at the Task Bar?

No, not like "show icons only" in the FbPanel Settings.

Is this possible?

What would i have to do?

RSH

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sat 08 Sep 2012, 15:14    Post subject:  

Dear RSH,

I don't think thunor has done the tray icon bit yet for gtkdialog - but you can use gtrayicon 1.1 for this purpose and have it run a gtkdialog script.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Sat 08 Sep 2012, 17:03    Post subject:  

vovchik wrote:
Dear RSH,

I don't think thunor has done the tray icon bit yet for gtkdialog - but you can use gtrayicon 1.1 for this purpose and have it run a gtkdialog script.

With kind regards,
vovchik

Thank you veery much, vovchik.

I did find gtrayicon already installed in LazY Puppy. Unfortunately the --help and --help-all command gives me nothing what I could understand to be able to run a script from gtrayicon.

Do you have any example code or similar?

RSH

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7841
Location: qld

PostPosted: Sat 08 Sep 2012, 18:35    Post subject:  

RSH

Here's a different approach
Code:
#include <gtk/gtk.h>
#include <gdk/gdk.h>

/* gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0` (to compile)*/

GdkPixbuf *a_pixbuf;
GError *gerror = NULL;
GtkStatusIcon *tray_icon;


void tray_icon_on_click(GtkStatusIcon *status_icon,
                        gpointer user_data)
{
        printf("Clicked on tray icon\n"); //you can comment this
        system("example.sh");
}


static GtkStatusIcon *create_tray_icon()
{
        //GtkStatusIcon *tray_icon;

        tray_icon = gtk_status_icon_new();
        g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
                         
        a_pixbuf=gdk_pixbuf_new_from_file("/usr/local/lib/X11/pixmaps/utility24.png",&gerror);
       
        gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
                                           
        gtk_status_icon_set_tooltip(tray_icon, "Start Utility Example");
                                   
        gtk_status_icon_set_visible(tray_icon, TRUE);

        return tray_icon;
}

int main(int argc, char **argv) {
      
      GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);
       
        tray_icon = create_tray_icon();
       
        gtk_main();

        return 0;
}

I named this file example.c

It will run anything in $PATH named example.sh. You can also add a right click menu (look at my tempicon_source for a rough example in utilities section)

Be careful with C! A little knowledge of it is dangerous! (like I am Laughing )

You also could try techno's SIT

There are also examples in genie language in the genie/vala thread, but they are a bit old now and will give compile warnings.
example.png
 Description   
 Filesize   43.9 KB
 Viewed   698 Time(s)

example.png


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sat 08 Sep 2012, 18:37    Post subject:  

RSH,

You might find technosaurus' SIT program useful here-
http://murga-linux.com/puppy/viewtopic.php?t=76431

It places an icon in the tray and allows you lots of options for running programs.

Cheers,
s
(SIT=Simple Icon Tray)
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4353

PostPosted: Sat 08 Sep 2012, 19:35    Post subject:  

seaside wrote:
RSH,

You might find technosaurus' SIT program useful here-
http://murga-linux.com/puppy/viewtopic.php?t=76431

It places an icon in the tray and allows you lots of options for running programs.

Cheers,
s
(SIT=Simple Icon Tray)
it will now do as many icons as will fit in your tray along with left and right mouse click actions, but most importantly it automatically refreshes the image when it is changed (gtkdialog and gtrayicon do not - though I posted a hacky patch for gtkdialog) The most recent version is cross platform too and still in <20 lines compiling to <3kb. Zigbert's ptray is a good alternative too if you are using jwm (I have started integrating that function into jwm tools too)
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Mon 10 Sep 2012, 17:08    Post subject:  

Hi everyone.

Thanks for all the replies and useful tips and suggestions. Very Happy

I will use this one, because it makes me totally independent in creating system tray applications - for the rest of my life. Cool

01micko wrote:
RSH

Here's a different approach
Code:
#include <gtk/gtk.h>
#include <gdk/gdk.h>

/* gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0` (to compile)*/

GdkPixbuf *a_pixbuf;
GError *gerror = NULL;
GtkStatusIcon *tray_icon;


void tray_icon_on_click(GtkStatusIcon *status_icon,
                        gpointer user_data)
{
        printf("Clicked on tray icon\n"); //you can comment this
        system("example.sh");
}


static GtkStatusIcon *create_tray_icon()
{
        //GtkStatusIcon *tray_icon;

        tray_icon = gtk_status_icon_new();
        g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
                         
        a_pixbuf=gdk_pixbuf_new_from_file("/usr/local/lib/X11/pixmaps/utility24.png",&gerror);
       
        gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
                                           
        gtk_status_icon_set_tooltip(tray_icon, "Start Utility Example");
                                   
        gtk_status_icon_set_visible(tray_icon, TRUE);

        return tray_icon;
}

int main(int argc, char **argv) {
      
      GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);
       
        tray_icon = create_tray_icon();
       
        gtk_main();

        return 0;
}

I named this file example.c

It will run anything in $PATH named example.sh. You can also add a right click menu (look at my tempicon_source for a rough example in utilities section)

Be careful with C! A little knowledge of it is dangerous! (like I am Laughing )

You also could try techno's SIT

There are also examples in genie language in the genie/vala thread, but they are a bit old now and will give compile warnings.

My knowledge on C is surely less than nothing. But -as you might know- if one has good/rich knowledge on at least one programming language makes it easier to read different code - especially if something like clear (human language) text is inside the code. I have good/rich knowledge of PASCAL (which is a lot different to C) and -by now- nearly good based knowledge on bash and so, i could read the code, could modify it for my purposes and was able to compile it.

Thanks a lot for this C example - it surely will be used in several applications to come.

RSH

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Tue 11 Sep 2012, 19:12    Post subject:  

Oh, that's wonderful.

I was able to add a right-click menu to the above C Code and also to add some new functions, that runs several applications. Also i do check inside this functions if the application is available. If not, it runs the RunScript for the use of the SFS.

That's pretty cool, since this was my first real "hack" ever on C Code.

@ 01micko

The tempicon application has been very helpful on that. I assume it will be alright, if i post my "hacked" Code here? I think it could be interesting to others and maybe someone will find a bug on this... Laughing

Code:
//#############################################################################
// System Tray Application Starter
// Original C Code by 01micko
// Modified by RSH for the use of the LazY DNS - (D)ow(N)load (S)uite
// LazY DNS Wrapper 0.3
//#############################################################################
// to compile: gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0`
//#############################################################################

// Include Files
#include <gtk/gtk.h>
#include <gdk/gdk.h>

// Icons
GdkPixbuf *a_pixbuf;
GtkStatusIcon *tray_icon;

// Error Check on File Open
GError *gerror = NULL;

// File and Filenames
FILE *fp;
char lazyfredname[37]="/usr/local/LazY-FReD/set_preferences";
char lazyreconame[30]="/usr/local/LazY-FReD/LazYReCo";
char lazymaidname[30]="/usr/local/LazY-MAID/LazYMAID";

//#############################################################################
// Right-Click Functions called from Menu
//#############################################################################

// Run LazY FReD
static run_lazy_fred(){
   fp = fopen(lazyfredname,"r");
   if(fp == NULL)
   {
      system("/root/.my-sfs-scripts/LP2_LazY-FReD-1.0.3.sfs.Scripts/LP2_LazY-FReD-1.0.3.sfs.LazY-FReD.run.sh &");
      return 1;
   }
   system("/usr/local/LazY-FReD/set_preferences &");
}

// Run LazY ReCo
static run_lazy_reco(){
   fp = fopen(lazyreconame,"r");
   if(fp == NULL)
   {
      system("/root/.my-sfs-scripts/LP2_LazY-FReD-1.0.3.sfs.Scripts/LP2_LazY-FReD-1.0.3.sfs.LazY-ReCo.run.sh &");
      return 1;
   }
   system("/usr/local/LazY-FReD/LazYReCo &");
}

// Run LazY MAID
static run_lazy_maid(){
   fp = fopen(lazymaidname,"r");
   if(fp == NULL)
   {
      system("/root/.my-sfs-scripts/LP2_LazY-MAID-1.0.2.sfs.Scripts/LP2_LazY-MAID-1.0.2.sfs.LazY-MAID.run.sh &");
      return 1;
   }
   system("/usr/local/LazY-MAID/LazYMAID &");
}

//#############################################################################
// Left-Click Function on System Tray Icon
//#############################################################################

// Run LazY DNS if left-clicked on icon
static tray_icon_on_click(GtkStatusIcon *status_icon,
                  gpointer user_data)
{
   system("/usr/local/LazY-DNS/LazYDNS");
}

//#############################################################################
// Right-Click-Menu Functions
//#############################################################################

// Menu Entry LazY DNS
void  view_popup_menu_run_lazy_dns (GtkWidget *menuitem, gpointer user_data)
{
    system("/usr/local/LazY-DNS/LazYDNS &");
}
// Menu Entry LazY FReD
void  view_popup_menu_run_lazy_fred (GtkWidget *menuitem, gpointer user_data)
{
    run_lazy_fred();
}
// Menu Entry LazY ReCo
void  view_popup_menu_run_lazy_reco (GtkWidget *menuitem, gpointer user_data)
{
    run_lazy_reco();
}
// Menu Entry LazY MAID
void  view_popup_menu_run_lazy_maid (GtkWidget *menuitem, gpointer user_data)
{
    run_lazy_maid();
}
// Menu Entry Quit
void  view_popup_menu_quit (GtkWidget *menuitem, gpointer user_data)
{
    gtk_main_quit();
}
// nothing
static  view_popup_menu_dummy (GtkWidget *menuitem, gpointer user_data)
{
   return 2;
}

//#############################################################################
// Menu Function
//#############################################################################

// Right-Click on System Tray Icon
void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
{
   GtkWidget *menu, *menuitem;
   menu = gtk_menu_new();
   menuitem = gtk_menu_item_new_with_label("LazY DNS 0.3 Download Suite");
   g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_dns, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new();
   //g_signal_connect(menuitem, "none", (GCallback) view_popup_menu_dummy, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new_with_label("LazY FReD Free Repository Downloader");
   g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_fred, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new_with_label("LazY ReCo Repository Collector");
   g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_reco, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new_with_label("LazY MAID Murga-Linux Attachment-Index Downloader");
   g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_maid, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new();
   //g_signal_connect(menuitem, "none", (GCallback) view_popup_menu_dummy, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   menuitem = gtk_menu_item_new_with_label("LazY DNS 0.3 Beenden");
   g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_quit, status_icon);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   gtk_widget_show_all(menu);
   gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, gdk_event_get_time(NULL));
}

//#############################################################################
// System Tray Icon
//#############################################################################

// Create Tray Icon
static GtkStatusIcon *create_tray_icon()
{
   tray_icon = gtk_status_icon_new();
   g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
    g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL);
   a_pixbuf=gdk_pixbuf_new_from_file("/usr/local/LazY-DNS/icons/lazydns24.png",&gerror);
   gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
   gtk_status_icon_set_tooltip(tray_icon, "LazY DNS 0.3 Download Suite");
   gtk_status_icon_set_visible(tray_icon, TRUE);
   return tray_icon;
}

//#############################################################################
// Main Program Functions
//#############################################################################

// Main Program
int main(int argc, char **argv)
{
   gtk_init(&argc, &argv);
   create_tray_icon();
   gtk_main();
   return 0;
}

//#############################################################################
// End of LazY DNS Wrapper
//#############################################################################


I have also written a script to compile this C Code. If you click the script it wants to compile example.c inside the script's directory. But you can drag & drop a C Code file from any else directory onto this script and it compiles the dropped file. So you can rename this or the above example.c and compile it using a new name for it.

This script is only for the use on the above posted C Code files!

Code:
#!/bin/sh

FindExec="gcc"
file_to_compile="$1"
f_t_c="`basename $file_to_compile`"
d_t_c="`dirname $file_to_compile`"
nlen="`echo ${#f_t_c}`"
o_f=${f_t_c:0:$nlen-2}

Titel="Compiling $f_t_c"

if [ "$(which $FindExec)" ]; then
   echo "C Compiler already loaded"
   else
   Xdialog --title "$Titel" --wrap --screen-center --center --ok-label "Load" --cancel-label "Do ot load" --yesno "\nC Compiler missing. \n\nUYou have to load the devx.sfs of your puppy." 0 0
   exit 1
   #if [ "$?" = "0" ]; then
   #   sfs_load --cli --quiet Your_DevX_Here.sfs
   #fi
fi

if [ "$(which $FindExec)" ]; then
   if [ "$file_to_compile" = "" ]; then
      # compile example.c
      lxterminal -e gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0`
      else
      # compile file dropped on the script
      cd $d_t_c
      lxterminal -e gcc -o "$o_f" "$f_t_c" `pkg-config --libs --cflags gtk+-2.0`
   fi
fi

exit 0

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1374s ][ Queries: 13 (0.0371s) ][ GZIP on ]