массив tcl - ошибка, такой элемент не найден

Я создал два виджета управления деревом и виджет полосы прокрутки. И у меня есть радиокнопки, которые позволяют пользователю выбирать, какой виджет прокручивать на основе выбора кнопки. Итак, я создал виджеты, как показано ниже:

package require Tk
package require treectrl

namespace eval ::at::GUI {
  variable Priv;
  variable OptionsRB;

  set Priv(treePrimary) "";
  set Priv(treeSecondary) "";
  set Priv(treeScrollbar) "";

  if { ![info exists OptionsRB] } { 
    set OptionsRB(optColor) "ColorOnDraw";
    set OptionsRB(optHighlight) "HighlightBold";

    set OptionsRB(matchColor) "NoColor";

    set OptionsRB(optSelHighlight) "";

    set OptionsRB(scrollTree) "LeftTree";
  }
}

proc ::at::GUI::DrawGUI {} {
  variable Priv;

  set frm_treeFrame [ttk::labelframe .treeFrame -text "Tree Area"];  

  set Priv(treePrimary) [treectrl $frm_treeFrame.treePrimary]
  set Priv(treeSecondary) [treectrl $frm_treeFrame.treeSecondary]

  set Priv(treeScrollbar) [ttk::scrollbar $frm_treeFrame.sb_treeScroll -command "::at::GUI::yview"]

  grid $Priv(treePrimary) $Priv(treeSecondary) $Priv(treeScrollbar) -sticky news;
  grid columnconfigure $frm_treeFrame 0 -weight 1;
  grid columnconfigure $frm_treeFrame 1 -weight 1;
  grid rowconfigure $frm_treeFrame 0 -weight 1;

  set frm_ST [ttk::labelframe .scrollTreeOptions -text "Scroll Option"];

  set rb_leftTree [ttk::radiobutton $frm_ST.rb1 -text "Left Tree" -variable [namespace current]::OptionsRB(scrollTree) -value LeftTree -command [namespace current]::configScroll ]
  set rb_rightTree [ttk::radiobutton $frm_ST.rb2 -text "Right Tree" -variable [namespace current]::OptionsRB(scrollTree) -value RightTree -command [namespace current]::configScroll ] 
  set rb_bothTree [ttk::radiobutton $frm_ST.rb3 -text "Both Tree" -variable [namespace current]::OptionsRB(scrollTree) -value BothTree -command [namespace current]::configScroll ] 

  grid $rb_leftTree -row 1 -padx {30 5} -pady 5 -sticky w
  grid $rb_rightTree -row 2 -padx {30 5} -pady 5 -sticky w
  grid $rb_bothTree -row 3 -padx {30 5} -pady 5 -sticky w

  # Grid all the frames in main window. 
  grid $frm_treeFrame -sticky news;
  grid $frm_ST -sticky news;

  ##############################
  ::at::GUI::CreateLemes $Priv(treePrimary)
  ::at::GUI::CreateLemes $Priv(treeSecondary)

  foreach tree [list $Priv(treePrimary) $Priv(treeSecondary)] {
    for {set i 0} {$i < 20} {incr i} {
      set parent [expr {int(rand()*$i)}]
      $tree item create -tag item$i -button auto
      $tree item lastchild $parent item$i
      $tree item text item$i name item$i
    }
  }
  return;  
}

proc ::at::GUI::CreateLemes {T} {
  $T element create rect rect -fill [list blue selected]
  $T element create name text

  set S [$T style create nameStyle]
  $T style elements $S {rect name};
  $T style layout $S rect -detach yes -iexpand xy;
  $T style layout $S name -detach no -iexpand xy -expand e;

  $T column create -tag name -itemstyle $S -text Items
  $T configure -treecolumn first;
}

