Using OCRA, FXRuby and pdf-writer problem

O

Omar Campos

Hello all,

I made a simple salary calculator as practice using FXRuby, OCRA to
create an .exe file and pdf-writer to generate a small "report" with the
results of the calculation. The program runs fine when run with the
ruby interpreter, although I get some warnings:

C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer/lang.rb:33:
warni
ng: method redefined; discarding old language=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer/strokestyle.rb:44
: warning: method redefined; discarding old cap=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer/strokestyle.rb:70
: warning: method redefined; discarding old join=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:434:
warning:
method redefined; discarding old compressed=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:471:
warning:
method redefined; discarding old absolute_left_margin
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:476:
warning:
method redefined; discarding old absolute_right_margin
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:481:
warning:
method redefined; discarding old absolute_top_margin
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:486:
warning:
method redefined; discarding old absolute_bottom_margin
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:492:
warning:
method redefined; discarding old margin_height
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:497:
warning:
method redefined; discarding old margin_width
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:502:
warning:
method redefined; discarding old absolute_x_middle
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:507:
warning:
method redefined; discarding old absolute_y_middle
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:512:
warning:
method redefined; discarding old margin_x_middle
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:517:
warning:
method redefined; discarding old margin_y_middle
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:526:
warning:
method redefined; discarding old y=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:535:
warning:
method redefined; discarding old pointer=
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:1878:
warning:
method redefined; discarding old column_width
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:1885:
warning:
method redefined; discarding old column_gutter
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:1891:
warning:
method redefined; discarding old column_number
C:/Ruby/lib/ruby/gems/1.8/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:1897:
warning:
method redefined; discarding old column_count

Here is my code:
require 'fox16'
require 'pdf/writer'
include Fox

#crea PdfViewer
File.open('pdfviewer.bat','w') do |f| f.write '%1' end

class SueldoCalc < FXMainWindow
def initialize(app)
super(app,"SueldoCalc 1.0" , :eek:pts=>
DECOR_TITLE|DECOR_BORDER|DECOR_CLOSE)

@descuentos = Hash.new

#seccion principal
@packer = FXPacker.new(self, :eek:pts=>LAYOUT_FILL)

