Finance-Quant

 view release on metacpan or  search on metacpan

scripts/FINANCE_QUANT_TRAY  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Glib qw/TRUE FALSE/;


package Gtk2::Ex::ZNotify;
use Gtk2;
use Glib qw/TRUE FALSE/;

use constant wbsize           => 16;    #window border size
use constant messageTextWidth => 300;

use Glib::Object::Subclass Gtk2::Window::
 ,#parent class, derived from Glib::Object
 signals => {
   show               => \&on_show,
   size_allocate      => \&on_size_allocate,
   style_set          => \&on_style_set,
   expose_event       => \&on_expose_event,
   enter_notify_event => \&on_enter_notify_event,
   leave_notify_event => \&on_leave_notify_event,
 },
 properties => [

   Glib::ParamSpec->object(
      'parent_widget',                                   'parent_widget',
      'The parent widget on which this popup will show', 'Gtk2::Widget',
      [ qw/readable writable/ ]
   ),
   Glib::ParamSpec->string(
      'message',
      'message',
      'The heading for this message',
      'This is sample heading',
      [ qw/readable writable/ ]
   ),

   Glib::ParamSpec->enum(
      'messageType',             'messageType',
      'Type of message this is', 'Gtk2::MessageType',
      'info', [ qw/readable writable/ ]
   ),

   Glib::ParamSpec->int(
      'timeout', 'timeout',
      'Timeout in milli-seconds before hide, 0 = never hide',
      0, 10000000, 0, [ qw/readable writable/ ]
   ),

   Glib::ParamSpec->int(
      'x', 'x',
      'x position for pointer',
      0, 64000, 0, [ qw/readable writable/ ]
   ),

   Glib::ParamSpec->int(
      'y', 'y',
      'y position for pointer',
      0, 64000, 0, [ qw/readable writable/ ]
   ),

 ];

sub INIT_INSTANCE {

   my $self = shift;

   $self->{ activeBackgroundColor } =
    new Gtk2::Gdk::Color( ( 249 * 257 ), ( 253 * 257 ), ( 202 * 257 ) );
    #Remember to * with 257!!
 
   $self->{ inactiveBackgroundColor } =
    new Gtk2::Gdk::Color( ( 255 * 257 ), ( 255 * 257 ), ( 255 * 257 ) );

#Initial setup
   $self->app_paintable( TRUE );
   $self->{ activebackground }   = undef;
   $self->{ inactivebackground } = undef;

#Create the layout of the window
   my $outBox = new Gtk2::HBox();
   $outBox->set_border_width( wbsize );

   $self->add( $outBox );

   my $closeBox = new Gtk2::VBox();
   $closeBox->set_border_width( 3 );

scripts/FINANCE_QUANT_TRAY  view on Meta::CPAN

      ( $xorg + 1 ) => ( ( $yorg + $width ) - 2 ),
      ( $xorg + 1 ) => ( ( $yorg + $width ) - 4 ),
      $xorg => ( ( $yorg + $width ) - 4 ),
   );
   return @list;
}

package main;

use Gtk2 -init;
use MIME::Base64;

# a 32 X 32 png
my $icodata = decode_base64(
      'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAAGXcA1uAAAABGdBTUEAALGPC/xhBQAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wBDgQJDdztR18AAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAB1ElEQVRIx81VzUrrQBT+kjpOzI10k51u3IobC14o6CwD+hA...
   );

my $icopixbuf = do {
     my $loader = Gtk2::Gdk::PixbufLoader->new();
     $loader->write( $icodata );
     $loader->close();
     $loader->get_pixbuf();
  };

my ($xscr, $yscr) = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height);
#print "$xscr $yscr\n";

my $window = Gtk2::Window->new;
$window->set_border_width(10);
$window->set_title('Window 0');
my $width = 300;
my $height = 100;
$window->set_size_request($width,$height);
$window->set_gravity('GDK_GRAVITY_SOUTH_EAST');
$window->signal_connect( delete_event => sub { Gtk2->main_quit; 1 } );
$window->move($xscr,$yscr);

my $window1 = Gtk2::Window->new;
$window1->set_border_width(10);
$window1->set_title('Window 1');
$window1->set_size_request($width,$height);
$window1->set_gravity('GDK_GRAVITY_SOUTH_WEST');
$window1->move(0,$yscr);

my $window2 = Gtk2::Window->new;
$window2->set_border_width(10);
$window2->set_title('Window 2');
$window2->set_size_request($width,$height);
$window2->set_gravity('GDK_GRAVITY_NORTH_WEST');
$window2->move(0,0);

my $statusicon = Gtk2::StatusIcon->new_from_pixbuf($icopixbuf);
# will make a nice icon automagically from a file if desired
#my $statusicon = Gtk2::StatusIcon->new_from_file('stock.png');

$statusicon->set_tooltip( "Info v1.0" );
#show in tray
$statusicon->set_visible( 1 );

$statusicon->signal_connect( 'activate',   sub { print "1\n" } );
$statusicon->signal_connect( 'popup-menu', \&config_it );

