RSS/Atom feed Twitter
Site is read-only, email is disabled

Anyone good at converting/porting scripts from perl to python?

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

8 of 8 messages available
Toggle history

Please log in to manage your subscriptions.

Anyone good at converting/porting scripts from perl to python? Rikard Johnels 02 Jun 03:39
  Anyone good at converting/porting scripts from perl to python? Carol Spears 02 Jun 04:09
  Anyone good at converting/porting scripts from perl to python? Joao S. O. Bueno Calligaris 02 Jun 04:13
   Anyone good at converting/porting scripts from perl to python? Rikard Johnels 02 Jun 08:25
    Anyone good at converting/porting scripts from perl to python? Sven Neumann 02 Jun 11:51
     Anyone good at converting/porting scripts from perl to python? Joao S. O. Bueno Calligaris 02 Jun 15:00
    Anyone good at converting/porting scripts from perl to python? Joao S. O. Bueno Calligaris 02 Jun 14:57
  Anyone good at converting/porting scripts from perl to python? Alan Horkan 02 Jun 16:20
Rikard Johnels
2005-06-02 03:39:30 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

I have been trying to get Gimp Perl to run without success for a while now. I have decided to try another way..
The script i want to run is as follows;

#!/usr/bin/perl

use Gimp qw( :auto ); use Gimp::Fu;

register "center_guide", "Creates h- & v-guides at the center of the image.", "Physical center = width/2 and height/2; Optical center = the Golden Mean.",
"Claes G Lindblad ", "Claes G Lindblad",
"990323",
"/Center Guide",
"*",
[
[PF_RADIO,
"center",
"center",
0,
[Physical => 0, Optical => 1] ]
],
sub {
my ($img, $layer, $center) = @_;

$w = $img->width(); $h = $img->height(); $hc = int($h/2 + 0.5); $vc = int($w/2 + 0.5);

if ($center == 1) { $hc = int(($h / 2.6179) + 0.5); };
$bit_bucket = $img->add_hguide($hc); $bit_bucket = $img->add_vguide($vc); gimp_drawable_update($layer, 0, 0, $w, $h); };
exit main;

How do i convert it to python? Python i DO have working...

(I did try to mail the author, but i got a bounced mail...)

Carol Spears
2005-06-02 04:09:23 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Thu, Jun 02, 2005 at 03:39:30AM +0200, Rikard Johnels wrote:

I have been trying to get Gimp Perl to run without success for a while now. I have decided to try another way..
The script i want to run is as follows;

just rewrite it.

pyslice has code that uses guides. you can search the gimps python guide calls via the python console.

just rewrite it.

i have found scripting with python and gimp to be fun and rewarding and a source of instant gratification.

ask specific questions here if you run into trouble.

i cannot imagine rewriting perl into python since i can read python and cannot read perl. how do you make something that is obfiscuated into something that is not? i say skip it and rewrite it, simply.

carol

Joao S. O. Bueno Calligaris
2005-06-02 04:13:42 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Wednesday 01 June 2005 22:39, Rikard Johnels wrote:

I have been trying to get Gimp Perl to run without success for a while now. I have decided to try another way.. The script i want to run is as follows;

I do not know much perl, but it is quite straightforward. I suppose you know that in python identation does matter, and is used to separate blocks, instead of { & } or begin & end.

That said, the script bellow becomes:

(I will let the perl lines commented on the script. you may erase then later)

#!/usr/bin/python

#use Gimp qw( :auto ); #use Gimp::Fu;
# I don't know what this "auto:" means, #but we normally just import gimpfu in python scripts/

from gimpfu import *

#register "center_guide", # the register call in python must come after the function definition #itself. Ok - this is thasy perl way, in which the function was #defined inside the funcion call for register. Python is a clean #language - the only way of doing this is with short functions #that can be written as lambdas.

# sub { # my ($img, $layer, $center) = @_; def center_guide (img, layer, center): #beware of indentation from this point on

