diff options
Diffstat (limited to 'ext/tk/sample/demos-en/widget')
-rw-r--r-- | ext/tk/sample/demos-en/widget | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index dc40f0a95f..9a0605d8b9 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -775,6 +775,12 @@ def showCode1(demo) TkLabel.new(f,'text'=>' pos:').pack('side'=>'left') posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x') if $tk_version =~ /^4\.[01]/ @@ -820,10 +826,21 @@ def showCode1(demo) TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0) } end + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise end + $code_window.title("Demo code: #{file}") $code_window.iconname(file) # fid = open(file, 'r') @@ -835,22 +852,7 @@ def showCode1(demo) #$code_text.set_insert('1.0') TkTextMarkInsert.new($code_text,'1.0') - btag = TkBindTag.new - - set_linenum = proc{|w| - line, pos = w.index('insert').split('.') - linenum.text = line - posnum.text = pos - } - - btag.bind('Key', set_linenum, '%W') - btag.bind('Button', set_linenum, '%W') - - btags = $code_text.bindtags - btags.insert(btags.index($code_text.class) + 1, btag) - $code_text.bindtags = btags - - set_linenum.call($code_text) + $set_linenum.call($code_text) fid.close end @@ -879,6 +881,12 @@ def showCode2(demo) TkLabel.new(lf, :text=>' pos:').pack(:side=>:left) posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + b_dis = TkButton.new(bf, :text=>'Dismiss', :default=>:active, :command=>proc{ $code_window.destroy @@ -909,6 +917,17 @@ def showCode2(demo) $code_window.bindinfo('Return').each{|cmd, arg| $code_window.bind_append('Escape', cmd, arg) } + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + btag.bind('Configure', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise @@ -921,22 +940,7 @@ def showCode2(demo) $code_text.insert('1.0', fid.read) TkTextMarkInsert.new($code_text,'1.0') - btag = TkBindTag.new - - set_linenum = proc{|w| - line, pos = w.index('insert').split('.') - linenum.text = line - posnum.text = pos - } - - btag.bind('Key', set_linenum, '%W') - btag.bind('Button', set_linenum, '%W') - - btags = $code_text.bindtags - btags.insert(btags.index($code_text.class) + 1, btag) - $code_text.bindtags = btags - - set_linenum.call($code_text) + $set_linenum.call($code_text) fid.close end |