proc ::at::GUI::configScroll {args}  {
  variable Priv;
  variable OptionsRB;

  if {$OptionsRB(scrollTree) eq "LeftTree"} {
    $Priv(treePrimary) -yscrollcommand "::at::GUI::yset    $Priv(treeScrollbar)";
  } elseif {$OptionsRB(scrollTree) eq "RightTree"} {
    $Priv(treeSecondary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
  } elseif {$OptionsRB(scrollTree) eq "BothTree"} {
    $Priv(treePrimary) -yscrollcommand "::at::GUI::yset    $Priv(treeScrollbar)";
    $Priv(treeSecondary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
  }
}

proc ::at::GUI::yset {sb args}  {
  uplevel [linsert $args 0 $sb set]
  ::at::GUI::yview moveto [lindex [$sb get] 0]
}

proc ::at::GUI::yview {args}  {
  variable Priv;
  variable OptionsRB;

  parray OptionsRB;

  if {![info exists $OptionsRB(scrollTree)]} {
    puts "INFO DOESN'T EXIST.";
  }

  if {$OptionsRB(scrollTree) eq "LeftTree"} {
    eval [linsert $args 0 $Priv(treePrimary) yview];
  } elseif {$OptionsRB(scrollTree) eq "RightTree"} {
    eval [linsert $args 0 $Priv(treeSecondary) yview];
  } elseif {$OptionsRB(scrollTree) eq "BothTree"} {
    eval [linsert $args 0 $Priv(treePrimary) yview];
    eval [linsert $args 0 $Priv(treeSecondary) yview];
  }
}

Итак, здесь, в процедуре ::at::GUI::yview, я получаю сообщение об ошибке, говорящее, что can't read "OptionsRB(scrollTree)": no such element in array while executing "info exists $OptionsRB(scrollTree)" .... Итак, я попытался распечатать данные массива, используя parray OptionsRB;, и результат

    OptionsRB(optColor) = ColorOnDraw
    OptionsRB(optHighlight) = HighlightBold
    OptionsRB(matchColor) = NoColor
    OptionsRB(optSelHighlight) = 

что странно, поскольку он не показывает мне элемент scrollTree. Я не знаю, упускаю ли я что-то. Я читал о проблеме с ключом массива здесь, но это, похоже, проблема с кавычками так что не уверен, чего не хватает. Любые комментарии?

Обновление: я вижу то, что есть, хотя я присваиваю значение этой переменной в своем пространстве имен set OptionsRB(scrollTree) "LeftTree";, но моя радиокнопка Left Tree не выбрана по умолчанию, что, как я думаю, является причиной ошибки, но тогда я не уверен, почему радиокнопка по умолчанию не выбрана.


person Puneet Mittal    schedule 16.01.2015    source источник
comment
Я еще не уверен, почему элемент массива отсутствует, но вызов info exists $OptionsRB(scrollTree)´ is wrong. What you are testing here is whether there exists a variable with a name that is equal to the value of OptionsRB(scrollTree). The invocation should be info существует OptionsRB(scrollTree)`.   -  person Peter Lewerin    schedule 16.01.2015
comment
Спасибо, Худикроу, я вижу свою ошибку. Но все же я не уверен в ошибке.   -  person Puneet Mittal    schedule 16.01.2015
comment
Я был занят пару часов, но когда я попробовал ваш код, он у меня сработал, и участник OptionsRB(scrollTree) присутствовал. Так что я понятия не имею, в чем твоя проблема. Однако у вас есть неуместный -yscrollcommand, который появляется, когда вы нажимаете один из переключателей.   -  person Peter Lewerin    schedule 17.01.2015
comment
Спасибо Худи. кажется по какой-то причине набор OptionsRB(scrollTree) LeftTree; не инициализировался в объявлении пространства имен. Итак, когда я добавил набор OptionsRB(scrollTree) LeftTree; внутри процедуры yview в условии if, где она проверяет существование переменной, все работает нормально. Так что я думаю, что это проблема инициализации. В любом случае проблема решена, спасибо за помощь.   -  person Puneet Mittal    schedule 20.01.2015