From: Omar Campos on
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" , :opts=>
DECOR_TITLE|DECOR_BORDER|DECOR_CLOSE)

@descuentos = Hash.new

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

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

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

#seccion botones
@botones = FXHorizontalFrame.new(@packer,:opts
=>LAYOUT_FILL_X|PACK_UNIFORM_WIDTH)
@btnSubmit = FXButton.new(@botones,"Calcular", :opts=>
BUTTON_NORMAL|LAYOUT_FILL_X)
@btnDesc =
FXButton.new(@botones,"Descuentos",:opts=>BUTTON_NORMAL|LAYOUT_FILL_X)
@btnExit = FXButton.new(@botones,"Salir", :opts=>
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",:opts=>DECOR_TITLE|DECOR_BORDER|DECOR_CLOSE)

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

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

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

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


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

#seccion lista
@lblDesc=FXLabel.new(@main_frame,"Descuentos
actuales:",:opts=>JUSTIFY_LEFT)
@lstDescuentos = FXList.new(@main_frame,:opts=>
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

--------------------------------

I noticed that when I run this code with rubyw, it does not execute,
but with ruby.exe, it runs fine. Am I doing something wrong?
--
Posted via http://www.ruby-forum.com/.

 | 
Pages: 1
Prev: rsruby gem
Next: invalid gem format