summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorpetasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e>2014-08-06 16:21:43 (GMT)
committerpetasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e>2014-08-06 16:21:43 (GMT)
commit98884afec896ed55aa2c61cae8e824fe73bec17c (patch)
treed4fa20f17d9cc5ee3028c028bf8b46e4de32fe80 /demos
parent7bc6b98d747850b0a6e094e3fa3cb132003215ac (diff)
downloadtkdnd-98884afec896ed55aa2c61cae8e824fe73bec17c.zip
tkdnd-98884afec896ed55aa2c61cae8e824fe73bec17c.tar.gz
tkdnd-98884afec896ed55aa2c61cae8e824fe73bec17c.tar.bz2
New demos!
Diffstat (limited to 'demos')
-rw-r--r--demos/complex_source.tcl39
-rw-r--r--demos/simple_source.tcl22
-rw-r--r--demos/simple_target.tcl58
3 files changed, 119 insertions, 0 deletions
diff --git a/demos/complex_source.tcl b/demos/complex_source.tcl
new file mode 100644
index 0000000..3255ea8
--- /dev/null
+++ b/demos/complex_source.tcl
@@ -0,0 +1,39 @@
+package require tkdnd
+catch {console show}
+
+##
+## Drag source
+##
+pack [ttk::button .drag_source -text " Drag Source "] \
+ -fill x -padx 20 -pady 20
+
+tkdnd::drag_source register .drag_source
+
+## Event <<DragInitCmd>>
+bind .drag_source <<DragInitCmd>> my_data
+
+proc my_data {} {
+ list copy [list \
+ DND_HTML {<html><p>Some nice HTML text!</p></html>} \
+ DND_Text {Some nice dropped text!} \
+ DND_Files [list /tmp/some_nice_dropped_file] \
+ ]
+};# my_data
+
+proc my_drop {w type data action} {
+ puts "Data drop ($type): \"$data\""
+ $w state !active
+ return $action
+};# my_drop
+
+##
+## Drop targets
+##
+foreach type {DND_HTML DND_Text DND_Files} {
+ set w [ttk::button .drop_target$type -text " Drop Target ($type) "]
+ pack $w -fill x -padx 20 -pady 20
+ tkdnd::drop_target register $w $type
+ bind $w <<DropEnter>> {%W state active}
+ bind $w <<DropLeave>> {%W state !active}
+ bind $w <<Drop>> [list my_drop %W %CPT %D %A]
+}
diff --git a/demos/simple_source.tcl b/demos/simple_source.tcl
new file mode 100644
index 0000000..53b0df3
--- /dev/null
+++ b/demos/simple_source.tcl
@@ -0,0 +1,22 @@
+package require tkdnd
+catch {console show}
+
+pack [ttk::button .drag_source_text -text " Drag Source (Text) "] \
+ -fill x -padx 20 -pady 20
+pack [ttk::button .drag_source_files -text " Drag Source (Files) "] \
+ -fill x -padx 20 -pady 20
+
+tkdnd::drag_source register .drag_source_text DND_Text
+tkdnd::drag_source register .drag_source_files DND_Files
+
+## Event <<DragInitCmd>>
+set filename [info script]
+bind .drag_source_text <<DragInitCmd>> \
+ {list copy DND_Text {Some nice dropped text!}}
+bind .drag_source_files <<DragInitCmd>> \
+ {list {copy move} DND_Files [list $filename $filename]}
+
+## Event <<DragEndCmd>>
+bind .drag_source_files <<DragEndCmd>> {
+ puts "Drop action: %A"
+}
diff --git a/demos/simple_target.tcl b/demos/simple_target.tcl
new file mode 100644
index 0000000..341cac2
--- /dev/null
+++ b/demos/simple_target.tcl
@@ -0,0 +1,58 @@
+package require tkdnd
+catch {console show}
+
+pack [ttk::button .drop_target -text " Drop Target (I can accept anything!) "] \
+ -fill x -padx 20 -pady 20
+
+tkdnd::drop_target register .drop_target *
+
+## Visual feedback:
+bind .drop_target <<DropEnter>> {%W state active}
+bind .drop_target <<DropLeave>> {%W state !active}
+
+## Position events:
+proc handle_position {widget mouse_x mouse_y drag_source_actions buttons} {
+ ## Limit drops to the left half part of the window...
+ set x [winfo rootx $widget]
+ set w [winfo width $widget]
+ set middle [expr {$x + $w / 2.}]
+ if {$mouse_x > $middle} {return refuse_drop}
+ if {"alt" in $buttons && "link" in $drag_source_actions} {
+ return link
+ } elseif {"ctrl" in $buttons && "move" in $drag_source_actions} {
+ return move
+ } elseif {"copy" in $drag_source_actions} {
+ return copy
+ } else {
+ return refuse_drop
+ }
+};# handle_position
+bind .drop_target <<DropPosition>> [list handle_position %W %X %Y %a %b]
+
+## Drop callbacks:
+bind .drop_target <<Drop>> {
+ puts "Generic data drop: \"%D\""
+ %W state !active
+ return %A
+}
+bind .drop_target <<Drop:DND_Text>> {
+ puts "Dropped text: \"%D\""
+ %W state !active
+ return %A
+}
+bind .drop_target <<Drop:DND_Files>> {
+ puts "Dropped files: \"[join %D {, }]\""
+ %W state !active
+ return %A
+}
+bind .drop_target <<Drop:DND_HTML>> {
+ puts "Dropped HTML: \"[join %D {, }]\""
+ %W state !active
+ return %A
+}
+bind .drop_target <<Drop:DND_Color>> {
+ puts "Dropped color: \"%D\""
+ %W state !active
+ return %A
+}
+