File: keymapconfig

package info (click to toggle)
osdsh 0.7.0-10.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 452 kB
  • ctags: 348
  • sloc: ansic: 1,063; tcl: 335; makefile: 121
file content (134 lines) | stat: -rwxr-xr-x 3,783 bytes parent folder | download | duplicates (9)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/wish

wm title . "Keymap Configurator"
set status "Ready"

entry .status -textvariable status
button .b1 -text "New Key" -command "new_key"
button .b2 -text "Edit Key" -command "edit_key"
button .b3 -text "Delete Key" -command "delete_key"
button .b4 -text "Load Keymap" -command "load_keymap"
button .b5 -text "Save Keymap" -command "save_keymap"
button .b6 -text "Quit" -command "destroy ."
button .b7 -text "Try this keys" -command "try_keys"

label .keyslabel -text "Current keys: "
listbox .keys -yscrollcommand ".keysscroll set"
scrollbar .keysscroll -command ".keys yview"

grid .keyslabel -column 0 -columnspan 3 -row 0 -sticky nsew
grid .keys -column 0 -rowspan 5 -sticky nsew -row 1
grid .keysscroll -column 1 -rowspan 5 -row 1 -sticky nsew
grid .b7 -column 0 -columnspan 2 -row 6 -sticky nsew

grid .b1 -column 2 -row 1 -sticky nsew
grid .b2 -column 2 -row 2 -sticky nsew
grid .b3 -column 2 -row 3 -sticky nsew
grid .b4 -column 2 -row 4 -sticky nsew
grid .b5 -column 2 -row 5 -sticky nsew
grid .b6 -column 2 -row 6 -sticky nsew

grid .status -column 0 -row 7 -columnspan 3 -sticky nsew

focus .b1

proc new_key {} {
	global status keycode keysym where
	set status "Press a Key"
	set where "end"
	set keysym ""
	set keycode ""
	.status configure -foreground red
#	toplevel .getkey
#	label .getkey.label -text "Press a key here"
#	pack .getkey.label -fill both -expand 1
	bind . <KeyPress> {set keycode %k;bind . <KeyPress> {};;get_keysym}
}


proc add_key {} {
	global status keycode keysym where
	set status "Ready"
	.keys insert $where "keycode $keycode = $keysym"
}

proc delete_key {} {
	.keys delete active
}

proc edit_key {} {
	global status keycode keysym where
	set where [.keys index active]
	set lista [split [.keys get active]]
	set keycode [lindex $lista 1]
	set keysym [lindex $lista 3]
	toplevel .edit
	wm title .edit "Edit Key"
	label .edit.label -text "Enter the keysym to assign to this keycode"
	label .edit.keycode -text "Keycode $keycode = "
	entry .edit.entry -textvariable keysym -width 15
	button .edit.button -text "OK" -command "delete_key;add_key;destroy .edit"
	button .edit.button2 -text "Cancel" -command "destroy .edit"
	bind .edit.entry <Return> "delete_key; add_key; destroy .edit"
	bind .edit.entry <Escape> "destroy .edit"

	grid .edit.label -sticky nsew -row 0 -columnspan 4
	grid .edit.keycode .edit.entry .edit.button2 .edit.button -row 1 -sticky nsew

}

proc save_keymap {} {
	global status
	set file [tk_getSaveFile]
	if {![string equal $file ""]} {
		set id [open $file w]

		for {set i 0} {[expr $i < [.keys index end]]} {incr i} {
			puts $id [string map {"\{" "" "\}" ""} [.keys get $i]]
		}

		close $id
	}
	set status "Saved keymap in $file"
}

proc get_keysym {} {
	global status keycode keysym
	toplevel .keysym
	wm title .keysym "Add key"
	label .keysym.label -text "Enter the keysym to assign\nRecommended: IA1-IA15 or IB1-IB15"
	entry .keysym.entry -textvariable keysym 
	button .keysym.button -text "OK" -command "add_key; destroy .keysym"
	grid .keysym.label -row 0 -columnspan 5 -sticky nsew
	grid .keysym.entry -row 1 -columnspan 4 -sticky nsew
	grid .keysym.button -row 1 -columnspan 1 -column 5 -sticky nsew
	bind .keysym.entry <Return> "add_key ; destroy .keysym"
	focus .keysym.entry
	.status configure -foreground black
	set status "Ready"
}

proc try_keys {} {
	global status
	set id [open tmpfile w+]
	for {set i 0} {$i < [.keys index end]} {incr i} {
		puts $id [string map {"\{" "" "\}" ""} [.keys get $i]]
	}
	close $id
	exec xmodmap tmpfile
}

proc load_keymap {} {
	global status where
	.keys delete 0 end
	set file [tk_getOpenFile]
	if {$file != ""} {
		set id [open $file r]
		while {[gets $id readbuffer] > 0} {
		.keys insert end $readbuffer
		}
		close $id
		set status "Read $file"
	}
}