~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-en/entry3.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
# based on Tcl/Tk8.4.4 widget demos
8
8
 
9
9
if defined?($entry3_demo) && $entry3_demo
10
 
  $entry3_demo.destroy 
 
10
  $entry3_demo.destroy
11
11
  $entry3_demo = nil
12
12
end
13
13
 
19
19
 
20
20
base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true)
21
21
 
22
 
TkLabel.new(base_frame, 
23
 
            :font=>$font, :wraplength=>'5i', :justify=>:left, 
 
22
TkLabel.new(base_frame,
 
23
            :font=>$font, :wraplength=>'5i', :justify=>:left,
24
24
            :text=><<EOL).pack(:side=>:top)
25
25
Four different entries are displayed below.  You can add characters \
26
26
by pointing, clicking and typing, though each is constrained in what \
63
63
def focusAndFlash(widget, fg, bg, count=5)
64
64
  return if count <= 0
65
65
  if fg && !fg.empty? && bg && !bg.empty?
66
 
    TkTimer.new(200, count, 
67
 
                proc{widget.configure(:foreground=>bg, :background=>fg)}, 
 
66
    TkTimer.new(200, count,
 
67
                proc{widget.configure(:foreground=>bg, :background=>fg)},
68
68
                proc{widget.configure(:foreground=>fg, :background=>bg)}
69
69
                ).start
70
70
  else
86
86
end
87
87
 
88
88
l1 = TkLabelFrame.new(base_frame, :text=>"Integer Entry")
89
 
TkEntry.new(l1, :validate=>:focus, 
 
89
TkEntry.new(l1, :validate=>:focus,
90
90
            :vcmd=>[
91
91
              proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
92
92
            ]) {|e|
97
97
}
98
98
 
99
99
l2 = TkLabelFrame.new(base_frame, :text=>"Length-Constrained Entry")
100
 
TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell}, 
 
100
TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell},
101
101
            :vcmd=>[proc{|s| s.length < 10}, '%P']
102
102
            ).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
103
103
 
171
171
 
172
172
def validatePhoneChange(widget, vmode, idx, char)
173
173
  return true if idx == nil
174
 
  Tk.after_idle(proc{widget.configure(:validate=>vmode, 
 
174
  Tk.after_idle(proc{widget.configure(:validate=>vmode,
175
175
                                      :invcmd=>proc{Tk.bell})})
176
176
  if !(idx<3 || idx==6 || idx==7 || idx==11 || idx>15) && char =~ /[0-9A-Za-z]/
177
177
    widget.delete(idx)
179
179
    Tk.after_idle(proc{phoneSkipRight(widget, -1)})
180
180
    return true
181
181
    # Tk.update(true) # <- Don't work 'update' inter validation callback.
182
 
                      #    It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). 
 
182
                      #    It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
183
183
  end
184
184
  return false
185
185
end
186
186
 
187
187
 
188
188
l3 = TkLabelFrame.new(base_frame, :text=>"US Phone-Number Entry")
189
 
TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, 
190
 
            :textvariable=>entry3content, 
 
189
TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
 
190
            :textvariable=>entry3content,
191
191
            :vcmd=>[
192
 
              proc{|w,v,i,s| validatePhoneChange(w,v,i,s)}, 
 
192
              proc{|w,v,i,s| validatePhoneChange(w,v,i,s)},
193
193
              "%W %v %i %S"
194
194
            ]){|e|
195
195
  # Click to focus goes to the first editable character...
205
205
}
206
206
 
207
207
l4 = TkLabelFrame.new(base_frame, :text=>"Password Entry")
208
 
TkEntry.new(l4, :validate=>:key, :show=>'*', 
 
208
TkEntry.new(l4, :validate=>:key, :show=>'*',
209
209
            :vcmd=>[
210
 
              proc{|s| s.length <= 8}, 
 
210
              proc{|s| s.length <= 8},
211
211
              '%P'
212
212
            ]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
213
213