How to use cairo with gtk

2008-03-21 Thread Ye Wenbin
Hi,
I try a new module VS::Chart which create chart using Cairo.
I want display the image as a Gtk widget without save the image
to disk. The problem is VS::Chart using Cairo::ImageSurface
to draw the chart, I can't find document for that.
Is it possible convert the Cairo::ImageSurface to Gtk2::Image?
I am especial appreciate if you can give some document
about the concepts in Gtk or Cairo, for example,
Gdk, graphic context, and so on. I'm not good at English,
so understanding these things is not easy for me.

-- 
Best Regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Glib::IO::add_watch doesn't work in Windows

2007-11-07 Thread Ye Wenbin
Hi,
The add_watch function seem not work in Windows. I test using
this script:

use Gtk2 '-init';
use Glib qw/FALSE TRUE/;
Glib::IO-add_watch(
 fileno(STDIN),
 'in',
 \callback,
 \*STDIN,
);
Gtk2-main;

sub callback {
 my ($fd, $cond, $fh) = @_;
 my $line = $fh;
 print You just input $line\n;
 return FALSE;
}

The script works in Ubuntu.
But in windows, seem the program is block in the mainloop, and
all inputs will appear in the command line after I press Ctrl-C.

-- 
Best regards.
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Suggestion for gtk2-perl port for win32

2007-10-02 Thread Ye Wenbin
在 Tue, 02 Oct 2007 03:52:36 +0800,Torsten Schoenfeld  
[EMAIL PROTECTED] 写道:



On Tue, 2007-10-02 at 01:38 +0800, Ye Wenbin wrote:

If you can provide a patch that implements your suggestions, and doesn't
break the build on other platforms, we'd be pleased to apply it to fix
those problems.


1. I can't figure out an clean way to solve the problem about the quote.
so I just copy the function and make a little change to make it fit to  
MSWin32.

The difficulty is the cmd use only double-quote and doesn't recognize
escape!
2. The Glib::MakeMaker is already make a choice for using Data::Dumper.
set enviroment variable FORCE_DATA_DUMPER to true. I add
$Data::Dumper::Indent=1 in the patch.



If I remember correctly, the cause for the long lines was related to the
automatic documentation generation.  So passing disable-apidoc to
Makefile.PL when running it should help.  But you lose the API docs, of
course.

the command link all object to a dynamic library is also too long(more  
than 4000 characters).

I get a error like:
NMAKE : fatal error U1095: expanded command line 'gcc -o  
blib\arch\auto\Gtk2\Gtk2.dll -Wl,--base-file -Wl,dll.base -mdll ${XSFILES}  
-Wl,--image-base,0x6910  ${LIBS} dll.exp' too long

(object file and libs are omit)

