hi list,
i’m experimenting with printoperation, on a cvs version of Fri Nov 10
11:47:07 2006.
and i found a “[BUG] Segmentation fault”
p context.page_setup.paper_size.inspect
in line 23 aborts the script.
i’m still experimenting with this stuff, all hints will be welcomed.
thanks
this is my script:
$ cat printer2.rb
require ‘gtk2’
Gtk.init
@w = Gtk::Window.new
@w.signal_connect(‘destroy’){Gtk.main_quit}
@w.set_default_size(300, 100)
pbutton=Gtk::Button.new
pbutton.set_image(Gtk::Image.new(Gtk::Stock::PRINT,Gtk::IconSize::LARGE_TOOLBAR))
pbutton.set_label(“PrintTest”)
pbutton.signal_connect(“clicked”){|me|
printo=Gtk::PrintOperation.new
printo.set_n_pages(1).set_show_progress(true)
printo.signal_connect(‘draw-page’){|me,context,page_number|
me.set_unit(Gtk::PaperSize::Unit::MM)
height = context.height
width = context.width
p Gtk::PaperSize::Unit
p me.unit
print width,“x”,height,"\n"
p context.page_setup.paper_size.inspect
p context.page_setup.orientation.inspect
cr = context.cairo_context
cr.rectangle(0,0,width,20)
cr.set_source_rgb(0, 0, 0)
cr.fill
layout = context.create_pango_layout
desc = Pango::FontDescription.new("sans 10")
layout.set_font_description(desc)
layout.set_text(@editor.buffer.get_text)
layout.set_width(width)
layout_width, layout_height = layout.size
text_height = layout_height / Pango::SCALE
cr.show_pango_layout(layout)
}
printo.signal_connect(‘end-print’){|me,context|
print “-=== printing ended\n”
}
printo.signal_connect(‘status-changed’){|me|
print “- status changed: “,me.status_string,”\n”
}
printr=printo.run(Gtk::PrintOperation::ACTION_PRINT_DIALOG,@w)
case printr
when Gtk::PrintOperation::RESULT_ERROR
print “error\n”
when Gtk::PrintOperation::RESULT_CANCEL
print “cancelled\n”
when Gtk::PrintOperation::RESULT_APPLY
print “applied\n”
when Gtk::PrintOperation::RESULT_IN_PROGRESS
print “in progress\n”
else
print “unknown result: “,printr.inspect,”\n”
end
printo.destroy
}
@editor=Gtk::TextView.new()
@editor.set_width_request(200)
holder=Gtk::VBox.new()
holder.pack_start(@editor)
holder.pack_end(pbutton)
@w.add(holder)
@w.show_all
Gtk.main