Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ask the user for a file name?

Searching for the call of a FileDialog

I would like to ask the user for a file name in Pharo 4.0

Through the spotter I found class

  FileDialogWindow

with a method

  answerFileName

Looking for the senders of #answerFileName I get to class

  UITheme

where it is called in the method

  chooseFileNameIn: aThemedMorph 
  title: title 
  extensions: exts 
  path: path preview: preview

And from there I come to class

 TEasilyThemed

with the method

 chooseFileName: title extensions: exts path: path preview: preview

From there finally I get to class

  WidgetExamples class >> exampleDialogs

And then I have the call

WidgetExamples exampleBuilder 
chooseFileName: 'Pick a file name' 
extensions: nil path: nil preview: nil.

However a print it of this expression does not give back a file name.

Question

What is the regular way of calling a file dialog?

Supplementary question after answers

Two classes are mentioned providing this service.

  • UIManager
  • UITheme

UIManager comment

UIManager is a dispatcher for various UI requests.

UITheme comment

Common superclass for User Interface themes. Provides methods for creating new morphs in a standard way, various "services" like a file dialog, message dialogs etc. and also methods for customising aspects of the appearance of various morphs. Though conceptually abstract, no code is "missing". Subclasses, therefore, should override the aspects they wish to change.

What is the difference between this two approaches?

like image 782
z-- Avatar asked Aug 25 '15 07:08

z--


People also ask

How do you ask for a filename in Python?

Use the input function on Python 3, or raw_input if you're using Python 2: # Python 3 with open(input(), 'rU') as input_file: # Python 2 with open(raw_input(), 'rU') as input_file: This prompts the user for text input and returns it as a string. In your case, this will prompt for a file path to be input.

How do you pass a file name as an argument in Python?

This can be done by passing a comma-separated list of file names as one of the arguments while running the script. FOr example, if you have a script called `myscipt.py' you would run it as: python myscript.py file1,file2,file3.

What Python function would you use if you wanted to prompt the user for a file name to open?

Input function would be used if you wanted to prompt the user for a file name to open. Hope it helps!


1 Answers

The easiest way is to use:

UIManager default chooseFileMatching: nil

You can specify patterns as:

UIManager default chooseFileMatching: #('*.jpg' '*.png')

You can also specify a label for the dialog:

UIManager default
    chooseFileMatching: #('*.jpg' '*.png')
    label: 'Please select and image to process'
like image 98
Uko Avatar answered Sep 30 '22 20:09

Uko