File: WDialogs.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (340 lines) | stat: -rw-r--r-- 10,174 bytes parent folder | download | duplicates (4)
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#  WDialogs.tcl ---
#  
#      This file is part of The Coccinella application. It implements some
#      of the dialogs for the whiteboard. 
#      
#  Copyright (c) 2007  Mats Bengtsson
#  
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  
# $Id: WDialogs.tcl,v 1.5 2008-05-05 14:22:29 matben Exp $
   
package provide WDialogs 1.0

namespace eval ::WDialogs:: {

}

# WDialogs::InfoOnPlugins ---
#  
#      It implements the dialog for presenting the loaded packages or helper 
#      applications.

proc ::WDialogs::InfoOnPlugins {} {
    global  prefs this wDlgs
    
    # Check first of there are *any* plugins.
    if {[llength [::Plugins::GetAllPackages loaded]] == 0} {
	::UI::MessageBox -icon info -type ok -message [mc "There are no plugins or helper applications identified on this system."]
	return  
    }
    set w $wDlgs(plugs)
    if {[winfo exists $w]} {
	return
    }
    ::UI::Toplevel $w -macstyle documentProc -usemacmainmenu 1
    wm title $w [mc "Plugins"]
    
    # Global frame.
    ttk::frame $w.frall
    pack $w.frall -fill both -expand 1

    set wbox $w.frall.f
    ttk::frame $wbox -padding [option get . dialogPadding {}]
    pack $wbox -fill both -expand 1

    # Button part.
    set frbot $wbox.b
    ttk::frame $frbot -padding [option get . okcancelTopPadding {}]
    ttk::button $frbot.btok -text [mc "OK"] -command [list destroy $w] \
      -default active
    pack $frbot.btok -side right
    pack $frbot -side bottom -fill x

    set fbox $wbox.f
    frame $fbox -bd 1 -relief sunken
    pack  $fbox -side top -fill both -expand 1
    
    set xtab1 80
    set xtab2 90
    set wtxt $fbox.txt
    set wysc $fbox.ysc
    ttk::scrollbar $wysc -orient vertical -command [list $wtxt yview]
    text $wtxt -yscrollcommand [list $wysc set] -highlightthickness 0  \
      -bg white -wrap word -width 50 -height 30  \
      -exportselection 1 -tabs [list $xtab1 right $xtab2 left]
    pack $wysc -side right -fill y
    pack $wtxt -side left -fill both -expand 1
    
    $wtxt tag configure ttitle -foreground black -background #dedede  \
      -spacing1 2 -spacing3 2 -lmargin1 20 -font CociSmallBoldFont
    $wtxt tag configure tkey -font CociSmallBoldFont -spacing1 2  \
      -tabs [list $xtab1 right $xtab2 left]
    $wtxt tag configure ttxt -font CociSmallFont -wrap word -lmargin1 $xtab2 \
      -lmargin2 $xtab2
    $wtxt tag configure tline -font {Helvetica -1} -background black
    
    # If mac or win and not QuickTime, make an ad as the first item.
    if {[::Plugins::IsHost QuickTimeTcl] &&  \
      ![::Plugins::HavePackage QuickTimeTcl]} {

	set ad "Get QuickTime for free from Apple at www.apple.com/quicktime.\
	  It adds a lot of functionality to this application."
	$wtxt insert end "\n" tline
	$wtxt insert end "QuickTimeTcl\n" ttitle
	$wtxt insert end "\n" tline
	$wtxt insert end "\tDownload:\t" tkey
	::Text::Parse $wtxt $ad ttxt
	$wtxt insert end "\n\n"
    }
	    
    # Try the known plugind and apps, and make a labelled frame for each.
    foreach plug [::Plugins::GetAllPackages loaded] {
	
	set txtver [::Plugins::GetVersionForPackage $plug]
	if {$txtver eq ""} {
	    set txtver "unknown"
	}
	set txtsuf [::Plugins::GetSuffixes $plug]
	if {$txtsuf eq ""} {
	    set txtsuff "none"
	}
	
	$wtxt insert end "\n" tline
	$wtxt insert end " " ttitle
	set icon [::Plugins::GetIconForPackage $plug 16]
	if {$icon ne ""} {
	    $wtxt image create end -image $icon
	}
	$wtxt insert end " $plug\n" ttitle
	$wtxt insert end "\n" tline
	set msg "\t"
	append msg [mc "Type"]
	append msg ":\t"
	$wtxt insert end $msg tkey
	$wtxt insert end "[::Plugins::GetTypeDesc $plug]\n" ttxt
	set msg "\t"
	append msg [mc "Description"]
	append msg ":\t"
	$wtxt insert end $msg tkey
	$wtxt insert end "[::Plugins::GetDescForPlugin $plug]\n" ttxt
	set msg "\t"
	append msg [mc "Version"]
	append msg ":\t"
	$wtxt insert end $msg tkey
	$wtxt insert end "$txtver\n" ttxt
	set msg "\t"
	append msg [mc "Extensions"]
	append msg ":\t"
	$wtxt insert end $msg tkey
	$wtxt insert end "$txtsuf\n" ttxt
	$wtxt insert end "\n"
    }
    $wtxt configure -state disabled
    bind $w <Return> [list $frbot.btok invoke]
    
    tkwait window $w
    grab release $w
}

