福祉支援サービス コミル

コミルは障害をお持ちの方の生活をモノの工夫によって豊かにすることをお手伝いします。

福祉支援サービス コミル

コミルは障害をお持ちの方の生活をモノの工夫によって豊かにすることをお手伝いします。

作成日:2006/10/30
タグ:,

言ノ葉のソースコード

#!/usr/bin/ruby

#
#        言ノ葉        ver.0.11        2005/12/01
#                                        (c) H.Mabuchi@comil
#

require "tk"
require "prime/prime"

root = TkRoot.new

$scanspeed = 10                                # スキャンスピード (x0.1秒)
$initconvword = %w(吸引 トイレ 痛い かゆい ベッド上 ベッド下)
                                                        # 未変換時に変換エリアに表示する単文
$sex = 'male'

$panelframes = Hash.new                # 各文字盤を収めるフレーム
$panelorder = Hash.new                        # 各文字盤のスキャン順

scanlevelmax = 3
scanlevel = 0                                # スキャンの深さ 0:待機 1:グループ(例) 2:列(例) 3:行(例)
l1_counter = -1                                # 各スキャンの深さ毎のスキャン位置
l2_counter = -1 
l3_counter = -1 

$convmodelist = ['out', 'in']                # 変換モード in/out
$convmode = $convmodelist.shift
$convstartpos = '1.0'                        # カーソル位置
$scanordertbl = []                        # 文字盤スキャン順の保管テーブル
$scanordertbl[0] = []
$prime = Prime.new                        # 予測変換機能の保持

# 各フレーム内のフォント定義

$editareafont = TkFont.new(['gothic', 40, []])
$convareafont = TkFont.new(['gothic', 40, []])
$panelfont = TkFont.new(['gothic', 40, []])

# 編集画面フレーム

editframe = TkFrame.new(root)
TkGrid.rowconfigure(editframe, 0, 'weight'=>1, 'minsize'=>0)
TkGrid.columnconfigure(editframe, 0, 'weight'=>1, 'minsize'=>0)
$editarea = TkText.new(editframe,
        'wrap'=>'char',
        'font'=>$editareafont,
        'width'=>'41', 'height'=>'7'
)
yscr = TkScrollbar.new(editframe)
Tk.grid($editarea, yscr, 'sticky'=>'news')
$editarea.yscrollbar(yscr)

# 変換画面フレーム

convframe = TkFrame.new(root)
$convarea = TkText.new(convframe,
        'wrap'=>'word',
        'font'=>$convareafont,
        'width'=>'41', 'height'=>'3'
).pack('fill'=>'x')

# 文字盤画面フレーム

panelframe = TkFrame.new(root)

# 文字ボタン

class KthCharButton < TkButton
        def initialize(frame, order, scanorder, char)
                @button = TkButton.new(
                        frame,
                        'text'=>char,
                        'font'=>$panelfont,
                        'background'=>'gray',
                        'command'=>proc{
                                if $convmode == 'out' 
                                        $convstartpos = $editarea.index( 'insert')
                                        $convmodelist.push( $convmode)
                                        $convmode = $convmodelist.shift
                                end
                                srcwordtag = TkTextTag.new($editarea, "background"=>"green")
                                $editarea.insert( 'insert', char, srcwordtag)
                                $scanordertbl[0]=[]
                                $convarea.delete( '1.0', 'end')
                                $prime.lookup_hybrid( $editarea.get( $convstartpos, 'insert')).each {|x|
                                        destbutton = TkButton.new( $convarea,
                                                'text'=>x.to_text_literal,
                                                'command'=>proc{
                                                        $editarea.delete( $convstartpos, 'insert')
                                                        if $convmode == 'in' 
                                                                $convstartpos = 'insert'
                                                                $convmodelist.push( $convmode)
                                                                $convmode = $convmodelist.shift
                                                        end
                                                        $editarea.insert( 'insert', x.to_text_literal)
                                                        $prime.learn_word( x.values[0], x.values[1], x.values[2])
                                                        $prime.update
#                                                        $scanordertbl[0] = []
#                                                        $convarea.delete( '1.0', 'end')
                                                        displaymsg
                                                },
                                                'font'=>$convareafont,
                                                'background'=>'yellow'
                                        )
                                        $scanordertbl[0] << destbutton
                                        TkTextWindow.new( $convarea, 'insert', 'window'=>destbutton)
                                        $convarea.insert( 'end', ' ')
                                }
                        }
                )
                # スキャン順の設定
                l1, l2, l3 = scanorder
                l1 -= 1
                l2 -= 1
                l3 -= 1
                if order[l1].nil? then
                        tl2 = []
                        tl3 = []
                        tl3[l3] = self
                        tl2[l2] = tl3
                        order[l1] = tl2
                elsif order[l1][l2].nil? then
                        tl3 = []
                        tl3[l3] = self
                        order[l1][l2] = tl3
                else
                        order[l1][l2][l3] = self
                end
                @path = @button.path
        end
