Translation update done using Pootle.
[wammu.git] / Wammu / ErrorMessage.py
bloba0e30a0f6424b07aa6d3b5e879eb85fbb5b28c05
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Error messages
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import wx
27 import os
28 import Wammu
29 import Wammu.Webbrowser
30 import Wammu.Paths
31 import Wammu.ErrorLog
34 BUG_SEARCH_URL = 'http://bugs.cihar.com/view_all_set.php?f=3&type=1&search=%s'
35 BUG_REPORT_URL = 'http://bugs.cihar.com/set_project.php?ref=bug_report_page.php&project_id=1'
37 class ErrorMessage(wx.Dialog):
38 '''
39 Error message box with support for saving debug log and reporting
40 bug to http://bugs.cihar.com/.
41 '''
42 def __init__(self, parent, message, title, traceid=None,
43 autolog=None, exception=None):
44 wx.Dialog.__init__(self, parent, -1, title)
46 sizer = wx.BoxSizer(wx.VERTICAL)
47 textsizer = wx.BoxSizer(wx.HORIZONTAL)
48 sizer.Add(textsizer, flag=wx.ALL, border=10)
50 bitmap = wx.Bitmap(Wammu.Paths.MiscPath('error'))
51 icon = wx.StaticBitmap(self, -1, bitmap,
52 size = (bitmap.GetWidth(), bitmap.GetHeight()))
53 textsizer.Add(icon, flag=wx.RIGHT, border=10)
55 if exception is not None:
56 message += '\n\n'
57 message += exception
58 if autolog is not None:
59 message += '\n\n'
60 message += (
61 _('Debug log has been automatically saved to %s, you are strongly encouraged to include it in bugreport.')
62 % autolog)
63 msg = wx.StaticText(self, -1, message)
64 msg.Wrap(400)
65 textsizer.Add(msg)
67 buttonsizer = wx.StdDialogButtonSizer()
68 buttonsizer.AddButton(wx.Button(self, wx.ID_OK))
70 if traceid is None:
71 savebutton = wx.Button(self, -1, _('Save debug log...'))
72 buttonsizer.SetCancelButton(savebutton)
73 self.Bind(wx.EVT_BUTTON, self.OnSave, savebutton)
74 else:
75 self.traceid = traceid
76 searchbutton = wx.Button(self, -1, _('Search for similar reports'))
77 buttonsizer.SetCancelButton(searchbutton)
78 self.Bind(wx.EVT_BUTTON, self.OnSearch, searchbutton)
80 self.reportbutton = wx.Button(self, -1, _('Report bug'))
81 buttonsizer.SetNegativeButton(self.reportbutton)
82 self.Bind(wx.EVT_BUTTON, self.OnReport, self.reportbutton)
84 buttonsizer.Realize()
85 sizer.Add(buttonsizer, flag = wx.ALIGN_RIGHT | wx.ALL, border = 10)
87 sizer.Fit(self)
88 self.SetAutoLayout(True)
89 self.SetSizer(sizer)
91 def OnSave(self, evt):
92 '''
93 Saves debug log to file.
94 '''
95 dlg = wx.FileDialog(self,
96 _('Save debug log as...'),
97 os.getcwd(),
98 'wammu.log',
99 '',
100 wx.SAVE | wx.OVERWRITE_PROMPT | wx.CHANGE_DIR)
101 if dlg.ShowModal() == wx.ID_OK:
102 Wammu.ErrorLog.SaveLog(filename = dlg.GetPath())
104 def OnSearch(self, evt):
106 Opens search for simmilar problems in browser.
108 Wammu.Webbrowser.Open(BUG_SEARCH_URL % self.traceid)
110 def OnReport(self, evt):
112 Opens web browser with bug reporting page.
114 Wammu.Webbrowser.Open(BUG_REPORT_URL)