PrintOperation on windows

hi,

ruby -e “require ‘gtk2’;p “gtk:#{Gtk::VERSION.inspect},
binding:#{Gtk::BINDING_VERSION.inspect}””
on a gentoo(ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux]):
“gtk:[2, 12, 11], binding:[0, 16, 0]”
on the XP(ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]):
“gtk:[2, 10, 6], binding:[0, 15, 0]” (strange it was installed by
ruby-gnome2-0.16.0-1-i386-mswin32.exe)

anyways, my problem is with printing on windows:
on the gentoo the following presents the dialog, but on the XP it just
stops responding, and hangs forever, no output.
ruby -e “require
‘gtk2’;Gtk::PrintOperation.new.run(Gtk::PrintOperation::ACTION_PRINT_DIALOG)”

do i miss something?
is it supported?
is there something i could do to make it work?

thanks in advice,
balint

ruby -e “require ‘gtk2’;Gtk::PrintOperation.run_page_setup_dialog”
also does not work.
but
ruby -e “require ‘gtk2’;p Gtk::PrintOperation.new.status”
#<Gtk::PrintOperation::Status initial>
and
ruby -e “require ‘gtk2’;p Gtk::PrintOperation.new.job_name”
“-e job #1
works. is it just the dialog?

Kou, can you please confirm this situation? is it not implemented, or am
i doing something wrong?
thanks in advice

hi,
i tested the dialog, it’s the same :frowning:
is there anything else i should try?
thanks
balint

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation on windows” on Sat, 02 Aug
2008 15:39:17 +0300,
Dobai-Pataky Bálint [email protected] wrote:

Kou, can you please confirm this situation? is it not implemented, or am i
doing something wrong?

I’m sorry but I don’t have a Windows environment…

Could you try with the current GTK+?

Thanks,

kou

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation on windows” on Mon, 04 Aug
2008 22:11:36 +0300,
Dobai-Pataky Bálint [email protected] wrote:

i tested the dialog, it’s the same :frowning:
is there anything else i should try?

If you have a GTK+ build environment (and you can write C)
on Windows, please try the same code in C. If you can
reproduce the problem in C, it’s a GTK+ problem. Otherwise,
it’s a Ruby/GTK+ (or Ruby/GLib) problem. Can you do it? If
you can’t write C, I will be able to write it.

Thanks,

kou

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation on windows” on Tue, 05 Aug
2008 21:10:38 +0900 (JST),
Kouhei S. [email protected] wrote:

i tested the dialog, it’s the same :frowning:
is there anything else i should try?

If you have a GTK+ build environment (and you can write C)
on Windows, please try the same code in C. If you can
reproduce the problem in C, it’s a GTK+ problem. Otherwise,
it’s a Ruby/GTK+ (or Ruby/GLib) problem. Can you do it? If
you can’t write C, I will be able to write it.

Or I will be able to build a test program binary on
my Debian GNU/Linux environment. (cross compile)

Thanks,

kou

Kouhei S. wrote:

If you have a GTK+ build environment (and you can write C)
on Windows, please try the same code in C. If you can
reproduce the problem in C, it’s a GTK+ problem. Otherwise,
it’s a Ruby/GTK+ (or Ruby/GLib) problem. Can you do it? If
you can’t write C, I will be able to write it.

Or I will be able to build a test program binary on
my Debian GNU/Linux environment. (cross compile)

please do so, i tried MSvisualC2008, but with no luck, yet.

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation on windows” on Thu, 07 Aug
2008 13:21:54 +0300,
Dobai-Pataky Bálint [email protected] wrote:

Or I will be able to build a test program binary on
my Debian GNU/Linux environment. (cross compile)

please do so, i tried MSvisualC2008, but with no luck, yet.

Here is a test program built from the following code:
http://ruby-gnome2.sourceforge.jp/gtk-print.exe

#include <gtk/gtk.h>

