#!/usr/bin/perl -w ####################################### # # Escputil GTK Perl FrontEnd - Italian # # Copyright (C) Justin Ribeiro # Project Page - http://www.j5studios.com/escputl/index.php # # Translation by Luca De Rugeriis # # 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. # ####################################### use Gtk; use strict; set_locale Gtk; init Gtk; ###################################### # # Set these variables # ###################################### # The name of your printer my $PrinterName = "Epson Stylus C42UX"; # 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/local/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 $window = new Gtk::Window( "toplevel" ); $window->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } ); $window->set_title( "$PrinterName" ); $window->set_usize( 225, 225); $window->border_width( 5 ); $box1 = new Gtk::VBox( $false, 5 ); $box1->show(); $box2 = new Gtk::VBox( $false, 10 ); $box2->border_width( 0 ); $box1->pack_start( $box2, $false, $false, 0 ); $box2->show(); $window->add( $box1 ); $table = new Gtk::Table( 1, 2, $true ); $box2->pack_start( $table, $true, $true, 0 ); # create a label $label = new Gtk::Label(" $PrinterName "); $label->set_justify('left'); $table->attach( $label, 0, 2, 0, 1, "fill", "fill", 0,0 ); $label->show(); $table->show(); $box2 = new Gtk::HBox( $false, 10 ); $box2->border_width( 5 ); $box1->pack_start( $box2, $false, $true, 0 ); $box2->show(); # Create test page print button $button1 = new Gtk::Button( "Prova" ); $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 Gtk::Button( "Pulisci" ); $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 Gtk::Button( "Allinea" ); $button3->signal_connect( "clicked", \&confirm_align_heads ); #$box2->pack_start( $button3, $true, $true, 0 ); #$button3->show(); $window->show(); # Ink Levels Frame $frame = new Gtk::Frame( "Livelli Inchiostro" ); $table2 = new Gtk::Table( 4, 2, $false ); $table2->set_row_spacings( "10" ); $table2->set_col_spacings( "5" ); # create Black Ink Label $labelB = new Gtk::Label("Nero "); $labelB->set_justify( 'left' ); $table2->attach( $labelB, 0, 1, 0, 1, "fill", "fill", 0,0 ); $labelB->show(); # create a Cyan Ink Label $labelC = new Gtk::Label("Ciano "); $labelC->set_justify( 'left' ); $table2->attach( $labelC, 0, 1, 1, 2, "fill", "fill", 0,0 ); $labelC->show(); # create a Magenta Ink Label $labelM = new Gtk::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 Gtk::Label("Giallo "); $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 if ($percents[3] == 100){ $percentageB = "1.0"; } else { $percentageB = "0." . $percents[3]; } $progressB = new Gtk::ProgressBar; $progressB->set_percentage( $percentageB ); $progressB->set_show_text( 1 ); $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]; } $progressC = new Gtk::ProgressBar; $progressC->set_percentage( $percentageC ); $progressC->set_show_text( 1 ); $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]; } $progressM = new Gtk::ProgressBar; $progressM->set_percentage( $percentageM ); $progressM->set_show_text( 1 ); $table2->attach( $progressM, 1, 2, 2, 3, "fill", "fill", 0,0 ); $progressM->show(); # create Yellow ProgressBar if ($percents[2] == 100){ $percentageY = "1.0"; } else { $percentageY = "0." . $percents[2]; } $progressY = new Gtk::ProgressBar; $progressY->set_percentage( $percentageY ); $progressY->set_show_text( 1 ); $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 Gtk; exit( 0 ); # Confirm Test Print Message sub confirm_test_print{ $dialogCD = new Gtk::Dialog(); $dialogCD->set_modal(1); $dialogCD->set_title("Conferma pagina di prova"); $buttonOK = new Gtk::Button( "Continua" ); $buttonOK->signal_connect( "clicked", \&test_print ); $buttonCA = new Gtk::Button( "Annulla" ); $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 Gtk::Label( "\n Sta per essere stampata una pagina di prova: \n" ); $labelNL = new Gtk::Label( "Assicurati che ci sia della carta nella stampante. \n" ); $labelBP = new Gtk::Label( "Quando sei pronto premi Continua \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 Gtk; } # Confirm Clean Heads Message sub confirm_clean_heads{ $dialogCD = new Gtk::Dialog(); $dialogCD->set_modal(1); $dialogCD->set_title("Conferma pulizia testine"); $buttonOK = new Gtk::Button( "Continua" ); $buttonOK->signal_connect( "clicked", \&clean_heads ); $buttonCA = new Gtk::Button( "Annulla" ); $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 Gtk::Label( "\n Sta per iniziare la pulizia delle testine \n" ); $labelBP = new Gtk::Label( "Quando sei pronto premi Continua \n" ); $dialogCD->vbox->pack_start( $labelNW, $true, $true, 0 ); $dialogCD->vbox->pack_start( $labelBP, $true, $true, 0 ); $labelNW->show(); $labelBP->show(); $dialogCD->show(); main Gtk; } # Confirm Align Print Heads Message sub confirm_align_heads{ $dialogCD = new Gtk::Dialog(); $dialogCD->set_modal(1); $dialogCD->set_title("Conferma allineamento testine"); $buttonOK = new Gtk::Button( "Continua" ); $buttonOK->signal_connect( "clicked", \&align_heads ); $buttonCA = new Gtk::Button( "Annulla" ); $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 Gtk::Label( "\n Stanno per essere allineate le testine" ); $labelNN = new Gtk::Label( "\n PUO' ESSERE PERICOLOSO SE NON ESEGUITO CORRETTAMENTE!!!!" ); $labelNL = new Gtk::Label( "\n Leggi la nota all' interno del programma prima di eseguire! \n" ); $labelBP = new Gtk::Label( "Quando sei pronto premi Continua \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 Gtk; } # Error Window sub error_message{ ($title, $message) = @_; $dialogEW = new Gtk::Dialog(); $dialogEW->set_modal(1); $dialogEW->set_title("Errore: $title"); $buttonEW = new Gtk::Button( "OK" ); $buttonEW->signal_connect( "clicked", \&HideButtonEvent ); $dialogEW->action_area->pack_start( $buttonEW, $true, $true, 0 ); $buttonEW->show(); $labelEW = new Gtk::Label( "$message" ); $dialogEW->vbox->pack_start( $labelEW, $true, $true, 0 ); $labelEW->show(); $dialogEW->show(); main Gtk; } # 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; }