Codice: Seleziona tutto
#!/usr/bin/perl -w
#######################################
#
# Escputil Gtk Perl FrontEnd
#
# Copyright (C) Justin Ribeiro <ribeiro@J5studios.com>
# Project Page - http://www.j5studios.com/escputl/index.php
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 of
# the License or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# 02/06/2003
# JDR - Need to fix align functionality. Been disabled for the time being.
#
# This software is a front end to Robert Krawitz's superb program
# escputil, which is part of the gimp-print project. You'll need
# escputil to use this program, because this script is only a
# simple Gtk Perl frontend to escputil.
#
# This program was written because I wanted a small little script to
# get ink levels, that didn't require many dependencies. While I was
# at it, I added some buttons for functions such as test print, cleaning
# heads and print head alignment.
#
# You must set the variables below for your specific printer.
# Tested with:
#
# Epson Stylus Photo 785EPX
# Epson Stylus C42UX
#
# Simply chmod +x this file, and you should be able to run it.
#
# Feel free to make changes and additions; I'm open to suggestions
# and fixes. Released under the GPL License. Use at your own risk.
#
#######################################
#
# Ported to Gtk2 by LuYu. 15 12 2003
#
#
#######################################
use Gtk2 '-init';
use strict;
######################################
#
# Set these variables
#
######################################
# The name of your printer
my $PrinterName = "Epson Stylus Color670";
# Raw printer device (i.e. If USB: /dev/usb/lp0 If Parallel: /dev/lpd0)
my $RawDevice = "/dev/usb/lp0";
# If USB printer, set to 1
my $USBp = "1";
# Path to escputil
# Default usually is /usr/local/bin/escputil
# Could be also /usr/bin/escputil
# run " which escputil " without quotes on command line to find your path.
#
my $escputil = "/usr/bin/escputil";
######################################
######################################
# Editing below this line could be a hazard....
######################################
my $false = 0;
my $true = 1;
my $Uvar = "";
my $window;
my $box1;
my $box2;
my $label;
my $button1; # Test
my $button2; # Clean
my $button3; # Align
my $frame; # Ink Level Frame
my $table; # Printer Name 1x2
my $table2; # Ink Levels 4x2
##### Ink Levels and Labels Vars
my @percents;
my $in;
my $labelB;
my $labelC;
my $labelM;
my $labelY;
my $progressB;
my $progressC;
my $progressM;
my $progressY;
my $percentageB;
my $percentageC;
my $percentageM;
my $percentageY;
##### Sub Confirm Windows Vars
my $dialogCD;
my $buttonOK;
my $buttonCA;
my $labelNW;
my $labelNL;
my $labelBP;
my $labelNN;
##### Sub error_message Vars
my $dialogEW;
my $buttonEW;
my $labelEW;
my $title;
my $message;
my $PrinterModel = "";
# Set the -u if we need it
if ($USBp == "1"){
my $Uvar = "-u";
} else {
my $Uvar = "";
}
# Create the window
my $window = Gtk2::Window->new( "toplevel" );
# $window = new Gtk2::Window( "toplevel" );
$window->signal_connect ( destroy => sub { Gtk2->main_quit; } );
# $window->signal_connect( "delete_event", sub { Gtk2->exit( 0 ); } );
$window->set_title( "$PrinterName" );
#$window->set_usize( 225, 225 );
#$window->border_width( 5 );
$box1 = new Gtk2::VBox( $false, 5 );
$box1->show();
$box2 = new Gtk2::VBox( $false, 10 );
#$box2->border_width( 0 );
$box1->pack_start( $box2, $false, $false, 0 );
$box2->show();
$window->add( $box1 );
$table = new Gtk2::Table( 1, 2, $true );
$box2->pack_start( $table, $true, $true, 0 );
# create a label
$label = new Gtk2::Label( " $PrinterName " );
$label->set_justify( 'left' );
$table->attach( $label, 0, 2, 0, 1, "fill", "fill", 0,0 );
$label->show();
$table->show();
$box2 = new Gtk2::HBox( $false, 10 );
#$box2->border_width( 5 );
$box1->pack_start( $box2, $false, $true, 0 );
$box2->show();
# Create test page print button
$button1 = new Gtk2::Button( "Test" );
$button1->signal_connect( "clicked", \&confirm_test_print);
$box2->pack_start( $button1, $true, $true, 0 );
$button1->show();
$window->show();
# Create clean print head button
$button2 = new Gtk2::Button( "Clean" );
$button2->signal_connect( "clicked", \&confirm_clean_heads );
$box2->pack_start( $button2, $true, $true, 0 );
$button2->show();
$window->show();
# Create align print head button
$button3 = new Gtk2::Button( "Align" );
$button3->signal_connect( "clicked", \&confirm_align_heads );
#$box2->pack_start( $button3, $true, $true, 0 );
#$button3->show();
$window->show();
# Ink Levels Frame
$frame = new Gtk2::Frame( "Ink Levels" );
$table2 = new Gtk2::Table( 4, 2, $false );
$table2->set_row_spacings( "10" );
$table2->set_col_spacings( "5" );
# create Black Ink Label
$labelB = new Gtk2::Label("Black ");
$labelB->set_justify( 'left' );
$table2->attach( $labelB, 0, 1, 0, 1, "fill", "fill", 0,0 );
$labelB->show();
# create a Cyan Ink Label
$labelC = new Gtk2::Label("Cyan ");
$labelC->set_justify( 'left' );
$table2->attach( $labelC, 0, 1, 1, 2, "fill", "fill", 0,0 );
$labelC->show();
# create a Magenta Ink Label
$labelM = new Gtk2::Label("Magenta ");
$labelM->set_justify( 'right' );
$table2->attach( $labelM, 0, 1, 2, 3, "fill", "fill", 0,0 );
$labelM->show();
# create a Yellow Ink Label
$labelY = new Gtk2::Label("Yellow ");
$labelY->set_justify( 'left' );
$table2->attach( $labelY, 0, 1, 3, 4, "fill", "fill", 0,0 );
$labelY->show();
# get percents
my @output = `$escputil -r $RawDevice -u -i -q`;
foreach $in (@output){
$in =~ s/\n//g ;
$in =~ s/[A-z]//g;
$in =~ s/ //g;
unshift(@percents, $in);
}
######
# create Black ProgressBar
$percentageB = $percents[3];
# if ( $percents[3] == 100 )
# {
# $percentageB = "1.0";
# }
# else
# {
# $percentageB = "0." . $percents[3];
# }
$progressB = new Gtk2::ProgressBar;
$progressB->set_fraction( $percentageB/100 );
$progressB->set_text( "$percentageB %" );
$table2->attach( $progressB, 1, 2, 0, 1, "fill", "fill", 0,0 );
$progressB->show();
# create Cyan ProgressBar
# if ($percents[0] == 100){
# $percentageC = "1.0";
# } else {
# $percentageC = "0." . $percents[0];
# }
$percentageC = $percents[2];
$progressC = new Gtk2::ProgressBar;
$progressC->set_fraction( $percentageC/100 );
$progressC->set_text( "$percentageC %" );
$table2->attach( $progressC, 1, 2, 1, 2, "fill", "fill", 0,0 );
$progressC->show();
# create Magenta ProgressBar
# if ($percents[1] == 100){
# $percentageM = "1.0";
# } else {
# $percentageM = "0." . $percents[1];
# }
$percentageM = $percents[1];
$progressM = new Gtk2::ProgressBar;
$progressM->set_fraction( $percentageM/100 );
$progressM->set_text( "$percentageM %" );
$table2->attach( $progressM, 1, 2, 2, 3, "fill", "fill", 0,0 );
$progressM->show();
# create Yellow ProgressBar
# if ($percents[0] == 100){
# $percentageY = "1.0";
# } else {
# $percentageY = "0." . $percents[2];
# }
$percentageY = $percents[0];
$progressY = new Gtk2::ProgressBar;
$progressY->set_fraction( $percentageY/100 );
$progressY->set_text( "$percentageY %" );
$table2->attach( $progressY, 1, 2, 3, 4, "fill", "fill", 0,0 );
$progressY->show();
$table->show();
$frame->add( $table2 );
$box1->pack_start( $frame, $false, $false, 0 );
$window->show_all();
# main Gtk2;
Gtk2->main;
exit( 0 );
# Confirm Test Print Message
sub confirm_test_print{
$dialogCD = new Gtk2::Dialog();
$dialogCD->set_modal(1);
$dialogCD->set_title("Confirm Test Print");
$buttonOK = new Gtk2::Button( "Continue" );
$buttonOK->signal_connect( "clicked", \&test_print );
$buttonCA = new Gtk2::Button( "Cancel" );
$buttonCA->signal_connect( "clicked", \&cancel );
$dialogCD->action_area->pack_start( $buttonOK, $true, $true, 0 );
$dialogCD->action_area->pack_start( $buttonCA, $true, $true, 0 );
$buttonOK->show();
$buttonCA->show();
$labelNW = new Gtk2::Label( "\n You are about to print a test page. \n" );
$labelNL = new Gtk2::Label( "Please make sure you have a piece of paper in the printer. \n" );
$labelBP = new Gtk2::Label( "When you are ready, hit continue below. \n" );
$dialogCD->vbox->pack_start( $labelNW, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelNL, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelBP, $true, $true, 0 );
$labelNW->show();
$labelNL->show();
$labelBP->show();
$dialogCD->show();
main Gtk2;
}
# Confirm Clean Heads Message
sub confirm_clean_heads{
$dialogCD = new Gtk2::Dialog();
$dialogCD->set_modal(1);
$dialogCD->set_title("Confirm Clean Heads");
$buttonOK = new Gtk2::Button( "Continue" );
$buttonOK->signal_connect( "clicked", \&clean_heads );
$buttonCA = new Gtk2::Button( "Cancel" );
$buttonCA->signal_connect( "clicked", \&cancel );
$dialogCD->action_area->pack_start( $buttonOK, $true, $true, 0 );
$dialogCD->action_area->pack_start( $buttonCA, $true, $true, 0 );
$buttonOK->show();
$buttonCA->show();
$labelNW = new Gtk2::Label( "\n You are about to clean the print heads. \n" );
$labelBP = new Gtk2::Label( "When you are ready, hit continue below. \n" );
$dialogCD->vbox->pack_start( $labelNW, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelBP, $true, $true, 0 );
$labelNW->show();
$labelBP->show();
$dialogCD->show();
main Gtk2;
}
# Confirm Align Print Heads Message
sub confirm_align_heads{
$dialogCD = new Gtk2::Dialog();
$dialogCD->set_modal(1);
$dialogCD->set_title("Confirm Align Heads");
$buttonOK = new Gtk2::Button( "Continue" );
$buttonOK->signal_connect( "clicked", \&align_heads );
$buttonCA = new Gtk2::Button( "Cancel" );
$buttonCA->signal_connect( "clicked", \&cancel );
$dialogCD->action_area->pack_start( $buttonOK, $true, $true, 0 );
$dialogCD->action_area->pack_start( $buttonCA, $true, $true, 0 );
$buttonOK->show();
$buttonCA->show();
$labelNW = new Gtk2::Label( "\n You are about to align the print heads." );
$labelNN = new Gtk2::Label( "\n THIS CAN BE DANGEROUS IF NOT SETUP CORRECTLY!!!!" );
$labelNL = new Gtk2::Label( "\n Please read the notice in this program before attempting! \n" );
$labelBP = new Gtk2::Label( "When you are ready, hit continue below. \n" );
$dialogCD->vbox->pack_start( $labelNW, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelNN, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelNL, $true, $true, 0 );
$dialogCD->vbox->pack_start( $labelBP, $true, $true, 0 );
$labelNW->show();
$labelNN->show();
$labelNL->show();
$labelBP->show();
$dialogCD->show();
main Gtk2;
}
# Error Window
sub error_message{
($title, $message) = @_;
$dialogEW = new Gtk2::Dialog();
$dialogEW->set_modal(1);
$dialogEW->set_title("Error: $title");
$buttonEW = new Gtk2::Button( "OK" );
$buttonEW->signal_connect( "clicked", \&HideButtonEvent );
$dialogEW->action_area->pack_start( $buttonEW, $true, $true, 0 );
$buttonEW->show();
$labelEW = new Gtk2::Label( "$message" );
$dialogEW->vbox->pack_start( $labelEW, $true, $true, 0 );
$labelEW->show();
$dialogEW->show();
main Gtk2;
}
# Test Print Command
sub test_print{
my $test_print = `$escputil -r $RawDevice $Uvar -n -q`;
$dialogCD->hide;
}
# Clean Heads Command
sub clean_heads{
my $clean_heads = `$escputil -r $RawDevice $Uvar -c -q`;
$dialogCD->hide;
}
# Align Heads Command
sub align_heads{
if ($PrinterModel != ""){
my $align_heads = `$escputil -m $PrinterModel -a -q`;
$dialogCD->hide;
} else {
my $align_heads = `$escputil -r $RawDevice $Uvar -a -q`;
$dialogCD->hide;
}
}
# Cancel Command
sub cancel{
$dialogCD->hide;
}
# Hide the Error Message Window
sub HideButtonEvent{
$dialogEW->hide;
}