#seccion horas
@seccion_horas = FXHorizontalFrame.new(@packer,:eek:pts
=>LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@lblHoras = FXLabel.new(@seccion_horas,"Entre las horas
trabajadas:",:eek:pts=>LAYOUT_FILL_X|JUSTIFY_LEFT)
@txtHoras= FXTextField.new(@seccion_horas,20,:eek:pts=>LAYOUT_FILL_X |
TEXTFIELD_INTEGER)

#seccion rate
@seccion_rate = FXHorizontalFrame.new(@packer,:eek:pts
=>LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@lblRate = FXLabel.new(@seccion_rate,"Entre las
rate/hora:",:eek:pts=>LAYOUT_FILL_X | JUSTIFY_LEFT)
@txtRate= FXTextField.new(@seccion_rate,20,:eek:pts=>LAYOUT_FILL_X |
TEXTFIELD_REAL )

#seccion botones
@botones = FXHorizontalFrame.new(@packer,:eek:pts
=>LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@btnSubmit = FXButton.new(@botones,"Calcular", :eek:pts=>
BUTTON_NORMAL|LAYOUT_FILL_X)
@btnDesc =
FXButton.new(@botones,"Descuentos",:eek:pts=>BUTTON_NORMAL|LAYOUT_FILL_X)
@btnExit = FXButton.new(@botones,"Salir", :eek:pts=>
BUTTON_NORMAL|LAYOUT_FILL_X)

#eventos
@btnSubmit.connect(SEL_COMMAND) do
sueldo = @txtHoras.to_s.to_f * @txtRate.to_s.to_f

#calcula descuentos
total_descuentos = 0
@descuentos.each_pair { |key,desc|
cant_descontar = (desc/100) * sueldo
total_descuentos = total_descuentos +cant_descontar
}

sueldo_neto = sueldo-total_descuentos

pdf = PDF::Writer.new
#pdf.select_font "Times-Roman"
pdf.text "SueldoCalc 1.0", :justification =>
:center,:font_size=>50
pdf.text "_" * 21

pdf.text "Informe de cálculo", :justification =>
:center,:font_size=>24


pdf.text "Sueldo Bruto: #{sprintf('%5.2f',sueldo)}",:font_size=>16
pdf.text "Sueldo Neto: #{sprintf('%5.2f',sueldo_neto)}"
pdf.text "Descuentos Aplicados:"
#mensaje full
#mensaje = "Sueldo Bruto: #{sprintf('%5.2f',sueldo)}\n"
#mensaje = mensaje +"Sueldo Neto:
#{sprintf('%5.2f',sueldo_neto)}\n"
#mensaje = mensaje + "Descuentos Aplicados:\n"

@descuentos.each_pair { |key,value|
pdf.text " "*5+key+": "+value.to_s+" \% \n"
}
pdf.text ' '
pdf.text "Gracias por utlizar nuestro programa!", :justification
=> :center

File.open("Sueldocalc.pdf","w") { |f| f.write pdf.render }

system "PdfViewer.bat Sueldocalc.pdf"

#FXMessageBox.information(self,MBOX_OK,"SueldoCalc",mensaje)

end

@btnExit.connect(SEL_COMMAND) do
exit
end

@btnDesc.connect(SEL_COMMAND) do
desc_form = Descuento.new(app,@descuentos)
desc_form.create
end


end

def create
super
show(PLACEMENT_SCREEN)
end

end

class Descuento < FXMainWindow

def Carga_Descuentos
@lstDescuentos.clearItems()
@descuentos.each_pair { |key,value| @lstDescuentos.appendItem( key +
': '+ value.to_s) }
end

def initialize(app,descuentos)
super(app,"Descuentos",:eek:pts=>DECOR_TITLE|DECOR_BORDER|DECOR_CLOSE)

#trae los descuentos de la forma principal
@descuentos = descuentos

#frame principal (vertical)
@main_frame =
FXVerticalFrame.new(self,:eek:pts=>LAYOUT_FILL|PACK_UNIFORM_WIDTH)

#seccion de añádir descuentos
#seccion de escribir el nombre
@add_desc_frame = FXHorizontalFrame.new(@main_frame,:eek:pts=>
LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@lblNombre= FXLabel.new(@add_desc_frame,"Nombre de
descuento:",:eek:pts=>LAYOUT_FILL_X|JUSTIFY_LEFT)
@txtNombreDesc =
FXTextField.new(@add_desc_frame,20,:eek:pts=>LAYOUT_FILL_X)

#seccion de escribir el descuento
@add_num_frame = FXHorizontalFrame.new(@main_frame,:eek:pts=>
LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@lblCantidad= FXLabel.new(@add_num_frame,"Cantidad a
descontar:",:eek:pts=>LAYOUT_FILL_X|JUSTIFY_LEFT)
@txtCantidad =
FXTextField.new(@add_num_frame,20,:eek:pts=>LAYOUT_FILL_X | TEXTFIELD_REAL)


#sección botones
@desc_botones =
FXHorizontalFrame.new(@main_frame,:eek:pts=>LAYOUT_FILL|PACK_UNIFORM_WIDTH)
@btnAdd=FXButton.new(@desc_botones,"Anadir",:eek:pts=>LAYOUT_FILL_X|BUTTON_NORMAL)
@btnDel=FXButton.new(@desc_botones,"Borrar",:eek:pts=>LAYOUT_FILL_X|BUTTON_NORMAL)
@btnReturn =
FXButton.new(@desc_botones,"Volver",:eek:pts=>LAYOUT_FILL_X|BUTTON_NORMAL)

#seccion lista
@lblDesc=FXLabel.new(@main_frame,"Descuentos
actuales:",:eek:pts=>JUSTIFY_LEFT)
@lstDescuentos = FXList.new(@main_frame,:eek:pts=>
LAYOUT_FILL_X|FRAME_SUNKEN )

#eventos
@btnReturn.connect(SEL_COMMAND) do
destroy
end

@btnAdd.connect(SEL_COMMAND) do
@descuentos [@txtNombreDesc.to_s] = @txtCantidad.to_s.to_f if
@txtNombreDesc.to_s.length >0 and @txtCantidad.to_s.to_f >0
self.Carga_Descuentos
@txtNombreDesc.text=''
@txtCantidad.text=''
end
end

def create
super
show(PLACEMENT_SCREEN)
end

end

app=FXApp.new
sc = SueldoCalc.new(app)

app.create
app.run
 
L

Luis Lavena

Hello all,

  I made a simple salary calculator as practice using FXRuby, OCRA to
create an .exe file and pdf-writer to generate a small "report" with the
results of the calculation.  The program runs fine when run with the
ruby interpreter, although I get some warnings:

Warnings are normal,

When you want to attach an application code, use services like Pastie
or Gist from GitHub to avoid long emails...

For some reason your or one of the libraries is outputting to the
standard console.

RubyW is a windowless environment and thus, all puts and things will
fail because there is no standard console attached to it.

When you run it with ruby.exe, do you get all these warnings? I guess
not, but just to verify.
 
O

Omar Campos

When you want to attach an application code, use services like Pastie
or Gist from GitHub to avoid long emails...

Ok, I'll keep that in mind. I'm still rather new to this forum. Where
can I find info about these services?
RubyW is a windowless environment and thus, all puts and things will
fail because there is no standard console attached to it.

When you run it with ruby.exe, do you get all these warnings? I guess
not, but just to verify.

Yes, the warnings appear only when using RubyW, or when running the .exe
made with OCRA with the script saved as .rb (which internally uses
ruby.exe, it seems). when running with RubyW, or the OCRA-made .exe
with script saved as .rbw, no warnings appear and the program simply
terminates.
 
O

Omar Campos

Hi again,

I did some more testing and found the following:

I commented out any lines that had to do with the pdf generation, ran
the app using RubyW and it worked. I then uncommented the the line:

require 'pdf/writer'

Now, running with rubyw, nothing happens. It seems that something
inside pdf/writer does not let rubyw work properly. Have you, or anyone
else out there, encountered this problem?
 
C

Chris Hulan

Hi again,

 I did some more testing and found the following:

I commented out any lines that had to do with the pdf generation, ran
the app using RubyW and it worked.  I then uncommented the the line:

require 'pdf/writer'

  Now, running with rubyw, nothing happens.  It seems that something
inside pdf/writer does not let rubyw work properly. Have you, or anyone
else out there, encountered this problem?

I think it is the warning messages that are causing the issue
They abort execution when using ruybw because stdout (or it maybe
stderr) doesn't exist
You may be able to redirect stdout and stderr to a file (or /dev/null)
before requiring the pdf lib so the messages have a valid place to go

cheers
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top