def __init__(self, app): self.app = app QtGui.QWidget.__init__(self, None) self.synthplot = EMPlot2DWidget(self.app) self.synthplot.show() # overall layout self.vbl1 = QtGui.QVBoxLayout() self.setLayout(self.vbl1) # First row contains general purpose controls self.hbl1 = QtGui.QHBoxLayout() self.vbl1.addLayout(self.hbl1) self.vcell = ValBox(self, (0, 128.0), "Cell:", 64) self.hbl1.addWidget(self.vcell) self.vncells = ValBox(self, (0, 128.0), "n Cells:", 1) self.hbl1.addWidget(self.vncells) self.voversamp = ValBox(self, (0, 128.0), "Oversample:", 1) self.hbl1.addWidget(self.voversamp) self.targfn = None self.vnsin = ValBox(self, (1, 64), "# Sin:", 16) self.vnsin.intonly = 1 self.hbl1.addWidget(self.vnsin) self.cbshowall = QtGui.QCheckBox("Show All") self.hbl1.addWidget(self.cbshowall) self.cbshifted = QtGui.QCheckBox("Shifted") self.hbl1.addWidget(self.cbshifted) self.cbtargfn = QtGui.QComboBox(self) self.cbtargfn.addItem("None") self.cbtargfn.addItem("triangle") self.cbtargfn.addItem("square") self.cbtargfn.addItem("square imp") self.cbtargfn.addItem("delta") self.cbtargfn.addItem("noise") self.cbtargfn.addItem("saw") self.cbtargfn.addItem("sin") self.cbtargfn.addItem("modsin") self.cbtargfn.addItem("modsin2") self.cbtargfn.addItem("modsin3") self.cbtargfn.addItem("sin low") self.cbtargfn.addItem("doubledelta") self.cbtargfn.addItem("sin bad f") self.cbtargfn.addItem("sin bad f2") self.hbl1.addWidget(self.cbtargfn) # Widget containing valsliders self.wapsliders = QtGui.QWidget(self) # self.wapsliders.setMinimumSize(800,640) self.gblap = QtGui.QGridLayout() self.gblap.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) self.gblap.setColumnMinimumWidth(0, 250) self.gblap.setColumnMinimumWidth(1, 250) self.wapsliders.setLayout(self.gblap) # ScrollArea providing view on slider container widget self.wapsarea = QtGui.QScrollArea(self) self.wapsarea.setWidgetResizable(True) self.wapsarea.setWidget(self.wapsliders) self.vbl1.addWidget(self.wapsarea) QtCore.QObject.connect(self.vcell, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vncells, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.voversamp, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vnsin, QtCore.SIGNAL("valueChanged"), self.nsinchange) QtCore.QObject.connect(self.cbshowall, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbshifted, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbtargfn, QtCore.SIGNAL("activated(int)"), self.newtargfn) self.wamp = [] self.wpha = [] self.curves = [] self.xvals = [] for i in range(65): self.wamp.append(ValSlider(self, (0.0, 1.0), "%2d:" % i, 0.0)) self.gblap.addWidget(self.wamp[-1], i, 0) QtCore.QObject.connect(self.wamp[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.wpha.append(ValSlider(self, (-180.0, 180.0), "%2d:" % i, 0.0)) self.gblap.addWidget(self.wpha[-1], i, 1) QtCore.QObject.connect(self.wpha[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.curves.append(EMData(64, 1)) if self.cbshowall.isChecked(): self.synthplot self.total = EMData(64, 1) self.nsinchange()
def __init__(self,imagenames,voltage=None,apix=None,cs=None,ac=10.0,box=256,ptcl=200): """The 'new' e2boxer interface. """ QtGui.QWidget.__init__(self,None) # self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png")) self.data=None self.curfilename = None # current selected file for boxing self.filenames=imagenames # list of available filenames self.micrograph=None self.boxes=None self.defaultvoltage=voltage self.defaultapix=apix self.defaultcs=cs self.defaultac=ac self.db = None # open JSON file for current image self.wimage=EMImage2DWidget() self.wimage.setWindowTitle("Micrograph") self.wparticles=EMImageMXWidget() self.wparticles.setWindowTitle("Particles") self.wrefs=EMImageMXWidget() self.wrefs.setWindowTitle("Box Refs") self.wbadrefs=EMImageMXWidget() self.wbadrefs.setWindowTitle("Bad Box Refs") #self.wfft=EMImage2DWidget() #self.wfft.setWindowTitle("e2evalimage - 2D FFT") #self.wplot=EMPlot2DWidget() #self.wplot.setWindowTitle("e2evalimage - Plot") self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedown"),self.imgmousedown) self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedrag"),self.imgmousedrag) self.wimage.connect(self.wimage,QtCore.SIGNAL("mouseup") ,self.imgmouseup) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mousedown"),self.ptclmousedown) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mousedrag"),self.ptclmousedrag) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mouseup") ,self.ptclmouseup) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mousedown"),self.refmousedown) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mousedrag"),self.refmousedrag) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mouseup") ,self.refmouseup) self.wimage.mmode="app" self.wparticles.mmode="app" # This object is itself a widget we need to set up self.gbl = QtGui.QGridLayout(self) self.gbl.setMargin(8) self.gbl.setSpacing(6) # Micrograph list self.setlist=QtGui.QListWidget(self) self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Expanding) for i in imagenames: self.setlist.addItem(i) self.gbl.addWidget(self.setlist,0,0,12,2) self.setlist.connect(self.setlist,QtCore.SIGNAL("currentRowChanged(int)"),self.newSet) self.setlist.connect(self.setlist,QtCore.SIGNAL("keypress"),self.listKey) # Mouse Modes self.mmode="manual" self.boxmm=QtGui.QGroupBox("Mouse Mode",self) self.boxmm.setFlat(False) self.gbl.addWidget(self.boxmm,0,2,3,2) self.hbl0=QtGui.QHBoxLayout(self.boxmm) self.bmmanual=QtGui.QPushButton("Manual") self.bmmanual.setToolTip("Manual selection of particles. No impact on autoselection.") self.bmmanual.setAutoExclusive(True) self.bmmanual.setCheckable(True) self.bmmanual.setChecked(True) self.hbl0.addWidget(self.bmmanual) self.bmdel=QtGui.QPushButton("Delete") self.bmdel.setToolTip("Delete particles from any mode. Can also shift-click in other mouse modes.") self.bmdel.setAutoExclusive(True) self.bmdel.setCheckable(True) self.hbl0.addWidget(self.bmdel) self.bmgref=QtGui.QPushButton("Good Refs") self.bmgref.setToolTip("Identify some good particles. Available to all autoboxers.") self.bmgref.setAutoExclusive(True) self.bmgref.setCheckable(True) self.hbl0.addWidget(self.bmgref) self.bmbref=QtGui.QPushButton("Bad Refs") self.bmbref.setToolTip("Identify regions which should not be selected as particles.") self.bmbref.setAutoExclusive(True) self.bmbref.setCheckable(True) self.hbl0.addWidget(self.bmbref) QtCore.QObject.connect(self.bmmanual,QtCore.SIGNAL("clicked(bool)"),self.setMouseManual) QtCore.QObject.connect(self.bmdel,QtCore.SIGNAL("clicked(bool)"),self.setMouseDel) QtCore.QObject.connect(self.bmgref,QtCore.SIGNAL("clicked(bool)"),self.setMouseGoodRef) QtCore.QObject.connect(self.bmbref,QtCore.SIGNAL("clicked(bool)"),self.setMouseBadRef) # Global parameters self.boxparm=QtGui.QGroupBox("Parameters",self) self.boxparm.setFlat(False) self.gbl.addWidget(self.boxparm,3,2,3,3) self.gbl1=QtGui.QGridLayout(self.boxparm) self.gbl1.setMargin(8) self.gbl1.setSpacing(6) self.vbbsize = ValBox(label="Box Size:",value=box) self.gbl1.addWidget(self.vbbsize,0,0) self.vbbpsize = ValBox(label="Ptcl Size:",value=ptcl) self.gbl1.addWidget(self.vbbpsize,0,1) self.vbbapix = ValBox(label="A/pix:",value=apix) self.gbl1.addWidget(self.vbbapix,0,2) self.vbvoltage = ValBox(label="Voltage:",value=voltage) self.gbl1.addWidget(self.vbvoltage,1,0) self.vbbac = ValBox(label="% AC:",value=ac) self.gbl1.addWidget(self.vbbac,1,1) self.vbcs = ValBox(label="Cs:",value=cs) self.gbl1.addWidget(self.vbcs,1,2) # Autoboxing Tabs self.autolbl = QtGui.QLabel("Autoboxing Methods:") self.gbl.addWidget(self.autolbl,7,2) self.autotab = QtGui.QTabWidget() self.gbl.addWidget(self.autotab,8,2,6,3) self.bautobox = QtGui.QPushButton("Autobox") self.gbl.addWidget(self.bautobox,7,4) QtCore.QObject.connect(self.bautobox,QtCore.SIGNAL("clicked(bool)"),self.doAutoBox) # Individual tabs from Dictionary self.abwid=[] for name,bname,cls in GUIBoxer.aboxmodes: w=QtGui.QWidget() gl=QtGui.QGridLayout(w) self.abwid.append((w,gl)) cls.setup_gui(gl) self.autotab.addTab(w,name) self.setWindowTitle("e2boxer21 - Control Panel") self.wimage.show() # self.wfft.show() # self.wplot.show() E2loadappwin("e2boxer21","main",self) E2loadappwin("e2boxer21","image",self.wimage.qt_parent) E2loadappwin("e2boxer21","particles",self.wparticles.qt_parent) E2loadappwin("e2boxer21","refs",self.wrefs.qt_parent) E2loadappwin("e2boxer21","badrefs",self.wbadrefs.qt_parent) self.newSet(0)
class GUIFourierSynth(QtGui.QWidget): """This class represents an application for interactive Fourier synthesis""" def __init__(self, app): self.app = app QtGui.QWidget.__init__(self, None) self.synthplot = EMPlot2DWidget(self.app) self.synthplot.show() # overall layout self.vbl1 = QtGui.QVBoxLayout() self.setLayout(self.vbl1) # First row contains general purpose controls self.hbl1 = QtGui.QHBoxLayout() self.vbl1.addLayout(self.hbl1) self.vcell = ValBox(self, (0, 128.0), "Cell:", 64) self.hbl1.addWidget(self.vcell) self.vncells = ValBox(self, (0, 128.0), "n Cells:", 1) self.hbl1.addWidget(self.vncells) self.voversamp = ValBox(self, (0, 128.0), "Oversample:", 1) self.hbl1.addWidget(self.voversamp) self.targfn = None self.vnsin = ValBox(self, (1, 64), "# Sin:", 16) self.vnsin.intonly = 1 self.hbl1.addWidget(self.vnsin) self.cbshowall = QtGui.QCheckBox("Show All") self.hbl1.addWidget(self.cbshowall) self.cbshifted = QtGui.QCheckBox("Shifted") self.hbl1.addWidget(self.cbshifted) self.cbtargfn = QtGui.QComboBox(self) self.cbtargfn.addItem("None") self.cbtargfn.addItem("triangle") self.cbtargfn.addItem("square") self.cbtargfn.addItem("square imp") self.cbtargfn.addItem("delta") self.cbtargfn.addItem("noise") self.cbtargfn.addItem("saw") self.cbtargfn.addItem("sin") self.cbtargfn.addItem("modsin") self.cbtargfn.addItem("modsin2") self.cbtargfn.addItem("modsin3") self.cbtargfn.addItem("sin low") self.cbtargfn.addItem("doubledelta") self.cbtargfn.addItem("sin bad f") self.cbtargfn.addItem("sin bad f2") self.hbl1.addWidget(self.cbtargfn) # Widget containing valsliders self.wapsliders = QtGui.QWidget(self) # self.wapsliders.setMinimumSize(800,640) self.gblap = QtGui.QGridLayout() self.gblap.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) self.gblap.setColumnMinimumWidth(0, 250) self.gblap.setColumnMinimumWidth(1, 250) self.wapsliders.setLayout(self.gblap) # ScrollArea providing view on slider container widget self.wapsarea = QtGui.QScrollArea(self) self.wapsarea.setWidgetResizable(True) self.wapsarea.setWidget(self.wapsliders) self.vbl1.addWidget(self.wapsarea) QtCore.QObject.connect(self.vcell, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vncells, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.voversamp, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vnsin, QtCore.SIGNAL("valueChanged"), self.nsinchange) QtCore.QObject.connect(self.cbshowall, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbshifted, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbtargfn, QtCore.SIGNAL("activated(int)"), self.newtargfn) self.wamp = [] self.wpha = [] self.curves = [] self.xvals = [] for i in range(65): self.wamp.append(ValSlider(self, (0.0, 1.0), "%2d:" % i, 0.0)) self.gblap.addWidget(self.wamp[-1], i, 0) QtCore.QObject.connect(self.wamp[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.wpha.append(ValSlider(self, (-180.0, 180.0), "%2d:" % i, 0.0)) self.gblap.addWidget(self.wpha[-1], i, 1) QtCore.QObject.connect(self.wpha[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.curves.append(EMData(64, 1)) if self.cbshowall.isChecked(): self.synthplot self.total = EMData(64, 1) self.nsinchange() def newtargfn(self, index): "This function has a number of hardcoded 'target' functions" if index == 0: self.targfn = None else: nx = int(self.vcell.getValue()) self.targfn = EMData(nx, 1) if index == 1: # triangle for i in xrange(nx / 2): self.targfn[i] = -1.0 + 4.0 * i / nx for i in xrange(nx / 2, nx): self.targfn[i] = 3.0 - 4.0 * i / nx elif index == 2: # square for i in xrange(nx / 4): self.targfn[i] = -1.0 for i in xrange(nx / 4, nx * 3 / 4): self.targfn[i] = 1.0 for i in xrange(nx * 3 / 4, nx): self.targfn[i] = -1.0 elif index == 3: # square impulse self.targfn.to_zero() for i in xrange(nx / 4, nx / 2): self.targfn[i] = 1.0 elif index == 4: # delta self.targfn.to_zero() self.targfn[nx * 2 / 5] = 1.0 elif index == 5: # noise self.targfn.process_inplace("testimage.noise.gauss", {"seed": 0}) elif index == 6: # saw self.targfn.to_zero() for i in xrange(nx / 4, nx / 2): self.targfn[i] = 4.0 * (i - nx / 4.0) / nx for i in xrange(nx / 2, nx * 3 / 4): self.targfn[i] = -1 + 4.0 * (i - nx / 2.0) / nx elif index == 7: # sin for i in xrange(nx): self.targfn[i] = sin(i * pi / 4.0) elif index == 8: # modulated sine for i in xrange(nx): self.targfn[i] = sin(i * pi / 4.0) * sin(i * pi / 32) elif index == 9: # modulated sine 2 for i in xrange(nx): self.targfn[i] = sin(i * pi / 4.0) * sin(i * pi / 29) elif index == 10: # modulated sine 3 for i in xrange(nx): self.targfn[i] = sin(i * pi / 4.0) * sin(i * pi / 126) elif index == 11: # sin low for i in xrange(nx): self.targfn[i] = sin(i * pi / 16.0) elif index == 12: # double delta self.targfn.to_zero() self.targfn[nx / 16] = 4.0 self.targfn[nx * 15 / 16] = 4.0 elif index == 13: # sin bad f for i in xrange(nx): self.targfn[i] = sin(i * pi / 15.5) elif index == 14: # sin bad f2 for i in xrange(nx): self.targfn[i] = sin(i * pi / 19) self.target2sliders() self.recompute() def target2sliders(self): nsin = int(self.vnsin.getValue()) # cp=self.targfn.process("xform.phaseorigin.tocenter") cp = self.targfn.copy() fft = cp.do_fft() fft[0] = fft[0] / 2.0 fft[fft["nx"] / 2 - 1] = fft[fft["nx"] / 2 - 1] / 2.0 fft.ri2ap() for i in xrange(min(fft["nx"] / 2, nsin + 1)): # print fft[i] amp = fft[i].real if fabs(amp) < 1.0e-5: amp = 0.0 self.wamp[i].setValue(amp * 2 / (fft["nx"] - 2), quiet=1) self.wpha[i].setValue(fft[i].imag * 180.0 / pi + 90.0, quiet=1) def nsinchange(self, value=None): if value == None: value = int(self.vnsin.getValue()) for i in range(65): if i > value: self.wamp[i].hide() self.wpha[i].hide() else: self.wamp[i].show() self.wpha[i].show() if self.targfn != None: self.target2sliders() self.recompute() def recompute(self, value=None): nsin = int(self.vnsin.getValue()) cell = int(self.vcell.getValue()) ncells = self.vncells.getValue() oversamp = int(self.voversamp.getValue()) samples = int(cell * ncells * oversamp) self.xvals = [xn / float(oversamp) for xn in range(samples)] self.total.set_size(samples) self.total.to_zero() for i in range(nsin + 1): self.curves[i].set_size(samples) if i == 0: self.curves[i].to_one() if self.wpha[0].getValue() > 180.0: self.curves[i].mult(-1.0) else: self.curves[i].process_inplace( "testimage.sinewave", { "wavelength": cell * oversamp / float(i), "phase": self.wpha[i].getValue() * pi / 180.0 }) self.curves[i].mult(self.wamp[i].getValue()) self.total.add(self.curves[i]) self.synthplot.set_data((self.xvals, self.total.get_data_as_vector()), "Sum", replace=True, quiet=True, linewidth=2) if self.targfn != None: self.synthplot.set_data(self.targfn, "Target", quiet=True, linewidth=1, linetype=2, symtype=0) if self.cbshowall.isChecked(): csum = self.total["minimum"] * 1.1 for i in range(nsin): if self.wamp[i].getValue() == 0: continue csum -= self.wamp[i].getValue() * 1.1 if self.cbshifted.isChecked(): self.curves[i].add(csum) self.synthplot.set_data( (self.xvals, self.curves[i].get_data_as_vector()), "%d" % i, quiet=True, linewidth=1, color=2) csum -= self.wamp[i].getValue() * 1.1 self.synthplot.updateGL()
class GUIBoxer(QtGui.QWidget): # Dictionary of autopickers # to add a new one, provide name:(Qt_setup_function,picker_execution_function) # Qt_setup_function(self,empty_grid_layout) # picker_execution_function(self,... aboxmodes = [ ("by Ref","auto_ref",boxerByRef), ("Gauss","auto_gauss",boxerGauss) ] boxcolors = { "selected":(0.9,0.9,0.9), "manual":(0,0,0), "refgood":(0,0.8,0), "refbad":(0.8,0,0), "unknown":[.4,.4,.1], "auto_ref":(.1,.1,.4), "auto_gauss":(.4,.1,.4) } def __init__(self,imagenames,voltage=None,apix=None,cs=None,ac=10.0,box=256,ptcl=200): """The 'new' e2boxer interface. """ QtGui.QWidget.__init__(self,None) # self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png")) self.data=None self.curfilename = None # current selected file for boxing self.filenames=imagenames # list of available filenames self.micrograph=None self.boxes=None self.defaultvoltage=voltage self.defaultapix=apix self.defaultcs=cs self.defaultac=ac self.db = None # open JSON file for current image self.wimage=EMImage2DWidget() self.wimage.setWindowTitle("Micrograph") self.wparticles=EMImageMXWidget() self.wparticles.setWindowTitle("Particles") self.wrefs=EMImageMXWidget() self.wrefs.setWindowTitle("Box Refs") self.wbadrefs=EMImageMXWidget() self.wbadrefs.setWindowTitle("Bad Box Refs") #self.wfft=EMImage2DWidget() #self.wfft.setWindowTitle("e2evalimage - 2D FFT") #self.wplot=EMPlot2DWidget() #self.wplot.setWindowTitle("e2evalimage - Plot") self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedown"),self.imgmousedown) self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedrag"),self.imgmousedrag) self.wimage.connect(self.wimage,QtCore.SIGNAL("mouseup") ,self.imgmouseup) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mousedown"),self.ptclmousedown) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mousedrag"),self.ptclmousedrag) self.wparticles.connect(self.wparticles,QtCore.SIGNAL("mouseup") ,self.ptclmouseup) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mousedown"),self.refmousedown) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mousedrag"),self.refmousedrag) self.wrefs.connect(self.wparticles,QtCore.SIGNAL("mouseup") ,self.refmouseup) self.wimage.mmode="app" self.wparticles.mmode="app" # This object is itself a widget we need to set up self.gbl = QtGui.QGridLayout(self) self.gbl.setMargin(8) self.gbl.setSpacing(6) # Micrograph list self.setlist=QtGui.QListWidget(self) self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Expanding) for i in imagenames: self.setlist.addItem(i) self.gbl.addWidget(self.setlist,0,0,12,2) self.setlist.connect(self.setlist,QtCore.SIGNAL("currentRowChanged(int)"),self.newSet) self.setlist.connect(self.setlist,QtCore.SIGNAL("keypress"),self.listKey) # Mouse Modes self.mmode="manual" self.boxmm=QtGui.QGroupBox("Mouse Mode",self) self.boxmm.setFlat(False) self.gbl.addWidget(self.boxmm,0,2,3,2) self.hbl0=QtGui.QHBoxLayout(self.boxmm) self.bmmanual=QtGui.QPushButton("Manual") self.bmmanual.setToolTip("Manual selection of particles. No impact on autoselection.") self.bmmanual.setAutoExclusive(True) self.bmmanual.setCheckable(True) self.bmmanual.setChecked(True) self.hbl0.addWidget(self.bmmanual) self.bmdel=QtGui.QPushButton("Delete") self.bmdel.setToolTip("Delete particles from any mode. Can also shift-click in other mouse modes.") self.bmdel.setAutoExclusive(True) self.bmdel.setCheckable(True) self.hbl0.addWidget(self.bmdel) self.bmgref=QtGui.QPushButton("Good Refs") self.bmgref.setToolTip("Identify some good particles. Available to all autoboxers.") self.bmgref.setAutoExclusive(True) self.bmgref.setCheckable(True) self.hbl0.addWidget(self.bmgref) self.bmbref=QtGui.QPushButton("Bad Refs") self.bmbref.setToolTip("Identify regions which should not be selected as particles.") self.bmbref.setAutoExclusive(True) self.bmbref.setCheckable(True) self.hbl0.addWidget(self.bmbref) QtCore.QObject.connect(self.bmmanual,QtCore.SIGNAL("clicked(bool)"),self.setMouseManual) QtCore.QObject.connect(self.bmdel,QtCore.SIGNAL("clicked(bool)"),self.setMouseDel) QtCore.QObject.connect(self.bmgref,QtCore.SIGNAL("clicked(bool)"),self.setMouseGoodRef) QtCore.QObject.connect(self.bmbref,QtCore.SIGNAL("clicked(bool)"),self.setMouseBadRef) # Global parameters self.boxparm=QtGui.QGroupBox("Parameters",self) self.boxparm.setFlat(False) self.gbl.addWidget(self.boxparm,3,2,3,3) self.gbl1=QtGui.QGridLayout(self.boxparm) self.gbl1.setMargin(8) self.gbl1.setSpacing(6) self.vbbsize = ValBox(label="Box Size:",value=box) self.gbl1.addWidget(self.vbbsize,0,0) self.vbbpsize = ValBox(label="Ptcl Size:",value=ptcl) self.gbl1.addWidget(self.vbbpsize,0,1) self.vbbapix = ValBox(label="A/pix:",value=apix) self.gbl1.addWidget(self.vbbapix,0,2) self.vbvoltage = ValBox(label="Voltage:",value=voltage) self.gbl1.addWidget(self.vbvoltage,1,0) self.vbbac = ValBox(label="% AC:",value=ac) self.gbl1.addWidget(self.vbbac,1,1) self.vbcs = ValBox(label="Cs:",value=cs) self.gbl1.addWidget(self.vbcs,1,2) # Autoboxing Tabs self.autolbl = QtGui.QLabel("Autoboxing Methods:") self.gbl.addWidget(self.autolbl,7,2) self.autotab = QtGui.QTabWidget() self.gbl.addWidget(self.autotab,8,2,6,3) self.bautobox = QtGui.QPushButton("Autobox") self.gbl.addWidget(self.bautobox,7,4) QtCore.QObject.connect(self.bautobox,QtCore.SIGNAL("clicked(bool)"),self.doAutoBox) # Individual tabs from Dictionary self.abwid=[] for name,bname,cls in GUIBoxer.aboxmodes: w=QtGui.QWidget() gl=QtGui.QGridLayout(w) self.abwid.append((w,gl)) cls.setup_gui(gl) self.autotab.addTab(w,name) self.setWindowTitle("e2boxer21 - Control Panel") self.wimage.show() # self.wfft.show() # self.wplot.show() E2loadappwin("e2boxer21","main",self) E2loadappwin("e2boxer21","image",self.wimage.qt_parent) E2loadappwin("e2boxer21","particles",self.wparticles.qt_parent) E2loadappwin("e2boxer21","refs",self.wrefs.qt_parent) E2loadappwin("e2boxer21","badrefs",self.wbadrefs.qt_parent) self.newSet(0) #QWidget *firstPageWidget = new QWidget; #QWidget *secondPageWidget = new QWidget; #QWidget *thirdPageWidget = new QWidget; #QStackedWidget *stackedWidget = new QStackedWidget; #stackedWidget->addWidget(firstPageWidget); #stackedWidget->addWidget(secondPageWidget); #stackedWidget->addWidget(thirdPageWidget); #QVBoxLayout *layout = new QVBoxLayout; #layout->addWidget(stackedWidget); #setLayout(layout); #QComboBox *pageComboBox = new QComboBox; #pageComboBox->addItem(tr("Page 1")); #pageComboBox->addItem(tr("Page 2")); #pageComboBox->addItem(tr("Page 3")); #connect(pageComboBox, SIGNAL(activated(int)),stackedWidget, SLOT(setCurrentIndex(int))); #self.lboxmode=QtGui.QLabel("Mode:",self) #self.gbl.addWidget(self.lboxmode,10,0) #self.sboxmode=QtGui.QComboBox(self) #self.sboxmode.addItem("Manual") #self.sboxmode.addItem("Reference") #self.sboxmode.setCurrentIndex(1) #self.gbl.addWidget(self.sboxmode,10,1) #self.lanmode=QtGui.QLabel("Annotate:",self) #self.gbl.addWidget(self.lanmode,12,0) #self.sanmode=QtGui.QComboBox(self) #self.sanmode.addItem("Box") #self.sanmode.addItem("Box+dot") #self.sanmode.addItem("Circle") #self.sanmode.addItem("None") #self.gbl.addWidget(self.sanmode,12,1) #self.sdefocus=ValSlider(self,(0,5),"Defocus:",0.0,90) #self.gbl.addWidget(self.sdefocus,0,2,1,3) #self.squality=ValSlider(self,(0,9),"Quality (0-9):",0,90) #self.squality.setIntonly(True) #self.gbl.addWidget(self.squality,6,2,1,3) #self.brefit=QtGui.QPushButton("Autobox") #self.gbl.addWidget(self.brefit,7,2) #self.bclrauto=QtGui.QPushButton("Clear Auto") #self.gbl.addWidget(self.bclrauto,7,3) #self.bclrall=QtGui.QPushButton("Clear All") #self.gbl.addWidget(self.bclrall,7,4) #self.sapix=ValBox(self,(0,500),"A/pix:",1.0,90) #if self.defaultapix!=None : self.sapix.setValue(self.defaultapix) #self.gbl.addWidget(self.sapix,10,2) #self.svoltage=ValBox(self,(0,500),"Voltage (kV):",200,90) #if self.defaultvoltage!=None : self.svoltage.setValue(self.defaultvoltage) #self.gbl.addWidget(self.svoltage,11,2) #self.scs=ValBox(self,(0,5),"Cs (mm):",4.1,90) #if self.defaultcs!=None : self.scs.setValue(self.defaultcs) #self.gbl.addWidget(self.scs,12,2) #self.sboxsize=ValBox(self,(0,500),"Box Size:",256,90) #self.sboxsize.intonly=True #self.gbl.addWidget(self.sboxsize,13,2) #self.sptclsize=ValBox(self,(0,500),"Ptcl Size:",256,90) #self.sptclsize.intonly=True #self.gbl.addWidget(self.sptclsize,14,2) #QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.sboxsize, QtCore.SIGNAL("valueChanged"), self.newBox) ## QtCore.QObject.connect(self.soversamp, QtCore.SIGNAL("valueChanged"), self.newBox) #QtCore.QObject.connect(self.squality,QtCore.SIGNAL("valueChanged"),self.newQualityFactor) #QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("currentRowChanged(int)"),self.newSet) #QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("keypress"),self.listkey) #QtCore.QObject.connect(self.sboxmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.newBoxMode) #self.resize(720,380) # figured these values out by printing the width and height in resize event #### This section is responsible for background updates #self.busy=False #self.needupdate=True #self.needredisp=False #self.procthread=None #self.errors=None # used to communicate errors back from the reprocessing thread #self.timer=QTimer() #QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.timeOut) #self.timer.start(100) # self.recalc() def setMouseManual(self,x): self.mmode="manual" def setMouseDel(self,x): self.mmode="del" def setMouseGoodRef(self,x): self.mmode="refgood" def setMouseBadRef(self,x): self.mmode="refbad" def imgmousedown(self,event) : m=self.wimage.scr_to_img((event.x(),event.y())) boxsize2=self.vbbsize.getValue()//2 ptclsize=self.vbbpsize.getValue() self.curbox=0 # check to see if click was inside an existing box, in which case we move it for i in self.boxes: if abs(m.x-i[0])<boxsize2 and abs(m.y-i[1])<boxsize2 : self.curbox=i break else : # Create a new box if self.mmode=="del" : return # This is for creating a new box, so clearly not desirable in delete mode self.curbox=len(self.boxes) self.boxes.append((m[0],m[1],self.mmode)) self.__addBox(self.curbox,self.boxes[-1]) #self.guiim.add_shape("cen",["rect",.9,.9,.4,x0,y0,x0+2,y0+2,1.0]) def imgmousedrag(self,event) : if self.calcmode==0: m=self.wimage.scr_to_img((event.x(),event.y())) parms=self.parms[self.curset] parms[2]=(m[0]-parms[0]/2,m[1]-parms[0]/2) self.needredisp=True self.recalc() # box deletion when shift held down #if event.modifiers()&Qt.ShiftModifier: #for i,j in enumerate(self.boxes): def imgmouseup(self,event) : m=self.wimage.scr_to_img((event.x(),event.y())) if self.calcmode==1: parms=self.parms[self.curset] nx=self.data["nx"]/parms[0]-1 grid=int((m[0]-parms[0]/2)/parms[0])+int((m[1]-parms[0]/2)/parms[0])*nx if grid in parms[3] : parms[3].remove(grid) else: parms[3].add(grid) self.needredisp=True self.recalc() def ptclmousedown(self,event) : return def ptclmousedrag(self,event) : return def ptclmouseup(self,event) : return def refmousedown(self,event) : return def refmousedrag(self,event) : return def refmouseup(self,event) : return def newSet(self,val): "called when a new data set is selected from the list" first=True newfilename=str(self.setlist.item(val).text()) if newfilename==self.curfilename : return # Write the current image parameters to the database if self.curfilename!=None and self.boxes!=None : self.save_boxes() first=False self.micrograph=load_micrograph(newfilename) self.wimage.set_data(self.micrograph) if first : E2loadappwin("e2boxer21","image",self.wimage.qt_parent) self.curfilename=newfilename self.restore_boxes() def save_boxes(self): js=js_open_dict(info_name(self.curfilename)) js["boxes"]=self.boxes def restore_boxes(self): # first we restore the list of box locations js=js_open_dict(info_name(self.curfilename)) try: self.boxes=js["boxes"] except: self.boxes=[] boxsize=self.vbbsize.getValue() ptclsize=self.vbbpsize.getValue() micro=self.wimage.get_data() self.wimage.del_shapes() if len(self.boxes)==0 : self.wparticles.set_data([]) return # Then we extract the actual boxed out particles goodrefs=[] badrefs=[] self.particles=[] for i,box in enumerate(self.boxes): self.__addBox(i,box) # extract the data boxim=self.micrograph.get_clip(Region(box[0]-boxsize//2,box[1]-boxsize//2,boxsize,boxsize)) boxim["ptcl_source_coord"]=(box[0],box[1]) if box[2]=="refgood": goodrefs.append(boxim) elif box[2]=="refbad": badrefs.append(boxim) else: self.particles.append(boxim) # finally redisplay as appropriate self.wimage.update() self.wparticles.set_data(self.particles) if len(self.particles)>0 : self.wparticles.show() if len(goodrefs)+len(badrefs)!=0: self.goodrefs=goodrefs self.badrefs=badrefs self.wrefs.set_data(self.goodrefs) self.wbadrefs.set_data(self.badrefs) if len(self.goodrefs)>0 : self.wrefs.show() if len(self.badrefs)>0 : self.wbadrefs.show() def __addBox(self,i,box): """takes the number of the box in self.boxes and the (x,y,mode) tuple and displays it""" # Display the actual box boxsize=self.vbbsize.getValue() ptclsize=self.vbbpsize.getValue() try: color=self.boxcolors[box[2]] except: color=self.boxcolors["unknown"] self.wimage.add_shape("box{}".format(i),EMShape(("rect",color[0],color[1],color[2],box[0]-boxsize//2,box[1]-boxsize//2,box[0]+boxsize//2,box[1]+boxsize//2,2))) self.wimage.add_shape("cir{}".format(i),EMShape(("circle",color[0],color[1],color[2],box[0],box[1],ptclsize/2,1.5))) def listKey(self,event): pass #if event.key()>=Qt.Key_0 and event.key()<=Qt.Key_9 : #q=int(event.key())-Qt.Key_0 #self.squality.setValue(q) #elif event.key() == Qt.Key_Left: #self.sdefocus.setValue(self.sdefocus.getValue()-0.03) #elif event.key() == Qt.Key_Right: #self.sdefocus.setValue(self.sdefocus.getValue()+0.03) #elif event.key()==Qt.Key_I : #self.doImport() #elif event.key()==Qt.Key_U : #self.unImport() def doAutoBox(self,b): """Autobox button pressed, find the right algorithm and call it""" name,bname,fn1=self.aboxmodes[self.autotab.currentIndex()] print name," called" def closeEvent(self,event): # QtGui.QWidget.closeEvent(self,event) E2saveappwin("e2boxer21","main",self) E2saveappwin("e2boxer21","image",self.wimage.qt_parent) E2saveappwin("e2boxer21","particles",self.wparticles.qt_parent) E2saveappwin("e2boxer21","refs",self.wrefs.qt_parent) E2saveappwin("e2boxer21","badrefs",self.wbadrefs.qt_parent) #self.writeCurParm() event.accept() QtGui.qApp.exit(0)
def __init__(self,app): self.app=app QtGui.QWidget.__init__(self,None) self.synthplot=EMPlot2DWidget(self.app) self.synthplot.show() # overall layout self.vbl1=QtGui.QVBoxLayout() self.setLayout(self.vbl1) # First row contains general purpose controls self.hbl1=QtGui.QHBoxLayout() self.vbl1.addLayout(self.hbl1) self.vcell=ValBox(self,(0,128.0),"Cell:",64) self.hbl1.addWidget(self.vcell) self.vncells=ValBox(self,(0,128.0),"n Cells:",1) self.hbl1.addWidget(self.vncells) self.voversamp=ValBox(self,(0,128.0),"Oversample:",1) self.hbl1.addWidget(self.voversamp) self.targfn=None self.vnsin=ValBox(self,(1,64),"# Sin:",16) self.vnsin.intonly=1 self.hbl1.addWidget(self.vnsin) self.cbshowall=QtGui.QCheckBox("Show All") self.hbl1.addWidget(self.cbshowall) self.cbshifted=QtGui.QCheckBox("Shifted") self.hbl1.addWidget(self.cbshifted) self.cbtargfn=QtGui.QComboBox(self) self.cbtargfn.addItem("None") self.cbtargfn.addItem("triangle") self.cbtargfn.addItem("square") self.cbtargfn.addItem("square imp") self.cbtargfn.addItem("delta") self.cbtargfn.addItem("noise") self.cbtargfn.addItem("saw") self.cbtargfn.addItem("sin") self.cbtargfn.addItem("modsin") self.cbtargfn.addItem("modsin2") self.cbtargfn.addItem("modsin3") self.cbtargfn.addItem("sin low") self.cbtargfn.addItem("doubledelta") self.hbl1.addWidget(self.cbtargfn) # Widget containing valsliders self.wapsliders=QtGui.QWidget(self) # self.wapsliders.setMinimumSize(800,640) self.gblap=QtGui.QGridLayout() self.gblap.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) self.gblap.setColumnMinimumWidth(0,250) self.gblap.setColumnMinimumWidth(1,250) self.wapsliders.setLayout(self.gblap) # ScrollArea providing view on slider container widget self.wapsarea=QtGui.QScrollArea(self) self.wapsarea.setWidgetResizable(True) self.wapsarea.setWidget(self.wapsliders) self.vbl1.addWidget(self.wapsarea) QtCore.QObject.connect(self.vcell, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vncells, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.voversamp, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vnsin, QtCore.SIGNAL("valueChanged"), self.nsinchange) QtCore.QObject.connect(self.cbshowall, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbshifted, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbtargfn,QtCore.SIGNAL("activated(int)"),self.newtargfn) self.wamp=[] self.wpha=[] self.curves=[] self.xvals=[] for i in range(65): self.wamp.append(ValSlider(self,(0.0,1.0),"%2d:"%i,0.0)) self.gblap.addWidget(self.wamp[-1],i,0) QtCore.QObject.connect(self.wamp[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.wpha.append(ValSlider(self,(-180.0,180.0),"%2d:"%i,0.0)) self.gblap.addWidget(self.wpha[-1],i,1) QtCore.QObject.connect(self.wpha[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.curves.append(EMData(64,1)) if self.cbshowall.isChecked() : self.synthplot self.total=EMData(64,1) self.nsinchange()
class GUIFourierSynth(QtGui.QWidget): """This class represents an application for interactive Fourier synthesis""" def __init__(self,app): self.app=app QtGui.QWidget.__init__(self,None) self.synthplot=EMPlot2DWidget(self.app) self.synthplot.show() # overall layout self.vbl1=QtGui.QVBoxLayout() self.setLayout(self.vbl1) # First row contains general purpose controls self.hbl1=QtGui.QHBoxLayout() self.vbl1.addLayout(self.hbl1) self.vcell=ValBox(self,(0,128.0),"Cell:",64) self.hbl1.addWidget(self.vcell) self.vncells=ValBox(self,(0,128.0),"n Cells:",1) self.hbl1.addWidget(self.vncells) self.voversamp=ValBox(self,(0,128.0),"Oversample:",1) self.hbl1.addWidget(self.voversamp) self.targfn=None self.vnsin=ValBox(self,(1,64),"# Sin:",16) self.vnsin.intonly=1 self.hbl1.addWidget(self.vnsin) self.cbshowall=QtGui.QCheckBox("Show All") self.hbl1.addWidget(self.cbshowall) self.cbshifted=QtGui.QCheckBox("Shifted") self.hbl1.addWidget(self.cbshifted) self.cbtargfn=QtGui.QComboBox(self) self.cbtargfn.addItem("None") self.cbtargfn.addItem("triangle") self.cbtargfn.addItem("square") self.cbtargfn.addItem("square imp") self.cbtargfn.addItem("delta") self.cbtargfn.addItem("noise") self.cbtargfn.addItem("saw") self.cbtargfn.addItem("sin") self.cbtargfn.addItem("modsin") self.cbtargfn.addItem("modsin2") self.cbtargfn.addItem("modsin3") self.cbtargfn.addItem("sin low") self.cbtargfn.addItem("doubledelta") self.hbl1.addWidget(self.cbtargfn) # Widget containing valsliders self.wapsliders=QtGui.QWidget(self) # self.wapsliders.setMinimumSize(800,640) self.gblap=QtGui.QGridLayout() self.gblap.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) self.gblap.setColumnMinimumWidth(0,250) self.gblap.setColumnMinimumWidth(1,250) self.wapsliders.setLayout(self.gblap) # ScrollArea providing view on slider container widget self.wapsarea=QtGui.QScrollArea(self) self.wapsarea.setWidgetResizable(True) self.wapsarea.setWidget(self.wapsliders) self.vbl1.addWidget(self.wapsarea) QtCore.QObject.connect(self.vcell, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vncells, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.voversamp, QtCore.SIGNAL("valueChanged"), self.recompute) QtCore.QObject.connect(self.vnsin, QtCore.SIGNAL("valueChanged"), self.nsinchange) QtCore.QObject.connect(self.cbshowall, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbshifted, QtCore.SIGNAL("stateChanged(int)"), self.recompute) QtCore.QObject.connect(self.cbtargfn,QtCore.SIGNAL("activated(int)"),self.newtargfn) self.wamp=[] self.wpha=[] self.curves=[] self.xvals=[] for i in range(65): self.wamp.append(ValSlider(self,(0.0,1.0),"%2d:"%i,0.0)) self.gblap.addWidget(self.wamp[-1],i,0) QtCore.QObject.connect(self.wamp[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.wpha.append(ValSlider(self,(-180.0,180.0),"%2d:"%i,0.0)) self.gblap.addWidget(self.wpha[-1],i,1) QtCore.QObject.connect(self.wpha[-1], QtCore.SIGNAL("valueChanged"), self.recompute) self.curves.append(EMData(64,1)) if self.cbshowall.isChecked() : self.synthplot self.total=EMData(64,1) self.nsinchange() def newtargfn(self,index): "This function has a number of hardcoded 'target' functions" if index==0 : self.targfn=None else : nx=int(self.vcell.getValue()) self.targfn=EMData(nx,1) if index==1 : # triangle for i in xrange(nx/2): self.targfn[i]=-1.0+4.0*i/nx for i in xrange(nx/2,nx): self.targfn[i]=3.0-4.0*i/nx elif index==2 : # square for i in xrange(nx/4): self.targfn[i]=-1.0 for i in xrange(nx/4,nx*3/4): self.targfn[i]=1.0 for i in xrange(nx*3/4,nx): self.targfn[i]=-1.0 elif index==3 : # square impulse self.targfn.to_zero() for i in xrange(nx/4,nx/2): self.targfn[i]=1.0 elif index==4 : # delta self.targfn.to_zero() self.targfn[nx*2/5]=1.0 elif index==5 : # noise self.targfn.process_inplace("testimage.noise.gauss",{"seed":0}) elif index==6 : # saw self.targfn.to_zero() for i in xrange(nx/4,nx/2): self.targfn[i]=4.0*(i-nx/4.0)/nx for i in xrange(nx/2,nx*3/4): self.targfn[i]=-1+4.0*(i-nx/2.0)/nx elif index==7 : # sin for i in xrange(nx): self.targfn[i]=sin(i*pi/4.0) elif index==8 : # modulated sine for i in xrange(nx): self.targfn[i]=sin(i*pi/4.0)*sin(i*pi/32) elif index==9 : # modulated sine 2 for i in xrange(nx): self.targfn[i]=sin(i*pi/4.0)*sin(i*pi/29) elif index==10 : # modulated sine 3 for i in xrange(nx): self.targfn[i]=sin(i*pi/4.0)*sin(i*pi/126) elif index==11 : # sin low for i in xrange(nx): self.targfn[i]=sin(i*pi/16.0) elif index==12 : # double delta self.targfn.to_zero() self.targfn[nx/16]=4.0 self.targfn[nx*15/16]=4.0 self.target2sliders() self.recompute() def target2sliders(self): nsin=int(self.vnsin.getValue()) # cp=self.targfn.process("xform.phaseorigin.tocenter") cp=self.targfn.copy() fft=cp.do_fft() fft[0]=fft[0]/2.0 fft[fft["nx"]/2-1]=fft[fft["nx"]/2-1]/2.0 fft.ri2ap() for i in xrange(min(fft["nx"]/2,nsin+1)): # print fft[i] amp=fft[i].real if fabs(amp)<1.0e-5 : amp=0.0 self.wamp[i].setValue(amp*2/(fft["nx"]-2),quiet=1) self.wpha[i].setValue(fft[i].imag*180.0/pi+90.0,quiet=1) def nsinchange(self,value=None): if value==None : value=int(self.vnsin.getValue()) for i in range(65): if i>value: self.wamp[i].hide() self.wpha[i].hide() else : self.wamp[i].show() self.wpha[i].show() if self.targfn!=None : self.target2sliders() self.recompute() def recompute(self,value=None): nsin=int(self.vnsin.getValue()) cell=int(self.vcell.getValue()) ncells=self.vncells.getValue() oversamp=int(self.voversamp.getValue()) samples=int(cell*ncells*oversamp) self.xvals=[xn/float(oversamp) for xn in range(samples)] self.total.set_size(samples) self.total.to_zero() for i in range(nsin+1): self.curves[i].set_size(samples) if i==0: self.curves[i].to_one() if self.wpha[0].getValue()>180.0 : self.curves[i].mult(-1.0) else: self.curves[i].process_inplace("testimage.sinewave",{"wavelength":cell*oversamp/float(i),"phase":self.wpha[i].getValue()*pi/180.0}) self.curves[i].mult(self.wamp[i].getValue()) self.total.add(self.curves[i]) self.synthplot.set_data((self.xvals,self.total.get_data_as_vector()),"Sum",replace=True,quiet=True,linewidth=2) if self.targfn!=None: self.synthplot.set_data(self.targfn,"Target",quiet=True,linewidth=1,linetype=2,symtype=0) if self.cbshowall.isChecked() : csum=self.total["minimum"]*1.1 for i in range(nsin): if self.wamp[i].getValue()==0: continue csum-=self.wamp[i].getValue()*1.1 if self.cbshifted.isChecked() : self.curves[i].add(csum) self.synthplot.set_data((self.xvals,self.curves[i].get_data_as_vector()),"%d"%i,quiet=True,linewidth=1,color=2) csum-=self.wamp[i].getValue()*1.1 self.synthplot.updateGL()
def __init__(self, imagenames, voltage=None, apix=None, cs=None, ac=10.0, box=256, ptcl=200): """The 'new' e2boxer interface. """ QtGui.QWidget.__init__(self, None) # self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png")) self.data = None self.curfilename = None # current selected file for boxing self.filenames = imagenames # list of available filenames self.micrograph = None self.boxes = None self.defaultvoltage = voltage self.defaultapix = apix self.defaultcs = cs self.defaultac = ac self.db = None # open JSON file for current image self.wimage = EMImage2DWidget() self.wimage.setWindowTitle("Micrograph") self.wparticles = EMImageMXWidget() self.wparticles.setWindowTitle("Particles") self.wrefs = EMImageMXWidget() self.wrefs.setWindowTitle("Box Refs") self.wbadrefs = EMImageMXWidget() self.wbadrefs.setWindowTitle("Bad Box Refs") #self.wfft=EMImage2DWidget() #self.wfft.setWindowTitle("e2evalimage - 2D FFT") #self.wplot=EMPlot2DWidget() #self.wplot.setWindowTitle("e2evalimage - Plot") self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedown"), self.imgmousedown) self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedrag"), self.imgmousedrag) self.wimage.connect(self.wimage, QtCore.SIGNAL("mouseup"), self.imgmouseup) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedown"), self.ptclmousedown) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedrag"), self.ptclmousedrag) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mouseup"), self.ptclmouseup) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedown"), self.refmousedown) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedrag"), self.refmousedrag) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mouseup"), self.refmouseup) self.wimage.mmode = "app" self.wparticles.mmode = "app" # This object is itself a widget we need to set up self.gbl = QtGui.QGridLayout(self) self.gbl.setMargin(8) self.gbl.setSpacing(6) # Micrograph list self.setlist = QtGui.QListWidget(self) self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) for i in imagenames: self.setlist.addItem(i) self.gbl.addWidget(self.setlist, 0, 0, 12, 2) self.setlist.connect(self.setlist, QtCore.SIGNAL("currentRowChanged(int)"), self.newSet) self.setlist.connect(self.setlist, QtCore.SIGNAL("keypress"), self.listKey) # Mouse Modes self.mmode = "manual" self.boxmm = QtGui.QGroupBox("Mouse Mode", self) self.boxmm.setFlat(False) self.gbl.addWidget(self.boxmm, 0, 2, 3, 2) self.hbl0 = QtGui.QHBoxLayout(self.boxmm) self.bmmanual = QtGui.QPushButton("Manual") self.bmmanual.setToolTip( "Manual selection of particles. No impact on autoselection.") self.bmmanual.setAutoExclusive(True) self.bmmanual.setCheckable(True) self.bmmanual.setChecked(True) self.hbl0.addWidget(self.bmmanual) self.bmdel = QtGui.QPushButton("Delete") self.bmdel.setToolTip( "Delete particles from any mode. Can also shift-click in other mouse modes." ) self.bmdel.setAutoExclusive(True) self.bmdel.setCheckable(True) self.hbl0.addWidget(self.bmdel) self.bmgref = QtGui.QPushButton("Good Refs") self.bmgref.setToolTip( "Identify some good particles. Available to all autoboxers.") self.bmgref.setAutoExclusive(True) self.bmgref.setCheckable(True) self.hbl0.addWidget(self.bmgref) self.bmbref = QtGui.QPushButton("Bad Refs") self.bmbref.setToolTip( "Identify regions which should not be selected as particles.") self.bmbref.setAutoExclusive(True) self.bmbref.setCheckable(True) self.hbl0.addWidget(self.bmbref) QtCore.QObject.connect(self.bmmanual, QtCore.SIGNAL("clicked(bool)"), self.setMouseManual) QtCore.QObject.connect(self.bmdel, QtCore.SIGNAL("clicked(bool)"), self.setMouseDel) QtCore.QObject.connect(self.bmgref, QtCore.SIGNAL("clicked(bool)"), self.setMouseGoodRef) QtCore.QObject.connect(self.bmbref, QtCore.SIGNAL("clicked(bool)"), self.setMouseBadRef) # Global parameters self.boxparm = QtGui.QGroupBox("Parameters", self) self.boxparm.setFlat(False) self.gbl.addWidget(self.boxparm, 3, 2, 3, 3) self.gbl1 = QtGui.QGridLayout(self.boxparm) self.gbl1.setMargin(8) self.gbl1.setSpacing(6) self.vbbsize = ValBox(label="Box Size:", value=box) self.gbl1.addWidget(self.vbbsize, 0, 0) self.vbbpsize = ValBox(label="Ptcl Size:", value=ptcl) self.gbl1.addWidget(self.vbbpsize, 0, 1) self.vbbapix = ValBox(label="A/pix:", value=apix) self.gbl1.addWidget(self.vbbapix, 0, 2) self.vbvoltage = ValBox(label="Voltage:", value=voltage) self.gbl1.addWidget(self.vbvoltage, 1, 0) self.vbbac = ValBox(label="% AC:", value=ac) self.gbl1.addWidget(self.vbbac, 1, 1) self.vbcs = ValBox(label="Cs:", value=cs) self.gbl1.addWidget(self.vbcs, 1, 2) # Autoboxing Tabs self.autolbl = QtGui.QLabel("Autoboxing Methods:") self.gbl.addWidget(self.autolbl, 7, 2) self.autotab = QtGui.QTabWidget() self.gbl.addWidget(self.autotab, 8, 2, 6, 3) self.bautobox = QtGui.QPushButton("Autobox") self.gbl.addWidget(self.bautobox, 7, 4) QtCore.QObject.connect(self.bautobox, QtCore.SIGNAL("clicked(bool)"), self.doAutoBox) # Individual tabs from Dictionary self.abwid = [] for name, bname, cls in GUIBoxer.aboxmodes: w = QtGui.QWidget() gl = QtGui.QGridLayout(w) self.abwid.append((w, gl)) cls.setup_gui(gl) self.autotab.addTab(w, name) self.setWindowTitle("e2boxer21 - Control Panel") self.wimage.show() # self.wfft.show() # self.wplot.show() E2loadappwin("e2boxer21", "main", self) E2loadappwin("e2boxer21", "image", self.wimage.qt_parent) E2loadappwin("e2boxer21", "particles", self.wparticles.qt_parent) E2loadappwin("e2boxer21", "refs", self.wrefs.qt_parent) E2loadappwin("e2boxer21", "badrefs", self.wbadrefs.qt_parent) self.newSet(0)
class GUIBoxer(QtGui.QWidget): # Dictionary of autopickers # to add a new one, provide name:(Qt_setup_function,picker_execution_function) # Qt_setup_function(self,empty_grid_layout) # picker_execution_function(self,... aboxmodes = [("by Ref", "auto_ref", boxerByRef), ("Gauss", "auto_gauss", boxerGauss)] boxcolors = { "selected": (0.9, 0.9, 0.9), "manual": (0, 0, 0), "refgood": (0, 0.8, 0), "refbad": (0.8, 0, 0), "unknown": [.4, .4, .1], "auto_ref": (.1, .1, .4), "auto_gauss": (.4, .1, .4) } def __init__(self, imagenames, voltage=None, apix=None, cs=None, ac=10.0, box=256, ptcl=200): """The 'new' e2boxer interface. """ QtGui.QWidget.__init__(self, None) # self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png")) self.data = None self.curfilename = None # current selected file for boxing self.filenames = imagenames # list of available filenames self.micrograph = None self.boxes = None self.defaultvoltage = voltage self.defaultapix = apix self.defaultcs = cs self.defaultac = ac self.db = None # open JSON file for current image self.wimage = EMImage2DWidget() self.wimage.setWindowTitle("Micrograph") self.wparticles = EMImageMXWidget() self.wparticles.setWindowTitle("Particles") self.wrefs = EMImageMXWidget() self.wrefs.setWindowTitle("Box Refs") self.wbadrefs = EMImageMXWidget() self.wbadrefs.setWindowTitle("Bad Box Refs") #self.wfft=EMImage2DWidget() #self.wfft.setWindowTitle("e2evalimage - 2D FFT") #self.wplot=EMPlot2DWidget() #self.wplot.setWindowTitle("e2evalimage - Plot") self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedown"), self.imgmousedown) self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedrag"), self.imgmousedrag) self.wimage.connect(self.wimage, QtCore.SIGNAL("mouseup"), self.imgmouseup) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedown"), self.ptclmousedown) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedrag"), self.ptclmousedrag) self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mouseup"), self.ptclmouseup) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedown"), self.refmousedown) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedrag"), self.refmousedrag) self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mouseup"), self.refmouseup) self.wimage.mmode = "app" self.wparticles.mmode = "app" # This object is itself a widget we need to set up self.gbl = QtGui.QGridLayout(self) self.gbl.setMargin(8) self.gbl.setSpacing(6) # Micrograph list self.setlist = QtGui.QListWidget(self) self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) for i in imagenames: self.setlist.addItem(i) self.gbl.addWidget(self.setlist, 0, 0, 12, 2) self.setlist.connect(self.setlist, QtCore.SIGNAL("currentRowChanged(int)"), self.newSet) self.setlist.connect(self.setlist, QtCore.SIGNAL("keypress"), self.listKey) # Mouse Modes self.mmode = "manual" self.boxmm = QtGui.QGroupBox("Mouse Mode", self) self.boxmm.setFlat(False) self.gbl.addWidget(self.boxmm, 0, 2, 3, 2) self.hbl0 = QtGui.QHBoxLayout(self.boxmm) self.bmmanual = QtGui.QPushButton("Manual") self.bmmanual.setToolTip( "Manual selection of particles. No impact on autoselection.") self.bmmanual.setAutoExclusive(True) self.bmmanual.setCheckable(True) self.bmmanual.setChecked(True) self.hbl0.addWidget(self.bmmanual) self.bmdel = QtGui.QPushButton("Delete") self.bmdel.setToolTip( "Delete particles from any mode. Can also shift-click in other mouse modes." ) self.bmdel.setAutoExclusive(True) self.bmdel.setCheckable(True) self.hbl0.addWidget(self.bmdel) self.bmgref = QtGui.QPushButton("Good Refs") self.bmgref.setToolTip( "Identify some good particles. Available to all autoboxers.") self.bmgref.setAutoExclusive(True) self.bmgref.setCheckable(True) self.hbl0.addWidget(self.bmgref) self.bmbref = QtGui.QPushButton("Bad Refs") self.bmbref.setToolTip( "Identify regions which should not be selected as particles.") self.bmbref.setAutoExclusive(True) self.bmbref.setCheckable(True) self.hbl0.addWidget(self.bmbref) QtCore.QObject.connect(self.bmmanual, QtCore.SIGNAL("clicked(bool)"), self.setMouseManual) QtCore.QObject.connect(self.bmdel, QtCore.SIGNAL("clicked(bool)"), self.setMouseDel) QtCore.QObject.connect(self.bmgref, QtCore.SIGNAL("clicked(bool)"), self.setMouseGoodRef) QtCore.QObject.connect(self.bmbref, QtCore.SIGNAL("clicked(bool)"), self.setMouseBadRef) # Global parameters self.boxparm = QtGui.QGroupBox("Parameters", self) self.boxparm.setFlat(False) self.gbl.addWidget(self.boxparm, 3, 2, 3, 3) self.gbl1 = QtGui.QGridLayout(self.boxparm) self.gbl1.setMargin(8) self.gbl1.setSpacing(6) self.vbbsize = ValBox(label="Box Size:", value=box) self.gbl1.addWidget(self.vbbsize, 0, 0) self.vbbpsize = ValBox(label="Ptcl Size:", value=ptcl) self.gbl1.addWidget(self.vbbpsize, 0, 1) self.vbbapix = ValBox(label="A/pix:", value=apix) self.gbl1.addWidget(self.vbbapix, 0, 2) self.vbvoltage = ValBox(label="Voltage:", value=voltage) self.gbl1.addWidget(self.vbvoltage, 1, 0) self.vbbac = ValBox(label="% AC:", value=ac) self.gbl1.addWidget(self.vbbac, 1, 1) self.vbcs = ValBox(label="Cs:", value=cs) self.gbl1.addWidget(self.vbcs, 1, 2) # Autoboxing Tabs self.autolbl = QtGui.QLabel("Autoboxing Methods:") self.gbl.addWidget(self.autolbl, 7, 2) self.autotab = QtGui.QTabWidget() self.gbl.addWidget(self.autotab, 8, 2, 6, 3) self.bautobox = QtGui.QPushButton("Autobox") self.gbl.addWidget(self.bautobox, 7, 4) QtCore.QObject.connect(self.bautobox, QtCore.SIGNAL("clicked(bool)"), self.doAutoBox) # Individual tabs from Dictionary self.abwid = [] for name, bname, cls in GUIBoxer.aboxmodes: w = QtGui.QWidget() gl = QtGui.QGridLayout(w) self.abwid.append((w, gl)) cls.setup_gui(gl) self.autotab.addTab(w, name) self.setWindowTitle("e2boxer21 - Control Panel") self.wimage.show() # self.wfft.show() # self.wplot.show() E2loadappwin("e2boxer21", "main", self) E2loadappwin("e2boxer21", "image", self.wimage.qt_parent) E2loadappwin("e2boxer21", "particles", self.wparticles.qt_parent) E2loadappwin("e2boxer21", "refs", self.wrefs.qt_parent) E2loadappwin("e2boxer21", "badrefs", self.wbadrefs.qt_parent) self.newSet(0) #QWidget *firstPageWidget = new QWidget; #QWidget *secondPageWidget = new QWidget; #QWidget *thirdPageWidget = new QWidget; #QStackedWidget *stackedWidget = new QStackedWidget; #stackedWidget->addWidget(firstPageWidget); #stackedWidget->addWidget(secondPageWidget); #stackedWidget->addWidget(thirdPageWidget); #QVBoxLayout *layout = new QVBoxLayout; #layout->addWidget(stackedWidget); #setLayout(layout); #QComboBox *pageComboBox = new QComboBox; #pageComboBox->addItem(tr("Page 1")); #pageComboBox->addItem(tr("Page 2")); #pageComboBox->addItem(tr("Page 3")); #connect(pageComboBox, SIGNAL(activated(int)),stackedWidget, SLOT(setCurrentIndex(int))); #self.lboxmode=QtGui.QLabel("Mode:",self) #self.gbl.addWidget(self.lboxmode,10,0) #self.sboxmode=QtGui.QComboBox(self) #self.sboxmode.addItem("Manual") #self.sboxmode.addItem("Reference") #self.sboxmode.setCurrentIndex(1) #self.gbl.addWidget(self.sboxmode,10,1) #self.lanmode=QtGui.QLabel("Annotate:",self) #self.gbl.addWidget(self.lanmode,12,0) #self.sanmode=QtGui.QComboBox(self) #self.sanmode.addItem("Box") #self.sanmode.addItem("Box+dot") #self.sanmode.addItem("Circle") #self.sanmode.addItem("None") #self.gbl.addWidget(self.sanmode,12,1) #self.sdefocus=ValSlider(self,(0,5),"Defocus:",0.0,90) #self.gbl.addWidget(self.sdefocus,0,2,1,3) #self.squality=ValSlider(self,(0,9),"Quality (0-9):",0,90) #self.squality.setIntonly(True) #self.gbl.addWidget(self.squality,6,2,1,3) #self.brefit=QtGui.QPushButton("Autobox") #self.gbl.addWidget(self.brefit,7,2) #self.bclrauto=QtGui.QPushButton("Clear Auto") #self.gbl.addWidget(self.bclrauto,7,3) #self.bclrall=QtGui.QPushButton("Clear All") #self.gbl.addWidget(self.bclrall,7,4) #self.sapix=ValBox(self,(0,500),"A/pix:",1.0,90) #if self.defaultapix!=None : self.sapix.setValue(self.defaultapix) #self.gbl.addWidget(self.sapix,10,2) #self.svoltage=ValBox(self,(0,500),"Voltage (kV):",200,90) #if self.defaultvoltage!=None : self.svoltage.setValue(self.defaultvoltage) #self.gbl.addWidget(self.svoltage,11,2) #self.scs=ValBox(self,(0,5),"Cs (mm):",4.1,90) #if self.defaultcs!=None : self.scs.setValue(self.defaultcs) #self.gbl.addWidget(self.scs,12,2) #self.sboxsize=ValBox(self,(0,500),"Box Size:",256,90) #self.sboxsize.intonly=True #self.gbl.addWidget(self.sboxsize,13,2) #self.sptclsize=ValBox(self,(0,500),"Ptcl Size:",256,90) #self.sptclsize.intonly=True #self.gbl.addWidget(self.sptclsize,14,2) #QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"), self.newCTF) #QtCore.QObject.connect(self.sboxsize, QtCore.SIGNAL("valueChanged"), self.newBox) ## QtCore.QObject.connect(self.soversamp, QtCore.SIGNAL("valueChanged"), self.newBox) #QtCore.QObject.connect(self.squality,QtCore.SIGNAL("valueChanged"),self.newQualityFactor) #QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("currentRowChanged(int)"),self.newSet) #QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("keypress"),self.listkey) #QtCore.QObject.connect(self.sboxmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.newBoxMode) #self.resize(720,380) # figured these values out by printing the width and height in resize event #### This section is responsible for background updates #self.busy=False #self.needupdate=True #self.needredisp=False #self.procthread=None #self.errors=None # used to communicate errors back from the reprocessing thread #self.timer=QTimer() #QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.timeOut) #self.timer.start(100) # self.recalc() def setMouseManual(self, x): self.mmode = "manual" def setMouseDel(self, x): self.mmode = "del" def setMouseGoodRef(self, x): self.mmode = "refgood" def setMouseBadRef(self, x): self.mmode = "refbad" def imgmousedown(self, event): m = self.wimage.scr_to_img((event.x(), event.y())) boxsize2 = self.vbbsize.getValue() // 2 ptclsize = self.vbbpsize.getValue() self.curbox = 0 # check to see if click was inside an existing box, in which case we move it for i in self.boxes: if abs(m.x - i[0]) < boxsize2 and abs(m.y - i[1]) < boxsize2: self.curbox = i break else: # Create a new box if self.mmode == "del": return # This is for creating a new box, so clearly not desirable in delete mode self.curbox = len(self.boxes) self.boxes.append((m[0], m[1], self.mmode)) self.__addBox(self.curbox, self.boxes[-1]) #self.guiim.add_shape("cen",["rect",.9,.9,.4,x0,y0,x0+2,y0+2,1.0]) def imgmousedrag(self, event): if self.calcmode == 0: m = self.wimage.scr_to_img((event.x(), event.y())) parms = self.parms[self.curset] parms[2] = (m[0] - parms[0] / 2, m[1] - parms[0] / 2) self.needredisp = True self.recalc() # box deletion when shift held down #if event.modifiers()&Qt.ShiftModifier: #for i,j in enumerate(self.boxes): def imgmouseup(self, event): m = self.wimage.scr_to_img((event.x(), event.y())) if self.calcmode == 1: parms = self.parms[self.curset] nx = self.data["nx"] / parms[0] - 1 grid = int((m[0] - parms[0] / 2) / parms[0]) + int( (m[1] - parms[0] / 2) / parms[0]) * nx if grid in parms[3]: parms[3].remove(grid) else: parms[3].add(grid) self.needredisp = True self.recalc() def ptclmousedown(self, event): return def ptclmousedrag(self, event): return def ptclmouseup(self, event): return def refmousedown(self, event): return def refmousedrag(self, event): return def refmouseup(self, event): return def newSet(self, val): "called when a new data set is selected from the list" first = True newfilename = str(self.setlist.item(val).text()) if newfilename == self.curfilename: return # Write the current image parameters to the database if self.curfilename != None and self.boxes != None: self.save_boxes() first = False self.micrograph = load_micrograph(newfilename) self.wimage.set_data(self.micrograph) if first: E2loadappwin("e2boxer21", "image", self.wimage.qt_parent) self.curfilename = newfilename self.restore_boxes() def save_boxes(self): js = js_open_dict(info_name(self.curfilename)) js["boxes"] = self.boxes def restore_boxes(self): # first we restore the list of box locations js = js_open_dict(info_name(self.curfilename)) try: self.boxes = js["boxes"] except: self.boxes = [] boxsize = self.vbbsize.getValue() ptclsize = self.vbbpsize.getValue() micro = self.wimage.get_data() self.wimage.del_shapes() if len(self.boxes) == 0: self.wparticles.set_data([]) return # Then we extract the actual boxed out particles goodrefs = [] badrefs = [] self.particles = [] for i, box in enumerate(self.boxes): self.__addBox(i, box) # extract the data boxim = self.micrograph.get_clip( Region(box[0] - boxsize // 2, box[1] - boxsize // 2, boxsize, boxsize)) boxim["ptcl_source_coord"] = (box[0], box[1]) if box[2] == "refgood": goodrefs.append(boxim) elif box[2] == "refbad": badrefs.append(boxim) else: self.particles.append(boxim) # finally redisplay as appropriate self.wimage.update() self.wparticles.set_data(self.particles) if len(self.particles) > 0: self.wparticles.show() if len(goodrefs) + len(badrefs) != 0: self.goodrefs = goodrefs self.badrefs = badrefs self.wrefs.set_data(self.goodrefs) self.wbadrefs.set_data(self.badrefs) if len(self.goodrefs) > 0: self.wrefs.show() if len(self.badrefs) > 0: self.wbadrefs.show() def __addBox(self, i, box): """takes the number of the box in self.boxes and the (x,y,mode) tuple and displays it""" # Display the actual box boxsize = self.vbbsize.getValue() ptclsize = self.vbbpsize.getValue() try: color = self.boxcolors[box[2]] except: color = self.boxcolors["unknown"] self.wimage.add_shape( "box{}".format(i), EMShape(("rect", color[0], color[1], color[2], box[0] - boxsize // 2, box[1] - boxsize // 2, box[0] + boxsize // 2, box[1] + boxsize // 2, 2))) self.wimage.add_shape( "cir{}".format(i), EMShape(("circle", color[0], color[1], color[2], box[0], box[1], ptclsize / 2, 1.5))) def listKey(self, event): pass #if event.key()>=Qt.Key_0 and event.key()<=Qt.Key_9 : #q=int(event.key())-Qt.Key_0 #self.squality.setValue(q) #elif event.key() == Qt.Key_Left: #self.sdefocus.setValue(self.sdefocus.getValue()-0.03) #elif event.key() == Qt.Key_Right: #self.sdefocus.setValue(self.sdefocus.getValue()+0.03) #elif event.key()==Qt.Key_I : #self.doImport() #elif event.key()==Qt.Key_U : #self.unImport() def doAutoBox(self, b): """Autobox button pressed, find the right algorithm and call it""" name, bname, fn1 = self.aboxmodes[self.autotab.currentIndex()] print name, " called" def closeEvent(self, event): # QtGui.QWidget.closeEvent(self,event) E2saveappwin("e2boxer21", "main", self) E2saveappwin("e2boxer21", "image", self.wimage.qt_parent) E2saveappwin("e2boxer21", "particles", self.wparticles.qt_parent) E2saveappwin("e2boxer21", "refs", self.wrefs.qt_parent) E2saveappwin("e2boxer21", "badrefs", self.wbadrefs.qt_parent) #self.writeCurParm() event.accept() QtGui.qApp.exit(0)