Небольшой кусок из отрисовки гуя програмым на Tk. Сижу переосмысляю архитектуру, реализацию. Перерабатываю 1500 строк, написанных как приведено ниже. Поругайте, подскажите как лучше.Заранее благодарю:
#Require main packages for work
package require Tk
# Data for non user settings
dict set nonUserSettings 0 title "tkProgram"
dict set nonUserSettings 0 minWidth 800
dict set nonUserSettings 0 minHeight 600
dict set nonUserSettings 0 resizableX 1
dict set nonUserSettings 0 resizableY 1
dict set nonUserSettings 0 minWidth 800
dict set nonUserSettings 0 minHeight 600
# Data for user settings
dict set userSettings 0 menuBar true
# Data for biuld menubar
dict set menuBarSettings 0 name mainMenuBar
dict set menuBarSettings 0 tearOff 1
# Data for 0-level menu
dict set menuBarItems_ZeroLevel 0 name connectionItem
dict set menuBarItems_ZeroLevel 0 text_item "Connection"
dict set menuBarItems_ZeroLevel 1 name helpItem
dict set menuBarItems_ZeroLevel 1 text_item "Help"
# Data for 1-level menu
dict set menuBarItems_FirstLevel 0 parent 0
dict set menuBarItems_FirstLevel 0 label "LogIn"
dict set menuBarItems_FirstLevel 0 command NONE
dict set menuBarItems_FirstLevel 1 parent 0
dict set menuBarItems_FirstLevel 1 label "LogOut"
dict set menuBarItems_FirstLevel 1 command NONE
dict set menuBarItems_FirstLevel 2 parent 0
dict set menuBarItems_FirstLevel 2 label "Exit"
dict set menuBarItems_FirstLevel 2 command { exit; }
dict set menuBarItems_FirstLevel 3 parent 1
dict set menuBarItems_FirstLevel 3 label "About"
dict set menuBarItems_FirstLevel 3 command NONE
dict set menuBarItems_FirstLevel 4 parent 1
dict set menuBarItems_FirstLevel 4 label "Help"
dict set menuBarItems_FirstLevel 4 command NONE
# Procedure for builing menu bar
proc assembleMyMenu {} {
global userSettings
global menuBarSettings
global menuBarItems_ZeroLevel
global menuBarItems_FirstLevel
if {[dict get $userSettings 0 "menuBar"]==true} {
menu .[dict get $menuBarSettings 0 "name"]
. config -menu .[dict get $menuBarSettings 0 "name"]
dict for {id info} $menuBarItems_ZeroLevel {
dict with info {
menu .[dict get $menuBarSettings 0 "name"].$name
.[dict get $menuBarSettings 0 "name"] add cascade -label $text_item -menu .[dict get $menuBarSettings 0 "name"].$name
dict for {iter data} $menuBarItems_FirstLevel {
dict with data {
if {$id==$parent} {
.[dict get $menuBarSettings 0 "name"].$name add command -label $label -command $command
}
}
}
}
}
}
}
# Window Manager main settings
wm title . [dict get $nonUserSettings 0 "title"]
wm resizable . [dict get $nonUserSettings 0 "resizableX"] [dict get $nonUserSettings 0 "resizableY"]
wm minsize . [dict get $nonUserSettings 0 "minWidth"] [dict get $nonUserSettings 0 "minHeight"]
option add *tearOff [dict get $menuBarSettings 0 "tearOff"]
assembleMyMenu