gd.tcl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. #
  2. # gd: the built in Midnight Commander GUI designer
  3. # (C) 1996 the Free Software Foundation
  4. # See the file COPYING for details
  5. #
  6. # Author: Miguel de Icaza
  7. #
  8. set min_width 10
  9. set min_height 10
  10. set dragging 0
  11. set new_dialog 1
  12. proc reset_counters {} {
  13. global dialog_rows
  14. global dialog_columns
  15. global frame_count
  16. global text_count
  17. global line_count
  18. set dialog_rows 4
  19. set dialog_columns 4
  20. set frame_count 0
  21. set text_count 0
  22. set line_count 0
  23. }
  24. #
  25. # create a division
  26. #
  27. # what = { row, column }
  28. # if visible then allow the user to add columns and make them visibles
  29. #
  30. proc create_division {root index what visible} {
  31. global dialog_columns
  32. global dialog_rows
  33. set cn [expr $index*2]
  34. if {$what == "row"} {
  35. set owhat "column"
  36. set width height
  37. set stick we
  38. } else {
  39. set owhat "row"
  40. set width width
  41. set stick ns
  42. }
  43. set c \$dialog_${owhat}s
  44. if {$visible} {
  45. frame $root.$what@$cn -$width 3 -back gray -relief sunken -borderwidth 4
  46. bind $root.$what@$cn <Enter> "$root.$what@$cn configure -back red"
  47. bind $root.$what@$cn <Leave> "$root.$what@$cn configure -back gray"
  48. bind $root.$what@$cn <ButtonRelease-1> "new_division $root $index $what"
  49. } else {
  50. frame $root.$what@$cn -$width 3
  51. }
  52. grid $root.$what@$cn -$what $cn -$owhat 0 -${what}span 1 -${owhat}span [expr $c*2] -sticky $stick
  53. }
  54. proc create_column {root column visible} {
  55. create_division $root $column column $visible
  56. }
  57. proc create_row {root row visible} {
  58. create_division $root $row row $visible
  59. }
  60. proc column_space {root column} {
  61. global min_width
  62. grid columnconfigure $root [expr $column*2+1] -minsize $min_width
  63. }
  64. proc row_space {root row} {
  65. global min_height
  66. grid rowconfigure $root [expr $row*2+1] -minsize $min_height
  67. }
  68. #
  69. # When inserting a column or row, move all of the widgets after
  70. # the insertion point
  71. #
  72. proc move_childs {root index what} {
  73. global components
  74. set pix [expr $index*2]
  75. foreach i $components {
  76. set info [grid info $root.$i]
  77. set idx [lsearch $info -$what]
  78. if {$idx >= 0} {
  79. incr idx
  80. set cp [lindex $info $idx]
  81. if {$cp >= $pix} {
  82. grid $root.$i -$what [expr $cp+2]
  83. }
  84. }
  85. }
  86. }
  87. #
  88. # Update the separators spans after a column or row has been added
  89. #
  90. proc reconfig_spans {root} {
  91. global dialog_rows
  92. global dialog_columns
  93. for {set i 0} {$i <= $dialog_rows} {incr i} {
  94. set j [expr $i*2]
  95. grid $root.row@$j -columnspan [expr $dialog_columns*2]
  96. }
  97. for {set i 0} {$i <= $dialog_columns} {incr i} {
  98. set j [expr $i*2]
  99. grid $root.column@$j -rowspan [expr $dialog_rows*2]
  100. }
  101. }
  102. proc new_division {root index what} {
  103. global dialog_columns
  104. global dialog_rows
  105. set var [incr dialog_${what}s]
  106. create_$what $root $var 1
  107. ${what}_space $root $var
  108. reconfig_spans $root
  109. move_childs $root $index $what
  110. }
  111. proc create_gui_canvas {frame} {
  112. if {$frame == "."} { set base "" } else { set base $frame }
  113. set bw $base.widgets
  114. catch "frame $bw"
  115. grid $bw -column 1 -row 1 -sticky nwse -padx 2 -pady 2 -ipady 12
  116. }
  117. proc create_workspace {frame} {
  118. global dialog_rows
  119. global dialog_columns
  120. global env
  121. global components
  122. puts "Create_workspace llamado"
  123. if {$frame == "."} { set base "" } else { set base $frame }
  124. set bw $base.widgets
  125. # If user wants to edit this, then the workspace has been already created.
  126. if ![string compare .$env(MC_EDIT) $frame] {
  127. return 0
  128. }
  129. create_gui_canvas $frame
  130. $bw configure -relief sunken -borderwidth 2
  131. canvas $base.h -back white -height 8 -relief sunken -borderwidth 2
  132. canvas $base.v -back white -width 8 -relief sunken -borderwidth 2
  133. grid $bw -column 1 -row 1 -sticky nwse -padx 2 -pady 2 -ipady 12
  134. grid $base.h -column 1 -row 0 -sticky we
  135. grid $base.v -column 0 -row 1 -sticky ns
  136. for {set col 0} {$col <= $dialog_columns} {incr col} {
  137. column_space $bw $col
  138. create_column $bw $col 1
  139. }
  140. for {set row 0} {$row <= $dialog_rows} {incr row} {
  141. row_space $bw $row
  142. create_row $bw $row 1
  143. }
  144. }
  145. proc get_stick {root widget} {
  146. global props
  147. set a $props(stick.n.$widget)
  148. set b $props(stick.s.$widget)
  149. set c $props(stick.e.$widget)
  150. set d $props(stick.w.$widget)
  151. return "$a$b$c$d"
  152. }
  153. #
  154. # Callbacks for configuring widgets, frames and extra text
  155. #
  156. proc set_stick {root widget} {
  157. if {$root == "."} { set base "" } else { set base $root }
  158. grid $base.widgets.$widget -sticky [get_stick $root $widget]
  159. }
  160. proc make_sticky_button {root window widget sval} {
  161. checkbutton $window.$sval -text $sval -variable props(stick.$sval.$widget) \
  162. -command "set_stick $root $widget" -onvalue $sval -offvalue ""
  163. }
  164. #
  165. # Configure a widget
  166. #
  167. proc config_widget {root widget} {
  168. global components
  169. global props
  170. set w .config-$widget
  171. toplevel $w
  172. frame $w.f
  173. make_sticky_button $root $w.f $widget n
  174. make_sticky_button $root $w.f $widget s
  175. make_sticky_button $root $w.f $widget e
  176. make_sticky_button $root $w.f $widget w
  177. label $w.f.l -text "Anchor"
  178. pack $w.f.l $w.f.n $w.f.s $w.f.e $w.f.w
  179. pack $w.f
  180. }
  181. proc make_radio_button {root window widget state} {
  182. radiobutton $window.$state -text $state -variable frame_relief -value $state \
  183. -command "$root.widgets.$widget configure -relief $state"
  184. pack $window.$state
  185. }
  186. #
  187. # Configure a frame
  188. #
  189. proc config_frame {root widget} {
  190. set w .config-$widget
  191. toplevel $w
  192. make_radio_button $root $w $widget sunken
  193. make_radio_button $root $w $widget groove
  194. make_radio_button $root $w $widget ridge
  195. make_radio_button $root $w $widget raised
  196. }
  197. proc set_text {root widget from} {
  198. set text [.config-$widget.f.entry get]
  199. puts "Texto: $text"
  200. $root.widgets.$widget configure -text $text
  201. }
  202. proc config_text {root widget} {
  203. config_widget $root $widget
  204. entry .config-$widget.f.entry -text [lindex [$root.widgets.$widget configure -text] 4]
  205. pack .config-$widget.f.entry
  206. bind .config-$widget.f.entry <Return> "set_text $root $widget .config-$widget.f.entry"
  207. }
  208. proc config_line {root widget} {
  209. # Nothing is configurable on a line.
  210. }
  211. proc reconfig_rows {root} {
  212. global dialog_rows
  213. global dialog_columns
  214. for {set i 0} {$i < $dialog_rows} {incr i} {
  215. set cn [expr $i*2]
  216. grid $root.row@cn -columnspan [expr $dialog_columns*2+2]
  217. }
  218. }
  219. #
  220. # Set the column for a widget
  221. #
  222. proc set_widget_col {root w col} {
  223. global dialog_columns
  224. if {$root == "."} { set base "" } else { set base $root }
  225. if {$col >= $dialog_columns} {
  226. return
  227. }
  228. grid $base.widgets.$w -column [expr $col*2+1]
  229. }
  230. #
  231. # Set the row for a widget
  232. #
  233. proc set_widget_row {root w row} {
  234. global dialog_rows
  235. if {$root == "."} { set base "" } else { set base $root }
  236. if {$row >= $dialog_rows} {
  237. return
  238. }
  239. grid $base.widgets.$w -row [expr $row*2+1]
  240. }
  241. #
  242. # Set the number of spanning lines for a widget
  243. #
  244. proc set_span_col {root w n} {
  245. if {$root == "."} { set base "" } else { set base $root }
  246. grid $base.widgets.$w -columnspan [expr $n*2-1]
  247. }
  248. #
  249. # Set the number of spanning rows for a widget
  250. #
  251. proc set_span_row {root w n} {
  252. if {$root == "."} { set base "" } else { set base $root }
  253. grid $base.widgets.$w -rowspan [expr $n*2-1]
  254. }
  255. proc set_sticky {root w s} {
  256. global props
  257. if {$root == "."} { set base "" } else { set base $root }
  258. grid $base.widgets.$w -sticky $s
  259. foreach stick_dir {n s w e} {
  260. if [regexp $stick_dir $s] {
  261. set props(stick.$stick_dir.$w) $stick_dir
  262. }
  263. }
  264. }
  265. #
  266. # Start a drag
  267. #
  268. proc drag {root w x y} {
  269. global dragging
  270. global root_x
  271. global root_y
  272. if {$root == "."} { set base "" } else { set base $root }
  273. if {!$dragging} {
  274. set dragging 1
  275. button $base.widgets.drag -text "$w"
  276. }
  277. place $base.widgets.drag -x [expr $x-$root_x] -y [expr $y-$root_y]
  278. }
  279. #
  280. # Drop action
  281. #
  282. proc drop {root w x y} {
  283. global root_x
  284. global root_y
  285. global dragging
  286. if {$root == "."} { set base "" } else { set base $root }
  287. set pos [grid location $base.widgets [expr $x-$root_x] [expr $y-$root_y]]
  288. set col [expr [lindex $pos 0]/2]
  289. set row [expr [lindex $pos 1]/2]
  290. set_widget_row $root $w $row
  291. set_widget_col $root $w $col
  292. set dragging 0
  293. catch "destroy $root.widgets.drag"
  294. }
  295. #
  296. # Setup before the drag
  297. #
  298. proc button_press {root} {
  299. global root_x
  300. global root_y
  301. if {$root == "."} { set base "" } else { set base $root }
  302. set root_x [expr [winfo rootx $base.widgets]]
  303. set root_y [expr [winfo rooty $base.widgets]]
  304. }
  305. #
  306. # Extract a value from a {key value ...} list returned by Tk
  307. #
  308. proc extract_parameter {parameters key} {
  309. return [lindex $parameters [expr [lsearch $parameters $key]+1]]
  310. }
  311. #
  312. # Return the value of a variable stored in the props() array
  313. #
  314. proc get_prop {root win} {
  315. global props
  316. return $props($root.props.$win)
  317. }
  318. #
  319. # Save the layout as defined by the user
  320. #
  321. proc save_gui {root dlg} {
  322. global dialog_columns
  323. global dialog_rows
  324. global components
  325. global frame_count
  326. global text_count
  327. global line_count
  328. if {$root == "."} { set base "" } else { set base $root }
  329. set file [open "gui$dlg.tcl" w]
  330. puts $file "set props($dlg.columns) $dialog_columns"
  331. puts $file "set props($dlg.rows) $dialog_rows"
  332. puts $file "set props($dlg.frames) $frame_count"
  333. puts $file "set props($dlg.texts) $text_count"
  334. puts $file "set props($dlg.lines) $line_count"
  335. set cnum [llength $components]
  336. puts $file "set props($dlg.components) \"$components\""
  337. puts $file "set props($dlg.count) $cnum"
  338. # 1. dump components
  339. foreach i $components {
  340. set winfo [grid info $base.widgets.$i]
  341. puts $file "set props($dlg.props.$i) \"$winfo\""
  342. }
  343. # 2. dump frames
  344. for {set i 0} {$i < $frame_count} {incr i} {
  345. set winfo [grid info $base.widgets.frame$i]
  346. set relief [lindex [$base.widgets.frame$i configure -relief] end]
  347. puts $file "set props($dlg.frame$i) \"$winfo\""
  348. puts $file "set props($dlg.relief.frame$i) $relief"
  349. }
  350. # 3. dump texts
  351. for {set i 0} {$i < $text_count} {incr i} {
  352. set winfo [grid info $base.widgets.text$i]
  353. set text [lindex [$base.widgets.text$i configure -text] end]
  354. puts $file "set props($dlg.text$i) \"$winfo\""
  355. puts $file "set props($dlg.text.text$i) \"$text\""
  356. }
  357. # 4. dump lines
  358. for {set i 0} {$i < $line_count} {incr i} {
  359. set winfo [grid info $base.widgets.line$i]
  360. puts $file "set props($dlg.line$i) \"$winfo\""
  361. }
  362. close $file
  363. }
  364. #
  365. # Setup the bindings for a given widget to make it drag and droppable
  366. #
  367. proc make_draggable {root wn short} {
  368. bind $wn <ButtonPress-1> "button_press $root; update idletasks"
  369. bind $wn <B1-Motion> "drag $root $short %X %Y; update idletasks"
  370. bind $wn <ButtonRelease-1> "drop $root $short %X %Y; update idletasks"
  371. }
  372. #
  373. # root, window name, what = { frame, text, widget }
  374. #
  375. proc make_config_button {root i what} {
  376. if {$root == "."} { set base "" } else { set base $root }
  377. frame .gui-widgets.$i
  378. button .gui-widgets.$i.button -command "config_$what $root $i " -text "$i"
  379. set spans [grid info $base.widgets.$i]
  380. scale .gui-widgets.$i.scale-x -orient horizontal -from 1 -to 10 -label "span-x" \
  381. -command "set_span_col $root $i"
  382. scale .gui-widgets.$i.scale-y -orient horizontal -from 1 -to 10 -label "span-y" \
  383. -command "set_span_row $root $i"
  384. .gui-widgets.$i.scale-y set [expr 1+([lindex $spans [expr 1+[lsearch $spans -rowspan]]]-1)/2]
  385. .gui-widgets.$i.scale-x set [expr 1+([lindex $spans [expr 1+[lsearch $spans -columnspan]]]-1)/2]
  386. pack .gui-widgets.$i.button .gui-widgets.$i.scale-x .gui-widgets.$i.scale-y -side left
  387. pack .gui-widgets.$i -side top
  388. }
  389. #
  390. # Create a new border (these are widgets not known by mc)
  391. #
  392. proc new_border {root} {
  393. global frame_count
  394. if {$root == "."} { set base "" } else { set base $root }
  395. set short frame$frame_count
  396. set wn $base.widgets.$short
  397. incr frame_count
  398. # create the frame
  399. frame $wn -relief sunken -borderwidth 2
  400. grid $wn -row 1 -column 1 -columnspan 1 -rowspan 1 -sticky wens -padx 2 -pady 2
  401. lower $wn
  402. # drag and dropability
  403. make_draggable $root $wn $short
  404. # configurability
  405. make_config_button $root $short frame
  406. }
  407. #
  408. # Create a new line separator (these are widgets not known by mc)
  409. #
  410. proc new_line {root} {
  411. global line_count
  412. if {$root == "."} { set base "" } else { set base $root }
  413. set short line$line_count
  414. set wn $base.widgets.$short
  415. incr line_count
  416. # create the line
  417. frame $wn -height 3 -bd 1 -relief sunken
  418. grid $wn -row 1 -column 1 -columnspan 1 -rowspan 1 -sticky wens -padx 2 -pady 2
  419. lower $wn
  420. # drag and dropability
  421. make_draggable $root $wn $short
  422. # configurability
  423. make_config_button $root $short line
  424. }
  425. #
  426. # Create a new text (these are widgets not known by mc)
  427. #
  428. proc new_text {root} {
  429. global text_count
  430. if {$root == "."} { set base "" } else { set base $root }
  431. set short text$text_count
  432. set wn $base.widgets.$short
  433. incr text_count
  434. label $wn -text "Text..."
  435. grid $wn -row 1 -column 1 -columnspan 1 -rowspan 1
  436. make_draggable $root $wn $short
  437. make_config_button $root $short text
  438. }
  439. #
  440. # Start up the GUI designer
  441. #
  442. proc gui_design {root components} {
  443. global props
  444. global new_dialog
  445. # May be created in layout_with_grid if reconfiguring
  446. catch {toplevel .gui-widgets}
  447. if {$root == "."} {
  448. set base ""
  449. } else {
  450. set base $root
  451. }
  452. if {$new_dialog} {
  453. reset_counters
  454. }
  455. # Work around Tk 4.1 bug
  456. frame $base.widgets.bug-work-around
  457. grid $base.widgets.bug-work-around -row 60 -column 60
  458. foreach i $components {
  459. set def_layout [catch "get_prop $root $i" val]
  460. if {$def_layout} {
  461. set_widget_col $root $i 0
  462. set_widget_row $root $i 0
  463. }
  464. make_draggable $root $base.widgets.$i $i
  465. make_config_button $root $i widget
  466. }
  467. frame .gui-widgets.buttons
  468. button .gui-widgets.buttons.save -text "Save to: gui$root.tcl" -command "save_gui $root $root"
  469. button .gui-widgets.buttons.abort -text "abort" -command "exit"
  470. button .gui-widgets.buttons.newf -text "New border" -command "new_border $root"
  471. button .gui-widgets.buttons.newl -text "New line" -command "new_line $root"
  472. button .gui-widgets.buttons.newt -text "New text" -command "new_text $root"
  473. pack\
  474. .gui-widgets.buttons.save \
  475. .gui-widgets.buttons.abort \
  476. .gui-widgets.buttons.newf \
  477. .gui-widgets.buttons.newt \
  478. -side left -expand y
  479. pack .gui-widgets.buttons
  480. }
  481. #
  482. # Attempt to layout a grided dialog. If something fails, return 0
  483. # to give the application the chance to run the GUI designer
  484. #
  485. proc layout_with_grid {dialog count} {
  486. global props
  487. global components
  488. global min_width
  489. global min_height
  490. global env
  491. global dialog_columns
  492. global dialog_rows
  493. global frame_count
  494. global text_count
  495. global line_count
  496. global new_dialog
  497. set expr "set saved_count \$props(.\$dialog.count)"
  498. set new_dialog 1
  499. if [catch "eval $expr"] {
  500. puts "Calling editor, reason: count"
  501. return 0
  502. }
  503. set bw .$dialog.widgets
  504. if {$saved_count != $count} {
  505. puts "Calling editor, reason: more widgets"
  506. return 0
  507. }
  508. set new_dialog 0
  509. # Check if the user wants to modify this dialog
  510. if ![string compare $env(MC_EDIT) $dialog] {
  511. set modify_dialog 1
  512. toplevel .gui-widgets
  513. } else {
  514. set modify_dialog 0
  515. }
  516. # First, hack around the crash problem of Tk 4.2 beta 1
  517. frame .$dialog.widgets.work-around
  518. grid .$dialog.widgets.work-around -row 60 -column 60
  519. set dialog_columns $props(.$dialog.columns)
  520. set dialog_rows $props(.$dialog.rows)
  521. for {set i 0} {$i <= $dialog_columns} {incr i} {
  522. column_space $bw $i
  523. create_column $bw $i $modify_dialog
  524. }
  525. for {set i 0} {$i <= $dialog_rows} {incr i} {
  526. row_space $bw $i
  527. create_row $bw $i $modify_dialog
  528. }
  529. grid .$dialog.widgets -column 0 -row 0 -ipadx 8 -ipady 8 -sticky nswe
  530. # 1. Load the borders (first, because they may cover other widgets)
  531. set frame_count $props(.$dialog.frames)
  532. for {set i 0} {$i < $frame_count} {incr i} {
  533. frame .$dialog.widgets.frame$i -relief $props(.$dialog.relief.frame$i) -borderwidth 2
  534. eval grid .$dialog.widgets.frame$i "$props(.$dialog.frame$i)"
  535. if {$modify_dialog} {
  536. lower .$dialog.widgets.frame$i
  537. make_draggable .$dialog .$dialog.widgets.frame$i frame$i
  538. make_config_button .$dialog frame$i frame
  539. }
  540. }
  541. # 1.1 Load the lines (before texts, since they may cover other widgets)
  542. if {![catch {set line_count $props(.$dialog.lines)}]} {
  543. for {set i 0} {$i < $line_count} {incr i} {
  544. frame .$dialog.widgets.line$i -relief sunken -bd 1 -height 3
  545. eval grid .$dialog.widgets.line$i "$props(.$dialog.line$i)"
  546. if {$modify_dialog} {
  547. lower .$dialog.widgets.line$i
  548. make_draggable .$dialog .$dialog.widgets.line$i line$i
  549. make_config_button .$dialog line$i line
  550. }
  551. }
  552. }
  553. # 2. Load the components
  554. foreach i $components {
  555. eval grid .$dialog.widgets.$i "$props(.$dialog.props.$i)"
  556. raise .$dialog.widgets.$i
  557. }
  558. # 3 . Load the texts
  559. set text_count $props(.$dialog.texts)
  560. for {set i 0} {$i < $text_count} {incr i} {
  561. label .$dialog.widgets.text$i -text $props(.$dialog.text.text$i)
  562. eval grid .$dialog.widgets.text$i "$props(.$dialog.text$i)"
  563. raise .$dialog.widgets.text$i
  564. if {$modify_dialog} {
  565. make_draggable .$dialog .$dialog.widgets.text$i text$i
  566. # make_config_button .$dialog text$i text
  567. }
  568. }
  569. if {$modify_dialog} {
  570. puts "Calling editor, reason: modify_dialog set"
  571. return 0
  572. }
  573. return 1
  574. }
  575. #
  576. # For testing the GUI builder. Not used by the Midnight Commander
  577. #
  578. proc mc_create_buttons {root} {
  579. if {$root == "."} { set base "" } else { set base $root }
  580. button $base.widgets.button#1 -text "Oki\ndoki\nmy\friends"
  581. button $base.widgets.button#2 -text "Cancel"
  582. entry $base.widgets.entry#1
  583. radiobutton $base.widgets.radio#1 -text "Primera opcion"
  584. radiobutton $base.widgets.radio#2 -text "Segunda opcion"
  585. radiobutton $base.widgets.radio#3 -text "Tercera opcion"
  586. }
  587. proc test_gui {} {
  588. global components
  589. button .a -text "A"
  590. pack .a
  591. toplevel .hola
  592. create_gui_canvas .hola
  593. set components {button#1 button#2 entry#1 radio#1 radio#2 radio#3}
  594. mc_create_buttons .hola
  595. if [layout_with_grid hola 6] {
  596. puts corriendo
  597. } else {
  598. create_workspace .hola
  599. gui_design .hola $components
  600. }
  601. }
  602. # initialize
  603. reset_counters
  604. if ![info exists env(MC_EDIT)] {
  605. set env(MC_EDIT) non-existant-toplevel-never-hit
  606. }
  607. if [catch {set x $mc_running}] { set mc_running 0 }
  608. if {$use_separate_gui_files} {
  609. if [catch "glob gui.*.tcl" files] {
  610. set files ""
  611. }
  612. foreach i $files {
  613. puts "loading $i..."
  614. source $i
  615. }
  616. } else {
  617. source $LIBDIR/gui.tcl
  618. }
  619. if {$mc_running == 0} {
  620. test_gui
  621. }