int
main(int argc, char **argv)
{
GtkPrintOperation *operation;
GtkPrintOperationResult result;
GError *error = NULL;

gtk_init(&argc, &argv);

operation = gtk_print_operation_new();
result = gtk_print_operation_run(operation,
                                 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                 NULL,
                                 &error);
if (error) {
    g_warning("%d:%s", error->code, error->message);
    g_error_free(error);
} else {
    g_print("RESULT: %d\n", result);
}

return 0;

}

Thanks,
kou

Hi,

2008/8/7 Kouhei S. [email protected]:

Or I will be able to build a test program binary on
my Debian GNU/Linux environment. (cross compile)

please do so, i tried MSvisualC2008, but with no luck, yet.

Here is a test program built from the following code:
http://ruby-gnome2.sourceforge.jp/gtk-print.exe

BTW, did you run a “Printing” sample from gtk-demo.exe?

Thanks,

kou

Kouhei S. wrote:

Here is a test program built from the following code:
http://ruby-gnome2.sourceforge.jp/gtk-print.exe

BTW, did you run a “Printing” sample from gtk-demo.exe?

yes, it presents the printer chooser, i did not go further.
now i tried, and was able to setup a new printer from it, and was able
to print to file from it. so i think that works as your gtk-print.exe
in the ruby-gtk2-demo there is no printing.

thank you

Kouhei S. wrote:

please do so, i tried MSvisualC2008, but with no luck, yet.
GtkPrintOperation *operation;
if (error) {
Thanks,
kou

this is the error:

but i have c:\ruby\lib\GTK\bin\libglib-2.0-0.dll

ops, it runs if i copied it to c:\ruby\lib\GTK\bin
it presents the nice printer chooser.
thanks

Kouhei S. wrote:

now i tried, and was able to setup a new printer from it, and was able to print
kou

“not a Gtk::MessageDialog::ButtonType” error i get in line 26
i tried replacing the buttons parameter with
Gtk::MessageDialog::ButtonsType::CLOSE, and with 2, but no luck, same
error.
so i replaced the dialog part with a “p $!.message”
and if i press the print button now i see: “not a Gtk::PaperSize::Unit”

this line generates the error, around line number 60
operation.unit = :points

so i removed that line, i wanna see any printings now, don’t care if
it’s not calculated correctly.

but than:
“not a Gtk::PrintOperation::Action” in line 63
by the line: operation.run(:print_dialog,self)

so i replace :print_dialog with 0
and we get to the begining of the problem. it hangs, and does not
present the dialog.

Dobai-Pataky Bálint wrote:

“not a Gtk::MessageDialog::ButtonType” error i get in line 26
i tried replacing the buttons parameter with
Gtk::MessageDialog::ButtonsType::CLOSE, and with 2, but no luck, same
error.
so i replaced the dialog part with a “p $!.message”
and if i press the print button now i see: “not a Gtk::PaperSize::Unit”

There was a patch applied by Kou in latest trunk. Can you check if this
works?

Best Regards,
Joachim G.

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] PrintOperation on windows” on Thu, 07 Aug
2008 21:25:37 +0300,
Dobai-Pataky Bálint [email protected] wrote:

BTW, did you run a "Printing" sample from gtk-demo.exe?

yes, it presents the printer chooser, i did not go further.
now i tried, and was able to setup a new printer from it, and was able to print
to file from it. so i think that works as your gtk-print.exe
in the ruby-gtk2-demo there is no printing.

Here is a “Printing” sample in Ruby. Please put it to
gtk/sample/gtk-demo/ directory, run main.rb and try
“Printing” sample.

Thanks,

kou

Copyright (c) 2008 Ruby-GNOME2 Project Team

This program is licenced under the same licence as Ruby-GNOME2.

=begin
= Printing

Gtk::PrintOperation offers a simple API to support printing
in a cross-platform way.
=end

require ‘common’

module Demo
class Printing < BasicWindow
Data = Struct.new(:font_size, :lines_per_page, :lines, :n_pages)
HEADER_HEIGHT = 10 * 72 / 25.4
HEADER_GAP = 3 * 72 / 25.4