Anyway, now I can build the Gtk2. The procedure is as following:
1. Get all tools required. I use ActivePerl v5.8.8, which build by Mingw  
gcc and nmake, so you have to get them first. And then install Gtk+/Win32  
Runtime and Development Environment(from  
http://gladewin32.sourceforge.net/modules/news/).
2. Setup environment variable, make sure the nmake, gcc, pkg-config is  
available in cmd. Serval environment variables is important:

 a. PATH  - which all command is located in one of these directories
 b. CPATH - the directories that contain header file which can be  
specified with -I.
 c. LIBRARY_PATH - the directories that contain .lib files which can be  
specified with -L.
 d. PKG_CONFIG_PATH - pkg-config search these these directories for  
packages.

3. run commands in cmd:
  set FORCE_DATA_DUMPER=1
  perl Makefile.PL
4. for Glib, just nmake
5. for Gtk2,

nmake /N  make.bat

The nmake signal error like:
NMAKE : fatal error U1095: expanded command line 'gcc -o  
blib\arch\auto\Gtk2\Gtk2.dll -Wl,--base-file -Wl,dll.base -mdll ${XSFILES}  
-Wl,--image-base,0x6910  ${LIBS} dll.exp' too long
 copy the string in the quote from 'gcc' to 'dll.exp' to make.bat. run  
make.bat. Wait the compile done. Then

nmake /N  make.bat
 Now it signal the similar error again. Redo as above, copy the command to  
make.bat, run make.bat, then nmake /N  make.bat until all command is  
passed.

6. Finally, install it:
  nmake install

Seem stupid, but it works. All test is passed.

--
Best regards.
Ye Wenbin

MakeHelper.pm.patch
Description: Binary data


ParseXSDoc.pm.patch
Description: Binary data
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Suggestion for gtk2-perl port for win32

2007-10-01 Thread Ye Wenbin
Hi,
When I build Gtk2 in windows, the main obstacle is some simple errors in  
Makefile.
For example, execute some one line perl code use single-quote, and use  
Storable
module which may lead to some unknown errors. So I suggest the MakeHelper  
module
so make some change to make the Makefile portable. For example, avoid to  
use
single-quote, use double-quote instead, and inside the string, use qq()  
instead
of double quote. And use Data::Dumper but Storable. The file will get a  
little
larger, but if choose a small indentation, it is not so big. More over, the
Dump result is more readable.

By the way, is there any advise for error the command is too long when  
use
nmake?

-- 
Best regards.
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Goo::Canvas is available

2007-09-28 Thread Ye Wenbin
Hi,
I spent sometime to write the bingdings for GooCanvas. I think it may
be useful if you want the Canvas widget is portable.
I rewrite all demo provided in goocanvas-0.6. Unforturenitely, there are  
some bugs
  that I can't fix. I mark them in the source code with 'FIXME'. If anyone  
know
what the problem is, please let me know.

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Goo::Canvas is available

2007-09-28 Thread Ye Wenbin
On Fri, 28 Sep 2007 22:25:27 +0800, Torsten Schoenfeld  
[EMAIL PROTECTED] wrote:

 How do we get the sources?
I just upload to CPAN. It may take some time. Is there other way to  
distribute the
module?

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Is it possible to stop a signal callback?

2007-08-05 Thread Ye Wenbin
Hi,
In my application, there is a callback which may take a long time to  
finish.
Is it possible to return from the callback when user really need? For  
example,
code as following, can I press the button 'cancel' to stop the counting?
Is there any document about thread in Gtk2?

use Gtk2 '-init';
use Glib qw(TRUE FALSE);
my $window = Gtk2::Window-new('toplevel');
$window-signal_connect('delete_event' = sub { Gtk2-main_quit; });

my $hbox= Gtk2::HBox-new(FALSE, 0);
my $but;
$but = Gtk2::Button-new('start');
$but-signal_connect(
 'clicked' = sub {
 my $i = 0;
 while ($i  10) {
 sleep( 1 );
 $i++;
 print I'm working\n;
 }
 return FALSE;
 }
);
$hbox-pack_start($but, TRUE, TRUE, 5);
$but = Gtk2::Button-new('Cancel');
$but-signal_connect(
 'clicked' = sub {
 die Stop it\n;
 }
);
$hbox-pack_start($but, TRUE, TRUE, 5);
$window-add($hbox);
$window-show_all();
Gtk2-main;


-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Is it possible to stop a signal callback?

2007-08-05 Thread Ye Wenbin
On Mon, 06 Aug 2007 01:35:41 +0800, zentara [EMAIL PROTECTED] wrote:

 Have you looked at
 http://forgeftp.novell.com/gtk2-perl-study/download/
 it will answer alot of questions.

I have read this document. It is really helpful.

 Don't use while(1) or sleep in a gui script, they cause malfunctions.

I did not use sleep to do some work periodly. I was trying to show the  
signal
callback will take a long time to finish. Maybe it need fork or using  
thread. But
the problem is I don't know how to communicate with subprocess. I will try
to find it.

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: How to draw some simple picture?

2007-08-04 Thread Ye Wenbin
Thanks for the reply. I also found the wonderful tutorial that you wrote.
That illustrate many things that I want to know.

On Sat, 04 Aug 2007 18:59:02 +0800, zentara [EMAIL PROTECTED] wrote:


 Anyways, see: http://perlmonks.org?node_id=583578
 for the code and explanation. Any improvements are welcome.

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: How to construct a tree that every nodes has an icon

2007-07-30 Thread Ye Wenbin
($iterb, FILE_ICON)
|| $model-get($itera, FILE_NAME) cmp $model-get($iterb, FILE_NAME);
 }
 });
 $model-set_sort_column_id(FILE_NAME, $column1-get_sort_order);
 $model-sort_column_changed();

Ok, this is the final version(Encode module is used to support file
name with multibyte characters):

use Gtk2 '-init';
use Glib qw(TRUE FALSE);
use Encode qw/encode decode/;
use constant {
 FILE_ICON  = 0,
 FILE_NAME  = 1,
 FILE_FULE_NAME = 2,
 FILE_MTIME = 3,
};

my $window = Gtk2::Window-new('toplevel');
$window-signal_connect('delete_event' = sub { Gtk2-main_quit; });
ret_vbox($window);
$window-show();
Gtk2-main;

sub ret_vbox {
 my $top = shift;
 my $dir = '.';
 $top-set_title('Directory contents of '. $dir);
 my $vbox = Gtk2::VBox-new(FALSE, 4);
 my $sw = Gtk2::ScrolledWindow-new;
 $sw-set_size_request (600, 400);
 $sw-set_policy ('automatic', 'automatic');
 # create TreeView
 my $model = create_model($dir);
 my $treeview = Gtk2::TreeView-new_with_model($model);
 open_dir($model, $dir, undef);
 add_columns($treeview);
 $treeview-signal_connect( 'row-expanded' = \expand_dir );
 $sw-add($treeview);
 $vbox-pack_start($sw,TRUE,TRUE,0);
 $vbox-show_all();
 $top-add($vbox);
}

