[ruby-list:49651] TkTableから入力すると全角スペースが入る?

From: dezawa <dezawa@...>
Date: 2013-10-18 03:13:38 UTC
List: ruby-list #49651
出沢です

多分これも Ruby/Tkではなく Tkの話だろうとは思うのですが。

TkTableにはめ込んだ TkVariableにKey入力してそれを読み込むと
前に全角スペースが付いてきます。
代入しただけのcellを読み込んだ場合は全角スペースは付いて
来ません。
半角スペースかと思って居たので strip していたのですが、
どうしてもとれない、良く調べたら全角でした。
とりあえずは stripの代わりに sub で取り除いて逃げました。

が、

TkTable も TkVarible も日本語でしか使わない

というものではないでしょうから、日本語エリアの全角スペースが
はいるのはなにか私の設定がおかしいのでは。。。
と疑っています。

怪しげな所があれば教えてください。
LANG=ja_JP.UTF-8  で、 # -*- coding: utf-8 -*- です

 @table_variable = TkVariable.new_hash
 @table_variable["row_size"]    =  @models.size
 @table_variable["column_size"] =  @labels.size
 @table =
    Tk::TkTable.new(window,:rows=>rows, :cols=>cols,
                   :variable=>@table_variable,
                   :width=>cols+@titles[1],
                   :height=>@models.size+@titles[0],
                   :titlerows=>@titles[0],  
                   :titlecols=>@titles[1],  # 固定する行とカラム数
                   :roworigin=>-@titles[0], :colorigin=>0,
                   :rowstretchmode=>:last, :colstretchmode=>:last,
                   :rowstretch=>:unset, :colstretch=>:unset,
                   :selectmode=>:extended, :sparsearray=>false
        ){
           xscrollbar(TkScrollbar.new(window).
             pack(:side=>:bottom,:fill=>:x))
           yscrollbar(TkScrollbar.new(window).
             pack(:side=>:right,:fill=>:y))
        }

      set_column_label
      set_column_attr
      @table.tag_configure('dis',    :state=>:disabled)

として、リードオンリー、編集モードにするとき、
        @table.state(:disabled)
        @table.state(:normal)
を実行します。
      set_column_label
      set_column_attr
は以下です。

    def set_column_label
      if (rowspan = @titles[0])>1
            :
            :
      else
        (0..@labels.size-1).each{ |c|
           @table_variable[-@titles[0],c] = @labels[c].label
        }
      end
    end

    def set_column_attr
      # カラムの幅
      idx=-1
      width=@labels.map{ |label| idx += 1;  [idx,label.size]}
      @table.set_width(*width)

      @table.tag_configure(:title,             #titleのcellは
                           :bg=>"lightblue",   # 背景色は
                           :fg=>"black",       # 文字は黒
                           :relief=> :groove  #境界に線を引く
                           )
    end

TkValiableからの取り込みは以下で行っています。
    def table2models(table,labels)
      clm_nr = table.variable["column_size"].to_i
      row_nr = table.variable["row_size"].to_i

      modellist=Array.new(row_nr){ |r| { }}
      (0..clm_nr-1).each{ |clm|
        label =  labels[clm]
        (0..row_nr-1).each{ |row|
          modellist[row][label.symbol] =
            case labels[clm]
            when windowを貼り付けたcellの場合
              widgetの型に応じた処理
            else
             table.variable[row,clm].gsub(/^[  ]+|[  ]+$/,"")
            end
        }
      }
      modellist
    end

labels は labelの配列
label は ARのModelの(Tableに出す)各属性のsymbol、表title、型などが
入れてあります。

In This Thread

Prev Next