~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/tkextlib/tile/repeater.tcl

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# $Id: repeater.tcl 11708 2007-02-12 23:01:19Z shyouhei $
 
3
#
 
4
# Demonstration of custom classes.
 
5
#
 
6
# The Tile button doesn't have built-in support for autorepeat.
 
7
# Instead of adding -repeatdelay and -repeatinterval options,
 
8
# and all the extra binding scripts required to deal with them,
 
9
# we create a custom widget class for autorepeating buttons.
 
10
#
 
11
# Usage:
 
12
#       ttk::button .b -class Repeater [... other options ...]
 
13
#
 
14
# TODO:
 
15
#       Use system settings for repeat interval and initial delay.
 
16
#
 
17
# Notes:
 
18
#       Repeater buttons work more like scrollbar arrows than
 
19
#       Tk repeating buttons: they fire once immediately when
 
20
#       first pressed, and $State(delay) specifies the initial 
 
21
#       interval before the button starts autorepeating.
 
22
#
 
23
 
 
24
namespace eval tile::Repeater {
 
25
    variable State
 
26
    set State(timer)    {}      ;# [after] id of repeat script
 
27
    set State(interval) 100     ;# interval between repetitions
 
28
    set State(delay)    300     ;# delay after initial invocation
 
29
}
 
30
 
 
31
### Class bindings.
 
32
#
 
33
 
 
34
bind Repeater <Enter>           { %W state active }
 
35
bind Repeater <Leave>           { %W state !active }
 
36
 
 
37
bind Repeater <Key-space>       { tile::Repeater::Activate %W }
 
38
bind Repeater <<Invoke>>        { tile::Repeater::Activate %W }
 
39
 
 
40
bind Repeater <ButtonPress-1>   { tile::Repeater::Press %W }
 
41
bind Repeater <ButtonRelease-1> { tile::Repeater::Release %W }
 
42
bind Repeater <B1-Leave>        { tile::Repeater::Pause %W }
 
43
bind Repeater <B1-Enter>        { tile::Repeater::Resume %W } ;# @@@ see below
 
44
 
 
45
# @@@ Workaround for metacity-induced bug:
 
46
bind Repeater <B1-Enter> \
 
47
    { if {"%d" ne "NotifyUngrab"} { tile::Repeater::Resume %W } }
 
48
 
 
49
### Binding procedures.
 
50
#
 
51
 
 
52
## Activate -- Keyboard activation binding. 
 
53
#       Simulate clicking the button, and invoke the command once. 
 
54
#
 
55
proc tile::Repeater::Activate {w} {
 
56
    $w instate disabled { return }
 
57
    set oldState [$w state pressed]
 
58
    update idletasks; after 100
 
59
    $w state $oldState
 
60
    after idle [list $w invoke]
 
61
}
 
62
 
 
63
## Press -- ButtonPress-1 binding.
 
64
#       Invoke the command once and start autorepeating after 
 
65
#       $State(delay) milliseconds.
 
66
#
 
67
proc tile::Repeater::Press {w} {
 
68
    variable State
 
69
    $w instate disabled { return }
 
70
    $w state pressed
 
71
    $w invoke
 
72
    after cancel $State(timer)
 
73
    set State(timer) [after $State(delay) [list tile::Repeater::Repeat $w]]
 
74
}
 
75
 
 
76
## Release -- ButtonRelease binding.
 
77
#       Stop repeating.
 
78
#
 
79
proc tile::Repeater::Release {w} {
 
80
    variable State
 
81
    $w state !pressed
 
82
    after cancel $State(timer)
 
83
}
 
84
 
 
85
## Pause -- B1-Leave binding
 
86
#       Temporarily suspend autorepeat.
 
87
#
 
88
proc tile::Repeater::Pause {w} {
 
89
    variable State
 
90
    $w state !pressed
 
91
    after cancel $State(timer)
 
92
}
 
93
 
 
94
## Resume -- B1-Enter binding
 
95
#       Resume autorepeat.
 
96
#
 
97
proc tile::Repeater::Resume {w} {
 
98
    variable State
 
99
    $w instate disabled { return }
 
100
    $w state pressed
 
101
    $w invoke
 
102
    after cancel $State(timer)
 
103
    set State(timer) [after $State(interval) [list tile::Repeater::Repeat $w]]
 
104
}
 
105
 
 
106
## Repeat -- Timer script
 
107
#       Invoke the command and reschedule another repetition 
 
108
#       after $State(interval) milliseconds.
 
109
#
 
110
proc tile::Repeater::Repeat {w} {
 
111
    variable State
 
112
    $w instate disabled { return }
 
113
    $w invoke
 
114
    set State(timer) [after $State(interval) [list tile::Repeater::Repeat $w]]
 
115
}
 
116
 
 
117
#*EOF*