#$w = $img->width(); #$h = $img->height();
#$hc = int($h/2 + 0.5);
#$vc = int($w/2 + 0.5);

w = img.width h = img.height
hc = int (h / 2.0 + 0.5)
vc = int (w / 2.0 + 0.5)

#if ($center == 1) { # $hc = int(($h / 2.6179) + 0.5); # };
if center == 1:
hc = int (h / 2.6179 + 0.5)

# $bit_bucket = $img->add_hguide($hc); # $bit_bucket = $img->add_vguide($vc); # gimp_drawable_update($layer, 0, 0, $w, $h); img.add_hguide (hc)
img.add_vguide (vc)
gimp.displays_flush()

# };

register ("center_guide", "Creates h- & v-guides at the center of the image.", "Physical center = width/2 and height/2; Optical center = the Golden Mean.",
"Claes G Lindblad ",
"Claes G Lindblad, pythonified by Joao S. O. Bueno Calligaris",
"990323",
"/Center Guides",
"*",
[
[PF_RADIO,
"center",
"center",
0,
(("Physical", 0), ("Optical", 1)) ]

],
[],
center_guide
)

#exit main;
main ()

How do i convert it to python?
Python i DO have working...

(I did try to mail the author, but i got a bounced mail...)

Rikard Johnels
2005-06-02 08:25:35 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Thursday 02 June 2005 04.13, Joao S. O. Bueno Calligaris wrote:

#!/usr/bin/python

#use Gimp qw( :auto ); #use Gimp::Fu;
# I don't know what this "auto:" means, #but we normally just import gimpfu in python scripts/

from gimpfu import *

#register        "center_guide", # the register call in python must come after the function definition #itself. Ok - this is  thasy perl way, in which the function was #defined inside the funcion call for register. Python is  a clean #language - the only way of doing this is with short functions #that can be written as lambdas.

#        sub { #                my ($img, $layer, $center) = @_; def center_guide (img, layer, center):      #beware of indentation from this point on

     #$w = $img->width();      #$h = $img->height();
     #$hc = int($h/2 + 0.5);
     #$vc = int($w/2 + 0.5);

     w = img.width      h = img.height
     hc = int (h / 2.0 + 0.5)
     vc = int (w / 2.0 + 0.5)

     #if ($center == 1) {      #      $hc = int(($h / 2.6179) + 0.5);      #    };
     if center == 1:
          hc = int (h / 2.6179 + 0.5)

     #          $bit_bucket = $img->add_hguide($hc);      #          $bit_bucket = $img->add_vguide($vc);      #          gimp_drawable_update($layer, 0, 0, $w, $h);      img.add_hguide (hc)
     img.add_vguide (vc)
     gimp.displays_flush()      

     #   };

register   ("center_guide",             "Creates h- & v-guides at the center of the image.",             "Physical center = width/2 and height/2; Optical center = the Golden Mean.",
             "Claes G Lindblad ",
             "Claes G Lindblad, pythonified by Joao S. O. Bueno Calligaris",
              "990323",
              "/Center Guides",
              "*",
              [
                [PF_RADIO,
                        "center",
                        "center",
                         0,
                         (("Physical", 0), ("Optical", 1))                 ]
                     
              ],
              [],
              center_guide
              )  
               

#exit main;
main ()

Very nice! Thank you Very much!

Works as expected. (almost) The image is flagged edited if i use the guides. How do i set something so it isn't edited? (Its just a guide, no change in the image)
Also, i was thinking of extending the script to use a choice "Thirds" too. (the rule of thirds), but i failed to get the hang of how to use the if statement...

I am not much of a programmer (as i have stated before), so i need all the "babytalk help" i can get...

I do understand more and more for each time.. Maybe in time when i get my new SGI machine ill be able to write my own code...

Sven Neumann
2005-06-02 11:51:41 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

Hi,

Rikard Johnels writes:

Works as expected. (almost) The image is flagged edited if i use the guides. How do i set something so it isn't edited? (Its just a guide, no change in the image)

