Re: GTKConvert Units.exw with Carpenters Fractions
- Posted by Senator
Aug 10, 2018
--# GtkConvertUnits.exw - <b>by Jim Roberts</b> - convert from one unit to another
-- Gtk interface by Irv Mullins -- Thanks, Irv!
-- several changes by Kenneth Rhodes including carpenters fractions display for inches
include GtkEngine.e
include GtkConvertUnits.e
constant
win=create(GtkWindow, "title=Convert by Jim Roberts,border_width=10,position=1,$destroy=Quit"),
panel=create(GtkBox, "orientation=HORIZONTAL,spacing=10"),
cb1=create(GtkComboBoxText, "tooltip text=Select Category of Unit Measures"),
V1=create(GtkEntry, "placeholder text=Value to convert,tooltip text=Enter Value to Convert,$changed=Convert" ),
cb2=create(GtkComboBoxText, "tooltip text = Select Input Unit, $changed=Convert"),
cb3=create(GtkComboBoxText, "tooltip text = Select Output Unit,$changed=Convert"),
V2=create(GtkEntry, "width chars=25, placeholder text=Results" )
add(win,panel) add(panel,{cb1,V1,cb2,cb3,V2})
for i = 1 to length(index) do
set(cb1,"append text",index[i])
end for
connect(cb1,"changed","Update")
show_all(win)
main()
function SelectUnits(integer i)
-- returns a sequence of unit labels
object units = {}
for a = 1 to length(Unit[i]) by 2 do
units = append(units, Unit[i][a])
end for
return units
end function
---------------------------
global function Update()
---------------------------
integer u = get(cb1,"active")
object units = SelectUnits(u)
set(cb2,"remove all") set(cb3,"remove all")
for j = 1 to length(units) do
set(cb2,"append text",units[j]) set(cb3,"append text",units[j])
end for
set(cb2,"active",1) set(cb3,"active",1)
return 1
end function
global function Convert()
----------------------------
atom val = to_number(get(V1,"text"))
object from_units = get(cb2,"active text")
object to_units = get(cb3,"active text")
object c ={}
if val = 0 then return 1 end if
if atom(from_units) or atom(to_units) then return 1 end if
object results = ConvertUnit(val,from_units, to_units)
results[1] = from_units results[2] = to_units results = append(results,val)
if match( "in", to_units) then
c= carp( results[3], in_in) c = prepend(c, from_units )
c = prepend(c, val)
c =sprintf("%g %s = %g %g/%g inches", {c[1],c[2],c[3],c[4],c[5]})
set(V2,"text", c)
set(V2,"tooltip markup",text:format("[4] [1] = [3] [2]",results))
else
set(V2,"tooltip markup",text:format("[4] [1] = [3] [2]",results))
results[3] = sprintf("%.4g",results[3])
set(V2, "text", text:format("[4] [1] = [3] [2]",results))
end if
return 1
end function
Not Categorized, Please Help
|
|