oskusalerma / blyte

Screenplay writing program

This URL has Read+Write access

blyte / bugreport.py
100644 90 lines (65 sloc) 2.798 kb
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
import os
import sys
 
import misc
import util
 
from wxPython.wx import *
 
# main program should set this as soon as the main frame is created
mainFrame = None
 
class BugReportHandler:
    def __init__(self):
 
        # data printed to stdout/stderr so far and not reported in some
        # way back to oskusoft.
        self.data = util.String()
 
        # size of data last time it was copied to the clipboard
        self.copyPos = 0
 
        # possible open BugReportDlg
        self.dlg = None
        
    def write(self, s):
        if not mainFrame:
            sys.__stderr__.write(s)
 
            return
        
        self.data += s
 
        if not self.dlg:
            self.dlg = BugReportDlg(mainFrame, self)
            self.dlg.Show()
        
class BugReportDlg(wxDialog):
    def __init__(self, parent, brh):
        wxDialog.__init__(self, parent, -1, "Error")
 
        self.brh = brh
 
        vsizer = wxBoxSizer(wxVERTICAL)
 
        s = "An error has occurred in the program. To help us fix it," \
            " please send a report to bugreport@oskusoft.com explaining" \
            " what you were doing and what went wrong. If possible, include" \
            " data needed to reproduce the problem.\n\n" \
            "" \
            "Also, and this is very important, press the \"Save\" button" \
            " below to save additional information about the problem to a" \
            " file, and then attach that file to your mail.\n\n" \
            "" \
            "If you have other windows besides the main window open in" \
            " this program, you may need to close them before being able to" \
            " press \"Save\".\n\n" \
            "" \
            "After doing all this, save your work (if possible), and" \
            " restart the program."
 
        vsizer.Add(wxTextCtrl(self, -1, s,
            size = wxSize(400, 300), style = wxTE_MULTILINE | wxTE_READONLY),
            1, wxEXPAND)
        
        btn = wxButton(self, -1, "Save")
        EVT_BUTTON(self, btn.GetId(), self.OnSave)
        vsizer.Add(btn, 0, wxALIGN_CENTER | wxTOP, 10)
 
        util.finishWindow(self, vsizer)
 
        EVT_CLOSE(self, self.OnCloseWindow)
 
    def OnCloseWindow(self, event):
        self.Destroy()
 
        self.brh.dlg = None
        self.brh.data = util.String(str(self.brh.data)[self.brh.copyPos:])
        self.brh.copyPos = 0
        
    def OnSave(self, event):
        dlg = wxFileDialog(self, "Filename to save as",
            defaultFile = "error_report.dat",
            style = wxSAVE | wxOVERWRITE_PROMPT)
 
        if dlg.ShowModal() == wxID_OK:
            self.brh.copyPos = len(self.brh.data)
            s = str(self.brh.data).encode("base64").encode("rot13")
            
            util.writeToFile(dlg.GetPath(), s, self)