Minsky
group.tcl
Go to the documentation of this file.
1 # @copyright Steve Keen 2012
2 # @author Russell Standish
3 # This file is part of Minsky.
4 #
5 # Minsky is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Minsky is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Minsky. If not, see <http://www.gnu.org/licenses/>.
17 #
18 
19 # Group (or block) functionality
20 
21 setGroupIconResource $minskyHome/icons/group.svg
22 
23 proc rightMouseGroup {x y X Y} {
24  if [selectVar $x $y] {
25  .wiring.context delete 0 end
26  .wiring.context add command -label "Edit" -command "editItem"
27  .wiring.context add command -label "Copy" -command "canvas.copyItem"
28  .wiring.context add command -label "Remove" -command "canvas.removeItemFromItsGroup"
29  .wiring.context post $X $Y
30  } else {
31  contextMenu $x $y $X $Y
32  }
33 }
34 
35 proc deiconifyEditGroup {} {
36  if {![winfo exists .wiring.editGroup]} {
37  toplevel .wiring.editGroup
38  wm title .wiring.editGroup "Edit Group"
39  wm transient .wiring.editGroup .wiring
40 
41  frame .wiring.editGroup.name
42  label .wiring.editGroup.name.label -text "Name"
43  entry .wiring.editGroup.name.val -width 20
44  pack .wiring.editGroup.name.label .wiring.editGroup.name.val -side left
45 
46  frame .wiring.editGroup.rot
47  label .wiring.editGroup.rot.label -text " Rotation"
48  entry .wiring.editGroup.rot.val -width 20
49  pack .wiring.editGroup.rot.label .wiring.editGroup.rot.val -side left
50 
51  pack .wiring.editGroup.name .wiring.editGroup.rot
52 
53  frame .wiring.editGroup.buttonBar
54  button .wiring.editGroup.buttonBar.ok -text OK
55  button .wiring.editGroup.buttonBar.cancel -text Cancel -command {
56  closeEditWindow .wiring.editGroup}
57  pack .wiring.editGroup.buttonBar.ok .wiring.editGroup.buttonBar.cancel -side left
58  pack .wiring.editGroup.buttonBar -side bottom
59 
60  bind .wiring.editGroup <Key-Return> {invokeOKorCancel .wiring.editGroup.buttonBar}
61  bind .wiring.editGroup <Key-Escape> {.wiring.editGroup.buttonBar.cancel invoke}
62  } else {
63  wm deiconify .wiring.editGroup
64  }
65  update
66 }
67 
68 proc groupEdit {} {
70  .wiring.editGroup.name.val delete 0 end
71  .wiring.editGroup.name.val insert 0 [minsky.canvas.item.title]
72  .wiring.editGroup.rot.val delete 0 end
73  .wiring.editGroup.rot.val insert 0 [minsky.canvas.item.rotation]
74  .wiring.editGroup.buttonBar.ok configure \
75  -command {
76  minsky.canvas.item.rotation [.wiring.editGroup.rot.val get]
77  minsky.canvas.item.title [.wiring.editGroup.name.val get]
78  minsky.canvas.requestRedraw
79  closeEditWindow .wiring.editGroup
80  }
81  grab .wiring.editGroup
82 }
83 
84 namespace eval group {
85 
86  proc save {} {
87  global workDir
88  set ext [minsky.canvas.item.defaultExtension]
89  set fname [tk_getSaveFile -defaultextension $ext -initialdir $workDir \
90  -filetypes [fileTypes $ext]]
91  if [string length $fname] {
92  eval saveCanvasItemAsFile {$fname}
93  }
94  }
95 
96 }
97