7 Documentation
Table of Contents
1. Introduction ................................................................................................................................................... 1 1. What is Pashua? ................................................................................................................................... 1 2. How to use Pashua ............................................................................................................................... 1 2.1. Creating a dialog ....................................................................................................................... 1 2.2. Getting values back from Pashua .............................................................................................. 1 2.3. Using the example scripts ......................................................................................................... 1 2. The window configuration ........................................................................................................................... 2 1. Basic configuration syntax rules .......................................................................................................... 2 1.1. A first example .......................................................................................................................... 3 2. Window attributes ................................................................................................................................. 4 3. Element type: button ........................................................................................................................ 6 4. Element type: cancelbutton .......................................................................................................... 7 5. Element type: checkbox .................................................................................................................... 8 6. Element type: combobox .................................................................................................................... 9 7. Element type: date ........................................................................................................................... 11 8. Element type: defaultbutton ...................................................................................................... 13 9. Element type: image ......................................................................................................................... 14 10. Element type: openbrowser ......................................................................................................... 16 11. Element type: password ................................................................................................................ 17 12. Element type: popup ....................................................................................................................... 19 13. Element type: radiobutton ......................................................................................................... 20 14. Element type: savebrowser ......................................................................................................... 22 15. Element type: text ......................................................................................................................... 24 16. Element type: textbox .................................................................................................................. 26 17. Element type: textfield ............................................................................................................. 28 3. Topics .......................................................................................................................................................... 30 1. Unicode and text encodings ............................................................................................................... 30 2. Localization ......................................................................................................................................... 31 3. Dynamic configuration strings ........................................................................................................... 31 4. Building real applications with Pashua ........................................................................................... 32 4. FAQ ............................................................................................................................................................. 34 1. How do I display 2 or more windows one after another? .................................................................. 34 2. When will Pashua support multiple checkboxes / radiobuttons / ? ................................................ 34 3. May I distribute applications based on Pashua? ................................................................................ 34 4. How can I hide the dock icon? .......................................................................................................... 34 5. Are there any tutorials on using Pashua? ........................................................................................... 34 6. WTF does Pashua mean? ................................................................................................................ 35 5. Version history ........................................................................................................................................... 36
iii
List of Tables
2.1. Window attributes ...................................................................................................................................... 4 2.2. Attributes for elements of type button .................................................................................................. 6 2.3. Attributes for elements of type cancelbutton .................................................................................... 7 2.4. Attributes for elements of type checkbox ............................................................................................. 8 2.5. Attributes for elements of type combobox ............................................................................................. 9 2.6. Attributes for elements of type date ..................................................................................................... 11 2.7. Attributes for elements of type defaultbutton ................................................................................ 13 2.8. Attributes for elements of type image .................................................................................................. 14 2.9. Attributes for elements of type openbrowser .................................................................................... 16 2.10. Attributes for elements of type password .......................................................................................... 18 2.11. Attributes for elements of type popup ................................................................................................. 19 2.12. Attributes for elements of type radiobutton .................................................................................. 21 2.13. Attributes for elements of type savebrowser .................................................................................. 22 2.14. Attributes for elements of type text ................................................................................................... 24 2.15. Attributes for elements of type textbox ............................................................................................ 26 2.16. Attributes for elements of type textfield ....................................................................................... 28 3.1. Table of supported encodings ................................................................................................................. 30
iv
List of Examples
2.1. Example window ...................................................................................................................................... 6 2.2. Example button ...................................................................................................................................... 7 2.3. Example cancelbutton ....................................................................................................................... 8 2.4. Example checkbox ................................................................................................................................. 9 2.5. Example combobox ............................................................................................................................... 11 2.6. Example date ........................................................................................................................................ 13 2.7. Example defaultbutton ................................................................................................................... 14 2.8. Example image ...................................................................................................................................... 15 2.9. Example openbrowser ........................................................................................................................ 17 2.10. Example password ............................................................................................................................. 19 2.11. Example popup .................................................................................................................................... 20 2.12. Example radiobutton ...................................................................................................................... 22 2.13. Example savebrowser ...................................................................................................................... 23 2.14. Example text ...................................................................................................................................... 26 2.15. Example textbox ............................................................................................................................... 27 2.16. Example textfield ........................................................................................................................... 29
Chapter 1. Introduction
1. What is Pashua?
Pashua ist a tool for creating native Aqua dialog windows on Mac OS X. It can be invoked from the shell and therefore is particularly useful for creating GUIs from programming languages that do not offer graphic user interfaces natively, for instance Perl, PHP or Ruby. Pashua was written by Carsten Blm and released as donationware (free to use, but donations welcome). Pashuas website is www.bluem.net/en/mac/pashua/ [http://www.bluem.net/en/mac/pashua/]
The window configuration You dont have to specify attributes in consecutive blocks. You can add as many empty lines as you like, and you could even mix up commands of different elements. When an attribute is specified more than once, the last one will be used: x.label = Label A x.label = Label B x.label = Label C would result in the element being labeled with Label C. An exception to this rule is option, which is used to set values for radiobuttons [20], combo boxes [9] and popups [19] and which may be used in multiple commands.
Or, if you like to keep things really simple, passing tx.type = textfield to Pashua would result in this window:
2. Window attributes
Window attributes are defined similar to element attributes. The only difference (apart from the fact that of course windows have other attributes than, lets say, textfields [28]) is the fact that you dont have to specify an element name before the attribute, but simply an asterisk, for instance *.title = My windowtitle
The window configuration Name transparency Purpose Sets the windows transparency, decimal value from 0 (invisible) to 1 (opaque) Only allowed value is metal, which will create a brushed metal window Required No Default 1 Since version < 0.9
appearance
No
< 0.9
autoclosetime
If No autoclosetimeis set to an integer number larger than 1, the dialog will automatically close after the specified number of seconds have passed. The timer starts in the very moment when Pashua has finished parsing the configuration string and everything is set up. Setting No autoclosetimeto 1will result in the window floating above other windows. Sets the horizontal No position where the window should be opened on the screen ( 0is the left border of the screen) Sets the vertical No position where the window should be opened on the screen
0.9.1
floating
0.9.3
0.9.3
0.9.3
The window configuration Name Purpose Required ( 0is the upper border of the screen) Default Since version
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured 6
The window configuration Name Purpose from the lower border of the content area If set to value 1, the element will be disabled, so that the default value cannot be changed. Text to use as tooltip for the button Required Default
disabled
No
Not disabled
tooltip
No
disabled
If set to value 1, the element will be disabled, so that the default value cannot be changed. Text to use as tooltip for the cancel button
No
tooltip
No
Return value: Either 1 (button clicked / user pressed Escape / user pressed Cmd-W) or 0 (button not clicked) 7
disabled
No
Not disabled
tooltip x
No
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window 8
relx
The window configuration Name Purpose border). Any integer can be used as relx value. Required Default
rely
Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
chk.type = checkbox chk.label = If you like, you can use a really long label, as the window will sc chk.tooltip = Yes, its that simple!
Adds a value to the list Yes (one option attribute of values. Can (usually is required, others are should) be used more than optional) once. Controls if and how autocompletion is performed. Possible No
completion
The window configuration Name Purpose Required values are 0 (no completion), 1 (completes the first item in the completion list which matches the entered string, case-sensitive), or 2 (ditto, but caseinsensitive). If set to value 1, the element will be disabled, so that the default value cannot be changed. Text to use as tooltip for the combo box Width in pixels No Default
disabled
Not disabled
tooltip width x
No No
200
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
10
Should the textual display No style be used instead of the graphical style? Should the user be able to No chose a date? Should the user be able to No chose the time? 11
date time
1 (Yes) 0 (No)
The window configuration Name default Purpose Required Default Current date and/or time
Default date and/or No time that should be selected when the dialog is opened. The only string format that is guaranteed to work is yyyy-mm-dd [hh:mm], for instance 2011-11-29 12:34 or 2011-11-29. Other string formats such as 12/24/2004, next wednesday or tomorrow may work, too. Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area If set to value 1, the element will be disabled, so that the default value cannot be changed. Text to use as tooltip for the button No
disabled
Not disabled
tooltip
No
Return value: Depends on the values of attributes date and time. If only a date can be selected, it will be a date string in yyyy-mm-dd format, if only a time can be selected, the format will be hh:mm. If both are enabled, you will get a date and time string in yyyy-mm-dd hh:mm format. If you only need part of this information, you have to extract the desired substrings yourself.
12
Note
A default button is added to each window automaticallyyou only have to specify it explicitly, if you want to set the label or a tooltip or need the return value (i.e.: was it clicked or not?) of this button.
tooltip
No
Return value: Either 1 (button clicked / user pressed Return) or 0 (button not clicked) 13
maxheight
No
tooltip x
No
Absolute horizontal No position in the window, measured from the left border of the content area 14
Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
15
default filetype
No
File types that can be No selected in the open dialog or dropped onto the textfield; takes a space-delimited list of filename extensions (such as jpg gif tif etc.). In addition to filename extensions, you can use directory to let the user choose directories. If only directory is specified, the user wont be able to choose any files. If only filename extensions are specified, the user wont be able to choose directories. If you dont specify filetype at all, the user will be able to choose anything in the open dialog box. Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured 16
The window configuration Name Purpose from the lower border of the content area Required Default
relx
Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
rely
Return value: Full filesystem path for the selected item (may be an empty string)
tooltip x
No
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
18
default
label disabled
No No
Not disabled
tooltip width x
No No
200
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured 19
The window configuration Name Purpose from the lower border of the content area Required Default
relx
Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
rely
Any string that should be Yes (at least one option used as a selectable value. is required) Should be used more than once. The value that should be selected by default. Of course, this must be one of the option values to work. If set to value 1, the element will be disabled, so that the default value cannot be changed. Text to use as tooltip for the button No
default
disabled
No
Not disabled
tooltip x
No
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any
relx
rely
21
The window configuration Name Purpose Required integer from -20 to 20 can be used as rely value. Default
default filetype
No
File extension to use for No the save dialog box; if this attribute is used, the user 22
The window configuration Name Purpose will be forced to use that extension for the name Required Default
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
Return value: Full filesystem path (may be an empty string, if no path chosen by user)
And this is the sheet you would get after clicking the Choose button: 23
The window configuration Name Purpose You can use the string [return] to insert a linebreak. Required Default
text
The text to display Yes (either default or (synonym for default). text must be set) You can use the string [return] to insert a linebreak. Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
25
Sets the height of the text No (in pixels) Sets the initial contents. You can use the string [return] to insert a linebreak. No
fontsize
Size of the text inside the No textbox. There are three sizes available, which conform to the systems standard sizes: regular, small, or mini . Set this to fixed if the text should be displayed using a monospace font. If set to value 1, the element will be disabled, so that the default value cannot be changed. No
regular
fonttype
disabled
No
Not disabled
26
The window configuration Name tooltip x Purpose Text to use as tooltip for the textbox Required No Default
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value.
relx
rely
27
tooltip x
No
Absolute horizontal No position in the window, measured from the left border of the content area Absolute vertical position No in the window, measured from the lower border of the content area Horizontal offset, relative No to the position the element would have if relx was not used (e.g.: relx specifies the distance from the left window border). Any integer can be used as relx value. Relative vertical distance No to the next element below (relative means that the value is added to the default distance). Any integer from -20 to 20 can be used as rely value. 28
relx
rely
The window configuration Return value: String contents (may be an empty string)
29
Chapter 3. Topics
1. Unicode and text encodings
Pashua versions 0.9.1 and above support setting a text encoding for values (but not for element names) in the configuration string, with Unicode (UTF-8) being among the supported encodings. For instance, this feature could be used to pass Japanese or Chinese characters to Pashua or read Russian or Korean characters from Pashua. While in 0.9.1, the encoding was defined in the dialog configuration itself (which, looking back, was a pretty stupid ideabut encodings didnt work reliably in 0.9.1, anyway ), versions 0.9.2 and above use an optional command-line argument -e that can be passed to Pashua. Nevertheless, you dont have to deal with that argument directly, but merely pass it as 2nd argument to the function that manages the communication with Pashua, provided you use one of the examples as a starting point. Practically, this simply means that: in Perl, you would have to call Pashua::run($conf, 'utf8') instead of Pashua::run($conf) in Python, you would have to call Pashua.run(conf, "utf8") instead of Pashua.run(conf) in PHP, you would have to call pashua_run($conf, "utf8") instead of pashua_run($conf) etc. I guess youll see how it works. Of course, you can use any valid encoding string instead of utf8. The supported encodings are:
latin1 utf8
winlatin1
Topics Encoding argument win1253 Description Microsoft Windows codepage 1253, encoding Greek characters (NSWindowsCP1253StringEncoding)
If you need to use, for instance, UTF-8 in your configuration string, it might be necessary to change the encoding of the script itself to match the encoding you want to use with Pashua; many editors support switching the encoding (also known as charset), so this shouldnt be much of a problem. If your editor does not support encodings or for some other reason its necessary to leave the script in MacRoman, you should use MacRoman representations of the characters. Simply enter the characters in TextEdit, convert to plaintext, save the document using the desired encoding, close the document and then reopen it in TextEdit, explicitly choosing MacRoman as encoding; you should now see a strange sequence of charaters ;-) Copy these characters into your MacRoman script and youre done.
2. Localization
Pashua is localized in German, French and English. The localizations are used for the menu bar, the application about box, button titles (default button [13], cancel button [7], savebrowser [22] and openbrowser [16] buttons) and of course for error messages. Its your applications responsibility to provide localization by passing an appropriate configuration string to Pashua for anything else that should be localized.
Topics user.label = Field label user.width = 160 EOCONF or this way: my $conf; my %hash = ( 'user', { type=>'textfield', 'label'=>'Field label', 'width'=>160 } ); while (my($element, $specs) = each(%hash)) { my %attributes = %$specs; foreach (sort keys %attributes) { $conf .= "${element}.$_ = $attributes{$_}\n"; } } The result would be exactly the same in any of these cases. If you take a look at the example scripts, you will see that they make use of dynamic configuration strings: the scripts directory is searched for two hidden image files (.bg.png and .icon.png) andin case they existthey are added to the window configuration.
Topics #!/bin/sh scriptpath=`dirname "$0"` osascript "$scriptpath/my_applescript.app" , but though this will work, the application wont finish launching (the Dock icon wont stop hopping).
33
Chapter 4. FAQ
1. How do I display 2 or more windows one after another?
You can call Pashua multiple times, but this will result in successive application launches (with the icon moving in and out of the Dock), which is annoying. Hiding the Dock icon [34] helps a lot in this case, but its only a remedyno real solution.
FAQ Keep in mind that the text uses the old syntax which worked until version 0.9.1. Hence, all occurrences of name_attribute in the examples should be changed to name.attribute. A more recent article was in the December 2007 issue of MacTech magazine.
35
36