eumandy/eugtk/examples/test190.ex
2016-11-25 00:33:18 -07:00

77 lines
2.5 KiB
Elixir

------------------------------------------------------------------------------------
--# Using GtkPrinter.e, print from a disk file;
------------------------------------------------------------------------------------
include GtkEngine.e
include GtkPrinter.e
constant docs = "Demo of how to print from a disk file"
constant custom_header =
"<span background='cyan' color='red' font='Purisa, Ubuntu Mono, Serif 10'>" &
"<i><b> [1] </b></i> </span>\n" &
"<span color='blue'><i>Please leave this 3x5\" card on [9]'s desk!</i>\n\n</span>"
constant win = create(GtkWindow,"border=10,size=300x100,position=1,$destroy=Quit")
constant panel = create(GtkBox,VERTICAL)
add(win,panel)
constant lbl = create(GtkLabel)
set(lbl,"markup",docs)
add(panel,lbl)
constant box = pack_end(panel,create(GtkButtonBox)),
btn1 = add(box,create(GtkButton,"gtk-quit","Quit")),
btn2 = add(box,create(GtkButton,"gtk-print",_("SelectFile"))),
btn3 = add(box,create(GtkButton,"gtk-print",_("PrintCard"),"~/demos/resources/license.txt"))
set(btn2,"tooltip markup","This prints on legal paper with the default header")
set(btn3,"tooltip markup","This prints a 3x5 index card with custom header")
show_all(win)
main()
------------------------------------------------------------------------
function SelectFile()
------------------------------------------------------------------------
object dlg = create(GtkFileChooserDialog,{
{"title","Open a file"},
{"transient for",win},
{"action",GTK_FILE_CHOOSER_ACTION_OPEN},
{"add button","gtk-cancel",MB_CANCEL},
{"add button","gtk-ok",MB_OK}})
if get(dlg,"run") = MB_OK then
printer:reset() -- use defaults
printer:PrintFile(get(dlg,"filename"))
end if
set(dlg,"hide")
return 1
end function
------------------------------------------------------------------------
function PrintCard(atom ctl, object name)
------------------------------------------------------------------------
object save = printer:header
printer:header = custom_header
printer:reset()
printer:paper_name = "na_index-3x5"
printer:orientation = 1
printer:auto_lpp = FALSE
printer:font = "Ubuntu 6"
printer:top_margin = .1
printer:use_line_numbers = FALSE
name = canonical_path(unpack(name))
if file_exists(name) then
PrintFile("LGPL",name)
else
Error(win,,"File not found",name)
end if
printer:header = save
return 1
end function