Move helper functions to front
[lilypond/dscho.git] / lilycontrib.tcl
blob2a92c27ccbc978009d9f6992f07056282aea5a2c
1 #!/usr/bin/wish
3 package require Tk
5 # Helper functions
7 set lily_dir $env(HOME)/lilypond
8 cd $lily_dir
10 proc write_to_output {s} {
11 .output.text insert insert $s
12 .output.text see end
15 proc write_file_to_output {f} {
16 if {[eof $f]} {
17 global git_command
18 fconfigure $f -blocking true
19 if {[catch {close $f} err]} {
20 tk_messageBox -type ok -message "Git aborted: $err"
22 unset git_command
23 } else {
24 write_to_output [read $f 24]
28 proc git {args} {
29 global lily_dir git_command
30 file mkdir $lily_dir
31 set git_command [linsert $args 0 "|git" "--git-dir=$lily_dir/.git"]
32 set git_command "$git_command 2>@1"
33 #.output.text insert end "$git_command\n"
34 set git [open $git_command r]
35 fconfigure $git -blocking false
36 fileevent $git readable [list write_file_to_output $git]
37 vwait git_command
40 proc config {args} {
41 global lily_dir
42 set p [open [linsert $args 0 "|git" --git-dir=$lily_dir/.git config] r]
43 set result [regsub "\n\$" [read $p] ""]
44 close $p
45 return $result
48 proc update_lilypond {} {
49 global lily_dir
50 if {![file exists $lily_dir]} {
51 file mkdir $lily_dir
52 git init
53 git config core.bare false
54 git remote add -t master \
55 origin git://repo.or.cz/lilypond.git
56 git fetch --depth 1
57 git reset --hard origin/master
58 git config branch.master.remote origin
59 git config branch.master.merge refs/heads/master
60 .update configure -text "Update LilyPond"
61 } else {
62 git fetch origin
63 git merge origin/master
65 write_to_output "Done.\n"
68 # GUI
70 wm title . "LilyPond Contributor's GUI"
72 # Buttons
74 panedwindow .buttons
75 button .buttons.update -text "Update LilyPond" -command update_lilypond
76 if {![file exists $lily_dir]} {
77 .update configure -text "Clone LilyPond"
79 pack .buttons.update -side left
81 # Output
83 panedwindow .output
84 text .output.text -width 80 -height 15 \
85 -xscrollcommand [list .output.horizontal set] \
86 -yscrollcommand [list .output.vertical set]
87 scrollbar .output.horizontal -orient h -command [list .output.text xview]
88 scrollbar .output.vertical -orient v -command [list .output.text yview]
89 pack .output.horizontal -side bottom -fill x
90 pack .output.vertical -side right -fill y
91 pack .output.text -expand true -anchor nw -fill both
93 pack .buttons .output