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

Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create*

This discussion is connected to the gimp-developer-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.

Ofnuts
2011-11-13 21:44:21 UTC (about 13 years ago)

Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create*

I'm writing a python plugin that saves things to a file, and I'm trying to come up with the right parameter type to obtain a filename form the user.

There are PF_FILE and PF_FILENAME parameter types. Both correspond to a string with the file name in it. Furthermore the file must exist for both, so they cannot be used for the name of a file to be created? Why are there two types if they do the same thing? Am I missing something?

Jerry Baker
2011-11-14 12:32:48 UTC (about 13 years ago)

Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create*

PF_FILENAME: Only allows the user to choose a file. PF_DIRNAME: Only allows the user to choose a directory.

PF_FILE: Allows the user to choose a file or a directory depending on what your default string is.

If you put a '/' at the end of the default string it will prompt the user for a directory.
If you leave off the '/' at the end of the default string it will prompt the user for a file.

Examples: (PF_FILE, "pf_afile", _("Choose File:"), "/home/jbaker"), # Choose a file
(PF_FILE, "pf_adir", _("Choose Directory:"), "/home/jbaker/"), # Choose a directory

or

(PF_FILE, "pf_afile", _("Choose File:"), ""), (PF_FILE, "pf_adir", _("Choose Directory:"), "/"),

-----Original Message----- From: Ofnuts
To: gimp-developer-list@gnome.org
Subject: [Gimp-developer] Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create* Date: Sun, 13 Nov 2011 22:44:21 +0100

I'm writing a python plugin that saves things to a file, and I'm trying to come up with the right parameter type to obtain a filename form the user.

There are PF_FILE and PF_FILENAME parameter types. Both correspond to a string with the file name in it. Furthermore the file must exist for both, so they cannot be used for the name of a file to be created? Why are there two types if they do the same thing? Am I missing something?

Ofnuts
2011-11-14 20:53:25 UTC (about 13 years ago)

Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create*

OK, makes sense. Now, how can I prompt for the name of a file that doesn't exist (yet)?

On 11/14/2011 01:32 PM, Jerry Baker wrote:

PF_FILENAME: Only allows the user to choose a file. PF_DIRNAME: Only allows the user to choose a directory.

PF_FILE: Allows the user to choose a file or a directory depending on what your default string is.

If you put a '/' at the end of the default string it will prompt the user for a directory.
If you leave off the '/' at the end of the default string it will prompt the user for a file.

Examples: (PF_FILE, "pf_afile", _("Choose File:"), "/home/jbaker"), # Choose a file
(PF_FILE, "pf_adir", _("Choose Directory:"), "/home/jbaker/"), # Choose a directory

or

(PF_FILE, "pf_afile", _("Choose File:"), ""), (PF_FILE, "pf_adir", _("Choose Directory:"), "/"),

-----Original Message----- *From*: Ofnuts >
*To*: gimp-developer-list@gnome.org > *Subject*: [Gimp-developer] Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create* *Date*: Sun, 13 Nov 2011 22:44:21 +0100

I'm writing a python plugin that saves things to a file, and I'm trying to come up with the right parameter type to obtain a filename form the user.

There are PF_FILE and PF_FILENAME parameter types. Both correspond to a string with the file name in it. Furthermore the file must exist for both, so they cannot be used for the name of a file to be created? Why are there two types if they do the same thing? Am I missing something?

Jerry Baker
2011-11-15 11:44:36 UTC (about 13 years ago)

Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create*

The only way that I know of is to use a widget for the directory and one for the file, then os.path.join them...

import os

from gimpfu import *

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def jbtest(project_directory, new_file):

final_str = "Test Text..."
output_file = open(os.path.join(project_directory, new_file), 'w') output_file.write(final_str)
output_file.close()

register( "jbtest",
N_("Choose a Directory and Filename:"), "Create a new file in the specified directory", "Jerry Baker",
"Jerry Baker",
"11/14/2011",
N_("jbtest"),
"",
[
# --- Parameters
(PF_DIRNAME, "project_directory", _("Project Directory:"), ""), (PF_STRING, "new_file", _("File Name:"), _("new_file.txt")), ],
[
# --- Results
],
jbtest,
menu="/_Dev",
domain=("gimp20-python", gimp.locale_directory) )

main()

-----Original Message----- From: Ofnuts
Cc: gimp-developer-list@gnome.org
Subject: Re: [Gimp-developer] Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create* Date: Mon, 14 Nov 2011 21:53:25 +0100

OK, makes sense. Now, how can I prompt for the name of a file that doesn't exist (yet)?

On 11/14/2011 01:32 PM, Jerry Baker wrote:

PF_FILENAME: Only allows the user to choose a file. PF_DIRNAME: Only allows the user to choose a directory.

PF_FILE: Allows the user to choose a file or a directory depending on what your default string is.

If you put a '/' at the end of the default string it will prompt the user for a directory.
If you leave off the '/' at the end of the default string it will prompt the user for a file.

Examples: (PF_FILE, "pf_afile", _("Choose File:"), "/home/jbaker"), # Choose a file
(PF_FILE, "pf_adir", _("Choose Directory:"), "/home/jbaker/"), # Choose a directory

or

(PF_FILE, "pf_afile", _("Choose File:"), ""), (PF_FILE, "pf_adir", _("Choose Directory:"), "/"),

-----Original Message----- From: Ofnuts
To: gimp-developer-list@gnome.org
Subject: [Gimp-developer] Python-fu: difference between PF_FILE and PF_FILENAME, and how to ask for a file name to *create* Date: Sun, 13 Nov 2011 22:44:21 +0100

I'm writing a python plugin that saves things to a file, and I'm trying to come up with the right parameter type to obtain a filename form the user.

There are PF_FILE and PF_FILENAME parameter types. Both correspond to a string with the file name in it. Furthermore the file must exist for both, so they cannot be used for the name of a file to be created? Why are there two types if they do the same thing? Am I missing something?