# WDialogs::ShowInfoServer --
#
#       It shows server information. Uses one of the connections to get a 
#       channel which is used to obtain information. If not connected, then 
#       give only the hostname if available.
#       
# Arguments:
#       
# Results:
#       none

proc ::WDialogs::ShowInfoServer { } {
    global  this wDlgs state prefs
    
    set w $wDlgs(infoServ)
    if {[winfo exists $w]} {
	return
    }
    array set boolToYesNo [list 0 [mc no] 1 [mc yes]]
    ::UI::Toplevel $w -macstyle documentProc -usemacmainmenu 1 \
      -macclass {document closeBox}
    wm title $w [mc "Server"]
    
    # Global frame.
    ttk::frame $w.frall
    pack $w.frall -fill both -expand 1

    set wbox $w.frall.f
    ttk::frame $wbox -padding [option get . dialogPadding {}]
    pack $wbox -fill both -expand 1
    
    set fr $wbox.f
    ttk::frame $fr -padding [option get . groupSmallPadding {}]
    pack $fr
    
    option add *$fr.TLabel.style Small.TLabel
    
    ttk::label $fr.x1 -text [mc "Activated"]:
    ttk::label $fr.x2 -text $boolToYesNo($state(isServerUp))
    ttk::label $fr.a1 -text "IP:"
    ttk::label $fr.b1 -text [mc "Host"]:
    ttk::label $fr.c1 -text [mc "Username"]:
    ttk::label $fr.d1 -text [mc "Port"]:
    ttk::label $fr.e1 -text [mc "Buffering support"]:
    ttk::label $fr.f1 -text [mc "Blocking support"]:
    ttk::label $fr.g1 -text [mc "Secured"]:

    if {!$state(isServerUp)} {
	ttk::label $fr.a2 -text $this(ipnum)
	ttk::label $fr.b2 -text $this(hostname)
	ttk::label $fr.c2 -text $this(username)
	ttk::label $fr.d2 -text [mc "not available"]
	ttk::label $fr.e2 -text [mc "not available"]
	ttk::label $fr.f2 -text [mc "not available"]
	ttk::label $fr.g2 -text [mc "not available"]
	
    } elseif {$state(isServerUp)} {
	set sockname [fconfigure $state(serverSocket) -sockname]
	ttk::label $fr.a2 -text $this(ipnum)
	ttk::label $fr.b2 -text $this(hostname)
	ttk::label $fr.c2 -text $this(username)
	ttk::label $fr.d2 -text $prefs(thisServPort)
	ttk::label $fr.e2 -text [mc "not available"]
	ttk::label $fr.f2 -text [mc "not available"]
	ttk::label $fr.g2 -text "$boolToYesNo($prefs(makeSafeServ))"

    }
    grid  $fr.x1  $fr.x2  -sticky e
    grid  $fr.a1  $fr.a2  -sticky e
    grid  $fr.b1  $fr.b2  -sticky e
    grid  $fr.c1  $fr.c2  -sticky e
    grid  $fr.d1  $fr.d2  -sticky e
    grid  $fr.e1  $fr.e2  -sticky e
    grid  $fr.f1  $fr.f2  -sticky e
    grid  $fr.g1  $fr.g2  -sticky e

    grid  $fr.x2  $fr.a2  $fr.b2  $fr.c2  $fr.d2  $fr.e2  $fr.f2  $fr.g2  -sticky w
	
    # button part
    set frbot $wbox.b
    ttk::frame $frbot -padding [option get . okcancelTopPadding {}]
    ttk::button $frbot.btok -text [mc "OK"] -command [list destroy $w]
    pack $frbot.btok -side right
    pack $frbot -side bottom -fill x

    wm resizable $w 0 0
    bind $w <Return> [list $frbot.btok invoke]
    
    tkwait window $w
    grab release $w
}

