-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrk2fit-dnd
executable file
·69 lines (54 loc) · 1.52 KB
/
wrk2fit-dnd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env tclsh
package require Tk 8.5
package require tkdnd 2.6
wm title . "wrk2fit"
wm minsize . 120 120
set defaultText "WRK → FIT"
set fitFileTypes {{"FIT Workout Files" ".fit"} {"All Files" "*"}}
set wrkFileTypes {{"Wokrout Description Files" ".wrk"} {"All Files" "*"}}
ttk::label .dropLabel -text $defaultText \
-anchor center -justify center -wraplength 120
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1
grid .dropLabel -row 0 -column 0 -sticky nesw -padx 5 -pady 5
tkdnd::drop_target register .dropLabel {DND_Files DND_Text}
proc onError {message} {
global defaultText
.dropLabel configure -background #dc322f -text $message
after 1000 {
.dropLabel configure -background {} -text $defaultText
}
}
proc writeFile {path data} {
# TODO: handle errors
set fd [open $path {BINARY CREAT WRONLY}]
puts -nonewline $fd $data
close $fd
}
proc handleText {wrk} {
# TODO
}
proc handleFile {wrkFile} {
global fitFileTypes
try {
set fit [exec ./wrk2il < $wrkFile | ./il2fit]
set path [tk_getSaveFile -filetypes $fitFileTypes]
writeFile $path $fit
} trap CHILDSTATUS {- opts} {
onError "Bad WRK"
}
}
bind .dropLabel <Double-1> {
set filePath [tk_getOpenFile -filetypes $wrkFileTypes]
if {$filePath ne ""} {
handleFile $filePath
} else {
onError "No file selected"
}
}
bind .dropLabel <<Drop:DND_Files>> {
handleFile [lindex %D 0]
}
bind .dropLabel <<Drop:DND_Text>> {
handleText %D
}