File: buttonentry.tcl

package info (click to toggle)
ppxp 0.99120923-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,812 kB
  • ctags: 3,704
  • sloc: ansic: 24,532; tcl: 3,992; makefile: 517; sh: 80
file content (106 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
#
#
#

set bent_proc(get)		bent:get
set bent_proc(delete)		bent:delete
set bent_proc(index)		bent:index
set bent_proc(insert)		bent:insert
set bent_proc(subwidget)	bent:subwidget

Widget:DefineClass ButtonEntry {} bent:create bent:config bent_proc

proc bent:create {w a} {
    entry $w.entry
    button $w.button -padx 0 -pady 0 -takefocus 0 -highlightthickness 0

    bent:set_state $w normal

    pack $w.entry -side left -fill x -expand yes
    pack $w.button -side left

    return $w
}

proc bent:set_state {w state} {
    switch $state {
	disabled {
	    set entry_state disabled
	    set button_state disabled
	    set mouse_action {}
	}
	readonly -
	buttononly {
	    set entry_state readonly
	    set button_state normal
	    set mouse_action [list $w.button invoke]
	}
	normal -
	editable -
	default {
	    set entry_state normal
	    set button_state normal
	    set mouse_action {}
	}
    }
    Widget:SetEntryState $w.entry $entry_state
    $w.button configure -state $button_state
    bind $w.entry <ButtonRelease-1> $mouse_action
}

proc bent:config {w opt val} {
    global bent_conf

    switch -- $opt {
	-width {
	    $w.entry configure -width $val
	}
	-height {
	    $w.entry configure -width $val
	}
	-variable {
	    $w.entry configure -textvariable $val
	}
	-buttonimage {
	    $w.button configure -image $val
	}
	-buttontext {
	    $w.button configure -text $val
	}
	-buttoncommand {
	    $w.button configure -command $val
	}
	-state {
	    bent:set_state $w $val
	}
	default {
	    return 1
	}
    }
    return 0
}

proc bent:get {w a} {
    $w.entry get
}

proc bent:delete {w a} {
    eval $w.entry delete $a
}

proc bent:index {w a} {
    eval $w.entry insert $a
}

proc bent:insert {w a} {
    eval $w.entry insert $a
}

proc bent:subwidget {w a} {
    switch [shift a] {
	entry {return $w.entry}
	button {return $w.button}
	default {return ""}
    }
}