Changeset e8bb5b6 in sasview for src/sas/perspectives/invariant
- Timestamp:
- Feb 18, 2015 3:20:54 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 66f21cd
- Parents:
- 054a3ad
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/invariant/report_dialog.py
r4ec242e re8bb5b6 15 15 """ 16 16 import wx 17 import sys18 17 import os 19 18 import wx.html as html 20 import logging 21 ISPDF = False 22 if sys.platform == "win32": 23 _STATICBOX_WIDTH = 450 24 PANEL_WIDTH = 500 25 PANEL_HEIGHT = 700 26 FONT_VARIANT = 0 27 ISMAC = False 28 ISPDF = True 29 elif sys.platform == "darwin": 30 _STATICBOX_WIDTH = 480 31 PANEL_WIDTH = 530 32 PANEL_HEIGHT = 700 33 FONT_VARIANT = 1 34 ISMAC = True 35 ISPDF = True 36 37 class ReportDialog(wx.Dialog): 19 20 from sas.guiframe.report_dialog import BaseReportDialog 21 22 class ReportDialog(BaseReportDialog): 38 23 """ 39 24 The report dialog box. 40 25 """ 41 26 42 def __init__(self, list, *args, **kwds):27 def __init__(self, report_list, *args, **kwds): 43 28 """ 44 29 Initialization. The parameters added to Dialog are: 45 30 46 :param list: report_list (list of html_str, text_str, image)31 :param report_list: list of html_str, text_str, image 47 32 from invariant_state 48 33 """ 49 kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE 50 wx.Dialog.__init__(self, *args, **kwds) 51 kwds["image"] = 'Dynamic Image' 34 super(ReportDialog, self).__init__(report_list, *args, **kwds) 35 52 36 # title 53 37 self.SetTitle("Report: Invariant computaion") 54 # size55 self.SetSize((720, 650))56 # font size57 self.SetWindowVariant(variant=FONT_VARIANT)58 38 59 # check if tit is MAC60 self.is_pdf = ISPDF61 62 # report string63 self.report_list = list64 39 # put image path in the report string 65 40 self.report_html = self.report_list[0] % "memory:img_inv.png" 66 41 # layout 67 42 self._setup_layout() 68 # wild card69 # pdf supporting only on MAC70 if self.is_pdf:71 self.wild_card = ' PDF files (*.pdf)|*.pdf|'72 else:73 self.wild_card = ''74 self.wild_card += 'HTML files (*.html)|*.html|'75 self.wild_card += 'Text files (*.txt)|*.txt'76 77 78 79 def _setup_layout(self):80 """81 Set up layout82 """83 hbox = wx.BoxSizer(wx.HORIZONTAL)84 85 # buttons86 id = wx.ID_OK87 button_close = wx.Button(self, id, "Close")88 button_close.SetToolTipString("Close this report window.")89 #hbox.Add((5,10), 1 , wx.EXPAND|wx.ADJUST_MINSIZE,0)90 hbox.Add(button_close)91 button_close.SetFocus()92 93 id = wx.NewId()94 button_preview = wx.Button(self, id, "Preview")95 button_preview.SetToolTipString("Print preview this report.")96 button_preview.Bind(wx.EVT_BUTTON, self.onPreview,97 id=button_preview.GetId())98 hbox.Add(button_preview)99 100 id = wx.NewId()101 button_print = wx.Button(self, id, "Print")102 button_print.SetToolTipString("Print this report.")103 button_print.Bind(wx.EVT_BUTTON, self.onPrint,104 id=button_print.GetId())105 hbox.Add(button_print)106 107 id = wx.NewId()108 button_save = wx.Button(self, id, "Save" )109 button_save.SetToolTipString("Save this report.")110 button_save.Bind(wx.EVT_BUTTON, self.onSave, id = button_save.GetId())111 hbox.Add(button_save)112 113 # panel for report page114 #panel = wx.Panel(self, -1)115 vbox = wx.BoxSizer(wx.VERTICAL)116 # html window117 self.hwindow = html.HtmlWindow(self,style=wx.BORDER)118 # set the html page with the report string119 self.hwindow.SetPage(self.report_html)120 121 # add panels to boxsizers122 vbox.Add(hbox)123 vbox.Add(self.hwindow, 1, wx.EXPAND|wx.ALL,0)124 125 self.SetSizer(vbox)126 self.Centre()127 self.Show(True)128 129 43 130 44 def onSave(self, event=None): … … 144 58 fName = dlg.GetPath() 145 59 ext_num = dlg.GetFilterIndex() 146 # index correction147 if not self.is_pdf:148 ind_cor = 1149 else:150 ind_cor = 0151 60 #set file extensions 152 if ext_num == (0 + 2 * ind_cor):153 61 if ext_num == (0 + 2 * self.index_offset): 62 # TODO: Sort this case out 154 63 ext = '.pdf' 155 64 img_ext = '_img.png' … … 186 95 os.remove(pic_fname) 187 96 return 188 elif ext_num == (1 - ind_cor):97 elif ext_num == (1 - self.index_offset): 189 98 ext = '.html' 190 99 img_ext = '_img4html.png' 191 100 report_frame = self.report_list[0] 192 elif ext_num == (2 - ind_cor):101 elif ext_num == (2 - self.index_offset): 193 102 ext = '.txt' 194 103 # changing the image extension actually changes the image … … 205 114 pic_fname = os.path.splitext(fName)[0] + img_ext 206 115 #put the image path in html string 207 if ext_num == (1 - ind_cor):116 if ext_num == (1 - self.index_offset): 208 117 report = report_frame % os.path.basename(pic_fname) 209 118 … … 214 123 self.report_list[2].savefig(pic_fname) 215 124 216 217 def onPreview(self, event=None):218 """219 Preview220 221 : event: Preview button event222 """223 previewh = html.HtmlEasyPrinting(name="Printing", parentWindow=self)224 previewh.PreviewText(self.report_html)225 if event is not None:226 event.Skip()227 228 def onPrint(self, event=None):229 """230 Print231 232 : event: Print button event233 """234 printh = html.HtmlEasyPrinting(name="Printing", parentWindow=self)235 printh.PrintText(self.report_html)236 if event is not None:237 event.Skip()238 239 def OnClose(self,event=None):240 """241 Close the Dialog242 243 : event: Close button event244 """245 self.Close()246 247 def HTML2PDF(self, data, filename):248 """249 Create a PDF file from html source string.250 Returns True is the file creation was successful.251 252 : data: html string253 : filename: name of file to be saved254 """255 try:256 from xhtml2pdf import pisa257 # open output file for writing (truncated binary)258 resultFile = open(filename, "w+b")259 # convert HTML to PDF260 pisaStatus = pisa.CreatePDF(data, dest=resultFile)261 # close output file262 resultFile.close()263 self.Update()264 return pisaStatus.err265 except:266 logging.error("Error creating pdf: %s" % sys.exc_value)267 return False
Note: See TracChangeset
for help on using the changeset viewer.