OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [demos/] [samples/] [FileDlg.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Tix Demostration Program
2
#
3
# This sample program is structured in such a way so that it can be
4
# executed from the Tix demo program "widget": it must have a
5
# procedure called "RunSample". It should also have the "if" statment
6
# at the end of this file so that it can be run as a standalone
7
# program using tixwish.
8
 
9
# This file demonstrates the use of the tixFileSelectDialog widget --
10
# This is a neat file selection dialog that looks like the Motif 
11
# file-selection dialog widget. I know that Motif sucks, but 
12
# tixFileSelectDialog looks neat nevertheless.
13
#
14
proc RunSample {w} {
15
 
16
    # Create an entry for the user to input a filename. If he can't
17
    # bother to type in the name, he can press the "Browse ..." button
18
    # and call up the file dialog
19
    #
20
    frame $w.top -border 1 -relief raised
21
 
22
    tixLabelEntry $w.top.ent -label "Select A File:" -labelside top \
23
        -options {
24
            entry.width 25
25
            entry.textVariable demo_fdlg_filename
26
            label.anchor w
27
        }
28
    bind [$w.top.ent subwidget entry] <Return> "fdlg:okcmd $w"
29
 
30
    uplevel #0 set demo_fdlg_filename {}
31
 
32
 
33
    button $w.top.btn -text "Browse ..." -command "fdlg:browse"
34
 
35
    pack $w.top.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4
36
    pack $w.top.btn -side left -anchor s -padx 4 -pady 4
37
 
38
    # Use a ButtonBox to hold the buttons.
39
    #
40
    tixButtonBox $w.box -orientation horizontal
41
    $w.box add ok     -text Ok     -underline 0 -command "fdlg:okcmd $w" \
42
        -width 6
43
    $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
44
        -width 6
45
 
46
    pack $w.box -side bottom -fill x
47
    pack $w.top -side top -fill both -expand yes
48
}
49
 
50
# Pop up a file selection dialog
51
#
52
proc fdlg:browse {} {
53
    # [Hint]
54
    # The best way to use an FileSelectDialog is not to create one yourself
55
    # but to call the command "tix filedialog". This command creates one file
56
    # dialog box that is shared by different parts of the application.
57
    # This way, your application can save resources because it doesn't
58
    # need to create a lot of file dialog boxes even if it needs to input
59
    # file names at a lot of different occasions.
60
    #
61
    set dialog [tix filedialog tixFileSelectDialog]
62
    $dialog config -command fdlg:select_file
63
 
64
    $dialog popup
65
}
66
 
67
proc fdlg:select_file {file} {
68
    global demo_fdlg_filename
69
 
70
    set demo_fdlg_filename $file
71
}
72
 
73
proc fdlg:okcmd {w} {
74
    global demo_fdlg_filename
75
 
76
    if {$demo_fdlg_filename != {}} {
77
        puts "You have selected the file $demo_fdlg_filename"
78
    } else {
79
        puts "You haven't selected any file"
80
    }
81
 
82
    destroy $w
83
}
84
 
85
# This "if" statement makes it possible to run this script file inside or
86
# outside of the main demo program "widget".
87
#
88
if {![info exists tix_demo_running]} {
89
    wm withdraw .
90
    set w .demo
91
    toplevel $w
92
    RunSample $w
93
    bind .demo <Destroy> exit
94
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.