Guides are part of the image and stored in XCF. So that is the correct behaviour. gimp-image-clean-all will unset the flag if you insist on violating the rules.

Sven

Joao S. O. Bueno Calligaris
2005-06-02 14:57:25 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Thursday 02 June 2005 03:25, Rikard Johnels wrote:

On Thursday 02 June 2005 04.13, Joao S. O. Bueno Calligaris wrote:

Very nice! Thank you Very much!

Works as expected. (almost) The image is flagged edited if i use the guides. How do i set something so it isn't edited? (Its just a guide, no change in the image)

Sorry - for the GIMP that is changing the image.There is no way to clean the dirty flag, but saving the image. If it is that important, one workaround would be to save the image to /dev/null - but it is a lot of hasle.

Also, i was thinking of extending the script to use a choice "Thirds" too. (the rule of thirds), but i failed to get the hang of how to use the if statement...

Just below the line that calculates the "golden mean" insert a elif center==2:
hc = h / 3
hv = w / 3
and a corresponding option pair in the "register" function

I am not much of a programmer (as i have stated before), so i need all the "babytalk help" i can get...

I'd recomend a visit to www.python.org and to the python tutorial therein. It wll take you from 20 to 30 minutes, and you will be able to read the scripts later, and top go back to the python reference to write your own stuff.

For gimp scripts, there are no changes, but the call to the register function, and the ability to use any of the hundreds of gimp functions displayed on the GIMP's PDB browser.

I do understand more and more for each time.. Maybe in time when i get my new SGI machine ill be able to write my own code...

Heh....

Regards,

JS
->

Joao S. O. Bueno Calligaris
2005-06-02 15:00:25 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Thursday 02 June 2005 06:51, Sven Neumann wrote:

Hi,

Rikard Johnels writes:

Works as expected. (almost) The image is flagged edited if i use the guides. How do i set something so it isn't edited? (Its just a guide, no change in the image)

Guides are part of the image and stored in XCF. So that is the correct behaviour. gimp-image-clean-all will unset the flag if you insist on violating the rules.

Sorry Rikard.
Just insert a:
pdb.gimp_image_clean_all (img)
call just after the add_vguide line.

Sven

Alan Horkan
2005-06-02 16:20:24 UTC (almost 19 years ago)

Anyone good at converting/porting scripts from perl to python?

On Thu, 2 Jun 2005, Rikard Johnels wrote:

Date: Thu, 2 Jun 2005 03:39:30 +0200 From: Rikard Johnels
To: gimp-user@lists.xcf.berkeley.edu Subject: [Gimp-user] Anyone good at converting/porting scripts from perl to python?

I have been trying to get Gimp Perl to run without success for a while now. I have decided to try another way..

The script i want to run is as follows;

register "center_guide",
"Creates h- & v-guides at the center of the image.", "Physical center = width/2 and height/2; Optical center = the Golden Mean.",

How do i convert it to python?
Python i DO have working...

(I did try to mail the author, but i got a bounced mail...)

I wrote a few scripts for manipulating guides using scheme (one to add a guide at specified pixel position and another to add guides based on a percentage of the image size, some of them are included in Gimp 2.2 see Image, Guides, ...). Maybe if you are repeating the same task a lot these are to generalised?

I suppose could rewrite the Centre Guides script in Python (nevermind, Jaoa has done it already). Thing is I would have rewritten it i Scheme already except that I was not convinced anyone would actually want to use this script.

I would be very interested to know why exactly is the centre guides script useful?
More importantly, what bigger problem are you trying to solve?

You mention you are also interested in extending the script to divide the image into thirds, which makes me seriously think there is something bigger going on you aren't telling us about.

With more information we might be able to offer an even better answer, and solve the bigger problem rather than only treating the symptoms.

Sincerely

Alan Horkan

Inkscape http://inkscape.org Abiword http://www.abisource.com
Dia http://gnome.org/projects/dia/
Open Clip Art http://OpenClipArt.org

Alan's Diary http://advogato.org/person/AlanHorkan/