end

class KthSpcCharButton < TkButton
        SpcCharTbl = {
                'daku' => { ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>''
                },
                'handaku' => { ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>''
                },
                'sokuyou' => { ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>'',
                        ''=>'', ''=>'', ''=>'', ''=>'', ''=>''
                }
        }
        def initialize(f, order, scanorder, char, func)
                @button = TkButton.new(
                        f,
                        'text'=>char,
                        'font'=>$panelfont,
                        'background'=>'gray',
                        'command'=>proc{
                                if $convmode == 'out' 
                                        $convstartpos = $editarea.index( 'insert')
                                        $convmodelist.push( $convmode)
                                        $convmode = $convmodelist.shift
                                end
                                sourcechar = $editarea.get('insert - 1 chars')
                                $editarea.delete('insert - 1 chars')
                                srcwordtag = TkTextTag.new($editarea, "background"=>"green")
                                $editarea.insert('insert', SpcCharTbl[func][sourcechar], srcwordtag)
                                $scanordertbl[0]=[]
                                $convarea.delete( '1.0', 'end')
                                $prime.lookup_hybrid( $editarea.get( $convstartpos, 'insert')).each {|x|
                                        destbutton = TkButton.new( $convarea,
                                                'text'=>x.to_text_literal,
                                                'command'=>proc{
                                                        $editarea.delete( $convstartpos, 'insert')
                                                        if $convmode == 'in' 
                                                                $convstartpos = 'insert'
                                                                $convmodelist.push( $convmode)
                                                                $convmode = $convmodelist.shift
                                                        end
                                                        $editarea.insert( 'insert', x.to_text_literal)
                                                        $prime.learn_word( x.values[0], x.values[1], x.values[2])
                                                        $prime.update
#                                                        $scanordertbl[0]=[]
#                                                        $convarea.delete( '1.0', 'end')
                                                        displaymsg
                                                },
                                                'font'=>$convareafont,
                                                'background'=>'yellow'
                                        )
                                        $scanordertbl[0] << destbutton
                                        TkTextWindow.new( $convarea, 'insert', 'window'=>destbutton)
                                        $convarea.insert( 'end', ' ')
                                }
                        }
                )
                # スキャン順の設定
                l1, l2, l3 = scanorder
                l1 -= 1
                l2 -= 1
                l3 -= 1
                if order[l1].nil? then
                        tl2 = []
                        tl3 = []
                        tl3[l3] = self
                        tl2[l2] = tl3
                        order[l1] = tl2
                elsif order[l1][l2].nil? then
                        tl3 = []
                        tl3[l3] = self
                        order[l1][l2] = tl3
                else
                        order[l1][l2][l3] = self
                end
                @path = @button.path
        end
end

class KthFuncButton < TkButton
        def initialize(f, order, scanorder, char, func)
                @button = TkButton.new(
                        f,
                        'text'=>char,
                        'font'=>$panelfont,
                        'background'=>'gray',
                        'command'=>proc{eval(func)}
                )
                # スキャン順の設定
                l1, l2, l3 = scanorder
                l1 -= 1
                l2 -= 1
                l3 -= 1
                if order[l1].nil? then
                        tl2 = []
                        tl3 = []
                        tl3[l3] = self
                        tl2[l2] = tl3
                        order[l1] = tl2
                elsif order[l1][l2].nil? then
                        tl3 = []
                        tl3[l3] = self
                        order[l1][l2] = tl3
                else
                        order[l1][l2][l3] = self
                end
                @path = @button.path
        end
end

class KthChgPnlButton < TkButton
        def initialize(f, order, scanorder, char, panel)
                @button = TkButton.new(
                        f,
                        'text'=>char,
                        'font'=>$panelfont,
                        'background'=>'gray',
                        'command'=>proc{
                                $panelframes[ panel].raise
                                $scanordertbl = $panelorder[ panel]
                                displaymsg
                        }
                )
                # スキャン順の設定
                l1, l2, l3 = scanorder
                l1 -= 1
                l2 -= 1
                l3 -= 1
                if order[l1].nil? then
                        tl2 = []
                        tl3 = []
                        tl3[l3] = self
                        tl2[l2] = tl3
                        order[l1] = tl2
                elsif order[l1][l2].nil? then
                        tl3 = []
                        tl3[l3] = self
                        order[l1][l2] = tl3
                else
                        order[l1][l2][l3] = self
                end
                @path = @button.path
        end
