def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel, size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw()
def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel) #,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.Bind(wx.EVT_PAINT, self.OnPaint) self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw()
def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw()
def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel)#,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.Bind(wx.EVT_PAINT, self.OnPaint) self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw()
def __init__(self, parent, owner=None, _larch=None): wx.Panel.__init__(self, parent) self.owner = owner vbox = wx.BoxSizer(wx.VERTICAL) self.plot2D = ImagePanel(self, size=(500, 500), messenger=self.owner.write_message) vbox.Add(self.plot2D, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.SetSizer(vbox)
def __init__(self,parent,type='2D image',owner=None,_larch=None,size=(500, 500)): wx.Panel.__init__(self, parent) self.owner = owner self.type = type self.ai = None self.on_calibration() vbox = wx.BoxSizer(wx.VERTICAL) self.plot2D = ImagePanel(self,size=size,messenger=self.owner.write_message) vbox.Add(self.plot2D,proportion=1,flag=wx.ALL|wx.EXPAND,border = 10) self.SetSizer(vbox) self.plot2D.cursor_callback = self.on_cursor
class CalibrationPopup(wx.Frame): def __init__(self, parent): self.frame = wx.Frame.__init__(self, parent, title='Calibration', size=(900, 700)) self.parent = parent self.statusbar = self.CreateStatusBar(2, wx.CAPTION) self.default_cal = 0 self.default_det = 0 self.img_fname = '' try: self.raw_img = parent.plt_img ## raw_img or flp_img or plt_img mkak 2016.10.28 self.img_fname = 'Image from diFFit2D viewer.' except: self.raw_img = np.zeros((1024, 1024)) self.Init() self.Show() # wx.Window.GetEffectiveMinSize # wx.GetBestSize(self) self.setDefaults() def Init(self): self.panel = wx.Panel(self) self.DirectionsSizer() self.MainSizer() # self.OKsizer() self.framebox = wx.BoxSizer(wx.VERTICAL) self.framebox.Add(self.dirbox, flag=wx.ALL | wx.EXPAND, border=10) self.framebox.Add(self.mainbox, flag=wx.ALL | wx.EXPAND, border=10) # self.framebox.Add(self.okbox, flag=wx.ALL|wx.ALIGN_RIGHT, border=10) ########################### ## Pack all together in self.panel self.panel.SetSizer(self.framebox) ########################### ## Set default information self.stepno = 0 self.checkRANGE() self.showDirection() def setDefaults(self): ## Sets some typical defaults specific to GSE 13-ID procedure self.entr_pix.SetValue('400') ## binned pixels (2x200um) self.entr_EorL.SetValue('19.0') ## 19.0 keV self.entr_dist.SetValue('0.5') ## 0.5 m self.ch_det.SetSelection(self.default_det) ## Perkin detector self.ch_cal.SetSelection(self.default_cal) ## CeO2 self.entr_calimg.SetValue(self.img_fname) self.entr_cntrx.SetValue(str(int(self.raw_img.shape[0] / 2))) ## x-position of beam self.entr_cntry.SetValue(str(int(self.raw_img.shape[1] / 2))) ## y-position of beam self.onDorPSel() def DirectionsSizer(self): ########################### ## Directions dirbx = wx.StaticBox(self.panel, label='DIRECTIONS', size=(100, 50)) self.dirbox = wx.StaticBoxSizer(dirbx, wx.VERTICAL) hbox_direct = wx.BoxSizer(wx.HORIZONTAL) self.followdir = wx.StaticText(self.panel, label='') #hbox_direct.Add(self.txt_shp, flag=wx.RIGHT, border=8) hbox_direct.Add(self.followdir, flag=wx.ALL | wx.EXPAND, border=8) self.dirbox.Add(hbox_direct, flag=wx.ALL | wx.EXPAND, border=10) hbox_next = wx.BoxSizer(wx.HORIZONTAL) self.btn_prev = wx.Button(self.panel, label='PREVIOUS') self.btn_next = wx.Button(self.panel, label='NEXT') self.btn_prev.Bind(wx.EVT_BUTTON, self.onPREVIOUS) self.btn_next.Bind(wx.EVT_BUTTON, self.onNEXT) hbox_next.Add(self.btn_prev, flag=wx.ALL, border=8) hbox_next.Add((-1, 100)) hbox_next.Add(self.btn_next, flag=wx.ALIGN_RIGHT | wx.ALL, border=8) self.dirbox.Add(hbox_next, flag=wx.ALL | wx.EXPAND, border=10) def MainSizer(self): self.mainbox = wx.BoxSizer(wx.VERTICAL) ########################### ## -----> Main Panel self.hmain = wx.BoxSizer(wx.HORIZONTAL) self.ImageSizer() self.ParameterSizer() self.hmain.Add(self.imagebox, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.hmain.Add(self.parbox, flag=wx.ALL, border=10) self.mainbox.Add(self.hmain, flag=wx.ALL | wx.EXPAND, border=10) def ParameterSizer(self): ''' This is where the parameters will be. ''' #self.parbox = wx.BoxSizer(wx.VERTICAL) prbx = wx.StaticBox(self.panel, label='PARAMETERS', size=(50, 100)) self.parbox = wx.StaticBoxSizer(prbx, wx.VERTICAL) ########################### ## Establish lists from pyFAI clbrnts = [] #['None'] self.dets = [] #['None'] for key, value in pyFAI.detectors.ALL_DETECTORS.items(): self.dets.append(key) if key == 'perkin': self.default_det = len(self.dets) - 1 for key, value in pyFAI.calibrant.ALL_CALIBRANTS.items(): clbrnts.append(key) if key == 'CeO2': self.default_cal = len(clbrnts) - 1 ##### ## Calibration Image selection hbox_cal1 = wx.BoxSizer(wx.HORIZONTAL) ttl_calimg = wx.StaticText(self.panel, label='Calibration Image:') self.entr_calimg = wx.TextCtrl(self.panel, size=(210, -1)) # btn_calimg = wx.Button(self.panel, label='Browse...') # btn_calimg.Bind(wx.EVT_BUTTON, self.loadIMAGE) hbox_cal1.Add(ttl_calimg, flag=wx.RIGHT, border=8) hbox_cal1.Add(self.entr_calimg, flag=wx.RIGHT | wx.EXPAND, border=8) # hbox_cal1.Add(btn_calimg, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal1, flag=wx.BOTTOM | wx.TOP, border=8) btn_calimg = wx.Button(self.panel, label='Browse...') btn_calimg.Bind(wx.EVT_BUTTON, self.loadIMAGE) self.parbox.Add(btn_calimg, flag=wx.BOTTOM | wx.ALIGN_RIGHT, border=8) ##### ## Calibrant selection hbox_cal2 = wx.BoxSizer(wx.HORIZONTAL) ttl_cal = wx.StaticText(self.panel, label='Calibrant:') self.ch_cal = wx.Choice(self.panel, choices=clbrnts) self.ch_cal.Bind(wx.EVT_CHOICE, self.onCalSel) hbox_cal2.Add(ttl_cal, flag=wx.RIGHT, border=8) hbox_cal2.Add(self.ch_cal, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal2, flag=wx.BOTTOM, border=30) ##### ## Set-up specific parameters hbox_cal3 = wx.BoxSizer(wx.HORIZONTAL) txt_exp = wx.StaticText(self.panel, label='SET-UP PARAMETERS') btn_pni = wx.Button(self.panel, label='Load file') btn_pni.Bind(wx.EVT_BUTTON, self.openPONI) hbox_cal3.Add(txt_exp, flag=wx.RIGHT, border=8) hbox_cal3.Add(btn_pni, flag=wx.LEFT, border=60) self.parbox.Add(hbox_cal3, flag=wx.BOTTOM, border=8) ##### ## Detector selection hbox_cal4 = wx.BoxSizer(wx.HORIZONTAL) self.ch_DorP = wx.Choice(self.panel, choices=['Detector name', 'Pixel size (um)']) self.ch_det = wx.Choice(self.panel, choices=self.dets) self.entr_pix = wx.TextCtrl(self.panel, size=(110, -1)) self.ch_det.Bind(wx.EVT_CHOICE, self.onDetSel) self.ch_DorP.Bind(wx.EVT_CHOICE, self.onDorPSel) hbox_cal4.Add(self.ch_DorP, flag=wx.RIGHT, border=8) hbox_cal4.Add(self.ch_det, flag=wx.RIGHT, border=8) hbox_cal4.Add(self.entr_pix, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal4, flag=wx.BOTTOM, border=8) ##### ## Energy or Wavelength hbox_cal5 = wx.BoxSizer(wx.HORIZONTAL) self.ch_EorL = wx.Choice(self.panel, choices=['Energy (keV)', 'Wavelength (A)']) self.entr_EorL = wx.TextCtrl(self.panel, size=(110, -1)) self.ch_EorL.Bind(wx.EVT_CHOICE, self.onEorLSel) hbox_cal5.Add(self.ch_EorL, flag=wx.RIGHT, border=8) hbox_cal5.Add(self.entr_EorL, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal5, flag=wx.BOTTOM, border=8) ## Distance hbox_cal6 = wx.BoxSizer(wx.HORIZONTAL) ttl_dist = wx.StaticText(self.panel, label='Detector distance (m):') self.entr_dist = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal6.Add(ttl_dist, flag=wx.RIGHT, border=8) hbox_cal6.Add(self.entr_dist, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal6, flag=wx.BOTTOM, border=8) ## Beam center x hbox_cal7 = wx.BoxSizer(wx.HORIZONTAL) ttl_cntrx = wx.StaticText(self.panel, label='Beam center, x (pixels):') self.entr_cntrx = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal7.Add(ttl_cntrx, flag=wx.RIGHT, border=8) hbox_cal7.Add(self.entr_cntrx, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal7, flag=wx.BOTTOM, border=8) ## Beam center y hbox_cal8 = wx.BoxSizer(wx.HORIZONTAL) ttl_cntry = wx.StaticText(self.panel, label='Beam center, y (pixels):') self.entr_cntry = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal8.Add(ttl_cntry, flag=wx.RIGHT, border=8) hbox_cal8.Add(self.entr_cntry, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal8, flag=wx.BOTTOM, border=8) def onCalSel(self, event=None): print('Selected calibrant: %s' % self.ch_cal.GetString(self.ch_cal.GetSelection())) def onDetSel(self, event=None): print('Selected detector: %s' % self.ch_det.GetString(self.ch_det.GetSelection())) def onEorLSel(self, event=None): if self.ch_EorL.GetSelection() == 1: energy = float(self.entr_EorL.GetValue()) ## units keV wavelength = lambda_from_E(energy) ## units: A self.entr_EorL.SetValue(str(wavelength)) else: wavelength = float(self.entr_EorL.GetValue()) * 1e-10 ## units: m energy = E_from_lambda(wavelength) ## units: keV self.entr_EorL.SetValue(str(energy)) def onDorPSel(self, event=None): if self.ch_DorP.GetSelection() == 0: self.entr_pix.Hide() self.ch_det.Show() else: self.ch_det.Hide() self.entr_pix.Show() self.panel.GetSizer().Layout() self.panel.GetParent().Layout() def loadIMAGE(self, event=None): wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*' if os.path.exists(self.entr_calimg.GetValue()): dfltDIR = self.entr_calimg.GetValue() else: dfltDIR = os.getcwd() dlg = wx.FileDialog(self, message='Choose XRD calibration file', defaultDir=dfltDIR, wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: # self.raw_img = plt.imread(path) self.raw_img = tifffile.imread(path) #self.raw_img = fabio.open(path).data except: print('Image not properly opened.') pass self.plot2Dimg.display(self.raw_img) self.plot2Dimg.redraw() self.AutoContrast() self.entr_calimg.Clear() self.entr_calimg.SetValue(path) #os.path.split(path)[-1] def ImageSizer(self): ''' Image Panel ''' self.imagebox = wx.BoxSizer(wx.VERTICAL) self.plot2Dimage() self.btn_image = wx.Button(self.panel, label='IMAGE TOOLS') self.btn_image.Bind(wx.EVT_BUTTON, self.onImageTools) self.imagebox.Add(self.plot2Dimg, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.imagebox.Add(self.btn_image, flag=wx.ALL, border=10) # def OKsizer(self): # ########################### # ## OK - CANCEL # self.okbox = wx.BoxSizer(wx.HORIZONTAL) # # okBtn = wx.Button(self.panel, wx.ID_OK ) # canBtn = wx.Button(self.panel, wx.ID_CANCEL ) # # self.okbox.Add(canBtn, flag=wx.RIGHT, border=5) # self.okbox.Add(okBtn, flag=wx.RIGHT, border=5) def write_message(self, s, panel=0): """write a message to the Status Bar""" self.SetStatusText(s, panel) def onImageTools(self, event=None): self.toolbox = ImageToolboxFrame(self.plot2Dimg, self.raw_img) def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel, size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw() def AutoContrast(self): self.minINT = int(np.min(self.raw_img)) self.maxINT = int(np.max(self.raw_img) / 15) # /15 scales image to viewable if self.maxINT == self.minINT: self.minINT = self.minINT - 50 self.maxINT = self.minINT + 100 self.minCURRENT = self.minINT self.maxCURRENT = self.maxINT if self.maxCURRENT > self.maxINT: self.maxCURRENT = self.maxINT self.plot2Dimg.conf.auto_intensity = False self.plot2Dimg.conf.int_lo[0] = self.minCURRENT self.plot2Dimg.conf.int_hi[0] = self.maxCURRENT # self.plot2Dimg.conf.int_lo['int'] = self.minCURRENT # self.plot2Dimg.conf.int_hi['int'] = self.maxCURRENT ## vertical flip default self.plot2Dimg.conf.flip_ud = True self.plot2Dimg.conf.flip_lr = False self.plot2Dimg.redraw() def checkRANGE(self): if self.stepno <= 0: self.stepno = 0 self.btn_prev.Disable() else: self.btn_prev.Enable() if self.stepno >= 8: self.stepno = 8 self.btn_next.Disable() else: self.btn_next.Enable() def onNEXT(self, event=None): self.stepno = self.stepno + 1 self.checkRANGE() self.showDirection() def onPREVIOUS(self, event=None): self.stepno = self.stepno - 1 self.checkRANGE() self.showDirection() def showDirection(self): dirsteps = [ 'Enter parameters into the fields below.', 'Select point(s) on the first ring.', 'Select point(s) on the second ring.', 'Select point(s) on the third ring.', 'Select point(s) on the fourth ring.', 'Select point(s) on the fifth ring.', 'Select point(s) on the sixth ring.', 'Check preliminary calibration. Continue for final refinement.', 'Refinement complete.' ] self.followdir.SetLabel(dirsteps[self.stepno]) def openPONI(self, event=None): wildcards = 'pyFAI calibration file (*.poni)|*.poni|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose pyFAI calibration file', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: print self.ai = pyFAI.load(path) print('Loading calibration file: %s' % path) except: print('Not recognized as a pyFAI calibration file: %s' % path) return ## Sets viewer to values in .poni file self.entr_dist.SetValue('%0.4f' % self.ai._dist) self.entr_pix.SetValue('%0.1f' % float(self.ai.detector.pixel1 * 1000000.)) self.ch_DorP.SetSelection(1) self.entr_EorL.SetValue('%0.4f' % float(self.ai._wavelength * 1.e10)) self.ch_EorL.SetSelection(1) self.onDorPSel() cenx = float(self.ai._poni1) / float(self.ai.detector.pixel1) ceny = float(self.ai._poni2) / float(self.ai.detector.pixel2) self.entr_cntrx.SetValue('%0.3f' % cenx) self.entr_cntry.SetValue('%0.3f' % ceny)
class MaskToolsPopup(wx.Frame): def __init__(self,parent): self.frame = wx.Frame.__init__(self, parent, title='Create mask',size=(800,600)) self.parent = parent self.statusbar = self.CreateStatusBar(2,wx.CAPTION ) try: self.raw_img = parent.plt_img ## raw_img or flp_img or plt_img mkak 2016.10.28 except: self.loadIMAGE() self.setDefaults() self.Init() self.Show() # wx.Window.GetEffectiveMinSize # wx.GetBestSize(self) def Init(self): self.panel = wx.Panel(self) self.MainSizer() self.framebox = wx.BoxSizer(wx.VERTICAL) self.framebox.Add(self.mainbox, flag=wx.ALL|wx.EXPAND, border=10) ########################### ## Pack all together in self.panel self.panel.SetSizer(self.framebox) def setDefaults(self): self.area_list = [] def MainSizer(self): self.mainbox = wx.BoxSizer(wx.VERTICAL) ########################### ## -----> Main Panel self.hmain = wx.BoxSizer(wx.HORIZONTAL) self.ImageSizer() self.DrawNewSizer() self.hmain.Add(self.imagebox,proportion=1,flag=wx.ALL|wx.EXPAND, border=10) self.hmain.Add(self.toolbox, flag=wx.ALL, border=10) self.mainbox.Add(self.hmain, flag=wx.ALL|wx.EXPAND, border=10) def DrawNewSizer(self): self.toolbox = wx.BoxSizer(wx.VERTICAL) ########################### ## Directions nwbx = wx.StaticBox(self.panel,label='Drawing Tools', size=(100, 50)) drawbox = wx.StaticBoxSizer(nwbx,wx.VERTICAL) ########################### ## Drawing tools hbox_shp = wx.BoxSizer(wx.HORIZONTAL) self.txt_shp = wx.StaticText(self.panel, label='DRAWING SHAPE') shapes = ['circle','pixel','polygon','square'] self.ch_shp = wx.Choice(self.panel,choices=shapes) self.ch_shp.Bind(wx.EVT_CHOICE,self.ShapeChoice) hbox_shp.Add(self.txt_shp, flag=wx.RIGHT, border=8) hbox_shp.Add(self.ch_shp, flag=wx.EXPAND, border=8) drawbox.Add(hbox_shp, flag=wx.ALL|wx.EXPAND, border=10) ########################### ## Drawn Areas vbox_areas = wx.BoxSizer(wx.VERTICAL) hbox_areas = wx.BoxSizer(wx.HORIZONTAL) self.slct_area = wx.ListBox(self.panel, 26, wx.DefaultPosition, (170, 130), self.area_list, wx.LB_SINGLE) self.btn_SHWarea = wx.Button(self.panel,label='SHOW') self.btn_DELarea = wx.Button(self.panel,label='DELETE') self.btn_SHWarea.Bind(wx.EVT_BUTTON,self.showAREA) self.btn_DELarea.Bind(wx.EVT_BUTTON,self.deleteAREA) hbox_areas.Add(self.btn_SHWarea, flag=wx.BOTTOM, border=10) hbox_areas.Add(self.btn_DELarea, flag=wx.BOTTOM, border=10) self.btn_clear = wx.Button(self.panel,label='CLEAR ALL') self.btn_clear.Bind(wx.EVT_BUTTON,self.clearMask) vbox_areas.Add(self.slct_area, flag=wx.ALL|wx.EXPAND, border=10) vbox_areas.Add(hbox_areas, flag=wx.ALL|wx.EXPAND, border=10) vbox_areas.Add(self.btn_clear, flag=wx.ALL|wx.EXPAND, border=10) drawbox.Add(vbox_areas, flag=wx.ALL|wx.EXPAND, border=10) self.toolbox.Add(drawbox, flag=wx.ALL, border=10) self.btn_save = wx.Button(self.panel,label='SAVE MASK') self.btn_save.Bind(wx.EVT_BUTTON,self.saveMask) self.toolbox.Add(self.btn_save, flag=wx.ALL, border=10) self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable() def startIMAGE(self): self.loadIMAGE() def loadIMAGE(self,event=None): wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose XRD image', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: # self.raw_img = plt.imread(path) self.raw_img = tifffile.imread(path) #self.raw_img = fabio.open(path).data except: print('Image not properly opened.') self.raw_img = np.zeros((1024,1024)) else: print('No image selected.') self.raw_img = np.zeros((1024,1024)) def ImageSizer(self): ''' Image Panel ''' self.imagebox = wx.BoxSizer(wx.VERTICAL) self.plot2Dimage() imagetools = wx.BoxSizer(wx.HORIZONTAL) self.btn_image = wx.Button(self.panel,label='IMAGE TOOLS') self.btn_load = wx.Button(self.panel,label='CHANGE IMAGE') self.btn_image.Bind(wx.EVT_BUTTON,self.onImageTools) self.btn_load.Bind(wx.EVT_BUTTON,self.loadIMAGE) imagetools.Add(self.btn_load, flag=wx.ALL, border=10) imagetools.Add(self.btn_image, flag=wx.ALL, border=10) self.imagebox.Add(self.plot2Dimg,proportion=1,flag=wx.ALL|wx.EXPAND, border=10) self.imagebox.Add(imagetools, flag=wx.ALL, border=10) def write_message(self, s, panel=0): """write a message to the Status Bar""" self.SetStatusText(s, panel) def onImageTools(self,event=None): self.toolbox = ImageToolboxFrame(self.plot2Dimg,self.raw_img) def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel)#,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.Bind(wx.EVT_PAINT, self.OnPaint) self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw() def AutoContrast(self): self.minINT = int(np.min(self.raw_img)) self.maxINT = int(np.max(self.raw_img)/15) # /15 scales image to viewable if self.maxINT == self.minINT: self.minINT = self.minINT-50 self.maxINT = self.minINT+100 self.minCURRENT = self.minINT self.maxCURRENT = self.maxINT if self.maxCURRENT > self.maxINT: self.maxCURRENT = self.maxINT self.plot2Dimg.conf.auto_intensity = False self.plot2Dimg.conf.int_lo[0] = self.minCURRENT self.plot2Dimg.conf.int_hi[0] = self.maxCURRENT # self.plot2Dimg.conf.int_lo['int'] = self.minCURRENT # self.plot2Dimg.conf.int_hi['int'] = self.maxCURRENT ## vertical flip default self.plot2Dimg.conf.flip_ud = True self.plot2Dimg.conf.flip_lr = False self.plot2Dimg.redraw() def ShapeChoice(self,event=None): print('The shape you choose: %s' % self.ch_shp.GetString(self.ch_shp.GetSelection())) print() print('Not implemented: ShapeChoice') self.addAREA() def OnPaint(self, event=None): print('Shape : %s' % self.ch_shp.GetString(self.ch_shp.GetSelection())) # dc = wx.PaintDC(self) # dc.Clear() # dc.SetPen(wx.Pen(wx.BLACK, 4)) # dc.DrawLine(0, 0, 50, 50) def clearMask(self,event=None): print('Clearing the mask...') ## provide a warning message? self.area_list = [] self.slct_area.Set(self.area_list) self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable() def saveMask(self,event=None): print('This will trigger the saving of a mask.') def addAREA(self,event=None): area_name = 'area %i (%s)' % (len(self.area_list),self.ch_shp.GetString(self.ch_shp.GetSelection())) self.area_list.append(area_name) self.slct_area.Set(self.area_list) if len(self.area_list) > 0: self.btn_SHWarea.Enable() self.btn_DELarea.Enable() self.btn_clear.Enable() self.btn_save.Enable() def showAREA(self,event=None): if len(self.area_list) > 0: area_str = self.slct_area.GetString(self.slct_area.GetSelection()) str_msg = 'Displaying: %s' % area_str self.write_message(str_msg,panel=0) ## show area on map, image def deleteAREA(self,event=None): if len(self.area_list) > 0: area_str = self.slct_area.GetString(self.slct_area.GetSelection()) str_msg = 'Deleting: %s' % area_str self.write_message(str_msg,panel=0) self.area_list.remove(self.slct_area.GetString(self.slct_area.GetSelection())) self.slct_area.Set(self.area_list) if len(self.area_list) == 0: self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable()
class CalibrationPopup(wx.Frame): def __init__(self,parent): self.frame = wx.Frame.__init__(self, parent, title='Calibration',size=(900,700)) self.parent = parent self.statusbar = self.CreateStatusBar(2,wx.CAPTION ) self.default_cal = 0 self.default_det = 0 self.img_fname = '' try: self.raw_img = parent.plt_img ## raw_img or flp_img or plt_img mkak 2016.10.28 self.img_fname = 'Image from diFFit2D viewer.' except: self.raw_img = np.zeros((1024,1024)) self.Init() self.Show() # wx.Window.GetEffectiveMinSize # wx.GetBestSize(self) self.setDefaults() def Init(self): self.panel = wx.Panel(self) self.DirectionsSizer() self.MainSizer() # self.OKsizer() self.framebox = wx.BoxSizer(wx.VERTICAL) self.framebox.Add(self.dirbox, flag=wx.ALL|wx.EXPAND, border=10) self.framebox.Add(self.mainbox, flag=wx.ALL|wx.EXPAND, border=10) # self.framebox.Add(self.okbox, flag=wx.ALL|wx.ALIGN_RIGHT, border=10) ########################### ## Pack all together in self.panel self.panel.SetSizer(self.framebox) ########################### ## Set default information self.stepno = 0 self.checkRANGE() self.showDirection() def setDefaults(self): ## Sets some typical defaults specific to GSE 13-ID procedure self.entr_pix.SetValue('400') ## binned pixels (2x200um) self.entr_EorL.SetValue('19.0') ## 19.0 keV self.entr_dist.SetValue('0.5') ## 0.5 m self.ch_det.SetSelection(self.default_det) ## Perkin detector self.ch_cal.SetSelection(self.default_cal) ## CeO2 self.entr_calimg.SetValue(self.img_fname) self.entr_cntrx.SetValue(str(int(self.raw_img.shape[0]/2))) ## x-position of beam self.entr_cntry.SetValue(str(int(self.raw_img.shape[1]/2))) ## y-position of beam self.onDorPSel(None) def DirectionsSizer(self): ########################### ## Directions dirbx = wx.StaticBox(self.panel,label='DIRECTIONS', size=(100, 50)) self.dirbox = wx.StaticBoxSizer(dirbx,wx.VERTICAL) hbox_direct = wx.BoxSizer(wx.HORIZONTAL) self.followdir = wx.StaticText(self.panel,label='') #hbox_direct.Add(self.txt_shp, flag=wx.RIGHT, border=8) hbox_direct.Add(self.followdir, flag=wx.ALL|wx.EXPAND, border=8) self.dirbox.Add(hbox_direct, flag=wx.ALL|wx.EXPAND, border=10) hbox_next = wx.BoxSizer(wx.HORIZONTAL) self.btn_prev = wx.Button(self.panel,label='PREVIOUS') self.btn_next = wx.Button(self.panel,label='NEXT') self.btn_prev.Bind(wx.EVT_BUTTON,self.onPREVIOUS) self.btn_next.Bind(wx.EVT_BUTTON,self.onNEXT) hbox_next.Add(self.btn_prev, flag=wx.ALL, border=8) hbox_next.Add((-1, 100)) hbox_next.Add(self.btn_next, flag=wx.ALIGN_RIGHT|wx.ALL, border=8) self.dirbox.Add(hbox_next, flag=wx.ALL|wx.EXPAND, border=10) def MainSizer(self): self.mainbox = wx.BoxSizer(wx.VERTICAL) ########################### ## -----> Main Panel self.hmain = wx.BoxSizer(wx.HORIZONTAL) self.ImageSizer() self.ParameterSizer() self.hmain.Add(self.imagebox,proportion=1,flag=wx.ALL|wx.EXPAND, border=10) self.hmain.Add(self.parbox, flag=wx.ALL, border=10) self.mainbox.Add(self.hmain, flag=wx.ALL|wx.EXPAND, border=10) def ParameterSizer(self): ''' This is where the parameters will be. ''' #self.parbox = wx.BoxSizer(wx.VERTICAL) prbx = wx.StaticBox(self.panel,label='PARAMETERS', size=(50, 100)) self.parbox = wx.StaticBoxSizer(prbx,wx.VERTICAL) ########################### ## Establish lists from pyFAI clbrnts = [] #['None'] self.dets = [] #['None'] for key,value in pyFAI.detectors.ALL_DETECTORS.items(): self.dets.append(key) if key == 'perkin': self.default_det = len(self.dets)-1 for key,value in pyFAI.calibrant.ALL_CALIBRANTS.items(): clbrnts.append(key) if key == 'CeO2': self.default_cal = len(clbrnts)-1 ##### ## Calibration Image selection hbox_cal1 = wx.BoxSizer(wx.HORIZONTAL) ttl_calimg = wx.StaticText(self.panel, label='Calibration Image:' ) self.entr_calimg = wx.TextCtrl(self.panel, size=(210, -1)) # btn_calimg = wx.Button(self.panel, label='Browse...') # btn_calimg.Bind(wx.EVT_BUTTON, self.loadIMAGE) hbox_cal1.Add(ttl_calimg, flag=wx.RIGHT, border=8) hbox_cal1.Add(self.entr_calimg, flag=wx.RIGHT|wx.EXPAND, border=8) # hbox_cal1.Add(btn_calimg, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal1, flag=wx.BOTTOM|wx.TOP, border=8) btn_calimg = wx.Button(self.panel, label='Browse...') btn_calimg.Bind(wx.EVT_BUTTON, self.loadIMAGE) self.parbox.Add(btn_calimg, flag=wx.BOTTOM|wx.ALIGN_RIGHT, border=8) ##### ## Calibrant selection hbox_cal2 = wx.BoxSizer(wx.HORIZONTAL) ttl_cal = wx.StaticText(self.panel, label='Calibrant:') self.ch_cal = wx.Choice(self.panel,choices=clbrnts) self.ch_cal.Bind(wx.EVT_CHOICE, self.onCalSel) hbox_cal2.Add(ttl_cal, flag=wx.RIGHT, border=8) hbox_cal2.Add(self.ch_cal, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal2, flag=wx.BOTTOM, border=30) ##### ## Set-up specific parameters hbox_cal3 = wx.BoxSizer(wx.HORIZONTAL) txt_exp = wx.StaticText(self.panel, label='SET-UP PARAMETERS') btn_pni = wx.Button(self.panel, label='Load file') btn_pni.Bind(wx.EVT_BUTTON, self.openPONI) hbox_cal3.Add(txt_exp, flag=wx.RIGHT, border=8) hbox_cal3.Add(btn_pni, flag=wx.LEFT, border=60) self.parbox.Add(hbox_cal3, flag=wx.BOTTOM, border=8) ##### ## Detector selection hbox_cal4 = wx.BoxSizer(wx.HORIZONTAL) self.ch_DorP = wx.Choice(self.panel,choices=['Detector name','Pixel size (um)']) self.ch_det = wx.Choice(self.panel, choices=self.dets) self.entr_pix = wx.TextCtrl(self.panel, size=(110, -1)) self.ch_det.Bind(wx.EVT_CHOICE, self.onDetSel) self.ch_DorP.Bind(wx.EVT_CHOICE, self.onDorPSel) hbox_cal4.Add(self.ch_DorP, flag=wx.RIGHT, border=8) hbox_cal4.Add(self.ch_det, flag=wx.RIGHT, border=8) hbox_cal4.Add(self.entr_pix, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal4, flag=wx.BOTTOM, border=8) ##### ## Energy or Wavelength hbox_cal5 = wx.BoxSizer(wx.HORIZONTAL) self.ch_EorL = wx.Choice(self.panel,choices=['Energy (keV)','Wavelength (A)']) self.entr_EorL = wx.TextCtrl(self.panel, size=(110, -1)) self.ch_EorL.Bind(wx.EVT_CHOICE, self.onEorLSel) hbox_cal5.Add(self.ch_EorL, flag=wx.RIGHT, border=8) hbox_cal5.Add(self.entr_EorL, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal5, flag=wx.BOTTOM, border=8) ## Distance hbox_cal6 = wx.BoxSizer(wx.HORIZONTAL) ttl_dist = wx.StaticText(self.panel, label='Detector distance (m):') self.entr_dist = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal6.Add(ttl_dist, flag=wx.RIGHT, border=8) hbox_cal6.Add(self.entr_dist, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal6, flag=wx.BOTTOM, border=8) ## Beam center x hbox_cal7 = wx.BoxSizer(wx.HORIZONTAL) ttl_cntrx = wx.StaticText(self.panel, label='Beam center, x (pixels):') self.entr_cntrx = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal7.Add(ttl_cntrx, flag=wx.RIGHT, border=8) hbox_cal7.Add(self.entr_cntrx, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal7, flag=wx.BOTTOM, border=8) ## Beam center y hbox_cal8 = wx.BoxSizer(wx.HORIZONTAL) ttl_cntry = wx.StaticText(self.panel, label='Beam center, y (pixels):') self.entr_cntry = wx.TextCtrl(self.panel, size=(110, -1)) hbox_cal8.Add(ttl_cntry, flag=wx.RIGHT, border=8) hbox_cal8.Add(self.entr_cntry, flag=wx.RIGHT, border=8) self.parbox.Add(hbox_cal8, flag=wx.BOTTOM, border=8) def onCalSel(self,event): print('Selected calibrant: %s' % self.ch_cal.GetString(self.ch_cal.GetSelection())) def onDetSel(self,event): print('Selected detector: %s' % self.ch_det.GetString(self.ch_det.GetSelection())) def onEorLSel(self,event): hc = constants.value(u'Planck constant in eV s') * \ constants.value(u'speed of light in vacuum') * 1e-3 ## units: keV-m if self.ch_EorL.GetSelection() == 1: energy = float(self.entr_EorL.GetValue()) ## units keV wavelength = hc/(energy)*1e10 ## units: A self.entr_EorL.SetValue(str(wavelength)) else: wavelength = float(self.entr_EorL.GetValue())*1e-10 ## units: m energy = hc/(wavelength) ## units: keV self.entr_EorL.SetValue(str(energy)) def onDorPSel(self,event): if self.ch_DorP.GetSelection() == 0: self.entr_pix.Hide() self.ch_det.Show() else: self.ch_det.Hide() self.entr_pix.Show() self.panel.GetSizer().Layout() self.panel.GetParent().Layout() def loadIMAGE(self, event): wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose XRD calibration file', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: self.raw_img = fabio.open(path).data except: print('This is not an image openable by fabio.') pass self.plot2Dimg.display(self.raw_img) self.plot2Dimg.redraw() self.AutoContrast() self.entr_calimg.Clear() self.entr_calimg.SetValue(path) #os.path.split(path)[-1] def ImageSizer(self): ''' Image Panel ''' self.imagebox = wx.BoxSizer(wx.VERTICAL) self.plot2Dimage() self.btn_image = wx.Button(self.panel,label='IMAGE TOOLS') self.btn_image.Bind(wx.EVT_BUTTON,self.onImageTools) self.imagebox.Add(self.plot2Dimg,proportion=1,flag=wx.ALL|wx.EXPAND, border=10) self.imagebox.Add(self.btn_image, flag=wx.ALL, border=10) # def OKsizer(self): # ########################### # ## OK - CANCEL # self.okbox = wx.BoxSizer(wx.HORIZONTAL) # # okBtn = wx.Button(self.panel, wx.ID_OK ) # canBtn = wx.Button(self.panel, wx.ID_CANCEL ) # # self.okbox.Add(canBtn, flag=wx.RIGHT, border=5) # self.okbox.Add(okBtn, flag=wx.RIGHT, border=5) def write_message(self, s, panel=0): """write a message to the Status Bar""" self.SetStatusText(s, panel) def onImageTools(self,event): self.toolbox = ImageToolboxFrame(self.plot2Dimg,self.raw_img) def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw() def AutoContrast(self): self.minINT = int(np.min(self.raw_img)) self.maxINT = int(np.max(self.raw_img)/15) # /15 scales image to viewable if self.maxINT == self.minINT: self.minINT = self.minINT-50 self.maxINT = self.minINT+100 self.minCURRENT = self.minINT self.maxCURRENT = self.maxINT if self.maxCURRENT > self.maxINT: self.maxCURRENT = self.maxINT self.plot2Dimg.conf.auto_intensity = False self.plot2Dimg.conf.int_lo[0] = self.minCURRENT self.plot2Dimg.conf.int_hi[0] = self.maxCURRENT # self.plot2Dimg.conf.int_lo['int'] = self.minCURRENT # self.plot2Dimg.conf.int_hi['int'] = self.maxCURRENT ## vertical flip default self.plot2Dimg.conf.flip_ud = True self.plot2Dimg.conf.flip_lr = False self.plot2Dimg.redraw() def checkRANGE(self): if self.stepno <= 0: self.stepno = 0 self.btn_prev.Disable() else: self.btn_prev.Enable() if self.stepno >= 8: self.stepno = 8 self.btn_next.Disable() else: self.btn_next.Enable() def onNEXT(self, event): self.stepno = self.stepno + 1 self.checkRANGE() self.showDirection() def onPREVIOUS(self,event): self.stepno = self.stepno - 1 self.checkRANGE() self.showDirection() def showDirection(self): dirsteps = ['Enter parameters into the fields below.', 'Select point(s) on the first ring.', 'Select point(s) on the second ring.', 'Select point(s) on the third ring.', 'Select point(s) on the fourth ring.', 'Select point(s) on the fifth ring.', 'Select point(s) on the sixth ring.', 'Check preliminary calibration. Continue for final refinement.', 'Refinement complete.' ] self.followdir.SetLabel(dirsteps[self.stepno]) def openPONI(self,event): wildcards = 'pyFAI calibration file (*.poni)|*.poni|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose pyFAI calibration file', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: print self.ai = pyFAI.load(path) print('Loading calibration file: %s' % path) except: print('Not recognized as a pyFAI calibration file: %s' % path) return ## Sets viewer to values in .poni file self.entr_dist.SetValue('%0.4f' % self.ai._dist) self.entr_pix.SetValue('%0.1f' % float(self.ai.detector.pixel1*1000000.)) self.ch_DorP.SetSelection(1) self.entr_EorL.SetValue('%0.4f' % float(self.ai._wavelength*1.e10)) self.ch_EorL.SetSelection(1) self.onDorPSel(None) cenx = float(self.ai._poni1)/float(self.ai.detector.pixel1) ceny = float(self.ai._poni2)/float(self.ai.detector.pixel2) self.entr_cntrx.SetValue('%0.3f' % cenx) self.entr_cntry.SetValue('%0.3f' % ceny)
class MaskToolsPopup(wx.Frame): def __init__(self, parent): self.frame = wx.Frame.__init__(self, parent, title='Create mask', size=(800, 600)) self.parent = parent self.statusbar = self.CreateStatusBar(2, wx.CAPTION) try: self.raw_img = parent.plt_img ## raw_img or flp_img or plt_img mkak 2016.10.28 except: self.loadIMAGE() self.setDefaults() self.Init() self.Show() # wx.Window.GetEffectiveMinSize # wx.GetBestSize(self) def Init(self): self.panel = wx.Panel(self) self.MainSizer() self.framebox = wx.BoxSizer(wx.VERTICAL) self.framebox.Add(self.mainbox, flag=wx.ALL | wx.EXPAND, border=10) ########################### ## Pack all together in self.panel self.panel.SetSizer(self.framebox) def setDefaults(self): self.area_list = [] def MainSizer(self): self.mainbox = wx.BoxSizer(wx.VERTICAL) ########################### ## -----> Main Panel self.hmain = wx.BoxSizer(wx.HORIZONTAL) self.ImageSizer() self.DrawNewSizer() self.hmain.Add(self.imagebox, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.hmain.Add(self.toolbox, flag=wx.ALL, border=10) self.mainbox.Add(self.hmain, flag=wx.ALL | wx.EXPAND, border=10) def DrawNewSizer(self): self.toolbox = wx.BoxSizer(wx.VERTICAL) ########################### ## Directions nwbx = wx.StaticBox(self.panel, label='Drawing Tools', size=(100, 50)) drawbox = wx.StaticBoxSizer(nwbx, wx.VERTICAL) ########################### ## Drawing tools hbox_shp = wx.BoxSizer(wx.HORIZONTAL) self.txt_shp = wx.StaticText(self.panel, label='DRAWING SHAPE') shapes = ['circle', 'pixel', 'polygon', 'square'] self.ch_shp = wx.Choice(self.panel, choices=shapes) self.ch_shp.Bind(wx.EVT_CHOICE, self.ShapeChoice) hbox_shp.Add(self.txt_shp, flag=wx.RIGHT, border=8) hbox_shp.Add(self.ch_shp, flag=wx.EXPAND, border=8) drawbox.Add(hbox_shp, flag=wx.ALL | wx.EXPAND, border=10) ########################### ## Drawn Areas vbox_areas = wx.BoxSizer(wx.VERTICAL) hbox_areas = wx.BoxSizer(wx.HORIZONTAL) self.slct_area = wx.ListBox(self.panel, 26, wx.DefaultPosition, (170, 130), self.area_list, wx.LB_SINGLE) self.btn_SHWarea = wx.Button(self.panel, label='SHOW') self.btn_DELarea = wx.Button(self.panel, label='DELETE') self.btn_SHWarea.Bind(wx.EVT_BUTTON, self.showAREA) self.btn_DELarea.Bind(wx.EVT_BUTTON, self.deleteAREA) hbox_areas.Add(self.btn_SHWarea, flag=wx.BOTTOM, border=10) hbox_areas.Add(self.btn_DELarea, flag=wx.BOTTOM, border=10) self.btn_clear = wx.Button(self.panel, label='CLEAR ALL') self.btn_clear.Bind(wx.EVT_BUTTON, self.clearMask) vbox_areas.Add(self.slct_area, flag=wx.ALL | wx.EXPAND, border=10) vbox_areas.Add(hbox_areas, flag=wx.ALL | wx.EXPAND, border=10) vbox_areas.Add(self.btn_clear, flag=wx.ALL | wx.EXPAND, border=10) drawbox.Add(vbox_areas, flag=wx.ALL | wx.EXPAND, border=10) self.toolbox.Add(drawbox, flag=wx.ALL, border=10) self.btn_save = wx.Button(self.panel, label='SAVE MASK') self.btn_save.Bind(wx.EVT_BUTTON, self.saveMask) self.toolbox.Add(self.btn_save, flag=wx.ALL, border=10) self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable() def startIMAGE(self): self.loadIMAGE() def loadIMAGE(self, event=None): wildcards = 'XRD image (*.edf,*.tif,*.tiff)|*.tif;*.tiff;*.edf|All files (*.*)|*.*' dlg = wx.FileDialog(self, message='Choose XRD image', defaultDir=os.getcwd(), wildcard=wildcards, style=wx.FD_OPEN) path, read = None, False if dlg.ShowModal() == wx.ID_OK: read = True path = dlg.GetPath().replace('\\', '/') dlg.Destroy() if read: try: # self.raw_img = plt.imread(path) self.raw_img = tifffile.imread(path) #self.raw_img = fabio.open(path).data except: print('Image not properly opened.') self.raw_img = np.zeros((1024, 1024)) else: print('No image selected.') self.raw_img = np.zeros((1024, 1024)) def ImageSizer(self): ''' Image Panel ''' self.imagebox = wx.BoxSizer(wx.VERTICAL) self.plot2Dimage() imagetools = wx.BoxSizer(wx.HORIZONTAL) self.btn_image = wx.Button(self.panel, label='IMAGE TOOLS') self.btn_load = wx.Button(self.panel, label='CHANGE IMAGE') self.btn_image.Bind(wx.EVT_BUTTON, self.onImageTools) self.btn_load.Bind(wx.EVT_BUTTON, self.loadIMAGE) imagetools.Add(self.btn_load, flag=wx.ALL, border=10) imagetools.Add(self.btn_image, flag=wx.ALL, border=10) self.imagebox.Add(self.plot2Dimg, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.imagebox.Add(imagetools, flag=wx.ALL, border=10) def write_message(self, s, panel=0): """write a message to the Status Bar""" self.SetStatusText(s, panel) def onImageTools(self, event=None): self.toolbox = ImageToolboxFrame(self.plot2Dimg, self.raw_img) def plot2Dimage(self): self.plot2Dimg = ImagePanel(self.panel) #,size=(300, 300)) self.plot2Dimg.messenger = self.write_message self.Bind(wx.EVT_PAINT, self.OnPaint) self.plot2Dimg.display(self.raw_img) self.AutoContrast() self.plot2Dimg.redraw() def AutoContrast(self): self.minINT = int(np.min(self.raw_img)) self.maxINT = int(np.max(self.raw_img) / 15) # /15 scales image to viewable if self.maxINT == self.minINT: self.minINT = self.minINT - 50 self.maxINT = self.minINT + 100 self.minCURRENT = self.minINT self.maxCURRENT = self.maxINT if self.maxCURRENT > self.maxINT: self.maxCURRENT = self.maxINT self.plot2Dimg.conf.auto_intensity = False self.plot2Dimg.conf.int_lo[0] = self.minCURRENT self.plot2Dimg.conf.int_hi[0] = self.maxCURRENT # self.plot2Dimg.conf.int_lo['int'] = self.minCURRENT # self.plot2Dimg.conf.int_hi['int'] = self.maxCURRENT ## vertical flip default self.plot2Dimg.conf.flip_ud = True self.plot2Dimg.conf.flip_lr = False self.plot2Dimg.redraw() def ShapeChoice(self, event=None): print('The shape you choose: %s' % self.ch_shp.GetString(self.ch_shp.GetSelection())) print() print('Not implemented: ShapeChoice') self.addAREA() def OnPaint(self, event=None): print('Shape : %s' % self.ch_shp.GetString(self.ch_shp.GetSelection())) # dc = wx.PaintDC(self) # dc.Clear() # dc.SetPen(wx.Pen(wx.BLACK, 4)) # dc.DrawLine(0, 0, 50, 50) def clearMask(self, event=None): print('Clearing the mask...') ## provide a warning message? self.area_list = [] self.slct_area.Set(self.area_list) self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable() def saveMask(self, event=None): print('This will trigger the saving of a mask.') def addAREA(self, event=None): area_name = 'area %i (%s)' % (len( self.area_list), self.ch_shp.GetString(self.ch_shp.GetSelection())) self.area_list.append(area_name) self.slct_area.Set(self.area_list) if len(self.area_list) > 0: self.btn_SHWarea.Enable() self.btn_DELarea.Enable() self.btn_clear.Enable() self.btn_save.Enable() def showAREA(self, event=None): if len(self.area_list) > 0: area_str = self.slct_area.GetString(self.slct_area.GetSelection()) str_msg = 'Displaying: %s' % area_str self.write_message(str_msg, panel=0) ## show area on map, image def deleteAREA(self, event=None): if len(self.area_list) > 0: area_str = self.slct_area.GetString(self.slct_area.GetSelection()) str_msg = 'Deleting: %s' % area_str self.write_message(str_msg, panel=0) self.area_list.remove( self.slct_area.GetString(self.slct_area.GetSelection())) self.slct_area.Set(self.area_list) if len(self.area_list) == 0: self.btn_SHWarea.Disable() self.btn_DELarea.Disable() self.btn_clear.Disable() self.btn_save.Disable()
def panel2DXRDplot(self, panel): self.plot2D = ImagePanel(panel, size=(500, 500)) self.plot2D.messenger = self.write_message
def __init__(self, parent=None, size=None, mode='intensity', lasso_callback=None, output_title='Tomography Display Frame', subtitles=None, user_menus=None, **kws): if size is None: size = (1500, 600) self.lasso_callback = lasso_callback self.user_menus = user_menus self.cursor_menulabels = {} self.cursor_menulabels.update(CURSOR_MENULABELS) self.title = output_title self.det = None self.xrmfile = None self.wxmplot_version = get_wxmplot_version() BaseFrame.__init__(self, parent=parent, title = output_title, output_title=output_title, size=size, **kws) self.cmap_panels = {} self.subtitles = {} self.config_mode = None if subtitles is not None: self.subtitles = subtitles sbar_widths = [-2, -1, -1] sbar = self.CreateStatusBar(len(sbar_widths), wx.CAPTION) sfont = sbar.GetFont() sfont.SetWeight(wx.BOLD) sfont.SetPointSize(10) sbar.SetFont(sfont) self.SetStatusWidths(sbar_widths) self.optional_menus = [] self.bgcol = rgb2hex(self.GetBackgroundColour()[:3]) splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) splitter.SetMinimumPaneSize(225) self.config_panel = wx.Panel(splitter) self.main_panel = wx.Panel(splitter) img_opts = dict(size = (700, 525), dpi = 100, data_callback = self.onDataChange, lasso_callback = self.onLasso, output_title = self.output_title) self.tomo_frame = [TomoFrameClass(panel=ImagePanel(self.main_panel, **img_opts), label='Sinogram'), TomoFrameClass(panel=ImagePanel(self.main_panel, **img_opts), label='Tomograph')] for iframe in self.tomo_frame: iframe.panel.nstatusbar = sbar.GetFieldsCount() self.BuildMenu() self.SetBackgroundColour('#F8F8F4') self.imin_val = {} self.imax_val = {} self.islider_range = {} self.config_mode = 'int' if mode.lower().startswith('rgb'): self.config_mode = 'rgb' self.Build_ConfigPanel() for iframe in self.tomo_frame: kwargs = {'frame':iframe} iframe.panel.add_cursor_mode('prof', motion = partial(self.prof_motion, **kwargs), leftdown = partial(self.prof_leftdown, **kwargs), leftup = partial(self.prof_leftup, **kwargs)) iframe.panel.report_leftdown = partial(self.report_leftdown, **kwargs) iframe.panel.messenger = self.write_message self.prof_plotter = None self.zoom_ini = None self.lastpoint = [None, None] self.this_point = None self.rbbox = None lsty = wx.ALIGN_LEFT|wx.LEFT|wx.TOP|wx.EXPAND gsizer = wx.GridSizer(1, 2, 2, 2) lsty |= wx.GROW|wx.ALL|wx.EXPAND|wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL gsizer.Add(self.tomo_frame[0].panel, 1, lsty, 2) gsizer.Add(self.tomo_frame[1].panel, 1, lsty, 2) pack(self.main_panel, gsizer) splitter.SplitVertically(self.config_panel, self.main_panel, 1) mainsizer = wx.BoxSizer(wx.VERTICAL) mainsizer.Add(splitter, 1, wx.GROW|wx.ALL, 5) pack(self, mainsizer)