Changeset dec793e in sasview for invariantview/perspectives/invariant
- Timestamp:
- Apr 5, 2011 7:32:45 PM (14 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:
- 4b470cf
- Parents:
- 8da09f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/report_dialog.py
rcf9b6950 rdec793e 24 24 PANEL_HEIGHT = 700 25 25 FONT_VARIANT = 0 26 ISMAC = False 26 27 else: 27 28 _STATICBOX_WIDTH = 480 … … 29 30 PANEL_HEIGHT = 700 30 31 FONT_VARIANT = 1 31 32 33 32 ISMAC = True 33 34 34 class ReportDialog(wx.Dialog): 35 35 """ … … 53 53 # font size 54 54 self.SetWindowVariant(variant=FONT_VARIANT) 55 56 # check if tit is MAC 57 self.is_mac = ISMAC 58 55 59 # report string 56 60 self.report_list = list … … 59 63 # layout 60 64 self._setup_layout() 65 # wild card 66 # pdf supporting only on MAC 67 if self.is_mac: 68 self.wild_card = ' PDF files (*.pdf)|*.pdf|' 69 else: 70 self.wild_card = '' 71 self.wild_card += 'HTML files (*.html)|*.html|' 72 self.wild_card += 'Text files (*.txt)|*.txt' 73 74 61 75 62 76 def _setup_layout(self): … … 109 123 self.Centre() 110 124 self.Show(True) 111 125 112 126 113 127 def onSave(self, event=None): … … 117 131 #todo: complete saving fig file and as a txt file 118 132 dlg = wx.FileDialog(self, "Choose a file", 119 wildcard='HTML files (*.html)|*.html|'+ 120 'Text files (*.txt)|*.txt', 133 wildcard=self.wild_card, 121 134 style=wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) 122 135 dlg.SetFilterIndex(0) #Set .html files to be default … … 125 138 dlg.Destroy() 126 139 return 127 140 128 141 fName = dlg.GetPath() 129 ext_num = dlg.GetFilterIndex() 130 142 ext_num = dlg.GetFilterIndex() 143 # index correction 144 if not self.is_mac: 145 ind_cor = 1 146 else: 147 ind_cor = 0 131 148 #set file extensions 132 if ext_num == 0: 149 if ext_num == (0 + 2 * ind_cor): 150 # TODO: Sort this case out 151 ext = '.pdf' 152 img_ext = '_img.png' 153 fName = os.path.splitext(fName)[0] + ext 154 dlg.Destroy() 155 156 #pic (png) file path/name 157 pic_fname = os.path.splitext(fName)[0] + img_ext 158 # save the image for use with pdf writer 159 self.report_list[2].savefig(pic_fname) 160 161 # put the image file path in the html data 162 html = self.report_list[0] % str(pic_fname) 163 164 # make/open file in case of absence 165 f = open(fName, 'w') 166 f.close() 167 # write pdf as a pdf file 168 pdf = self.HTML2PDF(data=html, filename=fName) 169 170 #open pdf 171 if pdf: 172 os.startfile(str(fName)) 173 #delete image file 174 os.remove(pic_fname) 175 return 176 elif ext_num == (1 - ind_cor): 133 177 ext = '.html' 134 178 img_ext = '_img4html.png' 135 179 report_frame = self.report_list[0] 136 elif ext_num == 1:180 elif ext_num == (2 - ind_cor): 137 181 ext = '.txt' 138 182 # changing the image extension actually changes the image … … 142 186 else: 143 187 return 144 188 145 189 #file name 146 190 fName = os.path.splitext(fName)[0] + ext … … 149 193 pic_fname = os.path.splitext(fName)[0] + img_ext 150 194 #put the image path in html string 151 if ext_num == 0:195 if ext_num == (1 - ind_cor): 152 196 report = report_frame % pic_fname 197 153 198 f = open(fName, 'w') 154 199 f.write(report)
Note: See TracChangeset
for help on using the changeset viewer.