Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/505ce122068b
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:38:12 2012
Кодировка:

# HG changeset patch
# User Danya Alexeyevsky
# Date 1276165448 -14400
# Node ID 505ce122068b0e26bb880ad2daf117818652fe61
# Parent 208ec59bad5b6afe2ce1ff6ad2bfde83da295f2c
Generalized tcl examples in the sandbox.

diff -r 208ec59bad5b -r 505ce122068b sandbox/common.tcl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sandbox/common.tcl Thu Jun 10 14:24:08 2010 +0400
@@ -0,0 +1,45 @@
+proc generate_lines {} {
+ global lines
+
+ set f [open "/dev/urandom"]
+
+ proc rand {class} {
+ global f
+ while {1} {
+ set c [read $f 1]
+ if {[string is $class $c]} { return $c }
+ }
+ }
+
+ set lines {}
+ for {set i 0} {$i < 800} {incr i} {
+ if {$i % 10 == 0} { puts "line $i"; }
+
+ set line {}
+ for {set j 0} {$j < 1000} {incr j} {
+ lappend line $i $j [rand upper] [rand integer]
+ }
+ lappend lines $line
+ }
+
+ set f [open "data/lines.tcl" w]
+ puts $f "set lines [list $lines]"
+ close $f
+}
+
+proc load_lines {} {
+ global lines
+ source "data/lines.tcl"
+}
+
+proc add_scrolls {w} {
+ scrollbar .w -orient horizontal -command {$w xview}
+ scrollbar .h -orient vertical -command {$w yview}
+ $w configure -xscrollcommand {.w set}
+ $w configure -yscrollcommand {.h set}
+ grid rowconfigure . 0 -weight 1
+ grid columnconfigure . 0 -weight 1
+ grid $w -row 0 -column 0 -sticky nsew
+ grid .w -row 1 -column 0 -sticky we
+ grid .h -row 0 -column 1 -sticky ns
+}
diff -r 208ec59bad5b -r 505ce122068b sandbox/tk-canvas.tcl
--- a/sandbox/tk-canvas.tcl Thu Jun 10 14:18:23 2010 +0400
+++ b/sandbox/tk-canvas.tcl Thu Jun 10 14:24:08 2010 +0400
@@ -1,43 +1,13 @@
-canvas .x
-grid .x -row 0 -column 0 -sticky nsew
+#!/bin/sh
+# vim: set ft=tcl: \
+exec wish "$0" "$@"

-scrollbar .w -orient horizontal -command {.x xview}
-scrollbar .h -orient vertical -command {.x yview}
-.x configure -xscrollcommand {.w set}
-.x configure -yscrollcommand {.h set}
-grid rowconfigure . 0 -weight 1
-grid columnconfigure . 0 -weight 1
-grid .w -row 1 -column 0 -sticky we
-grid .h -row 0 -column 1 -sticky ns
-.x configure -scrollregion {0 0 10000 8000}
+source "common.tcl"

-#set f [open "/dev/urandom"]
-#
-#proc rand {class} {
-# global f
-# while {1} {
-# set c [read $f 1]
-# if {[string is $class $c]} { return $c }
-# }
-#}
-#
-#set lines {}
-#for {set i 0} {$i < 800} {incr i} {
-# if {$i % 10 == 0} { puts "line $i"; }
-#
-# set line {}
-# for {set j 0} {$j < 1000} {incr j} {
-# lappend line $i $j [rand upper] [rand integer]
-# }
-# lappend lines $line
-#}
-#
-#set f [open "data/lines.tcl" w]
-#puts $f "set lines [list $lines]"
-#close $f
+canvas .x -scrollregion {0 0 10000 8000}
+add_scrolls .x

-source "data/lines.tcl"
-
+load_lines
puts "lines are ready"

foreach line $lines {
diff -r 208ec59bad5b -r 505ce122068b sandbox/tk-text.tcl
--- a/sandbox/tk-text.tcl Thu Jun 10 14:18:23 2010 +0400
+++ b/sandbox/tk-text.tcl Thu Jun 10 14:24:08 2010 +0400
@@ -2,29 +2,12 @@
# vim: set ft=tcl: \
exec wish "$0" "$@"

+source "common.tcl"
+
text .x -wrap no
-grid .x -row 0 -column 0 -sticky nsew
+add_scrolls .x

-scrollbar .w -orient horizontal -command {.x xview}
-scrollbar .h -orient vertical -command {.x yview}
-.x configure -xscrollcommand {.w set}
-.x configure -yscrollcommand {.h set}
-grid rowconfigure . 0 -weight 1
-grid columnconfigure . 0 -weight 1
-grid .w -row 1 -column 0 -sticky we
-grid .h -row 0 -column 1 -sticky ns
-
-# set f [open "/dev/urandom"]
-#
-# proc rand {class} {
-# global f
-# while {1} {
-# set c [read $f 1]
-# if {[string is $class $c]} { return $c }
-# }
-# }
-
-source "data/lines.tcl"
+load_lines

for {set i 0} {$i < 10} {incr i} {
.x tag configure $i -background #$i$i$i