]> www.wagner.pp.ru Git - oss/ck.git/blob - testck.tcl
Ck console graphics toolkit
[oss/ck.git] / testck.tcl
1
2 lappend auto_path .
3 package require Ck
4 set frame {ulcorner hline urcorner vline lrcorner llcorner}
5 option add *CkFDialog*Background blue
6 option add *CkChooseColor*Background green
7 option add *MenuBar*foreground black
8 option add *MenuBar*background white
9 option add *MenuBar*activeBackground black
10 option add *MenuBar*activeForeground white
11 option add *MenuBar*selectedBackground black
12 option add *MenuBar*selectedForeground white
13 option add *MenuBar*underlineAttributes {underline bold}
14 option add *MenuBar*underlineForeground yellow 
15 frame .menu -class MenuBar
16 menubutton .menu.file -text File -underline 0   -menu .menu.file.m
17 menu .menu.file.m -border $frame 
18 .menu.file.m add command -label "New" -command {fileNew}
19 .menu.file.m add command -label "Open..." -command {fileOpen}
20 .menu.file.m add command -label "Save..." -command {fileSave}
21 .menu.file.m add separator 
22 .menu.file.m add command -label "Exit" -command {destroy .}
23 menubutton .menu.dialog -text Dialogs -underline 0 -menu .menu.dialog.m
24 menu .menu.dialog.m -border $frame
25 .menu.dialog.m add command -label "Message box.." -command {ck_messageBox -title "MessageBox" -message "This is simple message box" -type ok}
26 .menu.dialog.m add command -label "Color Picker.." -command {ck_chooseColor}
27 .menu.dialog.m add command -label "Command window.." -command {ckCommand}
28 label .menu.hint -text "Press <F10> for menu" -foreground black -background white
29 pack .menu.hint -side right
30 pack .menu.file .menu.dialog -side left -padx 1
31 pack .menu -side top -fill x
32 frame .f
33 text .f.t -yscrollcommand ".f.y set" -foreground yellow -attributes bold -background blue
34 scrollbar .f.y -orient vert -command ".f.t yview"
35 pack .f.t -side left -expand y -fill both
36 pack .f.y -side right -expand n -fill y
37 pack .f -side top -expand y -fill both
38 focus .f.t
39 bind .f.t <F10> {focus .menu.file;.menu.file configure -state active}
40 proc fileOpen {} {
41    global fileName
42    set filename [ck_getOpenFile]
43    if {![string length filename]} return;
44    set f [open $filename]
45    .f.t delete 0.0 end
46    .f.t insert 0.0 [read $f]
47    close $f
48    set fileName $filename
49    .f.t mark set insert 0.0
50    focus .f.t
51 }   
52
53 proc fileSave {} {
54         global fileName
55         if {[info exists fileName]} {
56                 set filename [ck_getSaveFile -initialfile $filename]
57         } else {
58                 set filename [ck_getSaveFile]
59         }
60         if {![string length filename]} return;
61         set f [open $filename w]
62         puts -nonewline $f [.f.t get 0.0 end]
63         close $f
64         set fileName $filename
65         focus .f.t
66 }
67
68 proc fileNew {} {
69         global fileName
70         catch {unset fileName}
71         .f.t delete 0.0 end
72         focus .f.t
73 }       
74 tkwait window .
75