my $vbox = Gtk2::VBox->new;
my $b    = Gtk2::Button->new_from_stock( "gtk-close" );
$b->signal_connect('button_press_event' => sub { exit  });
$vbox->pack_start( $b, TRUE, TRUE, 0 );
$window->add( $vbox );
$vbox->show_all;

#$window->show_all();
#$window1->show_all();
#$window2->show_all();

# messageTypes: info warning question error

my $id3 = Glib::Timeout->add (10000, sub {

   my ($screen,$rect)=$statusicon->get_geometry;
   my ($x,$y,$w, $h) = $rect->values;
#  print "exposed $x $y $w $h\n";
  my @message = ();

  my $reports=`tree /tmp/Finance-Quant/ | egrep -c '*html'`;  
  my $bt=`tree /tmp/Finance-Quant/ | egrep -c '*data'`;
  my $stb=`tree -f /tmp/Finance-Quant/ | egrep -c 'ibes-strong-buy'`;
  my $symbols = `tree /tmp/Finance-Quant/ | egrep directories`;
  my $charts=`tree -f /tmp/Finance-Quant/ | egrep -c 'charts'`;
  

 # $symbols =~ s/^(.*)directories, (.*)files/$2/;
  
  
  
  my $test = Gtk2::Ex::ZNotify->new(
      type          => 'popup',
      #   parent_widget => $window, # undefind, use x y location
      "messageType"   => "info",
      "timeout"       => 10000,
      "message"       => "".($symbols)."strong buy:".($stb-1)."\nbacktests:".$bt."reports:".$reports." charts:".$charts,
      "x"             => ($x + $w/2),
      "y"             => ($y + $h ),
   );
 $test->show_all();
 return  1;	# don't run again
  });


Gtk2->main;


sub click {

   
   return 1;
}


#right click menu
sub menu {
   my $menu = Gtk2::Menu->new();

   #VCI
   my $menu_VCI = Gtk2::ImageMenuItem->new_with_label("CLI UI");
   $menu_VCI->set_image(Gtk2::Image->new_from_stock('gtk-refresh',
'menu'));

      $menu_VCI->signal_connect(activate => sub {
print system ('financequant &');
   });


   $menu->add($menu_VCI);

   #configure
   my $menu_pref = Gtk2::ImageMenuItem->new_with_label("XML DUMP");
      $menu_pref->signal_connect(activate => sub {
my $response=0;
 my $error =0;
print system ('FINANCE_QUANT_XML_RESULTS');

print $response;
   });
   $menu_pref->set_image(Gtk2::Image->new_from_stock('gtk-preferences','menu'));
   $menu->add($menu_pref);



   #configure
   my $menu_http = Gtk2::ImageMenuItem->new_with_label("HTTP REPORTS");
      $menu_http->signal_connect(activate => sub {
            system("FINANCE_QUANT_HTTP_SERVER &");
   });
   $menu_http->set_image(Gtk2::Image->new_from_stock('gtk-media-play','menu'));
   $menu->add($menu_http);



   #separator
   my $menu_sep = Gtk2::SeparatorMenuItem->new();
   $menu->add($menu_sep);

   #Quit
   my $menu_quit = Gtk2::ImageMenuItem->new_with_label("Quit");
   $menu_quit->signal_connect(activate => sub {Gtk2->main_quit});
   $menu_quit->set_image(Gtk2::Image->new_from_stock('gtk-quit', 'menu'));
   $menu->add($menu_quit);


   
   return $menu;
}



#Program interfaces
sub interface {
   my $interface = Gtk2::Menu->new;

   #menu items for VCI
   #Progress bar for number of downloads; just a countng bar

   #Add the correct controls to menu
   my $menu_vci_connect = Gtk2::ImageMenuItem->new_with_label("Connect");
   $interface->add($menu_vci_connect);
   my $menu_vci_stop = Gtk2::ImageMenuItem->new_with_label("Stop");
   $interface->add($menu_vci_stop);

   $interface->show_all;
    
   

}




sub config_it{

my $menu = menu();
   $menu->show_all();

 #to position the menu under the icon, instead of at mouse position
 my ($x, $y, $push_in) = Gtk2::StatusIcon::position_menu($menu, $statusicon);
 print "$x, $y, $push_in\n";
 $menu->popup( undef, undef, sub{return ($x,$y,0)} , undef, 0, 0 );
 return 1;
}

1;


__DATA__
=head1 NAME
  
  FINANCE_QUANT_TRAY
  
=head1 DESCRIPTION

  TRAY icon displaying calculation progress

=head1 SYNOPSIS

  FINANCE_QUANT_TRAY

=head1 SEE ALSO

  part of Finance::Quant  
  
=head1 AUTHOR

  Hagen Geissler, E<lt>santex@cpan.org<gt>
  
=head1 COPYRIGHT AND LICENSE
  Copyright (C) 2012 by Hagen Geissler
  This library is free software; you can redistribute it and/or modify
  it under the same terms as Perl itself, either Perl version 5.12.4 or,
  at your option, any later version of Perl 5 you may have available.
=cut



( run in 0.947 second using v1.01-cache-2.11-cpan-364913b4093 )