def initialize
  super('Printing')

  button = Gtk::Button.new("Print...")
  button.signal_connect("clicked") do
    begin
      run_print_operation
    rescue
      dialog = Gtk::MessageDialog.new(self, :destroy_with_parent, 

:error,
:close, $!.message)
dialog.signal_connect(“response”) do
dialog.destroy
true
end
dialog.show
end
true
end
add(button)
end

private
def run_print_operation
  operation = Gtk::PrintOperation.new

  data = Data.new
  data.font_size = 12.0
  operation.signal_connect("begin-print") do |_operation, context|
    on_begin_print(_operation, context, data)
  end
  operation.signal_connect("draw-page") do |_operation, context, 

page_number|
on_draw_page(_operation, context, page_number, data)
end
operation.signal_connect(“end-print”) do |_operation, context|
on_end_print(_operation, context, data)
end

  operation.use_full_page = false
  operation.unit = :points

  operation.run(:print_dialog, self)
end

def on_begin_print(operation, context, data)
  height = context.height - HEADER_HEIGHT - HEADER_GAP
  data.lines_per_page = (height / data.font_size).floor
  data.lines = File.readlines(__FILE__)
  data.n_pages = (data.lines.size - 1) / data.lines_per_page + 1
  operation.set_n_pages(data.n_pages)
end

def on_draw_page(operation, context, page_number, data)
  cr = context.cairo_context
  width = context.width

  cr.rectangle(0, 0, width, HEADER_HEIGHT)
  cr.set_source_rgb(0.8, 0.8, 0.8)
  cr.fill_preserve

  cr.set_source_rgb(0, 0, 0)
  cr.line_width = 1
  cr.stroke

  layout = context.create_pango_layout
  layout.font_description = Pango::FontDescription.new("sans 14")

  layout.text = File.basename(__FILE__)
  text_width, text_height = layout.pixel_size

  if (text_width > width)
    layout.width = width
    layout.ellipsize = :start
    text_width, text_height = layout.pixel_size
  end

  cr.move_to((width - text_width) / 2, (HEADER_HEIGHT - text_height) 

/ 2)
cr.show_pango_layout(layout)

  layout.text = "#{page_number + 1}/#{data.n_pages}"
  layout.width = -1
  text_width, text_height = layout.pixel_size
  cr.move_to(width - text_width - 4, (HEADER_HEIGHT - text_height) / 
  1. cr.show_pango_layout(layout)

    layout = context.create_pango_layout
    description = Pango::FontDescription.new(“monosapce”)
    description.size = data.font_size * Pango::SCALE
    layout.font_description = description

    cr.move_to(0, HEADER_HEIGHT + HEADER_GAP)
    start_line = page_number * data.lines_per_page
    data.lines[start_line, data.lines_per_page].each do |line|
    layout.text = line
    cr.show_pango_layout(layout)
    cr.rel_move_to(0, data.font_size)
    end
    end

    def on_end_print(operation, context, data)
    end
    end
    end

Joachim G. wrote:

There was a patch applied by Kou in latest trunk. Can you check if this
works?

Best Regards,
Joachim G.

no, i did not.
i can currently compile it on linux.
if you guide me in compiling it on windows, i’ll do it.

thanks,
balint

Joachim G. wrote:

If you use MinGW this should work at least on the machine on which it is
compiled.

i followed th link.
built everything up to ruby-glib2, which failed with
rbglib_maincontext.c:166: error: syntax error before “rb_thread_t”
rbglib_maincontext.c: In function source_prepare_add_poll': rbglib_maincontext.c:168: error:thread’ undeclared (first use in this
function )
rbglib_maincontext.c:168: error: (Each undeclared identifier is reported
only on ce
rbglib_maincontext.c:168: error: for each function it appears in.)
rbglib_maincontext.c:170: error: source' undeclared (first use in this function ) rbglib_maincontext.c: In functionsource_prepare_setup_poll_fd’:
rbglib_maincontext.c:199: error: rb_thread_t' undeclared (first use in this fun ction) rbglib_maincontext.c:199: error: syntax error before "thread" rbglib_maincontext.c:207: error:thread’ undeclared (first use in this
function )
rbglib_maincontext.c:207: error: rb_curr_thread' undeclared (first use in this function) rbglib_maincontext.c:211: error:THREAD_RUNNABLE’ undeclared (first use
in this function)
rbglib_maincontext.c:214: error: THREAD_KILLED' undeclared (first use in this f unction) make[1]: *** [rbglib_maincontext.o] Error 1 make[1]: Leaving directory/home/balint/rg2/glib/src’
make: *** [all] Error 2

