File: gui.tcl

package info (click to toggle)
moodss 9.0-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,540 kB
  • ctags: 609
  • sloc: sh: 8,869; tcl: 6,909; ansic: 113; makefile: 44
file content (271 lines) | stat: -rw-r--r-- 15,136 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# copyright (C) 1997-1999 Jean-Luc Fontaine (mailto:jfontain@multimania.com)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu

set rcsId {$Id: gui.tcl,v 1.21 1999/08/08 18:30:17 jfontain Exp $}

proc updateTitle {} {                                                          ;# show modules and poll time or mode in window title
    if {[llength $global::pollTimes]==0} {
        wm title . "moodss: [commaSeparatedString $modules::(names)] data (asynchronous)"
    } else {
        wm title . "moodss: [commaSeparatedString $modules::(names)] data (every $global::pollTime seconds)"
    }
}

proc createMenuWidget {parentPath readOnly includePollTime} {
    set menu [menu $parentPath.menu -tearoff 0]
    set help(bar) [new menuContextHelp $menu]
    set index(bar) -1

    menu $menu.file -tearoff 0
    set global::fileMenuContextHelper [new menuContextHelp $menu.file]
    set index(file) -1

    $menu add cascade -label File -menu $menu.file -underline 0
    menuContextHelp::set $help(bar) [incr index(bar)] {file related operations}

    if {!$readOnly} {
        $menu.file add command -label Save -command {save 0} -underline 1 -accelerator Ctrl+S
        bind $parentPath <Control-s> {save 0}
        set string {input file for saving configuration and viewers layout}
        set global::fileMenuContextHelperSaveIndex [incr index(file)]
        updateFileSaveMenuHelp $global::saveFile                          ;# save file may already have been defined in command line

        $menu.file add command -label {Save As...} -command {save 1} -underline 6 -accelerator Ctrl+A
        bind $parentPath <Control-a> {save 1}
        menuContextHelp::set $global::fileMenuContextHelper [incr index(file)] $string
    }

    $menu.file add separator
    incr index(file)
    $menu.file add command -label Exit -command exit -underline 1 -accelerator Ctrl+Q
    menuContextHelp::set $global::fileMenuContextHelper [incr index(file)] {close main window and exit program}
    bind $parentPath <Control-q> exit

    if {!$readOnly} {
        $menu add cascade -label Edit -menu [menu $menu.edit -tearoff 0] -underline 0
        set help(edit) [new menuContextHelp $menu.edit]
        menuContextHelp::set $help(bar) [incr index(bar)] {content editing, configuration and preferences}

        $menu.edit add command -label {Configuration...} -command {configuration::edit 0} -underline 0
        menuContextHelp::set $help(edit) 0 {edit current configuration}

        $menu.edit add cascade -label New -menu [menu $menu.edit.new -tearoff 0] -underline 0
        set help(new) [new menuContextHelp $menu.edit.new]
        menuContextHelp::set $help(edit) 1 {create empty data viewers}

        $menu.edit.new add command -label {Graph Chart...} -underline 0\
            -command "createCellsViewer dataGraph {} 1 $global::static \$global::pollTime"
        menuContextHelp::set $help(new) 0 {create an empty graph chart data viewer}

        $menu.edit.new add command -label {Overlap Bar Chart...} -underline 0\
            -command "createCellsViewer dataOverlapBarChart {} 1 $global::static"
        menuContextHelp::set $help(new) 1 {create an empty overlap bar chart data viewer}

        $menu.edit.new add command -label {Side Bar Chart...} -underline 5\
            -command "createCellsViewer dataSideBarChart {} 1 $global::static"
        menuContextHelp::set $help(new) 2 {create an empty side bar chart data viewer}

        $menu.edit.new add command -label {Stacked Bar Chart...} -underline 0\
            -command "createCellsViewer dataStackedBarChart {} 1 $global::static"
        menuContextHelp::set $help(new) 3 {create an empty stacked bar chart data viewer}

        $menu.edit.new add command -label {2D Pie Chart...} -underline 0\
            -command "createCellsViewer data2DPieChart {} 1 $global::static"
        menuContextHelp::set $help(new) 4 {create an empty 2D pie chart data viewer}

        $menu.edit.new add command -label {3D Pie Chart...} -underline 0\
            -command "createCellsViewer data3DPieChart {} 1 $global::static"
        menuContextHelp::set $help(new) 5 {create an empty 3D pie chart data viewer}

        $menu.edit.new add command -label {Summary Table...} -underline 8\
            -command "createCellsViewer summaryTable {} 1 $global::static"
        menuContextHelp::set $help(new) 6 {create an empty summary table data viewer}

        $menu.edit.new add command -label {Free Text...} -underline 0 -command "createCellsViewer freeText {} 1 $global::static"
        menuContextHelp::set $help(new) 7 {create an empty free text data viewer}

        $menu.edit add separator
        $menu.edit add command -label {Preferences...} -command {configuration::edit 1} -underline 0
        menuContextHelp::set $help(edit) 3 {edit application-wide preferences}
    }

    if {!$readOnly&&$includePollTime} {
        $menu add cascade -label View -menu [menu $menu.view -tearoff 0] -underline 0
        set help(options) [new menuContextHelp $menu.view]
        menuContextHelp::set $help(bar) [incr index(bar)] {data visualization settings}

        $menu.view add command -label {Poll Time...} -command inquirePollTime -underline 0
        menuContextHelp::set $help(options) 0 {change poll time for all synchronous modules}
    }

    $menu add cascade -label Help -menu [menu $menu.help -tearoff 0] -underline 0
    set help(help) [new menuContextHelp $menu.help]
    menuContextHelp::set $help(bar) [incr index(bar)] {help on moodss and modules}

    $menu.help add command -label Global... -underline 0 -accelerator F1 -command generalHelpWindow
    bind $parentPath <F1> generalHelpWindow
    menuContextHelp::set $help(help) 0 {global help for moodss user}

    $menu.help add cascade -label Modules -menu [menu $menu.help.modules -tearoff 0] -underline 0
    set help(modules) [new menuContextHelp $menu.help.modules]
    set index(modules) -1
    menuContextHelp::set $help(help) 1 {help on loaded modules}

    foreach module $modules::(namespaces) {
        $menu.help.modules add command -label $module... -command "moduleHelpWindow $module"
        menuContextHelp::set $help(modules) [incr index(modules)] "display $module module documentation"
    }

    $menu.help add command -label Copyright... -underline 0 -command {simpleTextDialogBox {moodss: Copyright} $help::copyright}
    menuContextHelp::set $help(help) 2 {display copyright information}

    $menu.help add command -label {Source Versions...} -underline 0 -command versionsDialogBox
    menuContextHelp::set $help(help) 3 {display all source files versions}

    $menu.help add command -label About... -underline 0 -command aboutDialogBox
    menuContextHelp::set $help(help) 4 {display author and general information}

    $parentPath configure -menu $menu
}

