~ubuntu-branches/ubuntu/saucy/solfege/saucy

« back to all changes in this revision

Viewing changes to src/tracebackwindow.py

  • Committer: Bazaar Package Importer
  • Author(s): Tom Cato Amundsen
  • Date: 2010-03-28 06:34:28 UTC
  • mfrom: (1.1.10 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100328063428-wg2bqvoce2aq4xfb
Tags: 3.15.9-1
* New upstream release.
* Redo packaging. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# GNU Solfege - free ear training software
2
 
# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2007, 2008  Tom Cato Amundsen
3
 
#
4
 
# This program is free software: you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation, either version 3 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
import gtk
18
 
import sys
19
 
import reportbug
20
 
import gu
21
 
 
22
 
class TracebackWindow(gtk.Dialog):
23
 
    def __init__(self, show_gtk_warnings):
24
 
        gtk.Dialog.__init__(self)
25
 
        self.m_show_gtk_warnings = show_gtk_warnings
26
 
        self.set_default_size(630, 400)
27
 
        self.vbox.set_border_width(8)
28
 
        label = gtk.Label(_("GNU Solfege message window"))
29
 
        label.set_name('Heading2')
30
 
        self.vbox.pack_start(label, False)
31
 
        label = gtk.Label(_("Please report this to the bug database or send an email to bug-solfege@gnu.org if the content of the message make you believe you have found a bug."))
32
 
        label.set_line_wrap(True)
33
 
        self.vbox.pack_start(label, False)
34
 
        scrollwin = gtk.ScrolledWindow()
35
 
        scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
36
 
        self.vbox.pack_start(scrollwin)
37
 
        self.g_text = gtk.TextView()
38
 
        scrollwin.add(self.g_text)
39
 
        self.g_report = gtk.Button()
40
 
        self.g_report.connect('clicked', self.do_report)
41
 
        box = gtk.HBox()
42
 
        self.g_report.add(box)
43
 
        im = gtk.image_new_from_stock('gtk-execute', gtk.ICON_SIZE_BUTTON)
44
 
        box.pack_start(im)
45
 
        label = gtk.Label()
46
 
        label.set_text_with_mnemonic(gu.escape(_('_Make automatic bug report')))
47
 
        label.set_use_markup(True)
48
 
        box.pack_start(label)
49
 
        self.action_area.pack_start(self.g_report)
50
 
        self.g_close = gtk.Button(stock='gtk-close')
51
 
        self.action_area.pack_start(self.g_close)
52
 
        self.g_close.connect('clicked', lambda w: self.hide())
53
 
    def do_report(self, *v):
54
 
        yesno = gu.dialog_yesno(_("Automatic bug reports are often mostly useless because people omit their email address and add very little info about what happened. Fixing bugs is difficult if we cannot contact you and ask for more information.\n\nI would prefer if you open a web browser and report your bug to the bug tracker at http://bugs.solfege.org.\n\nThis will give your bug report higher priority and it will be fixed faster.\n\nAre you willing to do that?"))
55
 
        if yesno:
56
 
            return
57
 
        self.m_send_exception = 'Nothing'
58
 
        b = self.g_text.get_buffer()
59
 
        d = reportbug.ReportBugWindow(self,
60
 
                        b.get_text(b.get_start_iter(), b.get_end_iter()))
61
 
        while 1:
62
 
            ret = d.run()
63
 
            if ret == gtk.RESPONSE_REJECT:
64
 
                break
65
 
            elif ret == reportbug.RESPONSE_SEND:
66
 
                self.m_send_exception = d.send_bugreport()
67
 
                break
68
 
            elif ret == reportbug.RESPONSE_SEE:
69
 
                showdlg = reportbug.ShowTextDialog(self, d.get_bugreport())
70
 
                r = showdlg.run()
71
 
                if r == reportbug.RESPONSE_SEND:
72
 
                    self.m_send_exception = d.send_bugreport()
73
 
                    showdlg.destroy()
74
 
                    break
75
 
                showdlg.destroy()
76
 
        if self.m_send_exception != 'Nothing':
77
 
            if self.m_send_exception:
78
 
                m = gtk.MessageDialog(self, gtk.DIALOG_MODAL,
79
 
                    gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
80
 
                    "Sending bugreport failed:\n%s" % self.m_send_exception)
81
 
            else:
82
 
                m = gtk.MessageDialog(self, gtk.DIALOG_MODAL,
83
 
                    gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
84
 
                    'Report sent to http://www.solfege.org')
85
 
            m.run()
86
 
            m.destroy()
87
 
        d.destroy()
88
 
    def write(self, txt):
89
 
        if ("DeprecationWarning:" in txt) or \
90
 
           (not self.m_show_gtk_warnings and (
91
 
            "GtkWarning" in txt
92
 
            or "PangoWarning" in txt
93
 
            or ("Python C API version mismatch" in txt and 
94
 
                ("solfege_c_midi" in txt or "swig" in txt))
95
 
            )):
96
 
            print txt
97
 
            return
98
 
        sys.stdout.write(txt)
99
 
        if txt.strip():
100
 
            self.show_all()
101
 
        buffer = self.g_text.get_buffer()
102
 
        buffer.insert(buffer.get_end_iter(), txt)
103
 
        self.set_focus(self.g_close)
104
 
    def flush(self, *v):
105
 
        pass
106
 
    def close(self, *v):
107
 
        pass