end

# 音声合成出力

def talk( str)
        open("| ~/Desktop/koto/galatea-v3.0/SSM/gtalk -C ~/Desktop/koto/galatea-v3.0/SSM/ssm.conf","w") {|io|
                io.print "set Speaker = #{$sex}01\n"
                io.print "set Text = #{str}\n"
                io.print "set Speak = NOW\n"
                io.print "set Run = EXIT\n"
        }        
end

# 編集画面の文字列削除

def editareadelete( range)
        $editarea.delete( range)
        if $editarea.value.empty? then
                displaymsg
        end
end

# ひらがな文字盤定義

$panelframes['kana'] = TkFrame.new(panelframe)
$panelorder['kana'] = []
kanabord = [
        [
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 1, 1], '', ''),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 1, 2], '', 'talk( $editarea.value)'),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 1, 3], '', ''),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 1, 4], '', ''),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 1, 5], '', '$editarea.delete(\'1.0\', \'end\');displaymsg')
        ],[
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 2, 1], '', 'editareadelete(\'insert - 1 chars\')'),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 2, 2], '', ''),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 2, 3], '', '$editarea.insert( \'insert\', \'\n\')'),
                KthChgPnlButton.new($panelframes['kana'], $panelorder['kana'], [2, 2, 4], '', 'alpha'),
                KthFuncButton.new($panelframes['kana'], $panelorder['kana'], [2, 2, 5], '', 'exit')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 3, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 3, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 3, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 3, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 3, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 4, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 4, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 4, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 4, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [2, 4, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 1, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 1, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 1, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 1, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 1, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 2, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 2, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 2, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 2, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 2, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 3, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 3, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 3, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 3, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 3, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 4, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 4, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 4, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 4, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 4, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 5, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 5, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 5, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 5, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [3, 5, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 1, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 1, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 1, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 1, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 1, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 2, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 2, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 2, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 2, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 2, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 3, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 3, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 3, 3], ''),
                KthSpcCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 3, 4], '', 'daku'),
                KthSpcCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 3, 5], '', 'sokuyou')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 4, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 4, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 4, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 4, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 4, 5], '')
        ],[
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 5, 1], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 5, 2], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 5, 3], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 5, 4], ''),
                KthCharButton.new($panelframes['kana'], $panelorder['kana'], [4, 5, 5], '')
        ]
]

# 英字記号文字盤定義

$panelframes['alpha'] = TkFrame.new(panelframe)
$panelorder['alpha'] = []
alphabord = [
        [
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 1, 1], '', ''),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 1, 2], '', 'talk( $editarea.value)'),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 1, 3], '', ''),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 1, 4], '', ''),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 1, 5], '', '$editarea.delete(\'1.0\', \'end\');displaymsg')
        ],[
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 2, 1], '', 'editareadelete(\'insert - 1 chars\')'),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 2, 2], '', ''),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 2, 3], '', '$editarea.insert( \'insert\', \'\n\')'),
                KthChgPnlButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 2, 4], '', 'kana'),
                KthFuncButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 2, 5], '', 'exit')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 3, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 3, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 3, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 3, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 3, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 4, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 4, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 4, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 4, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [2, 4, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 1, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 1, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 1, 3], '×'),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 1, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 1, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 2, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 2, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 2, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 2, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 2, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 3, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 3, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 3, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 3, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 3, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 4, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 4, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 4, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 4, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 4, 5], ' ')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 5, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 5, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 5, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 5, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [3, 5, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 1, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 1, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 1, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 1, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 1, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 2, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 2, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 2, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 2, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 2, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 3, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 3, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 3, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 3, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 3, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 4, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 4, 2], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 4, 3], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 4, 4], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 4, 5], '')
        ],[
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 5, 1], ''),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 5, 2], ' '),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 5, 3], ' '),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 5, 4], ' '),
                KthCharButton.new($panelframes['alpha'], $panelorder['alpha'], [4, 5, 5], ' ')
        ]
]

# 各文字盤ボタンの配置

kanabord.each_with_index do |x, i|
        x.each_with_index do |y, j|
                y.grid('row'=>j, 'column'=>i)
        end
