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.
What is the regular way of calling a file dialog?
Two classes are mentioned providing this service.
UIManager is a dispatcher for various UI requests.
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?
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.
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.
Input function would be used if you wanted to prompt the user for a file name to open. Hope it helps!
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With