Documentation‎ > ‎Chooser Buttons‎ > ‎

gnocl::fileChooserButton

A command which creates a button for selection of single files. Clicking on the displayed button will cause the display of a filechooser dialog.

Synopsis

gnocl::fileChooserButton [-option value...]

Screenshot


Options

-borderWidth int
Space around the widgets contents in pixels.
-data string (default: "")
User defined data which can be retrieved via the cget subcommand..
-focusClick boolean (default: 1)
Whether the button grabs focus when it is clicked with the mouse.
-hasFocus boolean (default: 0)
Name of the widget, can be used to set options in an rc file.
-heightGroup string (default: "")
The -heightGroup option can be an arbitrary string. All widgets with the same heightGroup request the same height. If packed with the fill flag set, they will have nevertheless different heights.
-name string (default: "")
Name of the widget, can be used to set options in an rc file..
-onFileSet string (default: "")
Tcl command which is executed in the global scope when a file is selected. Before evaluation the following percent strings are substituted:

%w   widget name
%f    name of the file selected
%g   glade/builder name
-sensitive boolean (default: 1)
Whether or not the item is sensitive to user input.
-tooltip string  (default: "")
Message that appear next to this widget when the mouse pointer is held over it for a short amount of time.
-title percent-string (default: "")

       Title to put on the file chooser dialog associated with the button.
-visible boolean (default: 1)
Whether or not the item is visible.
-widthGroup string (default: "")

The -widthGroup option can be an arbitrary string. All widgets with the same widthGroup request the same width. If packed with the fill flag set, they will have nevertheless different widths.

Description

A widget that lets the user select a file. If the button is clicked, it will launch a filechooser dialog and then display the name of the file selected and its associated icon type.

Commands

id cget option

Returns the value for the specified option. The option may have any of hte values accepted by configure.

id class

Returns the class of the widget, i.e. fileChooserButton

id configure [-option value...]

Configures the widget. Option may have any of the values accepted on creation of the widget.
id delete
Deletes the widget and the associated tcl command.

Example 1

#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set box [gnocl::box -orientation vertical]

set fileBut [gnocl::fileChooserButton \
    -borderWidth 10 \
    -widthChars 15 \
    -onFileSet {puts "You picked %f"}]

$box add $fileBut

gnocl::window -child $box


Example 2

The gnocl::fileChooserButton is a binding to the gtk_file_chooser_button which is restricted to the "open" action and so does not produce a dialog with the appopriate default tiltes and icons. A simple workaround for this is shown below. The proc will create a button which, when clicked, will launch a file chooser dialog menu. If a file is choosen, the full path will be passed to the variable var and the button label set the the file filename, and the tooltip to the full path. If no file is selected then an empty string will returned. All options values pairs will be passed to the dialog.

#---------------
# Create alternative to gnocl::fileChooserButton which allows for all actions
#---------------
# Arguments:
#    val     name variable which will contain the name of the selected file
#    args    string of option value pairs to be passed to the dialog widget
# Returns:
#    res    widget-id
#
proc myFileButton { var args } {

    set res [gnocl::button -text [file tail [set $var]] -align left ]
    $res configure \
        -data [list $var $args] \
        -onClicked {
            set [lindex %d 0] [ gnocl::fileChooserDialog {*}[lindex %d 1] ] ;# treat list as individual args
           
            if { [set [lindex %d 0]] == ""} { set [lindex %d 0] "(none)" }
           
            %w configure \
                -text [file tail [set [lindex %d 0]] ] \
                -tooltip [set [lindex %d 0]]
            }
     
    return $res

}


Comments