source: trunk/gui/scripts/bugreport.tcl @ 676

Last change on this file since 676 was 676, checked in by mmc, 17 years ago

Fixed all fonts to set pixelsize instead of pointsize, so that fonts in
the latest X distribution look right.

Added initial Rappture::bugreport::submit command for submitting bug
reports to nanoHUB.org. This isn't tied in yet, but it's a start.

File size: 6.3 KB
Line 
1# ----------------------------------------------------------------------
2#  UTILITY: bugreport
3#
4#  This redefines the usual Tcl bgerror command to install a nicer
5#  looking bug handler.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2006  Purdue Research Foundation
9#
10#  See the file "license.terms" for information on usage and
11#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12# ======================================================================
13
14option add *BugReport*banner*foreground white startupFile
15option add *BugReport*banner*background #a9a9a9 startupFile
16option add *BugReport*banner*highlightBackground #a9a9a9 startupFile
17option add *BugReport*banner*font \
18    -*-helvetica-bold-r-normal-*-18-* startupFile
19option add *BugReport*expl.font \
20    -*-helvetica-medium-r-normal-*-12-* startupFile
21option add *BugReport*expl.wrapLength 3i startupFile
22
23namespace eval Rappture::bugreport { # forward declaration }
24
25# ----------------------------------------------------------------------
26# USAGE: install
27#
28# Called once in the main program to install this bug reporting
29# facility.  Any unexpected errors after this call will be handled
30# by this mechanism.
31# ----------------------------------------------------------------------
32proc Rappture::bugreport::install {} {
33    proc ::bgerror {err} { ::Rappture::bugreport::activate $err }
34}
35
36# ----------------------------------------------------------------------
37# USAGE: activate <error>
38#
39# Used internally to pop up the bug handler whenver a bug is
40# encountered.  Tells the user that there is a bug and logs the
41# problem, so it can be fixed.
42# ----------------------------------------------------------------------
43proc Rappture::bugreport::activate {err} {
44    global errorInfo
45
46    set w [winfo reqwidth .bugreport]
47    set h [winfo reqheight .bugreport]
48    set x [expr {([winfo screenwidth .bugreport]-$w)/2}]
49    set y [expr {([winfo screenheight .bugreport]-$w)/2}]
50
51    wm geometry .bugreport +$x+$y
52    wm deiconify .bugreport
53    raise .bugreport
54
55    .bugreport.details.text configure -state normal
56    .bugreport.details.text delete 1.0 end
57    .bugreport.details.text insert end "$err\n-----\n$errorInfo"
58    .bugreport.details.text configure -state disabled
59    # should log the error someday too...
60
61    catch {grab set .bugreport}
62}
63
64# ----------------------------------------------------------------------
65# USAGE: deactivate
66#
67# Used internally to take down the bug handler dialog.
68# ----------------------------------------------------------------------
69proc Rappture::bugreport::deactivate {} {
70    grab release .bugreport
71    wm withdraw .bugreport
72
73    # reset the grab in case it's hosed
74    Rappture::grab::reset
75}
76
77# ----------------------------------------------------------------------
78# USAGE: submit <stackTrace>
79#
80# Clients use this to send bug reports back to the hub site.  Errors
81# are posted to a URL that creates a support ticket.
82# ----------------------------------------------------------------------
83proc Rappture::bugreport::submit {stackTrace} {
84    global tcl_platform
85
86    package require http
87    package require tls
88    http::register https 443 ::tls::socket
89
90    if {![regexp {^([^\n]+)\n} $stackTrace match summary]} {
91        if {[string length $stackTrace] == 0} {
92            set summary "Unexpected error from Rappture"
93        } else {
94            set summary $stackTrace
95        }
96    }
97    if {[string length $summary] > 50} {
98        set summary "[string range $summary 0 50]..."
99    }
100    append summary " (in tool \"[Rappture::Tool::get -name]\")"
101
102    set query [http::formatQuery \
103        option com_support \
104        task create \
105        no_html 1 \
106        report $stackTrace
107        login $tcl_platform(user) \
108        email "" \
109        hostname [info hostname] \
110        category rappture \
111        summary $summary \
112        referrer "tool \"[Rappture::Tool::get -name]\"" \
113    ]
114
115puts "avoid hard-coded web site URL!"
116    set url https://zooley.nanohub.org/index2.php
117    set token [http::geturl $url -query $query]
118
119    if {[http::ncode] != 200} {
120        error [http::code]
121    }
122    upvar #0 $token rval
123    if {[regexp {Ticket #[0-9]+ \((.*:?)\) [0-9]+ times} $rval(body) match]} {
124        return $match
125    }
126    error "Report received, but ticket may not have been filed"
127}
128
129# ----------------------------------------------------------------------
130# Build the bug reporting dialog
131# ----------------------------------------------------------------------
132toplevel .bugreport -class BugReport -borderwidth 1 -relief solid
133wm overrideredirect .bugreport 1
134wm withdraw .bugreport
135
136frame .bugreport.banner -background #a9a9a9
137pack .bugreport.banner -side top -fill x
138label .bugreport.banner.icon -image [Rappture::icon alert]
139pack .bugreport.banner.icon -side left -padx 2 -pady 2
140label .bugreport.banner.title -text "Oops! Unexpected Error"
141pack .bugreport.banner.title -side left -padx {0 8} -pady 2
142
143button .bugreport.ok -text "OK" -command Rappture::bugreport::deactivate
144pack .bugreport.ok -side bottom -pady {0 8}
145
146label .bugreport.expl -text "You've found a bug in this application.\n\nIf it's not a serious bug, you may be able to continue using the tool.  But if the tool doesn't seem to behave properly after this, please close this session and start the tool again.\n\nYou can help us improve nanoHUB by reporting this error.  Click on the \"Report Problems\" link in the web page containing this tool session, and tell us what you were doing when the error occurred." -justify left
147pack .bugreport.expl -padx 8 -pady 8
148
149bind .bugreport.expl <Control-1><Control-1><Control-3><Control-3> {
150    pack forget .bugreport.expl
151    pack .bugreport.details -after .bugreport.ok \
152        -expand yes -fill both -padx 8 -pady 8
153}
154
155bind .bugreport.expl <Control-1><Control-1><Control-Shift-1><Control-Shift-1> {
156    pack forget .bugreport.expl
157    pack .bugreport.details -after .bugreport.ok \
158        -expand yes -fill both -padx 8 -pady 8
159}
160
161Rappture::Scroller .bugreport.details -xscrollmode auto -yscrollmode auto
162text .bugreport.details.text -wrap none
163.bugreport.details contents .bugreport.details.text
164
165# this binding keeps the bugreport window on top
166bind BugReportOnTop <ButtonPress> {
167    wm deiconify %W
168    raise %W
169}
170set btags [bindtags .bugreport]
171bindtags .bugreport [linsert $btags 0 BugReportOnTop]
Note: See TracBrowser for help on using the repository browser.