should i try other version than ruby-1.8.5?
thanks

Dobai-Pataky Bálint wrote:

no, i did not.
i can currently compile it on linux.
if you guide me in compiling it on windows, i’ll do it.

This wiki entry can help you:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&p=compile_mingw&key=win32

If you use MinGW this should work at least on the machine on which it is
compiled.

Dobai-Pataky Bálint wrote:

This wiki entry can help you:
this function )
this function )
should i try other version than ruby-1.8.5?
thanks

built with 1.8.7-p71

someone please update the rg2 wiki on installing on windows:
i ran into rcairo not configuring:

~/rcairo-1.6.3
$ ruby extconf.rb && make && make install
checking for GCC… yes
checking for cairo version (>= 1.2.0)… *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

~/rcairo-1.6.3
$pkg-config.exe --cflags gtk±2.0
Package pixman-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `pixman-1.pc’
to the PKG_CONFIG_PATH environment variable
Package ‘pixman-1’, required by ‘cairo’, not found

this link helped me out:
http://www.nabble.com/pixman-1-was-not-found-in-the-pkg-config-td16842574.html
i’ve built http://cairographics.org/releases/pixman-0.10.0.tar.gz with
the following:
./configure --prefix=/MinGW && make && make install

then in the rcairo source:
export PKG_CONFIG_PATH=“$PKG_CONFIG_PATH:/C/MinGW/lib/pkgconfig/”

$ pkg-config.exe --cflags gtk±2.0
-mms-bitfields -Ic:/GTK/include/gtk-2.0 -Ic:/GTK/lib/gtk-2.0/include
-Ic:/GTK/include/atk-1.0 -Ic:/GTK/include/cairo
-Ic:/GTK/include/pango-1.0 -Ic:/GTK/include/glib-2.0
-Ic:/GTK/lib/glib-2.0/include -Ic:/GTK/include/freetype2

but than i ran into:
~/rcairo-1.6.3
$ make
gcc -I. -I. -Ic:/MinGW/lib/ruby/1.8/i386-mingw32 -I.
-DRUBY_CAIRO_PLATFORM_WIN32 -DRB_CAIRO_COMPILATION -g -O2 -Wall
-I/target/include/cairo -I/target/include/freetype2 -I/target/include
-I/target/include/libpng12 -I/MinGW/include/pixman-1 -mms-bitfields -c
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo_context.c
-osrc/rb_cairo_context.o
In file included from
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo_context.c:15:
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo.h:19:19: cairo.h: No
such file or directory
In file included from
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo_context.c:15:
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo.h:162: error: syntax
error before ‘*’ token
C:/msys/1.0/home/balint/rcairo-1.6.3/src/rb_cairo.h:162: warning: type
defaults to int' in declaration of rb_cairo_context_from_ruby_object’

so i extracted include/cairo/*h from cairo-dev-1.6.4-2.zip into
MinGW/include/
and make of rcairo finished
make install succeeded

for making rg2 modules(like pango,gdkpixbuf, and finally gtk and atk) i
have to export 2 variables:
export PKG_CONFIG_PATH=“$PKG_CONFIG_PATH:/C/MinGW/lib/pkgconfig/”
export CAIRO_PATH=/home/balint/rcairo-1.6.3/

testing:
require ‘gtk2’
Gtk::PrintOperation.run_page_setup_dialog

presents the dialog. :slight_smile:

so my question: how do i deploy this mess onto other windows machines?
zip/unzip everything?
or should i wait for a windows release of rg2, which includes the
working PrintOperation?

thanks for your help