Changeset a94c4e1 in sasview for invariantview/perspectives/invariant
- Timestamp:
- Jul 25, 2010 2:20:47 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:
- 55f5a77
- Parents:
- cb463b4
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/invariant_panel.py
rcb463b4 ra94c4e1 7 7 8 8 import sys,os 9 9 10 from wx.lib.scrolledpanel import ScrolledPanel 10 11 from sans.invariant import invariant … … 81 82 self.new_state = False 82 83 self.is_power_out = False 83 84 84 85 #container of invariant value 85 86 self.inv_container = None … … 95 96 ## Default file location for save 96 97 self._default_save_location = os.getcwd() 97 98 98 99 def err_check_on_data(self): 99 100 """ … … 648 649 from report_dialog import ReportDialog 649 650 650 report_string = self.state.report_str 651 self.state.set_report_string() 652 report_string = self.state.report_str 651 653 dialog = ReportDialog(report_string, None, -1, "") 652 654 dialog.ShowModal() … … 1138 1140 else: 1139 1141 return False 1142 1140 1143 1141 1144 def _reset_output(self): … … 1701 1704 """ 1702 1705 import sans.perspectives.invariant as invariant 1706 #from wx.lib.buttons import GenBitmapTextButton 1707 1703 1708 path = invariant.get_data_path(media='media') 1704 1709 self.undo_png = os.path.join(path,"undo.png") … … 1711 1716 self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png))#wx.Button(self, id, "Undo",size=(50,20)) 1712 1717 self.button_undo.SetToolTipString("Undo") 1718 #self.button_undo.SetBackgroundColour('#c2e6f8') 1719 1713 1720 self.Bind(wx.EVT_BUTTON, self.undo, id=id) 1714 1721 self.button_undo.Disable() … … 1724 1731 self.button_bookmark.SetToolTipString("Bookmark: right-click on the panel to retrieve") 1725 1732 self.Bind(wx.EVT_BUTTON, self._on_bookmark, id=id) 1726 #self.button_bookmark.Disable()1727 1733 #report button 1728 1734 id = wx.NewId() -
invariantview/perspectives/invariant/invariant_state.py
rcb463b4 ra94c4e1 93 93 self.timestamp = "('00:00:00', '00/00/0000')" 94 94 self.container = None 95 #plot image 96 self.wximbmp = None 95 97 # report_html strings 96 98 import sans.perspectives.invariant as invariant … … 487 489 continue 488 490 489 self.report_str = str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18) 490 491 # make plot image 492 self.set_plot_state(extra_high=bool_0[1],extra_low=bool_1[1]) 493 494 # get ready for report with setting all the html strings 495 self.report_str = str(self.template_str)% (s_1,s_2,s_3,s_4,s_5,s_6,s_7,s_8,s_9,s_10,s_11,s_12,s_13,s_14,s_15,s_16,s_17,s_18,self.file,self.wximbmp) 496 497 491 498 def set_saved_state(self, name, value): 492 499 """ … … 520 527 pass 521 528 522 529 def set_plot_state(self,extra_high=False,extra_low=False): 530 """ 531 Build image state that wx.html understand 532 by plotting, putting it into wx.FileSystem image object 533 534 : extrap_high,extra_low: low/high extrapolations are possible extra-plots 535 """ 536 # some imports 537 import cStringIO 538 import matplotlib,wx 539 matplotlib.use('Agg') 540 import matplotlib.pyplot as plt 541 import Image 542 543 #we use simple plot, not plotpanel 544 #make matlab figure 545 fig = plt.figure() 546 graph = fig.add_subplot(111) 547 548 #data plot 549 graph.errorbar(self.data.x, self.data.y, yerr=self.data.dy, fmt='o') 550 #low Q extrapolation fit plot 551 if not extra_low == 'False': 552 graph.plot(self.theory_lowQ.x,self.theory_lowQ.y) 553 #high Q extrapolation fit plot 554 if not extra_high == 'False': 555 graph.plot(self.theory_highQ.x,self.theory_highQ.y) 556 graph.set_xscale("log", nonposx='clip') 557 graph.set_yscale("log", nonposy='clip') 558 plt.xlabel('$\\rm{Q}(\\AA^{-1})$', fontsize = 12) 559 plt.ylabel('$\\rm{Intensity}(cm^{-1})$', fontsize = 12) 560 561 #make python.Image object 562 imagedata = cStringIO.StringIO() 563 fig.savefig(imagedata,format='png') 564 imagedata.seek(0) 565 img = Image.open(imagedata) 566 #convert to wx.Image 567 wxim = wx.EmptyImage(img.size[0],img.size[1]) 568 wxim.SetData(img.convert("RGB").tostring()) 569 #get the dynamic image for the htmlwindow 570 wximbmp = wx.BitmapFromImage(wxim) 571 #store the image in wx.FileSystem Object 572 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 573 # use wx.MemoryFSHandler 574 self.imgRAM = wx.MemoryFSHandler() 575 #AddFile, image can be retrieved with 'memory:filename' 576 self.imgRAM.AddFile('img_inv.png',wximbmp, wx.BITMAP_TYPE_PNG) 577 578 self.wximbmp = 'memory:img_inv.png' 579 523 580 524 581 class Reader(CansasReader): -
invariantview/perspectives/invariant/report_dialog.py
rcb463b4 ra94c4e1 18 18 import sys,os 19 19 import wx.html as html 20 20 import Image 21 21 if sys.platform.count("win32")>0: 22 22 _STATICBOX_WIDTH = 450 … … 45 45 kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE 46 46 wx.Dialog.__init__(self, *args, **kwds) 47 kwds["image"] = 'Dynamic Image' 47 48 # title 48 49 self.SetTitle("Report: Invariant computaion") … … 55 56 # layout 56 57 self._setup_layout() 57 58 58 59 def _setup_layout(self): 59 60 """ … … 75 76 button_preview.SetToolTipString("Print preview this report.") 76 77 button_preview.Bind(wx.EVT_BUTTON, self.onPreview, id = button_preview.GetId()) 77 #hbox.Add(button_preview)78 hbox.Add(button_preview) 78 79 79 80 id = wx.NewId() … … 100 101 self.Show(True) 101 102 102 def onSave(self,event ):103 def onSave(self,event=None): 103 104 """ 105 Save 104 106 """ 105 pass 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() 106 120 107 def onPreview(self,event): 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): 108 128 """ 129 Preview 130 131 : event: Preview button event 109 132 """ 110 pass 133 previewh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 134 previewh.PreviewText(self.report_string) 111 135 112 def onPrint(self,event ):136 def onPrint(self,event=None): 113 137 """ 138 Print 139 140 : event: Print button event 114 141 """ 115 gg=html.HtmlEasyPrinting(name="Printing", parentWindow=self)116 117 gg.PreviewText(self.report_string) 142 printh=html.HtmlEasyPrinting(name="Printing", parentWindow=self) 143 printh.PrintText(self.report_string) 144 118 145 119 146
Note: See TracChangeset
for help on using the changeset viewer.