root/branch/NetworkInventory/umit/gui/CrashReport.py @ 4300

Revision 4300, 8.2 kB (checked in by gpolo, 4 years ago)

Merged revisions 4291-4299 via svnmerge from
http://svn.umitproject.org/svnroot/umit/trunk

........

r4291 | gpolo | 2009-03-05 22:10:12 -0300 (Thu, 05 Mar 2009) | 1 line


Added classifier for python 2.4

........

r4292 | gpolo | 2009-03-05 22:12:32 -0300 (Thu, 05 Mar 2009) | 1 line


Added missing commas.

........

r4293 | gpolo | 2009-03-06 13:03:40 -0300 (Fri, 06 Mar 2009) | 1 line


typo fix.

........

r4294 | gpolo | 2009-03-06 13:07:45 -0300 (Fri, 06 Mar 2009) | 3 lines


Avoiding a "GtkWarning?: gtk_label_set_label: assertion `str != NULL'
failed" when not giving a value to text.

........

r4295 | gpolo | 2009-03-06 13:10:00 -0300 (Fri, 06 Mar 2009) | 1 line


Adjusted example to work with the current paths.

........

r4296 | gpolo | 2009-03-06 13:11:51 -0300 (Fri, 06 Mar 2009) | 1 line


Removed bad sys.exit (which didn't even work since sys was never imported here).

........

r4297 | gpolo | 2009-03-06 13:17:37 -0300 (Fri, 06 Mar 2009) | 1 line


Fixed bad widget packing.

........

r4298 | gpolo | 2009-03-06 13:38:11 -0300 (Fri, 06 Mar 2009) | 1 line


Misc tweaks, also removed the broken example.

........

r4299 | gpolo | 2009-03-06 13:50:40 -0300 (Fri, 06 Mar 2009) | 1 line


read_file is gone for more than one year, removed its use here. This code doesn't replace the previous read_file func.

........

Line 
1# Copyright (C) 2005-2006 Insecure.Com LLC.
2# Copyright (C) 2007 Adriano Monteiro Marques
3#
4# Authors: Adriano Monteiro Marques <py.adriano@gmail.com>
5#          Frederico Silva Ribeiro <ribeiro.fsilva@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21import gtk
22import gobject
23import webbrowser
24
25from higwidgets.higdialogs import HIGAlertDialog
26from higwidgets.higlabels import HIGSectionLabel, HIGHintSectionLabel
27from higwidgets.higtables import HIGTable
28from higwidgets.higwindows import HIGWindow
29from higwidgets.higboxes import HIGHBox, HIGVBox
30
31from umit.core.BugRegister import BugRegister
32from umit.core.I18N import _
33
34class CrashReport(HIGWindow):
35    def __init__(self, summary, description):
36        HIGWindow.__init__(self)
37        gtk.Window.__init__(self)
38        self.set_title(_('Crash Report'))
39        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
40       
41        self.response_id = False
42       
43        self._create_widgets()
44        self._pack_widgets()
45        self._connect_widgets()
46
47        self.summary = summary
48        self.description = description
49
50    def _create_widgets(self):
51        self.vbox = HIGVBox()
52        self.button_box = gtk.HButtonBox()
53       
54        self.private_check = gtk.CheckButton(_("Only Umit project members should read this \
55bug report"))
56       
57        self.email_label = HIGHintSectionLabel(_("Email"),
58                                               _("Please, inform a valid e-mail address, from \
59where you can be reached to be notified when the bug get fixed. Not used for other purposes."))
60        self.email_entry = gtk.Entry()
61
62        self.description_label = HIGHintSectionLabel(_("Description"),
63                                                     _("This is where you should really write \
64about the bug, describing it as clear as possible, and giving as many informations as you can \
65along with your system informations, like: Which operating system you're using? \
66Which Nmap version you have insalled?"))
67        self.description_scrolled = gtk.ScrolledWindow()
68        self.description_text = gtk.TextView()
69
70        self.bug_icon = gtk.Image()
71        self.bug_text = gtk.Label(_("This Bug Report dialog, allows you to easily tell us \
72about a problem that you may have found on Umit. Doing so, you help us to help you, by \
73fixing and improving Umit faster than usual."))
74
75        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
76        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
77
78        self.hbox = HIGHBox()
79        self.table = HIGTable()
80
81    def _pack_widgets(self):
82        self.description_scrolled.add(self.description_text)
83        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
84        self.description_scrolled.set_size_request(400, 150)
85        self.description_text.set_wrap_mode(gtk.WRAP_WORD)
86
87        self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
88        self.bug_icon.set_padding(10, 0)
89        self.bug_text.set_line_wrap(True)
90
91        self.hbox.set_border_width(12)
92        self.vbox.set_border_width(6)
93       
94        self.table.attach_label(self.email_label, 0, 1, 0, 1)
95        self.table.attach_entry(self.email_entry, 1, 2, 0, 1)
96
97        self.table.attach_label(self.description_label, 0, 1, 1, 2)
98        self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3)
99
100        self.hbox._pack_noexpand_nofill(self.bug_icon)
101        self.hbox._pack_expand_fill(self.bug_text)
102
103        self.button_box.set_layout(gtk.BUTTONBOX_END)
104        self.button_box.pack_start(self.btn_ok)
105        self.button_box.pack_start(self.btn_cancel)
106       
107        self.vbox._pack_noexpand_nofill(self.hbox)
108        self.vbox._pack_expand_fill(self.table)
109        self.vbox._pack_noexpand_nofill(self.button_box)
110        self.add(self.vbox)
111
112    def _connect_widgets(self):
113        self.btn_ok.connect("clicked", self.send_report)
114        self.btn_cancel.connect("clicked", self.close)
115        self.connect("delete-event", self.close)
116
117    def send_report(self, widget):
118        if self.description == "" or self.email == "":
119            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
120                                               message_format=_("Bug report is incomplete!"),
121                                               secondary_text=_("The bug report is incomplete. \
122You must inform a description that explains clearly what is happening and a valid e-mail, \
123so you can be contacted when the bug get fixed."))
124            cancel_dialog.run()
125            cancel_dialog.destroy()
126            return None
127
128        bug_register = BugRegister()
129
130        bug_register.is_private = self.private
131        bug_register.category_id = "862568"
132        bug_register.summary = self.summary
133        bug_register.details = "%s\n\nEmail: %s" % (self.description, self.email)
134       
135        bug_page = None
136        try:
137            bug_page = bug_register.report()
138        except:
139            cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
140                                           message_format=_("Bug not reported!"),
141                                           secondary_text=_("The bug description could \
142not be reported. This problem may be caused by the lack of Internet Access or \
143indisponibility of the bug tracker server. Please, verify your internet access, and \
144then try to report the bug once again."))
145            cancel_dialog.run()
146            cancel_dialog.destroy()
147        else:
148            ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
149                                       message_format=_("Bug sucessfully reported!"),
150                                       secondary_text=_("The bug description was \
151sucessfully reported. A web page with detailed description about this report is \
152going to be openned in your default web browser."))
153            ok_dialog.run()
154            ok_dialog.destroy()
155
156            self.close()
157
158        if bug_page:
159            try:
160                webbrowser.open(bug_page)
161            except:
162                page_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
163                                             message_format=_("Could not open default Web Browser"),
164                                             secondary_text=_("Umit was unable to open your default \
165web browser to show the bug tracker page with the report status. Try to visit the Umit's \
166bug tracker page to see if your bug was reported (you won't see if you marked the check box \
167that makes the report private)."))
168                page_dialog.run()
169                page_dialog.destroy()
170
171        self.close()
172
173    def close(self, widget=None, event=None):
174        self.destroy()
175        gtk.main_quit()
176
177    def get_description(self):
178        buff = self.description_text.get_buffer()
179        return buff.get_text(buff.get_start_iter(), buff.get_end_iter())
180
181    def set_description(self, description):
182        self.description_text.get_buffer().set_text(description)
183
184    def get_private(self):
185        if self.private_check.get_active():
186            return "1"
187        return "0"
188
189    def set_private(self, private):
190        self.private_check.set_active(private)
191
192    def get_email(self):
193        return self.email_entry.get_text()
194
195    def set_email(self, email):
196        self.email_entry.set_text(email)
197
198    def run_unblocked(self):
199        if not self.modal:
200            self.set_modal(True)
201        self.show_all()
202
203    description = property(get_description, set_description)
204    private = property(get_private, set_private)
205    email = property(get_email, set_email)
206
207
208if __name__ == "__main__":
209    c = CrashReport("Sumariu", "Descricao")
210    c.show_all()
211    c.connect("delete-event", lambda x, y: gtk.main_quit())
212   
213    gtk.main()
Note: See TracBrowser for help on using the browser.