Changeset 49ab5d7 in sasview for src/sas/perspectives/calculator/image_viewer.py
- Timestamp:
- Mar 4, 2015 1:28:39 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:
- 2f732b0
- Parents:
- 76aed53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/calculator/image_viewer.py
rd90f91b r49ab5d7 36 36 """ 37 37 self.parent = parent 38 38 39 39 def load(self): 40 40 """ … … 66 66 ax.subplot.set_xlabel('x [pixel]') 67 67 ax.subplot.set_ylabel('y [pixel]') 68 ax.figure.subplots_adjust(left=0.15, bottom=0.1, 68 ax.figure.subplots_adjust(left=0.15, bottom=0.1, 69 69 right=0.95, top=0.95) 70 plot_frame.SetTitle('Picture -- %s --' % basename)70 plot_frame.SetTitle('Picture -- %s --' % basename) 71 71 plot_frame.Show(True) 72 72 if parent != None: … … 74 74 except: 75 75 print "parent", parent 76 err_msg += "Failed to load '%s'.\n" % basename76 err_msg += "Failed to load '%s'.\n" % basename 77 77 if err_msg: 78 78 if parent is not None: … … 80 80 else: 81 81 print err_msg 82 82 83 83 def choose_data_file(self, location=None): 84 84 """ … … 88 88 if location == None: 89 89 location = os.getcwd() 90 dlg = wx.FileDialog(self.parent, "Image Viewer: Choose a image file", 91 location, "", "", style=wx.FD_OPEN |wx.FD_MULTIPLE)90 dlg = wx.FileDialog(self.parent, "Image Viewer: Choose a image file", 91 location, "", "", style=wx.FD_OPEN | wx.FD_MULTIPLE) 92 92 if dlg.ShowModal() == wx.ID_OK: 93 93 path = dlg.GetPaths() … … 101 101 Frame for simple plot 102 102 """ 103 def __init__(self, parent, id, title, image=None, scale='log_{10}', 104 size=wx.Size(550, 470)): 103 def __init__(self, parent, id, title, image=None, scale='log_{10}', 104 size=wx.Size(550, 470)): 105 105 """ 106 106 comment … … 111 111 PlotFrame.__init__(self, parent, id, title, scale, size) 112 112 self.parent = parent 113 self.data = image 113 self.data = image 114 114 self.file_name = title 115 115 116 116 menu = wx.Menu() 117 117 id = wx.NewId() … … 127 127 wx.EVT_MENU(self, id, self.on_help) 128 128 self.menu_bar.Append(menu_help, "&Help") 129 129 130 130 self.SetMenuBar(self.menu_bar) 131 131 self.im_show(image) 132 132 133 133 def on_set_data(self, event): 134 134 """ … … 139 139 self.panel.ShowModal() 140 140 141 def on_help(self, event): 142 """ 143 Bring up Image Viewer Documentation from the image viewer window 144 whenever the help menu item "how to" is clicked. Calls 141 def on_help(self, event): 142 """ 143 Bring up Image Viewer Documentation from the image viewer window 144 whenever the help menu item "how to" is clicked. Calls 145 145 DocumentationWindow with the path of the location within the 146 documentation tree (after /doc/ ....". 147 146 documentation tree (after /doc/ ....". 147 148 148 :param evt: Triggers on clicking "how to" in help menu 149 149 """ 150 150 151 151 _TreeLocation = "user/perspectives/calculator/image_viewer_help.html" 152 152 _doc_viewer = DocumentationWindow(self, -1, \ 153 _TreeLocation, "Image Viewer Help")154 155 153 _TreeLocation, "Image Viewer Help") 154 155 156 156 class SetDialog(wx.Dialog): 157 157 """ 158 158 Dialog for Data Set 159 159 """ 160 def __init__(self, parent, id= -1, title="Convert to Data", image=None,160 def __init__(self, parent, id= -1, title="Convert to Data", image=None, 161 161 size=(_DIALOG_WIDTH, 270)): 162 162 wx.Dialog.__init__(self, parent, id, title, size) … … 170 170 self.is_png = self._get_is_png() 171 171 self._build_layout() 172 my_title = "Convert Image to Data - %s -" % self.title172 my_title = "Convert Image to Data - %s -" % self.title 173 173 self.SetTitle(my_title) 174 174 self.SetSize(size) 175 175 176 176 def _get_is_png(self): 177 177 """ … … 180 180 _, extension = os.path.splitext(self.title) 181 181 return extension.lower() == '.png' 182 182 183 183 def _build_layout(self): 184 184 """ … … 190 190 ybox = wx.BoxSizer(wx.HORIZONTAL) 191 191 btnbox = wx.BoxSizer(wx.VERTICAL) 192 192 193 193 sb_title = wx.StaticBox(self, -1, 'Transform Axes') 194 194 boxsizer = wx.StaticBoxSizer(sb_title, wx.VERTICAL) … … 203 203 z_ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH , 20), 204 204 style=wx.TE_PROCESS_ENTER) 205 205 206 206 xmin_ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 207 207 style=wx.TE_PROCESS_ENTER) … … 222 222 ymin_ctl.Bind(wx.EVT_TEXT, self._onparam) 223 223 ymax_ctl.Bind(wx.EVT_TEXT, self._onparam) 224 xbox.AddMany([(x_title , 0, wx.LEFT, 0), 225 (xmin_title , 0, wx.LEFT, 10), 226 (xmin_ctl , 0, wx.LEFT, 10), 227 (xmax_title , 0, wx.LEFT, 10), 224 xbox.AddMany([(x_title , 0, wx.LEFT, 0), 225 (xmin_title , 0, wx.LEFT, 10), 226 (xmin_ctl , 0, wx.LEFT, 10), 227 (xmax_title , 0, wx.LEFT, 10), 228 228 (xmax_ctl , 0, wx.LEFT, 10)]) 229 ybox.AddMany([(y_title , 0, wx.LEFT, 0), 230 (ymin_title , 0, wx.LEFT, 10), 231 (ymin_ctl , 0, wx.LEFT, 10), 232 (ymax_title , 0, wx.LEFT, 10), 233 (ymax_ctl , 0, wx.LEFT, 10)]) 234 zbox.AddMany([(z_title , 0, wx.LEFT, 0), 229 ybox.AddMany([(y_title , 0, wx.LEFT, 0), 230 (ymin_title , 0, wx.LEFT, 10), 231 (ymin_ctl , 0, wx.LEFT, 10), 232 (ymax_title , 0, wx.LEFT, 10), 233 (ymax_ctl , 0, wx.LEFT, 10)]) 234 zbox.AddMany([(z_title , 0, wx.LEFT, 0), 235 235 (ztime_title, 0, wx.LEFT, 10), 236 (z_ctl , 0, wx.LEFT, 7), 237 ]) 236 (z_ctl , 0, wx.LEFT, 7), 237 ]) 238 238 msg = "The data rescaled will show up in the Data Explorer. \n" 239 239 msg += "*Note: Recommend to use an image with 8 bit Grey \n" … … 269 269 By pass original txtcrl binding 270 270 """ 271 pass 272 271 pass 272 273 273 def _onparam(self, event=None): 274 274 """ … … 284 284 item.SetBackgroundColour("white") 285 285 try: 286 val = float(item.GetValue()) 286 val = float(item.GetValue()) 287 287 if val < -10.0 or val > 10.0: 288 288 item.SetBackgroundColour("pink") … … 297 297 err_msg += "between -10 and 10." 298 298 if self.base is not None: 299 wx.PostEvent(self.base, StatusEvent(status=err_msg, 299 wx.PostEvent(self.base, StatusEvent(status=err_msg, 300 300 info="error")) 301 301 else: … … 303 303 return flag 304 304 305 def _on_z_enter(self, event= None):305 def _on_z_enter(self, event=None): 306 306 """ 307 307 On z factor enter … … 309 309 item = event.GetEventObject() 310 310 self._check_z_ctrl(item) 311 311 312 312 def _check_z_ctrl(self, item, is_button=False): 313 313 """ … … 316 316 item.SetBackgroundColour("white") 317 317 try: 318 val = float(item.GetValue()) 318 val = float(item.GetValue()) 319 319 if val <= 0: 320 320 item.SetBackgroundColour("pink") … … 323 323 except: 324 324 item.SetBackgroundColour("pink") 325 item.Refresh() 325 item.Refresh() 326 326 flag = False 327 327 if not flag and is_button: 328 328 err_msg = "The z scale value should be larger than 0." 329 329 if self.base is not None: 330 wx.PostEvent(self.base, StatusEvent(status=err_msg, 330 wx.PostEvent(self.base, StatusEvent(status=err_msg, 331 331 info="error")) 332 332 else: 333 333 print err_msg 334 return flag 335 334 return flag 335 336 336 def on_set(self, event): 337 337 """ 338 Set image as data 338 Set image as data 339 339 """ 340 340 event.Skip() … … 357 357 err_msg = "Error occurred while converting Image to Data." 358 358 if self.base is not None: 359 wx.PostEvent(self.base, StatusEvent(status=err_msg, 359 wx.PostEvent(self.base, StatusEvent(status=err_msg, 360 360 info="error")) 361 361 else: 362 362 print err_msg 363 363 364 364 self.OnClose(event) 365 365 366 366 def convert_image(self, rgb, xmin, xmax, ymin, ymax, zscale): 367 367 """ … … 405 405 data = self.base.create_gui_data(output, self.title) 406 406 self.base.add_data({data.id:data}) 407 407 408 408 def rgb2gray(self, rgb): 409 409 """ … … 415 415 rgb = rgb[::-1] 416 416 if rgb.ndim == 2: 417 grey = np.rollaxis(rgb, axis =0)417 grey = np.rollaxis(rgb, axis=0) 418 418 else: 419 red, green, blue = np.rollaxis(rgb[..., :3], axis= -1)419 red, green, blue = np.rollaxis(rgb[..., :3], axis= -1) 420 420 grey = 0.299 * red + 0.587 * green + 0.114 * blue 421 421 max_i = rgb.max() 422 422 factor = 255.0 / max_i 423 grey *= factor 423 grey *= factor 424 424 return np.array(grey) 425 425 426 426 def OnClose(self, event): 427 427 """ … … 431 431 event.Skip() 432 432 self.Destroy() 433 433 434 434 if __name__ == "__main__": 435 app 435 app = wx.App() 436 436 ImageView(None).load() 437 app.MainLoop() 438 439 437 app.MainLoop() 438
Note: See TracChangeset
for help on using the changeset viewer.