end
alphabord.each_with_index do |x, i|
        x.each_with_index do |y, j|
                y.grid('row'=>j, 'column'=>i)
        end
end
$scanordertbl = $panelorder[ 'kana']

# 変換エリアに初期表示する単文の表示

def displaymsg
        $convarea.delete( '1.0', 'end')
#        $editarea.delete('1.0', 'end')
        $scanordertbl[0] = []
        $initconvword.each {|x|
                msgbutton = TkButton.new( $convarea,
                        'text'=>x,
                        'command'=>proc{
#                                $editarea.delete( $convstartpos, 'insert')
                                $editarea.insert( 'insert', x)
#                                $scanordertbl[0] = []
#                                $convarea.delete( '1.0', 'end')
                                displaymsg
                        },
                        'font'=>$convareafont,
                        'background'=>'yellow'
                )
                $scanordertbl[0] << msgbutton
                TkTextWindow.new( $convarea, 'insert', 'window'=>msgbutton)
                $convarea.insert( 'end', ' ')
        }
end

displaymsg

#  各フレームの表示

editframe.pack('fill'=>'both')
convframe.pack('fill'=>'x')
$panelframes['kana'].pack
$panelframes['alpha'].place( 'anchor' => 'nw').lower
panelframe.pack

# 右クリック(スイッチ入力)の処理

#ev_PushSw = TkVirtualEvent.new( 'ButtonPush-3', 'KeyPush-F11')
ev_RelSw = TkVirtualEvent.new( 'ButtonRelease-3', 'KeyRelease-F11')
root.bind( ev_RelSw, proc{
        case scanlevel
        when 1
                if l1_counter == 0 then
                        $scanordertbl[0].each {|x|
                                x.background('yellow')
                        }
                elsif not $scanordertbl[l1_counter].nil? then
                        $scanordertbl[l1_counter].each {|x|
                                x.each {|y|
                                        y.background('gray')
                                }
                        }
                end
                l2_counter = -1
                l3_counter = -1
        when 2
                if l1_counter == 0 then
                        $scanordertbl[0][l2_counter].invoke
                        scanlevel += 1
                elsif not $scanordertbl[l1_counter][l2_counter].nil? then
                        $scanordertbl[l1_counter][l2_counter].each {|x|
                                x.background('gray')
                        }
                end
                l3_counter = -1
        when 3
                button = $scanordertbl[l1_counter][l2_counter][l3_counter]
                if not button.nil?
                        button.flash
                        button.invoke
                        button.background('gray')
                end
                l1_counter = -1
                l2_counter = -1
                l3_counter = -1
        end
        scanlevel += 1
        scanlevel = 0 if scanlevel == scanlevelmax + 1
})
root.title('Kotonoha')
root.geometry('1024x740+0+0')

# スキャン
scanproc = TkAfter.new(
        $scanspeed * 100 , -1,
        proc{
                case scanlevel
                when 1
                        if l1_counter == 0 then
                                $scanordertbl[0].each {|x|
                                        x.background('yellow')
                                }
                        elsif not $scanordertbl[l1_counter].nil? then
                                $scanordertbl[l1_counter].each {|x|
                                        x.each {|y|
                                                y.background('gray')
                                        }
                                }
                        end
                        l1_counter += 1
                        l1_counter = 0 if l1_counter == $scanordertbl.size
                        if l1_counter == 0 then
                                $scanordertbl[0].each {|x|
                                        x.background('green')
                                }
                        elsif not $scanordertbl[l1_counter].nil? then
                                $scanordertbl[l1_counter].each {|x|
                                        x.each {|y|
                                                y.background('red')
                                        }
                                }
                        end
                when 2
                        if l1_counter == 0 then
                                $scanordertbl[0][l2_counter].background('yellow')
                        elsif not $scanordertbl[l1_counter][l2_counter].nil? then
                                $scanordertbl[l1_counter][l2_counter].each {|x|
                                        x.background('gray')
                                }
                        end
                        l2_counter += 1
                        l2_counter = 0 if l2_counter == $scanordertbl[l1_counter].size
                        if l1_counter == 0 then
                                $scanordertbl[0][l2_counter].background('green')
                        elsif not $scanordertbl[l1_counter][l2_counter].nil? then
                                $scanordertbl[l1_counter][l2_counter].each {|x|
                                        x.background('red')
                                }
                        end
                when 3
                        if not (l1_counter ==0 || $scanordertbl[l1_counter][l2_counter][l3_counter].nil?) then
                                $scanordertbl[l1_counter][l2_counter][l3_counter].background('gray')
                        end
                        l3_counter += 1
                        l3_counter = 0 if l3_counter == $scanordertbl[l1_counter][l2_counter].size
                        if not (l1_counter ==0 || $scanordertbl[l1_counter][l2_counter][l3_counter].nil?) then
                                $scanordertbl[l1_counter][l2_counter][l3_counter].background('red')
                        end
                end
        }
).start

