It is currently Sun Jun 30, 2024 3:56 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Script-fu skip run-mode parameter (solved)
PostPosted: Mon Nov 14, 2022 8:33 am  (#1) 
Offline
New Member

Joined: Nov 14, 2022
Posts: 4
Hi there. I'm new to this forum.

I wrote some script-fus and a python-fu, some of which don't need a dialogue and no run-mode parameter either. So i didn't include it in the registration's parameter list. But when I call these functions I am forced to put a RUN-NONINTERACTIVE or RUN-INTERACTIVE at the beginning of the argument list. To keep my code better readable I would be glad to know how to register the scripts without run-mode.

Gimp 2.10.32 on macOS Ventura 13.0.1.

Thanks in advance.
Volker


Last edited by preklov on Wed Nov 16, 2022 1:16 pm, edited 2 times in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Script-fu skip run-mode parameter
PostPosted: Mon Nov 14, 2022 4:49 pm  (#2) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Can you post the code? It would be easier to see what your referring.

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Script-fu skip run-mode parameter
PostPosted: Tue Nov 15, 2022 3:57 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Does the param require an int?
Try 1 or 0

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Script-fu skip run-mode parameter
PostPosted: Tue Nov 15, 2022 4:27 am  (#4) 
Offline
New Member

Joined: Nov 14, 2022
Posts: 4
Of course I could substitute the argument with 0 or 1 to shorten the code. But I use to come to work on Gimp macros only in intervals of years, and I fear that next time I try to understand my code I would puzzle about what the heck is that 0 or 1. So I'd prefer a more straightforward solution.

My code for two very simple python-fu macros, one to read a metadata value and the other to create a new directory:
from gimpfu import *

import xml.etree.ElementTree as ET
import os

def get_metadata_value(metadata, metadata_name):
  ic_name = metadata_name.lower()
  value   = ""
  root_node = ET.XML(metadata)
  for tag in root_node.findall('tag'):
    if tag.attrib['name'].lower() == ic_name:
      value = tag.text
      break
  return value

register(
  "python-fu-image-get-metadata-value",
  "Get the value of an image metadata tag",
  "Get the value of an image metadata tag.",
  "Volker Lenhardt",
  "Volker Lenhardt",
  "2022",
  "",
  None,
  [
    (PF_STRING, "metadata", "The metadata of an image as an xml string", ""),
    (PF_STRING, "metadata-name", "The tag name (case insensitive)", ""),
  ],
  [ (PF_STRING, "value", "Tag value"),],
  get_metadata_value,)

def make_dir(path):
  if not os.path.exists(path):
    os.mkdir(path)
    return 1
  elif os.path.isdir(path):
    return 0
  return -1

register(
  "python-fu-make-dir",
  "Make a new directory",
  "Make a new directory, if it does not exist.",
  "Volker Lenhardt",
  "Volker Lenhardt",
  "2022",
  "",
  None,
  [(PF_STRING, "path", "The full path to the new directory", ""),],
  [(PF_INT, "state", "The result state of the operation\n-1 = path exists as a normal file\n 0 = path exists as a directory\n 1 = path generated as a new directory"),],
  make_dir,)

main()


A clipping from a script-fu shows the use:
...
(let*
    (
      (title-tag
        "xmp.dc.title")
      (date-tag
        "xmp.exif.datetimeoriginal")
      (metadata
        (car (gimp-image-get-metadata image)))
      (title
        (string-trim (car (python-fu-image-get-metadata-value
                            RUN-NONINTERACTIVE metadata title-tag))))
      (date
        (car (python-fu-image-get-metadata-value
               RUN-NONINTERACTIVE metadata date-tag)))
...


Top
 Post subject: Re: Script-fu skip run-mode parameter
PostPosted: Tue Nov 15, 2022 5:32 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
The question is why you are making separate script-fu scripts to call your python code when you could have everything in one single python file? Everything in script-fu also exists in python-fu.

PS: and IMHO the "readability" is Scheme's main problem, whether Gimp is implied or not.

_________________
Image


Top
 Post subject: Re: Script-fu skip run-mode parameter
PostPosted: Tue Nov 15, 2022 7:58 am  (#6) 
Offline
New Member

Joined: Nov 14, 2022
Posts: 4
Many years ago I wrote a few script-fu (Tiny-fu in those days) macros to perform some batch tasks. I improved and extended them 7 years ago. For my needs now I could reuse the most part of them but for the few tasks that are not possible in Scheme (see my code).

I agree with you that Scheme is somehow deprecated, not only because of its readability problem (that you can reduce by a consequent indent structure to keep track of the parantheses). Some day I'll go about transferring the whole stuff to Python, I hope. I like to develop new code, but to refight old battles is not so desirable.

I don't call for a new feature, I only wanted to know if there is a way to keep Gimp from inserting a parameter that is not defined. If I get told that there is no way then I'll content myself with it.

Greetings, Volker


Top
 Post subject: Re: Script-fu skip run-mode parameter (solved)
PostPosted: Wed Nov 16, 2022 1:22 pm  (#7) 
Offline
New Member

Joined: Nov 14, 2022
Posts: 4
I found the solution.

For Python-fu there is a register parameter run_mode_param (listed at the very end) that defaults to True.
register(
  "python-fu-image-get-metadata-value",
  "Get the value of an image metadata tag",
  "Get the value of an image metadata tag.",
  "Volker Lenhardt",
  "Volker Lenhardt",
  "2022",
  "",
  None,
  [
    (PF_STRING, "metadata", "The metadata of an image as an xml string", ""),
    (PF_STRING, "metadata-name", "The tag name (case insensitive)", ""),
  ],
  [ (PF_STRING, "value", "Tag value"),],
  get_metadata_value,
  run_mode_param = False,)

Setting it to False did the trick.

Thank you for your attention, Volker


Top
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts wrong parameter type in pdb.plug_in_cubism

9

No new posts Invalid parameter name dialog status error

4

No new posts Python-fu gimp_drawable_levels(): "TypeError: wrong parameter type"

2

No new posts "Wrong parameter type" using Map object (Solved)

7

No new posts Open images in RGB mode automatically

1



* Login  



Powered by phpBB3 © phpBB Group