sub create_model {
 my $dir = shift;
 my $model = Gtk2::TreeStore-new(
 'Glib::String', 'Glib::String', 'Glib::String', 'Glib::Int'
 );
 return $model;
}

sub expand_dir {
 my ($treeview,$iter,$path,$self) = @_;
 my $model = $treeview-get_model();
 my $dir = $model-get($iter, FILE_FULE_NAME);
 my $first = $model-iter_nth_child($iter, 0);
 unless ( defined $model-get($first, FILE_NAME) ) {
 open_dir($model, $dir, $iter);
 $model-remove($first);
 }
 return FALSE;
}

sub open_dir {
 my ($model, $dir, $parent_iter) = @_;
 opendir(DIR, $dir) or die Can't open directory $dir: $!;
 foreach my $file ( readdir(DIR) ) {
 next if $file =~ /^[.]/;
 my $uni_name = decode('utf8', $file);
 my $full = $dir/$uni_name;
 my $iter = $model-append($parent_iter);
 $model-set(
 $iter,
 FILE_ICON, ( -d $full ? 'gtk-directory' : 'gtk-file' ),
 FILE_NAME, $uni_name,
 FILE_FULE_NAME, $full,
 FILE_MTIME, (stat($full))[9]
 );
 if ( -d $full ) {
 my $dummy = $model-append($iter);
 }
 }
}

sub add_columns {
 use Date::Format;
 my $treeview = shift;
 my $column;
 ## Add first column
 my $column1 = Gtk2::TreeViewColumn-new();
 $column1-set_title('file name');
 ### first cell for column one
 my $icon = Gtk2::CellRendererPixbuf-new();
 $column1-pack_start($icon, FALSE);
 $column1-set_attributes( $icon, 'stock-id' = FILE_ICON );
 ### second cell for column one
 my $name = Gtk2::CellRendererText-new();
 $column1-pack_start($name, FALSE);
 $column1-set_attributes( $name, 'text' = FILE_NAME );
 $column1-set_sort_column_id(FILE_NAME);
 # Set customized sort funciton
 my $model = $treeview-get_model;
 $model-set_sort_func(
 FILE_NAME,
 sub {
 my ($model, $itera, $iterb) = @_;
 if ( $model-get($itera, FILE_NAME)
$model-get($iterb, FILE_NAME)
$model-get($itera, FILE_ICON)
$model-get($iterb, FILE_ICON) ) {
 $model-get($itera, FILE_ICON) cmp $model-get($iterb,  
FILE_ICON)
  || $model-get($itera, FILE_NAME) cmp $model-get($iterb,  
FILE_NAME);
 }
 });
 $model-set_sort_column_id(FILE_NAME, $column1-get_sort_order);
 $model-sort_column_changed();
 $treeview-append_column($column1);
 ## Add second column
 $treeview-insert_column_with_data_func(
 1, modify time,
 Gtk2::CellRendererText-new(),
 sub {
 my ($tree_column, $cell, $model, $iter) = @_;
 my ($mtime) = $model-get ($iter, FILE_MTIME);
 my @lc = localtime($mtime);
 $cell-set (text = strftime(%c, @lc));
 }
 );
 $treeview-get_column(1)-set_sort_column_id(FILE_MTIME);
}

On Mon, 30 Jul 2007 22:18:30 +0800, muppet [EMAIL PROTECTED] wrote:

 Well, ugly is subjective, so what you're saying is unclear.  Are you  
 worried
 that the icon will not indent with child nodes?  Have you *tried* it?
Sorry for my poor english. I know it is my fault, not gtk-perl. In fact,  
gtk-perl
is powerful, and interesting, and I spent all the days to learn it.

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


How to construct a tree that every nodes has an icon

2007-07-28 Thread Ye Wenbin
Hi,
How can I construct a tree which nodes have an icon? I have read the
source code of podbrowser. He used two column: Gtk2::Gdk::Pixbuf
Glib::String
for every node. But when the level of the tree is deeper, the tree will be
ugly.
The Nautilus of gnome can show the tree what I mean to.
Is there a way in gtk2-perl?

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Is there an interactive shell for gtk-perl

2007-07-27 Thread Ye Wenbin
I just write one. I would like to share it with others who also want this.

#! /usr/bin/perl -w
package Gtksh::Subs;
use Data::Dumper qw(Dumper);

sub reload {
  my $mod = shift;
  (my $file = $mod) =~ s/::/\//g;
  delete $INC{$file..pm};
  eval({
require $mod;
1;
  });
  if ( $@ ) {
  print Reload $mod failed: [EMAIL PROTECTED];
  } else {
  print Successfully reload $mod\n;
  }
}