proc updateFileSaveMenuHelp {file} {
    if {[string length $file]==0} {
        set string {input file for saving configuration and viewers layout}
    } else {
        set string "into $file file, save configuration and viewers layout"
    }
    menuContextHelp::set $global::fileMenuContextHelper $global::fileMenuContextHelperSaveIndex $string
}

proc createMessageWidget {parentPath} {
    set global::messenger [new lifoLabel $parentPath -headerfont $font::(mediumBold) -font $font::(mediumNormal)]
    return $widget::($global::messenger,path)                                                             ;# return actual tk widget
}

proc dragEcho {data format} {
    return $data
}

proc createDragAndDropZone {parentPath} {
    set frame [frame $parentPath.drops]

    set label [label $frame.graph -image applicationIcon]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer dataGraph \$dragSite::data(DATACELLS) 1 $global::static \$global::pollTime"
    new widgetTip -path $label -text "graph chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::dataGraph}

    set label [label $frame.overlapBarChart -image [image create photo -data [dataOverlapBarChart::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer dataOverlapBarChart \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "overlap bar chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::dataOverlapBarChart}

    set label [label $frame.sideBarChart -image [image create photo -data [dataSideBarChart::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer dataSideBarChart \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "side bar chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::dataSideBarChart}

    set label [label $frame.stackedBarChart -image [image create photo -data [dataStackedBarChart::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer dataStackedBarChart \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "stacked bar chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::dataStackedBarChart}

    set label [label $frame.2DPieChart -image [image create photo -data [data2DPieChart::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer data2DPieChart \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "2D pie chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::data2DPieChart}

    set label [label $frame.3DPieChart -image [image create photo -data [data3DPieChart::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer data3DPieChart \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "3D pie chart\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::data3DPieChart}

    set label [label $frame.summaryTable -image [image create photo -data [summaryTable::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer summaryTable \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "summary table\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::summaryTable}

    set label [label $frame.freeText -image [image create photo -data [freeText::iconData]]]
    pack $label -pady 1 -side left
    new dropSite -path $label -formats DATACELLS\
        -command "createCellsViewer freeText \$dragSite::data(DATACELLS) 1 $global::static"
    new widgetTip -path $label -text "free text\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag VIEWER {dragEcho ::freeText}

    set trashData {
        R0lGODlhKAAoAKUAAP8A/8/Lz+/r71FRUZ6anpaSlv/7/wgICL66vkFBQYaChtfT17LA3LaytjAwMFlZWZaant/b3/fz96aipnFxcWlpaWFhYTAoKCAgICgo
        KOfj576yvklJSRAQEBAQCI6Slq6yrp6SnhgYGAAAAI6KjoaKhnl5ecfDx66ipiAoIOfr5ygwMJ6Slnlxce/j5zg4OL7Dx6aint/T38fLz4Z5hvf7/8/Tz66q
        tqairv/z939/f/fz79fLz0lRUXmChllRUSH5BAEAAAAALAAAAAAoACgAAAb+QIBwSBwGisikckkUDAhMYiEaNQwO06ggS00iDIXEQcFcLA5dpUDAaCgch8GD
        DIVEDJJJIp2URBQUFQoWCRcYGRkGihoBCnt8RQYbDxwZhx0eBwcYHyAMIRMDDpBEEwYPGBgiHSOtrh0PJCVhGaRDCw0JHq68vAkDJh0cfBIEHAoNGb3LvR0O
        DlBDJwsTSHcnBRaszNytAxMaa4oGJyRCAn4LBggMBAfd8BwQCxL1AiiPAOrjDRMU8PBSUDghIJyKFcOEBDAQIMKJCQqUAeQW54QEDREKjOACQIOGAhQ4iJgY
        0KIAFgcoFFlIgoKDXSS7UZAggIKIJAJCtFjxLib+NwcuNLwYkARGDAovevpchkFGhBFLEJhIupTbDA2jlBho8K/qsg400CzJ80Cp11Ydhi6JEIBEgm1nW2Hg
        kBDJFwQVHGCI6wqRWGs1ClRIMJLviAQmoCbBY4LDi1R8LUSwYSJJAAE3OhzogDBuBgISYNRCouFEhgHmAFCAWbUCugkvcKLCMYREA7MxNRjQMCFrkRMYog0x
        UCGFzwMcDORYMImYBhYJJHbTgUPGDow8eORKI2AHAkeqzB54QYG6ABkCFgSYESDACOFM0GGr8MCCBQo9FJgowAAHjjUCGODCAjxE0EAHFnSh2wkfkOADDSGw
        oIA/CTgwgH8MKKCAAC5S8MBAASLkw8QJBsgwAQEk0PBDYX4dgAMCrfg2AUqjUaGCAQsgQMIKRCHxT4K2EEEAOjZYIAJHRKQWJBEgCJCDkUtCgoJRHkQJCQkW
        bGTllrYEAQA7
    }
    set label [label $frame.trash -image [image create photo -data $trashData]]
    pack $label -pady 1 -side right
    new dropSite -path $label -formats OBJECTS -command "eval delete \$dragSite::data(OBJECTS)"
    new widgetTip -path $label -text "objects trashing\ndrag'n'drop site"
    set drag [new dragSite -path $label]
    dragSite::provide $drag KILL list                                           ;# drag data is unimportant, only the kill action is

    return $frame
}

proc inquirePollTime {} {
    set dialog\
        [new dialogBox . -buttons oc -default o -title {moodss: Poll Time} -die 0 -x [winfo pointerx .] -y [winfo pointery .]]
    set frame [frame $widget::($dialog,path).frame]
    set minimum [lindex $global::pollTimes 0]
    set message [message $frame.message\
        -width [winfo screenwidth .] -font $font::(mediumNormal) -justify center\
        -text "Enter new poll time (greater than $minimum):"\
    ]
    pack $message
    set entry [new spinEntry $frame -width 4 -list $global::pollTimes -side right]
    spinEntry::set $entry $global::pollTime
    wcb::callback $composite::($entry,entry,path) before insert wcb::checkStrForNum                   ;# filter on positive integers

    pack $widget::($entry,path) -anchor e -side left -expand 1 -padx 2       ;# evenly pack entry and label together near the center
    pack [label $frame.label -text seconds] -anchor w -side right -expand 1 -padx 2
    dialogBox::display $dialog $frame
    widget::configure $dialog -command "
        set time \[spinEntry::get $entry\]
        if {\$time<$minimum} {                                                                    ;# check against minimum poll time
            bell
            $message configure -text {Enter new poll time\n(must be greater than $minimum):}
        } else {                                                                                                ;# new time is valid
            if {\$time!=\$global::pollTime} {                                     ;# but check that it actually differs from current
                set global::pollTime \$time
                viewer::updateInterval \$time
                updateTitle
                refresh                                      ;# update immediately in case poll time was set to a much greater value
            }
            delete $dialog                                                                                     ;# destroy dialog box
        }
    "
    bind $frame <Destroy> "delete $entry"                                            ;# delete objects not managed by the dialog box
}