Saturday, February 7, 2009

Display Reminders In Gnome Panel

 It was a long standing requirement of mine to create a reminder software or something which can keep me reminding of things as I always keep forgetting things. So I made a reminder that displays my reminders on the Gnome Panel.
It looks something like this:

So how do we do it?

1st of all we need to display the program we need in the Add to Panel.

For that we add to the bonobo server list. We do this by adding the following code in the folder  /usr/lib/bonobo/servers/. Let us name the file as GNOME_PerlApplet.server
The content of this file should be :
<oaf_info>
  <oaf_server iid="OAFIID:PerlSampleApplet_Factory" type="exe" location="/home/rsrijith/perl/panel-applet">
    <oaf_attribute name="repo_ids" type="stringv">
      <item value="IDL:Bonobo/GenericFactory:1.0"/>
      <item value="IDL:Bonobo/Unknown:1.0"/>
    </oaf_attribute>
    <oaf_attribute name="name" type="string" value="Panel Reminder"/>
    <oaf_attribute name="description" type="string" value="Perl Program working in Panel"/>
  </oaf_server>

  <oaf_server iid="OAFIID:PerlSampleApplet" type="factory" location="OAFIID:PerlSampleApplet_Factory">
    <oaf_attribute name="repo_ids" type="stringv">
      <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
      <item value="IDL:Bonobo/Control:1.0"/>
      <item value="IDL:Bonobo/Unknown:1.0"/>
    </oaf_attribute>
    <oaf_attribute name="name" type="string" value="Panel Reminder"/>
    <oaf_attribute name="description" type="string" value="Perl Program working in Panel:R Srijith"/>
    <oaf_attribute name="panel:category" type="string" value="Amusements"/>
    <oaf_attribute name="panel:icon" type="string" value="bug-buddy.png"/>
  </oaf_server>
</oaf_info>
So this specifies the location of the perl file to run on adding this applet. So here it is /home/rsrijith/perl/panel-applet . This file should print the reminders to be printed on the panel.
The program need the Following packages:

Perl packages:

    • ExtUtils::Depends
    • ExtUtils::PkgConfig
    • Gnome2::GConf
    • Gnome2::PanelApplet
    You install this using
    sudo perl -MCPAN -e 'install <package-name>'

    Linux Package:
      • libpanelappletmm-2.6-1c2
      • libpanelappletmm-2.6-dev
      You install this using
      sudo apt-get install <package-name>

        Thus the perl file content is :
        #!/usr/bin/perl -w

        use warnings;
        use utf8;
        use Gnome2::PanelApplet;
        Gnome2::Program->init ('A Stupid Applet Written in Perl', '0.01', 'libgnomeui',
                               sm_connect => FALSE);

        Gnome2::PanelApplet::Factory->main ('OAFIID:PerlSampleApplet_Factory',
                                            'Gnome2::PanelApplet',
                                            \&fill);


        sub fill {
          my ($applet, $iid, $data) = @_;

          if ($iid ne 'OAFIID:PerlSampleApplet') {
            return FALSE;
          }
         
          my $menu_xml = <<EOX;
        <popup name="button3">
          <menuitem name="Properties Item"
                    verb="Birthdays"
                    _label="Birthdays"
                pixtype="stock"
                pixname="gtk-properties"/>
          <menuitem name="DesktopSwitcher Item"
                verb="DesktopSwitcher"
                _label="Wallpaper Switcher"
                pixtype="stock"
                pixname="gtk-stock"/>
            <menuitem name="Walldelete Item"
                verb="Walldelete"
                _label="Wallpaper Delete"
                pixtype="stock"
                pixname="gtk-stock"/>              
          <menuitem name="About Item"
                verb="About"
                _label="About"
                pixtype="stock"
                pixname="gnome-stock-about"/>
        </popup>
        EOX

          my $cb_mapping = {
            Birthdays => [\&properties_callback, 'default!'],
            DesktopSwitcher => \&deskswitcher_callback,
            Walldelete => \&walldelete_callback,
            About => \&about_callback,
          };

          $applet->setup_menu($menu_xml, $cb_mapping, 'default?');
          our $i=0;our @line;

          our $label = Gtk2::Label->new;
          $label->set_justify("left");
            $label->set_line_wrap(TRUE);
            $label->modify_font(Gtk2::Pango::FontDescription->from_string("Monospace 10"));
            $label->modify_fg("normal", Gtk2::Gdk::Color->parse("Black"));
          $applet->add ($label);
          $applet->show_all;
         
         Glib::Timeout->add (5000, \&update_value);
         #Glib::Timeout->add (500, \&update_list);
         sub update_list{
         open FILE,"/home/rsrijith/panel_remind";
          @line=<FILE>;
          close FILE;
         }
         sub update_value
         {
         
          my @string=split(':',$line[0]);
          $label->modify_fg("normal", Gtk2::Gdk::Color->parse($string[0]));
          $label->set_markup("\n".$string[1]);
          update_list();
         }
        }

        sub deskswitcher_callback
        {
         system('/home/rsrijith/shell/deskback 2>>/home/rsrijith/logs/desktopbackground');
        }

        sub walldelete_callback
        {
         system('/home/rsrijith/shell/deletewall 2>>/home/rsrijith/logs/desktopbackground');
        }

        sub properties_callback {
            my $b="";
                open BDAY,"/home/rsrijith/shell/birthdays1";
            while(<BDAY>)
            { $b.=$_."\n";
            }
          my $dialog = Gtk2::MessageDialog->new (undef, [],
                                                 'info', 'ok',
                                                 $b);
          $dialog->run;
          $dialog->destroy;
        }


        sub about_callback {
          my $about = Gnome2::About->new ('Panel Reminder', '0.1',
                                          'Perl Program working in Panel',
                                          '© 2009 R.Srijith',
                                          'R.Srijith <rsrijith007@gmail.com');
          $about->show;
        }

        This program prints the contents of /home/rsrijith/panel_remind
        An Example of the content of that file should be as

        Blue:Happy Birthday to Mahima
        So that's it!! And Happy Birthday Mahima.


        Comment me if you have any doubts or if it's not working.

        1 comment:

        1. on my laptop the installation of package "libpanelappletmm-2.6-dev" pulled an additional 15 MB of other dependent -dev packages(pacakge list is quite long). So I think this is side-effect of coding applet in perl, which is not that exciting. On the other hand coding applet in C/C++ might avoid the installing of -dev package on the end user's box(developers need them anyway).

          ReplyDelete