sub Dump {
  print Data::Dumper::Dumper(@_), \n;
}

sub help {
  use Pod::Perldoc;
  my $kw = shift;
  print `perldoc $kw`;
}

package main;

use Getopt::Long qw(:config no_ignore_case auto_help);
use Gtk2 '-init';
use Glib  qw(TRUE FALSE);

{
  no warnings qw(all);
  *x = \Gtksh::Subs::Dump;
  *reload = \Gtksh::Subs::reload;
}
our $DEBUG = 0;
our $PROMPT = gtksh ;
my $start_up;

GetOptions(
  'debug' = \$DEBUG,
  'prompt=s' = \$PROMPT,
  'start-up=s' = \$start_up,
);

print This is a simple perl shell for gtk-perl!\n;

if ( defined $start_up  -f $start_up ) {
  print Load $start_up...\n;
  require $start_up;
}

# Turn all buffering off.
select((select(STDOUT), $| = 1)[0]);
select((select(STDERR), $| = 1)[0]);
select((select(STDIN),  $| = 1)[0]);

print $PROMPT;
Glib::IO-add_watch (fileno(STDIN), [qw/in/], \watch_callback, \*STDIN);
Gtk2-main;

# make shell prompt print next line
END {
  print \n;
}

sub watch_callback {
my ($fd, $condition, $fh) = @_;
  # internal variable, strange name so that you seldom change them
  my $__exp__ = ;
  my $__line__;
  while (1) {
  $__line__ = $fh;
  unless (defined($__line__)) {
  exit;
  }
  chomp($__line__);
  if ($__line__ =~ s/\\\s*$//) {
  print + ;
  $__exp__ .= $__line__ . \n;
  } else {
  last;
  }
  }
  $__exp__ .= $__line__ . \n;
  print \nYou just input: $__exp__\n if $DEBUG;
  if ($__exp__ =~ /^(quit|exit|bye)$/) {
  exit;
  } elsif ( $__exp__ =~ /^(help\s+|\?)(.*)\s*$/ ) {
  Gtksh::Subs::help($2);
  } else {
  print Eval '$__exp__'\n if $DEBUG;
  my $res = eval(
  {
  no warnings 'all';
  $__exp__;
  }
  );
  if ($@) {
  print Error: [EMAIL PROTECTED];
  }
  print \nResult: , $res, \n if defined $res;
  }
  print $PROMPT;
return TRUE;
}

__END__

=head1 NAME

gtksh.pl - A simple perl shell for gtk-perl

=head1 SYNOPSIS

gtksh.pl

=head1 DESCRIPTION

gtksh.pl is intended to be a perl shell which is better than `perl -d`.
I use this program in emacs, and it works, but not powerful.

=head2 Predefined command

=over

=item x

A alias for CData::Dumper::Dumper. for example:

 perl $foo = {'a' = 1}

 Result: HASH(0x837c674)
 perl x $foo
 $VAR1 = {
   'a' = 1
 };

=item ?

=item help

Intend for replace input `perldoc` in this program. for example:

 perl help -f print
 print FILEHANDLE LIST
 print LIST
 print   Prints a string or a list of strings. Returns true if...

 perl help Math::Trig
 NAME
 Math::Trig - trigonometric functions

 SYNOPSIS
 ...

=item reload

Reload a module again. Equal to eval do($INC{Module.pm}. for example:

 perl require DBI

 Result: 1
 perl reload DBI
 Subroutine DBI::SQL_UDT redefined at /usr/lib/perl5/DBI.pm line 154,
STDIN line 2.
 

=item bye

=item exit

=item quit

Quit the program.

=back


=head1 AUTHOR

Ye Wenbin [EMAIL PROTECTED]

=head1 SEE ALSO

http://www.emacswiki.org/cgi-bin/emacs/inf-perl.el

=cut

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Is there an interactive shell for gtk-perl

2007-07-27 Thread Ye Wenbin
Hi, Sergei,
There are many thing that glade can't do. Glade only can show what  
property, signals
and other static things. But if I want to see the function of some method  
of widget
or debug some variable when the program is running, it can't help me.

On Sat, 28 Jul 2007 05:01:43 +0800, Sergei Steshenko [EMAIL PROTECTED]  
wrote:
 If the main issue is learning, then why not use 'glade' or 'glade3' - you
 can build a GUI using several clicks choosing widgets from menus on the  
 way.


-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Is there an interactive shell for gtk-perl

2007-07-26 Thread Ye Wenbin
Hi,
I wonder whether there is an interactive shell for gtk-perl like ptksh. I  
think it is useful for me to learn
gtk-perl. I can test the widget method dynamicly. It's better if the shell  
can run in bash, so it can
be a backend of emacs.

Thank you!
-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list