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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [demos/] [samples/] [HList1.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 tixHList widget -- you can
10
# use to display data in a tree structure. For example, your family tree
11
#
12
#
13
proc RunSample {w} {
14
 
15
    # Create the tixHList and the tixLabelEntry widgets on the on the top
16
    # of the dialog box
17
    #
18
    # [Hint] We create the tixHList and and the scrollbar by ourself,
19
    #        but it is more convenient to use the tixScrolledHlist widget
20
    #        which does all the chores for us.
21
    #
22
    # [Hint] Use of the -browsecmd and -command options:
23
    #        We want to set the tixLabelEntry accordingly whenever the user
24
    #        single-clicks on an entry in the HList box. Also, when the user
25
    #        double-clicks, we want to print out the selection and close
26
    #        the dialog box
27
    #
28
    frame $w.top -border 1 -relief raised
29
 
30
    tixHList $w.top.h -yscrollcommand "$w.top.s set" -separator / \
31
        -browsecmd "hlist1:browse $w.top.h" \
32
        -command "hlist1:activate $w.top.h"\
33
        -wideselection false \
34
        -indent 15
35
    scrollbar $w.top.s -command "$w.top.h yview" -takefocus 0
36
 
37
    # Some icons for our list entries
38
    #
39
    global folder1 folder2
40
    set img1 [image create bitmap -data $folder1]
41
    set img2 [image create bitmap -data $folder2]
42
 
43
    # Put our directories into the HList entry
44
    #
45
    set h $w.top.h
46
    set dirs {
47
        /
48
        /lib
49
        /pkg
50
        /usr
51
        /usr/lib
52
        /usr/local
53
        /usr/local/lib
54
        /pkg/lib
55
    }
56
    foreach d $dirs {
57
        $h add $d -itemtype imagetext -text $d -image $img2 -data $d
58
 
59
        # We only want the user to select the directories that
60
        # ends by "lib"
61
        if {![string match "*lib" $d]} {
62
            $h entryconfig $d -state disabled -image $img1
63
        }
64
    }
65
 
66
    # We use a LabelEntry to hold the installation directory. The user
67
    # can choose from the DirList widget, or he can type in the directory 
68
    # manually
69
    #
70
    tixLabelEntry $w.top.e -label "Installation Directory:" -labelside top \
71
        -options {
72
            entry.width 25
73
            entry.textVariable demo_hlist_dir
74
            label.anchor w
75
        }
76
    bind [$w.top.e subwidget entry] <Return> "hlist:okcmd $w"
77
 
78
    # Set the default value
79
    #
80
    uplevel #0 set demo_hlist_dir /usr/local/lib
81
    $h anchor set /usr/local/lib
82
    $h select set /usr/local/lib
83
 
84
    pack $w.top.h -side left -expand yes -fill both -padx 2 -pady 2
85
    pack $w.top.s -side left -fill y -pady 2
86
    pack $w.top.e -side left -expand yes -fill x -anchor s -padx 4 -pady 2
87
 
88
    # Use a ButtonBox to hold the buttons.
89
    #
90
    tixButtonBox $w.box -orientation horizontal
91
    $w.box add ok     -text Ok     -underline 0 -command "hlist:okcmd $w" \
92
        -width 6
93
    $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
94
        -width 6
95
 
96
    pack $w.box -side bottom -fill x
97
    pack $w.top -side top -fill both -expand yes
98
}
99
 
100
# In an actual program, you may want to tell the user how much space he has
101
# left in this directory
102
#
103
#
104
proc hlist1:browse {w dir} {
105
    global demo_hlist_dir
106
 
107
    set demo_hlist_dir [$w entrycget $dir -data]
108
}
109
 
110
# In an actual program, you will install your favorit application
111
# in the selected directory
112
#
113
proc hlist1:activate {w dir} {
114
    global demo_hlist_dir
115
 
116
    set demo_hlist_dir [$w entrycget $dir -data]
117
    puts "You have selected the directory $demo_hlist_dir"
118
 
119
    destroy [winfo toplevel $w]
120
}
121
 
122
proc hlist:okcmd {w} {
123
    global demo_hlist_dir
124
 
125
    puts "You have selected the directory $demo_hlist_dir"
126
 
127
    destroy $w
128
}
129
 
130
set folder1 {
131
#define foo_width 16
132
#define foo_height 12
133
static unsigned char foo_bits[] = {
134
   0x00, 0x00, 0x00, 0x3e, 0xfe, 0x41, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
135
   0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};}
136
 
137
set folder2 {
138
#define foo_width 16
139
#define foo_height 12
140
static unsigned char foo_bits[] = {
141
   0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x02, 0x40, 0x02, 0x44, 0xf2, 0x4f,
142
   0xf2, 0x5f, 0xf2, 0x4f, 0x02, 0x44, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};
143
}
144
 
145
# This "if" statement makes it possible to run this script file inside or
146
# outside of the main demo program "widget".
147
#
148
if {![info exists tix_demo_running]} {
149
    wm withdraw .
150
    set w .demo
151
    toplevel $w
152
    RunSample $w
153
    bind .demo <Destroy> exit
154
}
155
 

powered by: WebSVN 2.1.0

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