1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/sample/demos-jp/twind.rb

285 lines
8.2 KiB
Ruby
Raw Normal View History

#
# text (embedded windows) widget demo (called by 'widget')
#
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if defined?($twind_demo) && $twind_demo
$twind_demo.destroy
$twind_demo = nil
end
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$twind_demo = TkToplevel.new {|w|
title("Text Demonstration - Embedded Windows")
iconname("Embedded Windows")
positionWindow(w)
}
# frame <20><><EFBFBD><EFBFBD>
$twind_buttons = TkFrame.new($twind_demo) {|frame|
TkButton.new(frame) {
text <><CEBB>'
command proc{
tmppath = $twind_demo
$twind_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
command proc{showCode 'twind'}
}.pack('side'=>'left', 'expand'=>'yes')
}
$twind_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame <20><><EFBFBD><EFBFBD>
$twind_text = nil
TkFrame.new($twind_demo, 'highlightthickness'=>2, 'borderwidth'=>2,
'relief'=>'sunken') {|f|
$twind_text = TkText.new(f, 'setgrid'=>'true', 'font'=>$font,
'width'=>'70', 'height'=>35, 'wrap'=>'word',
'highlightthickness'=>0, 'borderwidth'=>0 ){|t|
TkScrollbar.new(f) {|s|
command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last}
}.pack('side'=>'right', 'fill'=>'y')
}.pack('expand'=>'yes', 'fill'=>'both')
}.pack('expand'=>'yes', 'fill'=>'both')
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$tag_center = TkTextTag.new($twind_text,
'justify' =>'center',
'spacing1'=>'5m',
'spacing3'=>'5m' )
$tag_buttons = TkTextTag.new($twind_text,
'lmargin1'=>'1c',
'lmargin2'=>'1c',
'rmargin' =>'1c',
'spacing1'=>'3m',
'spacing2'=>0,
'spacing3'=>0 )
# <20>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD><EFBFBD>
$twind_text.insert('end',
'<27>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD>widget<65><74><EFBFBD><EFBFBD>¾<EFBFBD><C2BE>widget<65><74><EFBFBD>Ȥ߹<C8A4><DFB9><EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD><DEA4><EFBFBD>')
$twind_text.insert('end',
'<27>Ȥ߹<C8A4><DFB9>ߥ<EFBFBD><DFA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><C9A5>ȸƤФ졢Ǥ<ECA1A2>դ<EFBFBD>widget<65><74><EFBFBD><EFBFBD>ǽ<EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>')
$twind_text.insert('end',
'<27><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ĤΥܥ<CEA5><DCA5><EFBFBD>widget<65><74><EFBFBD>Ȥ߹<C8A4><DFB9>ޤ<EFBFBD><DEA4>Ƥ<EFBFBD><C6A4>ޤ<EFBFBD><DEA4><EFBFBD>')
$twind_text.insert('end', '<27>ǽ<EFBFBD><C7BD>Υܥ<CEA5><DCA5><EFBFBD><EFBFBD>򥯥<EFBFBD><F2A5AFA5>å<EFBFBD><C3A5><EFBFBD><EFBFBD>ȿ<EFBFBD>ʿ<EFBFBD><CABF><EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {
#text 'ON'
text '<27><><EFBFBD><EFBFBD>'
command proc{textWindOn $twind_text,$twind_buttons}
cursor 'top_left_arrow'
})
$twind_text.insert('end', '<27>ˤ<EFBFBD><CBA4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD>ޤ<EFBFBD>2<EFBFBD>Ĥ<EFBFBD><C4A4>Υܥ<CEA5><DCA5><EFBFBD><EFBFBD>򥯥<EFBFBD><F2A5AFA5>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
$twind_text.insert('end', '<27><>ʿ<EFBFBD><CABF><EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {
#text 'OFF'
text '<27><><EFBFBD><EFBFBD>'
command proc{textWindOff $twind_text}
cursor 'top_left_arrow'
})
$twind_text.insert('end', '<27>ˤ<EFBFBD><CBA4>ޤ<EFBFBD><DEA4><EFBFBD>')
$twind_text.insert('end', '<27><EFBFBD>ҤȤĤ<C8A4><C4A4><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>')
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {
text '<27><><EFBFBD><EFBFBD><EFBFBD>򥯥<EFBFBD><F2A5AFA5>å<EFBFBD>'
command proc{textWindPlot $twind_text}
cursor 'top_left_arrow'
})
$twind_text.insert('end', '<27><><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>x-y<>ץ<EFBFBD><D7A5>åȤ<C3A5><C8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>')
$mark_plot = TkTextMark.new($twind_text, 'insert')
$mark_plot.gravity='left'
$twind_text.insert('end', '<27>ޥ<EFBFBD><DEA5><EFBFBD><EFBFBD>ǥǡ<C7A5><C7A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD><DEA4><EFBFBD>')
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {
text '<27>õ<EFBFBD>'
command proc{textWindDel $twind_text}
cursor 'top_left_arrow'
})
$twind_text.insert('end', '<EFBFBD>򥯥<EFBFBD><EFBFBD>å<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>
')
$twind_text.insert('end', '<27>Ȥ߹<C8A4><DFB9>ߥ<EFBFBD><DFA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><C9A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD>widget<65><74><EFBFBD>ˡ<EFBFBD><CBA1>ºݤ<C2BA>')
$twind_text.insert('end', '<27>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>ȤϤʤ<CFA4><CAA4><EFBFBD><EFBFBD>Ȥ߹<C8A4><DFB9><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>')
$twind_text.insert('end', '<27><><EFBFBD>ξ<EFBFBD><CEBE><EFBFBD><EFBFBD>ϡ<EFBFBD><CFA1>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD>widget<65>ϥ<EFBFBD><CFA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><C9A5>ޥ͡<DEA5><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
$twind_text.insert('end', '<27><EFBFBD><E8A4A6>ư<EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˤϥƥ<CFA5><C6A5><EFBFBD><EFBFBD><EFBFBD>widget<65><74>')
$twind_text.insert('end', '<27><><EFBFBD>äƥܥ<C6A5><DCA5>󤬤<EFBFBD><F3A4ACA4><EFBFBD><ECA4A4><EFBFBD>¤٤<C2A4><D9A4><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4>ޤ<EFBFBD><DEA4><EFBFBD>')
$twind_text.insert('end', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υܥ<CEA5><DCA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>طʿ<D8B7><CABF><EFBFBD><EFBFBD>Ѥ<EFBFBD><D1A4><EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD>')
$twind_text.insert('end', '("Default"<22>Ǹ<EFBFBD><C7B8>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><E1A4B9><EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD>)<29><>')
$twind_text.insert('end', '"Short"<22>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD>ܥ<EFBFBD><DCA5><EFBFBD><EFBFBD>򥯥<EFBFBD><F2A5AFA5>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD>')
$twind_text.insert('end', '<27>Ѥ<EFBFBD><D1A4><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>ưŪ<C6B0>˥ƥ<CBA5><C6A5><EFBFBD><EFBFBD><EFBFBD>widget<65><74>')
$twind_text.insert('end', '<27><EFBFBD><ECA5A4><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD>ޤ<EFBFBD><DEA4><EFBFBD>')
$twind_text.insert('end', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><EFBFBD><EFBFBD>ܥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>򲡤<EFBFBD><EFBFBD>ȸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>
')
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {|b|
text '<27>ǥե<C7A5><D5A5><EFBFBD><EFBFBD><EFBFBD>'
command proc{embDefBg $twind_text}
cursor 'top_left_arrow'
$tag_buttons.add('end')
},
'padx'=>3 )
embToggle = TkVariable.new('Short')
TkTextWindow.new($twind_text, 'end',
'window'=>TkCheckButton.new($twind_text) {
textvariable embToggle
indicatoron 0
variable embToggle
onvalue 'A much longer string'
offvalue 'Short'
cursor 'top_left_arrow'
pady 5
padx 2
},
'padx'=>3,
'pady'=>2 )
[ 'AntiqueWhite3', 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4',
'SlateBlue3', 'RoyalBlue1', 'SteelBlue2', 'DeepSkyBlue3', 'LightBlue1',
'DarkSlateGray1', 'Aquamarine2', 'DarkSeaGreen2', 'SeaGreen1',
'Yellow1', 'IndianRed1', 'IndianRed2', 'Tan1', 'Tan4'
].each{|twind_color|
TkTextWindow.new($twind_text, 'end',
'window'=>TkButton.new($twind_text) {
text twind_color
cursor 'top_left_arrow'
command proc{$twind_text.bg twind_color}
},
'padx'=>3,
'pady'=>2 )
}
# <20><EFBFBD>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD>
def textWindOn (w,f)
if defined? $twind_scroll
begin
$twind_scroll.destroy
rescue
end
$twind_scroll = nil
end
base = TkWinfo.parent( TkWinfo.parent(w) )
$twind_scroll = TkScrollbar.new(base) {|s|
orient 'horizontal'
command proc{|*args| w.xview(*args)}
w.xscrollcommand proc{|first,last| s.set first,last}
w.wrap 'none'
pack('after'=>f, 'side'=>'bottom', 'fill'=>'x')
}
return nil
end
def textWindOff (w)
if defined? $twind_scroll
begin
$twind_scroll.destroy
rescue
end
$twind_scroll = nil
end
w.xscrollcommand ''
w.wrap 'word'
end
def textWindPlot (t)
if (defined? $twind_plot) && (TkWinfo.exist?($twind_plot))
return
end
$twind_plot = TkCanvas.new(t) {
relief 'sunken'
width 450
height 300
cursor 'top_left_arrow'
}
font = '-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
TkcLine.new($twind_plot, 100, 250, 400, 250, 'width'=>2)
TkcLine.new($twind_plot, 100, 250, 100, 50, 'width'=>2)
TkcText.new($twind_plot, 225, 20,
'text'=>"A Simple Plot", 'font'=>font, 'fill'=>'brown')
(0..10).each {|i|
x = 100 + (i * 30)
TkcLine.new($twind_plot, x, 250, x, 245, 'width'=>2)
TkcText.new($twind_plot, x, 254,
'text'=>10*i, 'font'=>font, 'anchor'=>'n')
}
(0..5).each {|i|
y = 250 - (i * 40)
TkcLine.new($twind_plot, 100, y, 105, y, 'width'=>2)
TkcText.new($twind_plot, 96, y,
'text'=>"#{i*50}.0", 'font'=>font, 'anchor'=>'e')
}
for xx, yy in [[12,56],[20,94],[33,98],[32,120],[61,180],[75,160],[98,223]]
x = 100 + (3*xx)
y = 250 - (4*yy)/5
item = TkcOval.new($twind_plot, x-6, y-6, x+6, y+6,
'width'=>1, 'outline'=>'black', 'fill'=>'SkyBlue2')
item.addtag 'point'
end
$twind_plot.itembind('point', 'Any-Enter',
proc{$twind_plot.itemconfigure 'current', 'fill', 'red'})
$twind_plot.itembind('point', 'Any-Leave',
proc{$twind_plot.itemconfigure 'current', 'fill', 'SkyBlue2'})
$twind_plot.itembind('point', '1',
proc{|x,y| embPlotDown $twind_plot,x,y}, "%x %y")
$twind_plot.itembind('point', 'ButtonRelease-1',
proc{$twind_plot.dtag 'selected'})
$twind_plot.bind('B1-Motion',
proc{|x,y| embPlotMove $twind_plot,x,y}, "%x %y")
while ($twind_text.get($mark_plot) =~ /[ \t\n]/)
$twind_text.delete $mark_plot
end
$twind_text.insert $mark_plot,"\n"
TkTextWindow.new($twind_text, $mark_plot, 'window'=>$twind_plot)
$tag_center.add $mark_plot
$twind_text.insert $mark_plot,"\n"
end
$embPlot = {'lastX'=>0, 'lastY'=>0}
def embPlotDown (w, x, y)
w.dtag 'selected'
w.addtag_withtag 'selected', 'current'
w.raise 'current'
$embPlot['lastX'] = x
$embPlot['lastY'] = y
end
def embPlotMove (w, x, y)
w.move 'selected', x - $embPlot['lastX'], y - $embPlot['lastY']
$embPlot['lastX'] = x
$embPlot['lastY'] = y
end
def textWindDel (w)
if (defined? $twind_text) && TkWinfo.exist?($twind_plot)
$twind_text.delete $twind_plot
$twind_plot = nil
while ($twind_text.get($mark_plot) =~ /[ \t\n]/)
$twind_text.delete $mark_plot
end
$twind_text.insert $mark_plot," "
end
end
def embDefBg (w)
w['background'] = w.configinfo('background')[3]
end