#
# 設定変更画面
#

configsex = TkVariable.new( $sex)
configspeed = TkVariable.new( $scanspeed.to_s)

configwindow = TkToplevel.new( 'title'=>'Kotonoha Configure')
TkLabel.new( configwindow, 'text' => '言ノ葉 設定変更').pack
TkLabel.new( configwindow, 'text' => '').pack
TkLabel.new( configwindow, 'text' => '読み上げ音声').pack
TkRadioButton.new( configwindow, 'text' => '男性', 'value' => 'male', 'variable' => configsex).pack
TkRadioButton.new( configwindow, 'text' => '女性', 'value' => 'female', 'variable' => configsex).pack
TkLabel.new( configwindow, 'text' => '').pack
TkLabel.new( configwindow, 'text' => 'スキャン速度 (×0.1秒)').pack
TkScale.new( configwindow,
#        'label' => '',
        'orient' => 'h',
        'from' => '2',
        'to' =>'70',
        'variable' => configspeed
).pack
TkButton.new( configwindow, 'text'=>'適用', 'command'=>proc{
        $sex = configsex.value
        scanproc.stop
        $scanspeed = configspeed.value.to_i
        scanproc = TkAfter.new(
                $scanspeed * 100 , -1,
                proc{
                        case scanlevel
                        when 1
                                if l1_counter == 0 then
                                        $scanordertbl[0].each {|x|
                                                x.background('yellow')
                                        }
                                elsif not $scanordertbl[l1_counter].nil? then
                                        $scanordertbl[l1_counter].each {|x|
                                                x.each {|y|
                                                        y.background('gray')
                                                }
                                        }
                                end
                                l1_counter += 1
                                l1_counter = 0 if l1_counter == $scanordertbl.size
                                if l1_counter == 0 then
                                        $scanordertbl[0].each {|x|
                                                x.background('green')
                                        }
                                elsif not $scanordertbl[l1_counter].nil? then
                                        $scanordertbl[l1_counter].each {|x|
                                                x.each {|y|
                                                        y.background('red')
                                                }
                                        }
                                end
                        when 2
                                if l1_counter == 0 then
                                        $scanordertbl[0][l2_counter].background('yellow')
                                elsif not $scanordertbl[l1_counter][l2_counter].nil? then
                                        $scanordertbl[l1_counter][l2_counter].each {|x|
                                                x.background('gray')
                                        }
                                end
                                l2_counter += 1
                                l2_counter = 0 if l2_counter == $scanordertbl[l1_counter].size
                                if l1_counter == 0 then
                                        $scanordertbl[0][l2_counter].background('green')
                                elsif not $scanordertbl[l1_counter][l2_counter].nil? then
                                        $scanordertbl[l1_counter][l2_counter].each {|x|
                                                x.background('red')
                                        }
                                end
                        when 3
                                if not (l1_counter ==0 || $scanordertbl[l1_counter][l2_counter][l3_counter].nil?) then
                                        $scanordertbl[l1_counter][l2_counter][l3_counter].background('gray')
                                end
                                l3_counter += 1
                                l3_counter = 0 if l3_counter == $scanordertbl[l1_counter][l2_counter].size
                                if not (l1_counter ==0 || $scanordertbl[l1_counter][l2_counter][l3_counter].nil?) then
                                        $scanordertbl[l1_counter][l2_counter][l3_counter].background('red')
                                end
                        end
                }
        ).start
}).pack


#
# スイッチ入力の検出
#

# ゲームポート、パラレルポート入力

swpushed = false

Thread.start{
        open("/dev/js0","r") {|joy|
                loop {
                        joybutton = joy.read(8)
                        if joybutton[4] == 1
                        # pushed
                                swpushed = true
                        else
                        # released
                                if swpushed == true
                                        Tk.event_generate( root, ev_RelSw)
                                end
                                swpushed = false
                        end
                }
        }
}


# 伝の心形式シリアルポート入力


Tk.mainloop

blog comments powered by Disqus