# WDialogs::WelcomeCanvas --
# 
#       Is it the first time it is launched, then show the welcome canvas.
# DELETE CODE??? TODO
#proc ::WDialogs::WelcomeCanvas { } {
#    global  this
#    
#    set systemLocale [lindex [split $this(systemLocale) _] 0]
#    set floc [file join $this(docsPath) Welcome_${systemLocale}.can]
#    if {[file exists $floc]} {
#	set f $floc
#    } else {
#	set f [file join $this(docsPath) Welcome_en.can]
#    }
#    ::WDialogs::Canvas $f -title [mc "Welcome"] -encoding utf-8
#}

namespace eval ::WDialogs:: {
    
    # Running number to create unique toplevel paths.
    variable uidcan 0
}

# WDialogs::Canvas --
# 
#       Display a *.can file into simple canvas window.
#       A kind of minimal, readonly, whiteboard.

proc ::WDialogs::Canvas {filePath args} {
    global this prefs
    variable uidcan
    
    set w .spcan[incr uidcan]
    ::UI::Toplevel $w -macstyle documentProc -usemacmainmenu 1 \
      -macclass {document closeBox}
    wm withdraw $w
    
    # Make the namespace exist.
    namespace eval ::WB::${w}:: {}

    array set argsA [list -title [file rootname [file tail $filePath]]]
    array set argsA $args
    wm title $w $argsA(-title)
    wm resizable $w 0 0
    foreach {screenW screenH} [::UI::GetScreenSize] break
    set xmax 200
    set ymax 200
    set wcan $w.can
    canvas $wcan -width $xmax -height $ymax -highlightthickness 0 -bg white
    pack $wcan

    if {[catch {open $filePath r} fd]} {
	return
    }
    fconfigure $fd -encoding utf-8
    if {[info exists argsA(-encoding)]} {
	fconfigure $fd -encoding $argsA(-encoding)
    }
    
    while {[gets $fd line] >= 0} { 
	
	# Skip any comment lines and empty lines.
	if {[regexp {(^ *#|^[ \n\t]*$)} $line]} {
	    continue
	}
	set cmd [lindex $line 0]
	set type [lindex $line 1]
	
	switch -- $cmd {
	    create {
		
		# Make newline substitutions.
		set cmd [subst -nocommands -novariables $line]
		if {[string equal $type "text"]} {
		    set cmd [::CanvasUtils::FontHtmlToPointSize $cmd]
		}
		set id [eval $wcan $cmd]
	    }
	    import {
		set ind [lsearch -exact $line -file]
		if {$ind >= 0} {
		    ::Import::HandleImportCmd $wcan $line -where local \
		      -basepath [file dirname $filePath] -addundo 0
		}
	    }
	}
    }
    catch {close $fd}
    lassign [$wcan bbox all] x0 y0 x1 y1
    incr x1 20
    incr y1 20
    $wcan configure -width $x1 -height $y1
    update idletasks
    wm deiconify $w
    raise $w
}