G Messenger
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
  G::Messenger.pm G-language GAE Messaging API
Package variables
Privates (from "my" definitions)
%data;
$term;
$gimv = 'gimv'
$console;
$progress;
Included modules
Cwd
Inherit
AutoLoader Exporter
Synopsis
  use G::Messenger;

  &msg_send("this is an output"); #prints message to STDOUT
  &msg_error("this is an error"); #prints message to STDERR
  &msg_gimv("graph.png");         #shows the image via gimv (G-language IMage Viewer)
Description
  Methods used in Odyssey:

    msg_send()
        Prints out a regular output message. The output is STDOUT in CUI mode,
        and text output in Gtk+, wxWindows, and INSPIRE modes.
        Synonym of "print".

    msg_error()
	Prints out an error or system message. The output is STDERR in CUI mode,
        and system console in Gtk+, wxWindows, and INSPIRE modes.
        Synonym of "print STDOUT".

    msg_gimv()
        Shows the image via gimv (G-language IMage Viewer). The gimv program will
        startup in Gtk+ and wxWindows mode, and only the file path is passed on
        in INSPIRE mode.
        Synonym of "system('gimv image.png')".

  Methods used in Engines:

    msg_percent()
        Sets the progress bar to the given percentage.

  Methods used in User Interfaces (INSPIRE):

    msg_interface()
        Sets the interface that the system currently uses. 'GUI' for Gtk+ mode,
        'Wx' for wxWindows mode, 'Inspire' for INSPIRE mode, and none or 'STDOUT'
        for CUI mode. All Messenger output bases the interpretation of the current
        user interface on the value set with this function.

    msg_system_console()
        In Gtk+ and wxWindows mode, system console widget instance should be supplied.
        In INSPIRE mode, the reference to a subroutine that interpret the job of system
        console should be supplied. Messages sent with msg_error() are passed to the 
        given reference.

    msg_term_console()
        In Gtk+ and wxWindows mode, term console widget instance should be supplied.
        In INSPIRE mode, the reference to a subroutine that interpret the job of term
        console should be supplied. Messages sent with msg_send() are passed to the 
        given reference.

    msg_progress()
        In Gtk+ and wxWindows mode, progress bar widget instance should be supplied.
        In INSPIRE mode, the reference to a subroutine that interpret the job of progress
        bar may be supplied. Messages sent with msg_percent() are passed to the 
        given reference.

    msg_set_gimv()
        In INSPIRE mode, the reference to a subroutine that interpret the job of gimv
        should be supplied. Messages sent with msg_gimv() are passed to the given 
        reference.

    msg_ask_interface()
        Returns the current mode.
Methods
msg_ask_interface
No description
Code
msg_error
No description
Code
msg_gimv
No description
Code
msg_interface
No description
Code
msg_percent
No description
Code
msg_progress
No description
Code
msg_send
No description
Code
msg_set_gimv
No description
Code
msg_system_console
No description
Code
msg_term_console
No description
Code
Methods description
None available.
Methods code
msg_ask_interfacedescriptionprevnextTop
sub msg_ask_interface {
    return $data{"interface"};
}
msg_errordescriptionprevnextTop
sub msg_error {
    my @msg = @_;

    if ($data{"interface"} eq 'GUI'){
	$data{"system"} .= join('', @msg);
	$console->insert('','','',join('', @msg));
    }elsif ($data{"interface"} eq 'Wx'){
	my $tmp = join('', @msg);
	$data{"system"} .= $tmp;
	$console->WriteText(scalar($tmp));
    }elsif ($data{'interface'} eq 'Inspire'){
	my $tmp = join('', @msg);
	$data{"system"} .= $tmp;
	&$console($tmp);
    }else{
	print STDERR @msg;
    }
}
msg_gimvdescriptionprevnextTop
sub msg_gimv {
    my $file = shift;
    my $time = 'gimv' . time();

    if ($data{"interface"} eq 'Inspire'){
	&$gimv($file);
    }else{
	if('MSWin32' eq $^O){
	    my $dir = getcwd() unless (substr($file, 0, 1) eq '/');
	    my $filename = $dir . '/' . $file;
	    if ($filename =~ /[htm|html]$/){
		$data{$time} = Win32::InternetExplorer::Window->new();
	    }else{
		my ($x, $y) = Image::Size::imgsize($filename);
		$data{$time} = Win32::InternetExplorer::Window->new(
								    height=>$y+60,
								    width=>$x+50
								    );
	    }
	    $data{$time}->display('\G-language\title.jpg');
	    $data{$time}->display_wait($filename);
	}else{
	    $gimv = 'mozilla' if ($file =~ /html$/ && $gimv eq 'gimv');
	    $gimv = 'mozilla' if ($file =~ /svg$/ && $gimv eq 'gimv');
	    $file = 'file://' . getcwd() . '/' . $file if ($gimv eq 'mozilla');
	    system("$gimv $file &");
	}
    }
}
msg_interfacedescriptionprevnextTop
sub msg_interface {
    $data{"interface"} = shift;
}
msg_percentdescriptionprevnextTop
sub msg_percent {
    my $percent = shift;

    if ($data{"interface"} eq 'GUI'){
	$progress->update($percent);
    }elsif ($data{"interface"} eq 'Wx'){
	$progress->SetValue($percent);
        $progress->Refresh();
    }
}
msg_progressdescriptionprevnextTop
sub msg_progress {
    $progress = shift;
}
msg_senddescriptionprevnextTop
sub msg_send {
    my @msg = @_;

    if ($data{"interface"} eq 'GUI'){
	$data{"term"} .= join('',@msg);
	$term->insert('','','',join('',@msg));
    }elsif ($data{"interface"} eq 'Wx'){
	my $tmp = join('', @msg);
	$data{"term"} .= $tmp;
	$term->WriteText(scalar($tmp));
    }elsif ($data{'interface'} eq 'Inspire'){
	my $tmp = join('', @msg);
	$data{"term"} .= $tmp;
	&$term($tmp);
    }else{
	print STDOUT @msg;
    }
}
msg_set_gimvdescriptionprevnextTop
sub msg_set_gimv {
    $gimv = shift;
}
msg_system_consoledescriptionprevnextTop
sub msg_system_console {
    $console = shift;
}
msg_term_consoledescriptionprevnextTop
sub msg_term_console {
    $term = shift;
}
General documentation
INTRODUCTIONTop
  One of the key features of the G-language Genome Analysis Environment is the 
  ease of use and development of different user interfaces. With very little 
  modification, a script intended for commandline Perl use can be transformed
  into a cross-platform GUI application using wxWindows, or a web application 
  using INSPIRE. The Messaging API G::Messenger.pm is what makes this possible.
  All output in the software system is passed to the interface provided by this
  API, and Messenger interprets the current user interface to give correct form
  of output. It is essential to create Odyssey Subroutines using this API, and 
  to create new user interfaces.
AUTHORTop
  Kazuharu Arakawa, gaou@sfc.keio.ac.jp
SEE ALSOTop
perl(1).