1 | |
---|
2 | ################################################################################ |
---|
3 | #This software was developed by the University of Tennessee as part of the |
---|
4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
5 | #project funded by the US National Science Foundation. |
---|
6 | # |
---|
7 | #See the license text in license.txt |
---|
8 | # |
---|
9 | #copyright 2009, University of Tennessee |
---|
10 | ################################################################################ |
---|
11 | |
---|
12 | """ |
---|
13 | Dialog report panel to show and summarize the results of the invariant calculation. |
---|
14 | """ |
---|
15 | |
---|
16 | |
---|
17 | import wx |
---|
18 | import sys,os |
---|
19 | import wx.html as html |
---|
20 | import Image |
---|
21 | if sys.platform.count("win32")>0: |
---|
22 | _STATICBOX_WIDTH = 450 |
---|
23 | PANEL_WIDTH = 500 |
---|
24 | PANEL_HEIGHT = 700 |
---|
25 | FONT_VARIANT = 0 |
---|
26 | else: |
---|
27 | _STATICBOX_WIDTH = 480 |
---|
28 | PANEL_WIDTH = 530 |
---|
29 | PANEL_HEIGHT = 700 |
---|
30 | FONT_VARIANT = 1 |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | class ReportDialog(wx.Dialog): |
---|
35 | """ |
---|
36 | The report dialog box. |
---|
37 | """ |
---|
38 | |
---|
39 | def __init__(self, string, *args, **kwds): |
---|
40 | """ |
---|
41 | Initialization. The parameters added to Dialog are: |
---|
42 | |
---|
43 | :param string: report_string from invariant_state |
---|
44 | """ |
---|
45 | kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE |
---|
46 | wx.Dialog.__init__(self, *args, **kwds) |
---|
47 | kwds["image"] = 'Dynamic Image' |
---|
48 | # title |
---|
49 | self.SetTitle("Report: Invariant computaion") |
---|
50 | # size |
---|
51 | self.SetSize((720, 650)) |
---|
52 | # font size |
---|
53 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
54 | # report string |
---|
55 | self.report_string =string |
---|
56 | # layout |
---|
57 | self._setup_layout() |
---|
58 | |
---|
59 | def _setup_layout(self): |
---|
60 | """ |
---|
61 | Set up layout |
---|
62 | """ |
---|
63 | # panel for buttons |
---|
64 | bpanel = wx.Panel(self, -1) |
---|
65 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
66 | |
---|
67 | # buttons |
---|
68 | id = wx.NewId() |
---|
69 | button_save = wx.Button(self, id, "Save") |
---|
70 | button_save.SetToolTipString("Save this report.") |
---|
71 | button_save.Bind(wx.EVT_BUTTON, self.onSave, id = button_save.GetId()) |
---|
72 | hbox.Add(button_save) |
---|
73 | |
---|
74 | id = wx.NewId() |
---|
75 | button_preview = wx.Button(self, id, "Preview") |
---|
76 | button_preview.SetToolTipString("Print preview this report.") |
---|
77 | button_preview.Bind(wx.EVT_BUTTON, self.onPreview, id = button_preview.GetId()) |
---|
78 | hbox.Add(button_preview) |
---|
79 | |
---|
80 | id = wx.NewId() |
---|
81 | button_print = wx.Button(self, id, "Print") |
---|
82 | button_print.SetToolTipString("Print this report.") |
---|
83 | button_print.Bind(wx.EVT_BUTTON, self.onPrint, id = button_print.GetId()) |
---|
84 | hbox.Add(button_print) |
---|
85 | |
---|
86 | |
---|
87 | # panel for report page |
---|
88 | panel = wx.Panel(self, -1) |
---|
89 | vbox= wx.BoxSizer(wx.VERTICAL) |
---|
90 | # html window |
---|
91 | self.hwindow = html.HtmlWindow(panel, -1,style=wx.BORDER,size=(700,500)) |
---|
92 | # set the html page with the report string |
---|
93 | self.hwindow.SetPage(self.report_string) |
---|
94 | # add panels to boxsizers |
---|
95 | hbox.Add(bpanel) |
---|
96 | vbox.Add(hbox,40, wx.EXPAND) |
---|
97 | vbox.Add(panel,500, wx.EXPAND) |
---|
98 | |
---|
99 | self.SetSizerAndFit(vbox) |
---|
100 | self.Centre() |
---|
101 | self.Show(True) |
---|
102 | |
---|
103 | def onSave(self,event=None): |
---|
104 | """ |
---|
105 | Save |
---|
106 | """ |
---|
107 | #todo: complete saving fig file and as a txt file |
---|
108 | dlg = wx.FileDialog(self, "Choose a file",\ |
---|
109 | wildcard ='HTML files (*.html)|*.html|'+ |
---|
110 | 'Text files (*.txt)|*.txt', |
---|
111 | style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) |
---|
112 | dlg.SetFilterIndex(0) #Set .html files to be default |
---|
113 | |
---|
114 | if dlg.ShowModal() != wx.ID_OK: |
---|
115 | dlg.Destroy() |
---|
116 | return |
---|
117 | fName = dlg.GetPath() |
---|
118 | fName = os.path.splitext(fName)[0] + '.html' |
---|
119 | dlg.Destroy() |
---|
120 | |
---|
121 | html = self.report_string |
---|
122 | f = open(fName, 'w') |
---|
123 | f.write(html) |
---|
124 | f.close() |
---|
125 | |
---|
126 | |
---|
127 | def onPreview(self,event=None): |
---|
128 | """ |
---|
129 | Preview |
---|
130 | |
---|
131 | : event: Preview button event |
---|
132 | """ |
---|
133 | previewh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) |
---|
134 | previewh.PreviewText(self.report_string) |
---|
135 | |
---|
136 | def onPrint(self,event=None): |
---|
137 | """ |
---|
138 | Print |
---|
139 | |
---|
140 | : event: Print button event |
---|
141 | """ |
---|
142 | printh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) |
---|
143 | printh.PrintText(self.report_string) |
---|
144 | |
---|
145 | |
---|
146 | |
---|