2003-07-31 16:52:40 -04:00
|
|
|
|
#
|
|
|
|
|
# Canvas Text widget demo (called by 'widget')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if defined?($ctext_demo) && $ctext_demo
|
|
|
|
|
$ctext_demo.destroy
|
|
|
|
|
$ctext_demo = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
$ctext_demo = TkToplevel.new {|w|
|
|
|
|
|
title("Canvas Text Demonstration")
|
|
|
|
|
iconname("Text")
|
|
|
|
|
positionWindow(w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# label <20><><EFBFBD><EFBFBD>
|
|
|
|
|
TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'text'=>"<EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><EFBFBD>ˤϥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Х<EFBFBD>widget<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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><EFBFBD>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D><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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>"){
|
|
|
|
|
pack('side'=>'top')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# frame <20><><EFBFBD><EFBFBD>
|
|
|
|
|
$ctext_buttons = TkFrame.new($ctext_demo) {|frame|
|
|
|
|
|
TkButton.new(frame) {
|
2004-05-01 12:09:54 -04:00
|
|
|
|
#text 'λ<><CEBB>'
|
|
|
|
|
text '<27>Ĥ<EFBFBD><C4A4><EFBFBD>'
|
2003-07-31 16:52:40 -04:00
|
|
|
|
command proc{
|
|
|
|
|
tmppath = $ctext_demo
|
|
|
|
|
$ctext_demo = nil
|
|
|
|
|
tmppath.destroy
|
|
|
|
|
}
|
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes')
|
|
|
|
|
|
|
|
|
|
TkButton.new(frame) {
|
|
|
|
|
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
|
|
|
|
|
command proc{showCode 'ctext'}
|
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes')
|
|
|
|
|
}
|
|
|
|
|
$ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
|
|
|
|
|
|
|
|
|
|
# canvas <20><><EFBFBD><EFBFBD>
|
|
|
|
|
$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'borderwidth'=>0, 'width'=>500, 'height'=>350)
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')
|
|
|
|
|
|
|
|
|
|
# font <20><><EFBFBD><EFBFBD>
|
|
|
|
|
textFont = '-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*'
|
|
|
|
|
|
|
|
|
|
# canvas <20><><EFBFBD><EFBFBD>
|
|
|
|
|
TkcRectangle.new($ctext_canvas, 245, 195, 255, 205,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'outline'=>'black', 'fill'=>'red')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
$ctag_text = TkcTag.new($ctext_canvas)
|
|
|
|
|
$ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'text'=>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Х<EFBFBD>widget<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><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><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-D<>Ǿõ<C3B5>뤳<EFBFBD>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD><DEA4><EFBFBD>",
|
|
|
|
|
'width'=>440, 'anchor'=>'n',
|
|
|
|
|
'font'=>'-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*',
|
|
|
|
|
'kanjifont'=>'-*-r-*--24-*-jisx0208.1983-0',
|
|
|
|
|
'justify'=>'left') )
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
$ctag_text.bind('1', proc{|x,y| textB1Press $ctext_canvas,x,y}, "%x %y")
|
|
|
|
|
$ctag_text.bind('B1-Motion', proc{|x,y| textB1Move $ctext_canvas,x,y}, "%x %y")
|
|
|
|
|
$ctag_text.bind('Shift-1',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{|x,y| $ctext_canvas.seleect_adjust 'current', "@#{x},#{y}"},
|
|
|
|
|
"%x %y")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$ctag_text.bind('Shift-B1-Motion',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{|x,y| textB1Move $ctext_canvas,x,y}, "%x %y")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$ctag_text.bind('KeyPress', proc{|a| textInsert $ctext_canvas,a}, "%A")
|
|
|
|
|
$ctag_text.bind('Return', proc{textInsert $ctext_canvas,"\n"})
|
|
|
|
|
$ctag_text.bind('Control-h', proc{textBs $ctext_canvas})
|
|
|
|
|
$ctag_text.bind('BackSpace', proc{textBs $ctext_canvas})
|
|
|
|
|
$ctag_text.bind('Delete', proc{textDel $ctext_canvas})
|
|
|
|
|
$ctag_text.bind('2', proc{|x,y| textPaste $ctext_canvas, "@#{x},#{y}"},
|
2004-10-11 00:51:21 -04:00
|
|
|
|
"%x %y")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
# Next, create some items that allow the text's anchor position
|
|
|
|
|
# to be edited.
|
|
|
|
|
|
|
|
|
|
def mkTextConfig(w,x,y,option,value,color)
|
|
|
|
|
item = TkcRectangle.new(w, x, y, x+30, y+30,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'outline'=>'black', 'fill'=>color, 'width'=>1)
|
2003-07-31 16:52:40 -04:00
|
|
|
|
item.bind('1', proc{$ctag_text.configure option, value})
|
|
|
|
|
w.addtag_withtag('config', item)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
x = 50
|
|
|
|
|
y = 50
|
|
|
|
|
color = 'LightSkyBlue1'
|
|
|
|
|
mkTextConfig $ctext_canvas, x, y, 'anchor', 'se', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+30, y, 'anchor', 's', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+60, y, 'anchor', 'sw', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x, y+30, 'anchor', 'e', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+30, y+30, 'anchor', 'center', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+60, y+30, 'anchor', 'w', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x, y+60, 'anchor', 'ne', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+30, y+60, 'anchor', 'n', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+60, y+60, 'anchor', 'nw', color
|
|
|
|
|
item = TkcRectangle.new($ctext_canvas, x+40, y+40, x+50, y+50,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'outline'=>'black', 'fill'=>'red')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
item.bind('1', proc{$ctag_text.configure 'anchor', 'center'})
|
|
|
|
|
TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Text Position', 'anchor'=>'s',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
|
|
|
|
|
'fill'=>'brown')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
# Lastly, create some items that allow the text's justification to be
|
|
|
|
|
# changed.
|
|
|
|
|
|
|
|
|
|
x = 350
|
|
|
|
|
y = 50
|
|
|
|
|
color = 'SeaGreen2'
|
|
|
|
|
mkTextConfig $ctext_canvas, x, y, 'justify', 'left', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+30, y, 'justify', 'center', color
|
|
|
|
|
mkTextConfig $ctext_canvas, x+60, y, 'justify', 'right', color
|
|
|
|
|
TkcText.new($ctext_canvas, x+45, y-5, 'text'=>'Justification', 'anchor'=>'s',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'font'=>'-*-times-medium-r-normal--*-240-*-*-*-*-*-*',
|
|
|
|
|
'fill'=>'brown')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
$ctext_canvas.itembind('config', 'Enter', proc{textEnter $ctext_canvas})
|
|
|
|
|
$ctext_canvas.itembind('config', 'Leave',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
proc{$ctext_canvas\
|
|
|
|
|
.itemconfigure('current',
|
|
|
|
|
'fill'=>$textConfigFill)})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
$textConfigFill = ''
|
|
|
|
|
|
|
|
|
|
def textEnter(w)
|
|
|
|
|
$textConfigFill = (w.itemconfiginfo 'current', 'fill')[4]
|
|
|
|
|
w.itemconfigure 'current', 'fill', 'black'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textInsert(w, string)
|
|
|
|
|
return if string == ""
|
|
|
|
|
begin
|
|
|
|
|
$ctag_text.dchars 'sel.first', 'sel.last'
|
|
|
|
|
rescue
|
|
|
|
|
end
|
|
|
|
|
$ctag_text.insert 'insert', string
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textPaste(w, pos)
|
|
|
|
|
begin
|
|
|
|
|
$ctag_text.insert pos, TkSelection.get
|
|
|
|
|
rescue
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textB1Press(w,x,y)
|
|
|
|
|
w.icursor 'current', "@#{x},#{y}"
|
|
|
|
|
w.itemfocus 'current'
|
|
|
|
|
w.focus
|
|
|
|
|
w.select_from 'current', "@#{x},#{y}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textB1Move(w,x,y)
|
|
|
|
|
w.select_to 'current', "@#{x},#{y}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textBs(w)
|
|
|
|
|
begin
|
|
|
|
|
$ctag_text.dchars 'sel.first', 'sel.last'
|
|
|
|
|
rescue
|
|
|
|
|
char = $ctag_text.index('insert').to_i - 1
|
|
|
|
|
$ctag_text.dchars(char) if char >= 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def textDel(w)
|
|
|
|
|
begin
|
|
|
|
|
$ctag_text.dchars 'sel.first', 'sel.last'
|
|
|
|
|
rescue
|
|
|
|
|
$ctag_text.dchars 'insert'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|