Пример #1
0
class EMPDBInspector(QtGui.QWidget):
    def __init__(self, target, enable_advanced=False):
        QtGui.QWidget.__init__(self)
        self.target = weakref.ref(target)

        self.rotation_sliders = EMTransformPanel(target, self)

        self.text = QtGui.QLineEdit()
        text_value = self.target().current_text()
        if text_value:
            self.text.setText(text_value)
        self.browse = QtGui.QPushButton("Browse")

        hbl1 = QtGui.QHBoxLayout()
        hbl1.addWidget(self.text)
        hbl1.addWidget(self.browse)

        vbl = QtGui.QVBoxLayout()
        vbl.setMargin(0)
        vbl.setSpacing(6)
        vbl.addLayout(hbl1)

        self.rotation_sliders.addWidgets(vbl)

        self.setLayout(vbl)

        QtCore.QObject.connect(self.text,
                               QtCore.SIGNAL("textEdited(const QString&)"),
                               self.on_text_change)
        QtCore.QObject.connect(self.browse, QtCore.SIGNAL("clicked(bool)"),
                               self.on_browse)

    def on_text_change(self, text):
        print "Use the Browse button to update the pdb file"

    def on_browse(self):
        import os
        self.fileName = QtGui.QFileDialog.getOpenFileName(
            self, "open file", os.getcwd(), "Text files (*.pdb)")
        if (self.fileName == ""): return
        self.target().set_current_text(
            str(self.fileName
                ))  #self.target().text and self.text are what the user sees.
        self.text.setText(
            self.fileName
        )  #if self.text changes, then self.fName becomes self.text and the image regenerates
        self.target().updateGL()

    def update_rotations(self, t3d):
        self.rotation_sliders.update_rotations(t3d)

    def set_scale(self, val):
        self.rotation_sliders.set_scale(val)

    def set_xy_trans(self, x, y):
        self.rotation_sliders.set_xy_trans(x, y)

    def set_xyz_trans(self, x, y, z):
        self.rotation_sliders.set_xyz_trans(x, y, z)
Пример #2
0
class EMPDBInspector(QtGui.QWidget):
	def __init__(self,target,enable_advanced=False):
		QtGui.QWidget.__init__(self)
		self.target = weakref.ref(target)

		self.rotation_sliders = EMTransformPanel(target,self)
		
		self.text = QtGui.QLineEdit()
		text_value = self.target().current_text()
		if text_value:
			self.text.setText(text_value)
		self.browse = QtGui.QPushButton("Browse")

		hbl1 = QtGui.QHBoxLayout()
		hbl1.addWidget(self.text)
		hbl1.addWidget(self.browse)

		vbl = QtGui.QVBoxLayout()
		vbl.setMargin(0)
		vbl.setSpacing(6)
		vbl.addLayout(hbl1)
		
		self.rotation_sliders.addWidgets(vbl)

		self.setLayout(vbl)
		
		QtCore.QObject.connect(self.text, QtCore.SIGNAL("textEdited(const QString&)"), self.on_text_change)
		QtCore.QObject.connect(self.browse, QtCore.SIGNAL("clicked(bool)"), self.on_browse)
	
	def on_text_change(self,text):
		print "Use the Browse button to update the pdb file"

	def on_browse(self):
		import os
		self.fileName = QtGui.QFileDialog.getOpenFileName(self, "open file", os.getcwd(), "Text files (*.pdb)")
		if (self.fileName == ""): return
		self.target().set_current_text(str(self.fileName)) #self.target().text and self.text are what the user sees. 
		self.text.setText(self.fileName) #if self.text changes, then self.fName becomes self.text and the image regenerates	
		self.target().updateGL()
	
	def update_rotations(self,t3d):
		self.rotation_sliders.update_rotations(t3d)
	
	def set_scale(self,val):
		self.rotation_sliders.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.rotation_sliders.set_xy_trans(x,y)
	
	def set_xyz_trans(self,x,y,z):
		self.rotation_sliders.set_xyz_trans(x,y,z)
Пример #3
0
class EM3DAdvancedInspector(QtGui.QWidget,EMLightsInspectorBase):
	
	
	def __init__(self,target,parent=None):
		QtGui.QWidget.__init__(self,None)
		EMLightsInspectorBase.__init__(self)
		self.target=weakref.ref(target)
		self.parent=weakref.ref(parent)

		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")

		self.tabwidget = QtGui.QTabWidget()
		self.tabwidget.addTab(self.get_main_tab(), "Transform")
		self.tabwidget.addTab(self.get_light_tab(), "Lights")
		
		#self.tabwidget.addTab(self.get_GL_tab(),"GL")
		
		self.vbl.addWidget(self.tabwidget)
		

		QtCore.QObject.connect(self.persbut, QtCore.SIGNAL("pressed()"), self.perspective_clicked)
		QtCore.QObject.connect(self.orthbut, QtCore.SIGNAL("pressed()"), self.ortho_clicked)
	
	
	def get_main_tab(self):
		self.maintab = QtGui.QWidget()
		maintab = self.maintab
		maintab.vbl = QtGui.QVBoxLayout(self.maintab)
		
		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(2)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		
		self.persbut = QtGui.QRadioButton("Perspective")
		self.persbut.setChecked(self.target().perspective==True)
		
		self.orthbut = QtGui.QRadioButton("Orthographic")
		self.orthbut.setChecked(self.target().perspective==False)
		
		self.groupbox = QtGui.QVBoxLayout()
		self.groupbox.addWidget(self.persbut)
		self.groupbox.addWidget(self.orthbut)
		
		self.viewingvol = QtGui.QGroupBox("Viewing Volume")
		self.viewingvol.setLayout(self.groupbox)
		
		self.hbl.addWidget(self.viewingvol)
		
		maintab.vbl.addLayout(self.hbl)
		
		self.rotation_sliders = EMTransformPanel(self.target(),self)
		self.rotation_sliders.addWidgets(maintab.vbl)
		
		return self.maintab
		
	def get_transform_layout(self):
		return self.vbl
		
	def update_rotations(self,t3d):
		self.rotation_sliders.update_rotations(t3d)
		
	def set_scale(self,val):
		self.rotation_sliders.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.rotation_sliders.set_xy_trans(x,y)
	
	def set_xyz_trans(self, x, y,z):
		self.rotation_sliders.set_xyz_trans(x,y,z)
	
	def perspective_clicked(self):
		self.target().set_perspective(True)
		
	def ortho_clicked(self):
		self.target().set_perspective(False)
Пример #4
0
class EMIsoInspector(QtGui.QWidget):
    def __init__(self, target, enable_browse=False):
        QtGui.QWidget.__init__(self, None)

        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "desktop.png"))
        self.target = weakref.ref(target)
        self.rotation_sliders = EMTransformPanel(target, self)

        self.vbl = QtGui.QVBoxLayout(self)
        self.vbl.setMargin(0)
        self.vbl.setSpacing(6)
        self.vbl.setObjectName("vbl")

        self.mrcChanged = False  #added by Muthu

        if enable_browse:
            hblbrowse = QtGui.QHBoxLayout()
            self.mrc_text = QtGui.QLineEdit()
            hblbrowse.addWidget(self.mrc_text)
            self.mrc_browse = QtGui.QPushButton("Browse")
            hblbrowse.addWidget(self.mrc_browse)
            self.vbl.addLayout(hblbrowse)

            QtCore.QObject.connect(self.mrc_text,
                                   QtCore.SIGNAL("textEdited(const QString&)"),
                                   self.on_mrc_text_change)  #added by Muthu
            QtCore.QObject.connect(self.mrc_browse,
                                   QtCore.SIGNAL("clicked(bool)"),
                                   self.on_mrc_browse)  # added by Muthu

        self.hbl = QtGui.QHBoxLayout()
        self.hbl.setMargin(0)
        self.hbl.setSpacing(6)
        self.hbl.setObjectName("hbl")
        self.vbl.addLayout(self.hbl)

        self.hist = ImgHistogram(self)
        self.hist.setObjectName("hist")
        self.hbl.addWidget(self.hist)

        self.vbl2 = QtGui.QVBoxLayout()
        self.vbl2.setMargin(0)
        self.vbl2.setSpacing(6)
        self.vbl2.setObjectName("vbl2")
        self.hbl.addLayout(self.vbl2)

        self.wiretog = QtGui.QPushButton("Wire")
        self.wiretog.setCheckable(1)
        self.vbl2.addWidget(self.wiretog)

        self.lighttog = QtGui.QPushButton("Light")
        self.lighttog.setCheckable(1)
        self.vbl2.addWidget(self.lighttog)

        self.cubetog = QtGui.QPushButton("Cube")
        self.cubetog.setCheckable(1)
        self.vbl2.addWidget(self.cubetog)

        self.texturetog = QtGui.QPushButton("Texture")
        self.texturetog.setCheckable(1)
        self.vbl2.addWidget(self.texturetog)
        self.texture = False

        self.tabwidget = QtGui.QTabWidget()
        self.maintab = None
        self.tabwidget.addTab(self.get_main_tab(), "Main")
        self.texturetab = None
        self.tabwidget.addTab(self.get_GL_tab(), "GL")
        self.tabwidget.addTab(self.get_texture_tab(), "Texture")
        self.get_texture_tab().setEnabled(False)
        self.vbl.addWidget(self.tabwidget)
        self.n3_showing = False

        QtCore.QObject.connect(self.thr, QtCore.SIGNAL("valueChanged"),
                               self.on_threshold_slider)
        QtCore.QObject.connect(self.contrast, QtCore.SIGNAL("valueChanged"),
                               target.set_contrast)
        QtCore.QObject.connect(self.bright, QtCore.SIGNAL("valueChanged"),
                               target.set_brightness)
        QtCore.QObject.connect(self.cbb,
                               QtCore.SIGNAL("currentIndexChanged(QString)"),
                               self.set_material)
        QtCore.QObject.connect(self.smp, QtCore.SIGNAL("valueChanged(int)"),
                               target.set_sample)
        QtCore.QObject.connect(self.wiretog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_wire)
        QtCore.QObject.connect(self.lighttog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_light)
        QtCore.QObject.connect(self.texturetog, QtCore.SIGNAL("toggled(bool)"),
                               self.toggle_texture)
        QtCore.QObject.connect(self.cubetog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_cube)
        QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"),
                               target.set_GL_contrast)
        QtCore.QObject.connect(self.glbrightness,
                               QtCore.SIGNAL("valueChanged"),
                               target.set_GL_brightness)

        QtCore.QObject.connect(self.ambient_tab.r,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.ambient_tab.g,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.ambient_tab.b,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.diffuse_tab.r,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.diffuse_tab.g,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.diffuse_tab.b,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.specular_tab.r,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.specular_tab.g,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.specular_tab.b,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.emission_tab.r,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.emission_tab.g,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.emission_tab.b,
                               QtCore.SIGNAL("valueChanged"),
                               self.update_material)
        QtCore.QObject.connect(self.shininess, QtCore.SIGNAL("valueChanged"),
                               self.update_material)

    def on_mrc_text_change(self, text):  #if enable_browse, added by muthu
        print "Use the Browse button to update the mrc file"

    def on_mrc_browse(self):  #if enable_browse, added by muthu
        import os
        self.mrcfileName = QtGui.QFileDialog.getOpenFileName(
            self, "open file", os.getcwd(), "Text files (*.mrc)")
        if (self.mrcfileName == ""): return
        mrcData = EMData(str(self.mrcfileName))
        self.target().set_data(mrcData)
        self.mrc_text.setText(self.mrcfileName)
        self.mrcChanged = True
        self.target().updateGL()

    def update_rotations(self, t3d):
        self.rotation_sliders.update_rotations(t3d)

    def set_scale(self, val):
        self.rotation_sliders.set_scale(val)

    def set_xy_trans(self, x, y):
        self.rotation_sliders.set_xy_trans(x, y)

    def set_xyz_trans(self, x, y, z):
        self.rotation_sliders.set_xyz_trans(x, y, z)

    def get_transform_layout(self):
        return self.maintab.vbl

    def update_material(self):
        self.target().isocolor = "custom"
        custom = {}

        custom["ambient"] = [
            self.ambient_tab.r.getValue(),
            self.ambient_tab.g.getValue(),
            self.ambient_tab.b.getValue(), 1.0
        ]
        custom["diffuse"] = [
            self.diffuse_tab.r.getValue(),
            self.diffuse_tab.g.getValue(),
            self.diffuse_tab.b.getValue(), 1.0
        ]
        custom["specular"] = [
            self.specular_tab.r.getValue(),
            self.specular_tab.g.getValue(),
            self.specular_tab.b.getValue(), 1.0
        ]
        custom["emission"] = [
            self.emission_tab.r.getValue(),
            self.emission_tab.g.getValue(),
            self.emission_tab.b.getValue(), 1.0
        ]
        custom["shininess"] = self.shininess.getValue()
        self.target().colors["custom"] = custom

        n = self.cbb.findText(QtCore.QString("custom"))
        if n < 0: return
        self.cbb.setCurrentIndex(n)
        self.target().updateGL()

    def set_material(self, color):
        self.target().set_material(color)
        material = self.target().get_material()

        self.ambient_tab.r.setValue(material["ambient"][0])
        self.ambient_tab.g.setValue(material["ambient"][1])
        self.ambient_tab.b.setValue(material["ambient"][2])

        self.diffuse_tab.r.setValue(material["diffuse"][0])
        self.diffuse_tab.g.setValue(material["diffuse"][1])
        self.diffuse_tab.b.setValue(material["diffuse"][2])

        self.specular_tab.r.setValue(material["specular"][0])
        self.specular_tab.g.setValue(material["specular"][1])
        self.specular_tab.b.setValue(material["specular"][2])

        self.emission_tab.r.setValue(material["emission"][0])
        self.emission_tab.g.setValue(material["emission"][1])
        self.emission_tab.b.setValue(material["emission"][2])

        self.shininess.setValue(material["shininess"])

    def get_RGB_tab(self, name=""):
        return get_RGB_tab(self, name)
        #rgbtab = QtGui.QWidget(self)
        #rgbtab.vbl = QtGui.QVBoxLayout(rgbtab)
        #rgbtab.vbl.setMargin(0)
        #rgbtab.vbl.setSpacing(6)
        #rgbtab.vbl.setObjectName(name)

        #rgbtab.r = ValSlider(rgbtab,(0.0,1.0),"R:")
        #rgbtab.r.setObjectName("R")
        #rgbtab.r.setValue(0.5)
        #rgbtab.vbl.addWidget(rgbtab.r)

        #rgbtab.g = ValSlider(rgbtab,(0.0,1.0),"G:")
        #rgbtab.g.setObjectName("G")
        #rgbtab.g.setValue(0.5)
        #rgbtab.vbl.addWidget(rgbtab.g)

        #rgbtab.b = ValSlider(rgbtab,(0.0,1.0),"B:")
        #rgbtab.b.setObjectName("B")
        #rgbtab.b.setValue(0.5)
        #rgbtab.vbl.addWidget(rgbtab.b)

        #return rgbtab

    def get_GL_tab(self):
        self.gltab = QtGui.QWidget()
        gltab = self.gltab

        gltab.vbl = QtGui.QVBoxLayout(self.gltab)
        gltab.vbl.setMargin(0)
        gltab.vbl.setSpacing(6)
        gltab.vbl.setObjectName("GL")

        self.glcontrast = ValSlider(gltab, (1.0, 5.0), "GLShd:")
        self.glcontrast.setObjectName("GLShade")
        self.glcontrast.setValue(1.0)
        gltab.vbl.addWidget(self.glcontrast)

        self.glbrightness = ValSlider(gltab, (-1.0, 0.0), "GLBst:")
        self.glbrightness.setObjectName("GLBoost")
        self.glbrightness.setValue(0.1)
        self.glbrightness.setValue(0.0)
        gltab.vbl.addWidget(self.glbrightness)

        self.material_tab_widget = QtGui.QTabWidget()
        self.ambient_tab = self.get_RGB_tab("ambient")
        self.material_tab_widget.addTab(self.ambient_tab, "Ambient")

        self.diffuse_tab = self.get_RGB_tab("diffuse")
        self.material_tab_widget.addTab(self.diffuse_tab, "Diffuse")

        self.specular_tab = self.get_RGB_tab("specular")
        self.material_tab_widget.addTab(self.specular_tab, "Specular")

        self.emission_tab = self.get_RGB_tab("emission")
        self.material_tab_widget.addTab(self.emission_tab, "Emission")

        gltab.vbl.addWidget(self.material_tab_widget)

        self.shininess = ValSlider(gltab, (0, 128), "Shininess:")
        self.shininess.setObjectName("Shininess")
        self.shininess.setValue(64)
        gltab.vbl.addWidget(self.shininess)

        self.hbl_color = QtGui.QHBoxLayout()
        self.hbl_color.setMargin(0)
        self.hbl_color.setSpacing(6)
        self.hbl_color.setObjectName("Material")
        gltab.vbl.addLayout(self.hbl_color)

        self.color_label = QtGui.QLabel()
        self.color_label.setText('Material')
        self.hbl_color.addWidget(self.color_label)

        self.cbb = QtGui.QComboBox(gltab)
        self.hbl_color.addWidget(self.cbb)

        return gltab

    def toggle_texture(self):
        self.texture = not self.texture
        self.target().toggle_texture()
        self.get_texture_tab().setEnabled(self.texture)

    def get_texture_tab(self):
        if (self.texturetab == None):
            self.texturetab = QtGui.QWidget()
            texturetab = self.texturetab
            texturetab.vbl = QtGui.QVBoxLayout(self.texturetab)
            texturetab.vbl.setMargin(0)
            texturetab.vbl.setSpacing(6)
            texturetab.vbl.setObjectName("Main")

            self.contrast = ValSlider(texturetab, (0.0, 20.0), "Cont:")
            self.contrast.setObjectName("contrast")
            self.contrast.setValue(10.0)
            texturetab.vbl.addWidget(self.contrast)

            self.bright = ValSlider(texturetab, (-5.0, 5.0), "Brt:")
            self.bright.setObjectName("bright")
            self.bright.setValue(0.1)
            self.bright.setValue(0.0)
            texturetab.vbl.addWidget(self.bright)

            #self.glcontrast = ValSlider(texturetab,(1.0,5.0),"GLShd:")
            #self.glcontrast.setObjectName("GLShade")
            #self.glcontrast.setValue(1.0)
            #texturetab.vbl.addWidget(self.glcontrast)

            #self.glbrightness = ValSlider(texturetab,(-1.0,0.0),"GLBst:")
            #self.glbrightness.setObjectName("GLBoost")
            #self.glbrightness.setValue(0.1)
            #self.glbrightness.setValue(0.0)
            #texturetab.vbl.addWidget(self.glbrightness)

        return self.texturetab

    def get_main_tab(self):
        if (self.maintab == None):
            self.maintab = QtGui.QWidget()
            maintab = self.maintab
            maintab.vbl = QtGui.QVBoxLayout(self.maintab)
            maintab.vbl.setMargin(0)
            maintab.vbl.setSpacing(6)
            maintab.vbl.setObjectName("Main")

            self.thr = ValSlider(maintab, (0.0, 4.0), "Thr:")
            self.thr.setObjectName("thr")
            self.thr.setValue(0.5)
            maintab.vbl.addWidget(self.thr)

            self.hbl_smp = QtGui.QHBoxLayout()
            self.hbl_smp.setMargin(0)
            self.hbl_smp.setSpacing(6)
            self.hbl_smp.setObjectName("Sample")
            maintab.vbl.addLayout(self.hbl_smp)

            self.smp_label = QtGui.QLabel()
            self.smp_label.setText('Sample Level')
            self.hbl_smp.addWidget(self.smp_label)

            self.smp = QtGui.QSpinBox(maintab)
            self.smp.setValue(1)
            self.hbl_smp.addWidget(self.smp)

            self.rotation_sliders.addWidgets(maintab.vbl)

        return self.maintab

    def set_sampling_range(self, range):
        self.smp.setMinimum(1)
        self.smp.setMaximum(1 + range - 1)

    def slider_rotate(self):
        self.target().load_rotation(self.get_current_rotation())

    def set_materials(self, colors, current_color):
        a = 0
        for i in colors:
            self.cbb.addItem(i)
            if (i == current_color):
                self.cbb.setCurrentIndex(a)
            a += 1

    def on_threshold_slider(self, val):
        self.target().set_threshold(val)
        self.bright.setValue(-val, True)

    def set_thresholds(self, low, high, val):
        self.thr.setRange(low, high)
        self.thr.setValue(val, True)
        self.bright.setValue(-val, True)

    def set_sample(self, low, high, val):
        self.smp.setRange(int(low), int(high))
        self.smp.setValue(val, True)

    def set_hist(self, hist, minden, maxden):
        self.hist.set_data(hist, minden, maxden)
Пример #5
0
class EM3DSliceInspector(QtGui.QWidget):
	def __init__(self,target) :
		self.busy = False
		QtGui.QWidget.__init__(self,None)
		self.setWindowIcon(QtGui.QIcon(get_image_directory() +"desktop.png"))
		self.transform_panel = EMTransformPanel(target,self)
		self.target=weakref.ref(target)
		
		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")
		
		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(0)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		self.vbl.addLayout(self.hbl)
		
		self.hist = ImgHistogram(self)
		self.hist.setObjectName("hist")
		self.hbl.addWidget(self.hist)
		
		self.vbl2 = QtGui.QVBoxLayout()
		self.vbl2.setMargin(0)
		self.vbl2.setSpacing(6)
		self.vbl2.setObjectName("vbl2")
		self.hbl.addLayout(self.vbl2)
	
		self.cubetog = QtGui.QPushButton("Cube")
		self.cubetog.setCheckable(1)
		self.vbl2.addWidget(self.cubetog)
		
		self.defaults = QtGui.QPushButton("Defaults")
		self.vbl2.addWidget(self.defaults)
		
		self.vbl.addWidget(self.get_main_tab())
		
		self.n3_showing = False
		
#		self.current_src = EULER_EMAN
		
		QtCore.QObject.connect(self.slice, QtCore.SIGNAL("valueChanged"), target.set_slice)
		QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"), target.set_GL_contrast)
		QtCore.QObject.connect(self.glbrightness, QtCore.SIGNAL("valueChanged"), target.set_GL_brightness)
		QtCore.QObject.connect(self.axisCombo, QtCore.SIGNAL("currentIndexChanged(QString)"), target.setAxis)
		QtCore.QObject.connect(self.cubetog, QtCore.SIGNAL("toggled(bool)"), target.toggle_cube)
		QtCore.QObject.connect(self.defaults, QtCore.SIGNAL("clicked(bool)"), self.set_defaults)
		QtCore.QObject.connect(self.contrast, QtCore.SIGNAL("valueChanged"), self.on_contrast_changed)
		QtCore.QObject.connect(self.bright, QtCore.SIGNAL("valueChanged"), self.on_brightness_changed)
	
	def on_contrast_changed(self,val):
		if self.busy: return
		self.target().set_contrast(val)
	
	def on_brightness_changed(self,val):
		if self.busy: return
		self.target().set_brightness(val)
	
	def set_contrast_bright(self,c,b):
		self.busy = True
		self.contrast.setValue(c)
		self.bright.setValue(b)
		self.busy = False
	def update_rotations(self,t3d):
		self.transform_panel.update_rotations(t3d)
	
	def set_scale(self,val):
		self.transform_panel.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.transform_panel.set_xy_trans(x,y)
		
	def set_xyz_trans(self,x,y,z):
		self.transform_panel.set_xyz_trans(x,y,z)	
	
	def get_transform_layout(self):
		return self.maintab.vbl
	
	def set_defaults(self):
		self.target().set_default_contrast_settings()
		self.set_contrast_bright(self.target().contrast,self.target().bright)
		self.glcontrast.setValue(1.0)
		self.glbrightness.setValue(0.0)
		self.transform_panel.set_defaults()
		
		self.target().generate_current_display_list()
		self.target().updateGL()

	def get_main_tab(self):
	
		self.maintab = QtGui.QWidget()
		maintab = self.maintab
		maintab.vbl = QtGui.QVBoxLayout(self.maintab)
		maintab.vbl.setMargin(0)
		maintab.vbl.setSpacing(6)
		maintab.vbl.setObjectName("Main")
		
		self.hbl_slice = QtGui.QHBoxLayout()
		self.hbl_slice.setMargin(0)
		self.hbl_slice.setSpacing(6)
		self.hbl_slice.setObjectName("Axis")
		maintab.vbl.addLayout(self.hbl_slice)
		
		self.slice = ValSlider(maintab,(0.0,10.0),"Slice:")
		self.slice.setObjectName("slice")
		self.slice.setValue(1.0)
		self.hbl_slice.addWidget(self.slice)
		
		self.axisCombo = QtGui.QComboBox(maintab)
		self.axisCombo.addItem(' z ')
		self.axisCombo.addItem(' y ')
		self.axisCombo.addItem(' x ')
		self.axisCombo.addItem(' track ')
		self.hbl_slice.addWidget(self.axisCombo)
		
		
		self.contrast = ValSlider(maintab,(0.0,20.0),"Cont:")
		self.contrast.setObjectName("contrast")
		self.contrast.setValue(1.0)
		maintab.vbl.addWidget(self.contrast)

		self.bright = ValSlider(maintab,(-5.0,5.0),"Brt:")
		self.bright.setObjectName("bright")
		self.bright.setValue(0.1)
		self.bright.setValue(0.0)
		maintab.vbl.addWidget(self.bright)
		
		self.glcontrast = ValSlider(maintab,(1.0,5.0),"GLShd:")
		self.glcontrast.setObjectName("GLShade")
		self.glcontrast.setValue(1.0)
		maintab.vbl.addWidget(self.glcontrast)
		
		self.glbrightness = ValSlider(maintab,(-1.0,0.0),"GLBst:")
		self.glbrightness.setObjectName("GLBoost")
		self.glbrightness.setValue(0.1)
		self.glbrightness.setValue(0.0)
		maintab.vbl.addWidget(self.glbrightness)
	
		self.transform_panel.addWidgets(maintab.vbl)
		
		return maintab
	
	def slider_rotate(self):
		self.target().load_rotation(self.get_current_rotation())

	def set_hist(self,hist,minden,maxden):
		self.hist.set_data(hist,minden,maxden)
		
	def set_slice(self,val):
		self.slice.setValue(val)
	
	def set_sliceRange(self,min,max):
		self.slice.setRange(min,max)
Пример #6
0
class EMIsoInspector(QtGui.QWidget):
	def __init__(self,target,enable_browse=False) :
		QtGui.QWidget.__init__(self,None)

		self.setWindowIcon(QtGui.QIcon(get_image_directory() +"desktop.png"))
		self.target=weakref.ref(target)
		self.rotation_sliders = EMTransformPanel(target,self)
		
		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")
		
		self.mrcChanged = False #added by Muthu
		
		if enable_browse:
			hblbrowse = QtGui.QHBoxLayout()
			self.mrc_text = QtGui.QLineEdit()
			hblbrowse.addWidget(self.mrc_text)
			self.mrc_browse = QtGui.QPushButton("Browse")
			hblbrowse.addWidget(self.mrc_browse)
			self.vbl.addLayout(hblbrowse)

			QtCore.QObject.connect(self.mrc_text, QtCore.SIGNAL("textEdited(const QString&)"), self.on_mrc_text_change) #added by Muthu
			QtCore.QObject.connect(self.mrc_browse, QtCore.SIGNAL("clicked(bool)"), self.on_mrc_browse) # added by Muthu

		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(0)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		self.vbl.addLayout(self.hbl)
		
		self.hist = ImgHistogram(self)
		self.hist.setObjectName("hist")
		self.hbl.addWidget(self.hist)
		
		self.vbl2 = QtGui.QVBoxLayout()
		self.vbl2.setMargin(0)
		self.vbl2.setSpacing(6)
		self.vbl2.setObjectName("vbl2")
		self.hbl.addLayout(self.vbl2)
		
		self.wiretog = QtGui.QPushButton("Wire")
		self.wiretog.setCheckable(1)
		self.vbl2.addWidget(self.wiretog)
		
		self.lighttog = QtGui.QPushButton("Light")
		self.lighttog.setCheckable(1)
		self.vbl2.addWidget(self.lighttog)
		
		self.cubetog = QtGui.QPushButton("Cube")
		self.cubetog.setCheckable(1)
		self.vbl2.addWidget(self.cubetog)
		
		self.texturetog = QtGui.QPushButton("Texture")
		self.texturetog.setCheckable(1)
		self.vbl2.addWidget(self.texturetog)
		self.texture = False
		
		self.tabwidget = QtGui.QTabWidget()
		self.maintab = None
		self.tabwidget.addTab(self.get_main_tab(), "Main")
		self.texturetab = None
		self.tabwidget.addTab(self.get_GL_tab(),"GL")
		self.tabwidget.addTab(self.get_texture_tab(),"Texture")
		self.get_texture_tab().setEnabled(False)
		self.vbl.addWidget(self.tabwidget)
		self.n3_showing = False
		
		QtCore.QObject.connect(self.thr, QtCore.SIGNAL("valueChanged"), self.on_threshold_slider)
		QtCore.QObject.connect(self.contrast, QtCore.SIGNAL("valueChanged"), target.set_contrast)
		QtCore.QObject.connect(self.bright, QtCore.SIGNAL("valueChanged"), target.set_brightness)
		QtCore.QObject.connect(self.cbb, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_material)
		QtCore.QObject.connect(self.smp, QtCore.SIGNAL("valueChanged(int)"), target.set_sample)
		QtCore.QObject.connect(self.wiretog, QtCore.SIGNAL("toggled(bool)"), target.toggle_wire)
		QtCore.QObject.connect(self.lighttog, QtCore.SIGNAL("toggled(bool)"), target.toggle_light)
		QtCore.QObject.connect(self.texturetog, QtCore.SIGNAL("toggled(bool)"), self.toggle_texture)
		QtCore.QObject.connect(self.cubetog, QtCore.SIGNAL("toggled(bool)"), target.toggle_cube)
		QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"), target.set_GL_contrast)
		QtCore.QObject.connect(self.glbrightness, QtCore.SIGNAL("valueChanged"), target.set_GL_brightness)
		
		QtCore.QObject.connect(self.ambient_tab.r, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.ambient_tab.g, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.ambient_tab.b, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.diffuse_tab.r, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.diffuse_tab.g, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.diffuse_tab.b, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.specular_tab.r, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.specular_tab.g, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.specular_tab.b, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.emission_tab.r, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.emission_tab.g, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.emission_tab.b, QtCore.SIGNAL("valueChanged"), self.update_material)
		QtCore.QObject.connect(self.shininess, QtCore.SIGNAL("valueChanged"), self.update_material)



	def on_mrc_text_change(self,text): #if enable_browse, added by muthu
		print "Use the Browse button to update the mrc file"

	def on_mrc_browse(self): #if enable_browse, added by muthu
		import os
		self.mrcfileName = QtGui.QFileDialog.getOpenFileName(self, "open file", os.getcwd(), "Text files (*.mrc)")
		if (self.mrcfileName == ""): return
		mrcData = EMData(str(self.mrcfileName))
		self.target().set_data(mrcData)
		self.mrc_text.setText(self.mrcfileName) 
		self.mrcChanged = True
		self.target().updateGL()
	
	def update_rotations(self,t3d):
		self.rotation_sliders.update_rotations(t3d)
	
	def set_scale(self,val):
		self.rotation_sliders.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.rotation_sliders.set_xy_trans(x,y)
	
	def set_xyz_trans(self,x,y,z):
		self.rotation_sliders.set_xyz_trans(x,y,z)
	
	def get_transform_layout(self):
		return self.maintab.vbl
	
	
	def update_material(self):
		self.target().isocolor = "custom"
		custom = {}
		
		custom["ambient"] = [self.ambient_tab.r.getValue(), self.ambient_tab.g.getValue(), self.ambient_tab.b.getValue(),1.0]
		custom["diffuse"] = [self.diffuse_tab.r.getValue(), self.diffuse_tab.g.getValue(), self.diffuse_tab.b.getValue(),1.0]
		custom["specular"] = [self.specular_tab.r.getValue(), self.specular_tab.g.getValue(), self.specular_tab.b.getValue(),1.0]
		custom["emission"] = [self.emission_tab.r.getValue(), self.emission_tab.g.getValue(), self.emission_tab.b.getValue(),1.0]
		custom["shininess"] = self.shininess.getValue()
		self.target().colors["custom"] = custom

		n = self.cbb.findText(QtCore.QString("custom"))
		if n < 0: return
		self.cbb.setCurrentIndex(n)
		self.target().updateGL()
	
	def set_material(self,color):
		self.target().set_material(color)
		material = self.target().get_material()
		
		self.ambient_tab.r.setValue(material["ambient"][0])
		self.ambient_tab.g.setValue(material["ambient"][1])
		self.ambient_tab.b.setValue(material["ambient"][2])
		
		self.diffuse_tab.r.setValue(material["diffuse"][0])
		self.diffuse_tab.g.setValue(material["diffuse"][1])
		self.diffuse_tab.b.setValue(material["diffuse"][2])
		
		self.specular_tab.r.setValue(material["specular"][0])
		self.specular_tab.g.setValue(material["specular"][1])
		self.specular_tab.b.setValue(material["specular"][2])
		
		self.emission_tab.r.setValue(material["emission"][0])
		self.emission_tab.g.setValue(material["emission"][1])
		self.emission_tab.b.setValue(material["emission"][2])
		
		self.shininess.setValue(material["shininess"])
	
	def get_RGB_tab(self, name=""):
		return get_RGB_tab(self,name)
		#rgbtab = QtGui.QWidget(self)
		#rgbtab.vbl = QtGui.QVBoxLayout(rgbtab)
		#rgbtab.vbl.setMargin(0)
		#rgbtab.vbl.setSpacing(6)
		#rgbtab.vbl.setObjectName(name)
		
		#rgbtab.r = ValSlider(rgbtab,(0.0,1.0),"R:")
		#rgbtab.r.setObjectName("R")
		#rgbtab.r.setValue(0.5)
		#rgbtab.vbl.addWidget(rgbtab.r)
		
		#rgbtab.g = ValSlider(rgbtab,(0.0,1.0),"G:")
		#rgbtab.g.setObjectName("G")
		#rgbtab.g.setValue(0.5)
		#rgbtab.vbl.addWidget(rgbtab.g)
		
		#rgbtab.b = ValSlider(rgbtab,(0.0,1.0),"B:")
		#rgbtab.b.setObjectName("B")
		#rgbtab.b.setValue(0.5)
		#rgbtab.vbl.addWidget(rgbtab.b)
		
		#return rgbtab
	
	def get_GL_tab(self):
		self.gltab = QtGui.QWidget()
		gltab = self.gltab
		
		gltab.vbl = QtGui.QVBoxLayout(self.gltab )
		gltab.vbl.setMargin(0)
		gltab.vbl.setSpacing(6)
		gltab.vbl.setObjectName("GL")
		
		
		self.glcontrast = ValSlider(gltab,(1.0,5.0),"GLShd:")
		self.glcontrast.setObjectName("GLShade")
		self.glcontrast.setValue(1.0)
		gltab.vbl.addWidget(self.glcontrast)
		
		self.glbrightness = ValSlider(gltab,(-1.0,0.0),"GLBst:")
		self.glbrightness.setObjectName("GLBoost")
		self.glbrightness.setValue(0.1)
		self.glbrightness.setValue(0.0)
		gltab.vbl.addWidget(self.glbrightness)
	
		self.material_tab_widget = QtGui.QTabWidget()
		self.ambient_tab = self.get_RGB_tab("ambient")
		self.material_tab_widget.addTab(self.ambient_tab, "Ambient")
		
		self.diffuse_tab = self.get_RGB_tab("diffuse")
		self.material_tab_widget.addTab(self.diffuse_tab, "Diffuse")
		
		self.specular_tab = self.get_RGB_tab("specular")
		self.material_tab_widget.addTab(self.specular_tab, "Specular")
		
		self.emission_tab = self.get_RGB_tab("emission")
		self.material_tab_widget.addTab(self.emission_tab, "Emission")
		
		gltab.vbl.addWidget(self.material_tab_widget)

		self.shininess = ValSlider(gltab,(0,128),"Shininess:")
		self.shininess.setObjectName("Shininess")
		self.shininess.setValue(64)
		gltab.vbl.addWidget(self.shininess)

		self.hbl_color = QtGui.QHBoxLayout()
		self.hbl_color.setMargin(0)
		self.hbl_color.setSpacing(6)
		self.hbl_color.setObjectName("Material")
		gltab.vbl.addLayout(self.hbl_color)
		
		self.color_label = QtGui.QLabel()
		self.color_label.setText('Material')
		self.hbl_color.addWidget(self.color_label)
		
		self.cbb = QtGui.QComboBox(gltab)
		self.hbl_color.addWidget(self.cbb)
		
		return gltab
	
	def toggle_texture(self):
		self.texture = not self.texture
		self.target().toggle_texture()
		self.get_texture_tab().setEnabled(self.texture)
	
	def get_texture_tab(self):
		if ( self.texturetab == None ):
			self.texturetab = QtGui.QWidget()
			texturetab = self.texturetab
			texturetab.vbl = QtGui.QVBoxLayout(self.texturetab)
			texturetab.vbl.setMargin(0)
			texturetab.vbl.setSpacing(6)
			texturetab.vbl.setObjectName("Main")
		
			self.contrast = ValSlider(texturetab,(0.0,20.0),"Cont:")
			self.contrast.setObjectName("contrast")
			self.contrast.setValue(10.0)
			texturetab.vbl.addWidget(self.contrast)
	
			self.bright = ValSlider(texturetab,(-5.0,5.0),"Brt:")
			self.bright.setObjectName("bright")
			self.bright.setValue(0.1)
			self.bright.setValue(0.0)
			texturetab.vbl.addWidget(self.bright)
			
			#self.glcontrast = ValSlider(texturetab,(1.0,5.0),"GLShd:")
			#self.glcontrast.setObjectName("GLShade")
			#self.glcontrast.setValue(1.0)
			#texturetab.vbl.addWidget(self.glcontrast)
			
			#self.glbrightness = ValSlider(texturetab,(-1.0,0.0),"GLBst:")
			#self.glbrightness.setObjectName("GLBoost")
			#self.glbrightness.setValue(0.1)
			#self.glbrightness.setValue(0.0)
			#texturetab.vbl.addWidget(self.glbrightness)
			
		return self.texturetab
	
	def get_main_tab(self):
		if ( self.maintab == None ):
			self.maintab = QtGui.QWidget()
			maintab = self.maintab
			maintab.vbl = QtGui.QVBoxLayout(self.maintab)
			maintab.vbl.setMargin(0)
			maintab.vbl.setSpacing(6)
			maintab.vbl.setObjectName("Main")
			
			self.thr = ValSlider(maintab,(0.0,4.0),"Thr:")
			self.thr.setObjectName("thr")
			self.thr.setValue(0.5)
			maintab.vbl.addWidget(self.thr)
			
			self.hbl_smp = QtGui.QHBoxLayout()
			self.hbl_smp.setMargin(0)
			self.hbl_smp.setSpacing(6)
			self.hbl_smp.setObjectName("Sample")
			maintab.vbl.addLayout(self.hbl_smp)
			
			self.smp_label = QtGui.QLabel()
			self.smp_label.setText('Sample Level')
			self.hbl_smp.addWidget(self.smp_label)
			
			self.smp = QtGui.QSpinBox(maintab)
			self.smp.setValue(1)
			self.hbl_smp.addWidget(self.smp)
	
			self.rotation_sliders.addWidgets(maintab.vbl)
			
		return self.maintab
	
	def set_sampling_range(self,range):
		self.smp.setMinimum(1)
		self.smp.setMaximum(1+range-1)
	
	def slider_rotate(self):
		self.target().load_rotation(self.get_current_rotation())
	
	
	def set_materials(self,colors,current_color):
		a = 0
		for i in colors:
			self.cbb.addItem(i)
			if ( i == current_color):
				self.cbb.setCurrentIndex(a)
			a += 1

	def on_threshold_slider(self,val):
		self.target().set_threshold(val)
		self.bright.setValue(-val,True)
		
	def set_thresholds(self,low,high,val):
		self.thr.setRange(low,high)
		self.thr.setValue(val, True)
		self.bright.setValue(-val,True)
	
	def set_sample(self,low,high,val):
		self.smp.setRange(int(low),int(high))
		self.smp.setValue(val, True)
		
	def set_hist(self,hist,minden,maxden):
		self.hist.set_data(hist,minden,maxden)
Пример #7
0
class EM3DAdvancedInspector(QtGui.QWidget,EMLightsInspectorBase):
	
	
	def __init__(self,target,parent=None):
		QtGui.QWidget.__init__(self,None)
		EMLightsInspectorBase.__init__(self)
		self.target=weakref.ref(target)
		self.parent=weakref.ref(parent)

		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")

		self.tabwidget = QtGui.QTabWidget()
		self.tabwidget.addTab(self.get_main_tab(), "Transform")
		self.tabwidget.addTab(self.get_light_tab(), "Lights")
		
		#self.tabwidget.addTab(self.get_GL_tab(),"GL")
		
		self.vbl.addWidget(self.tabwidget)
		

		QtCore.QObject.connect(self.persbut, QtCore.SIGNAL("pressed()"), self.perspective_clicked)
		QtCore.QObject.connect(self.orthbut, QtCore.SIGNAL("pressed()"), self.ortho_clicked)
	
	
	def get_main_tab(self):
		self.maintab = QtGui.QWidget()
		maintab = self.maintab
		maintab.vbl = QtGui.QVBoxLayout(self.maintab)
		
		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(2)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		
		self.persbut = QtGui.QRadioButton("Perspective")
		self.persbut.setChecked(self.target().perspective==True)
		
		self.orthbut = QtGui.QRadioButton("Orthographic")
		self.orthbut.setChecked(self.target().perspective==False)
		
		self.groupbox = QtGui.QVBoxLayout()
		self.groupbox.addWidget(self.persbut)
		self.groupbox.addWidget(self.orthbut)
		
		self.viewingvol = QtGui.QGroupBox("Viewing Volume")
		self.viewingvol.setLayout(self.groupbox)
		
		self.hbl.addWidget(self.viewingvol)
		
		maintab.vbl.addLayout(self.hbl)
		
		self.rotation_sliders = EMTransformPanel(self.target(),self)
		self.rotation_sliders.addWidgets(maintab.vbl)
		
		return self.maintab
		
	def get_transform_layout(self):
		return self.vbl
		
	def update_rotations(self,t3d):
		self.rotation_sliders.update_rotations(t3d)
		
	def set_scale(self,val):
		self.rotation_sliders.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.rotation_sliders.set_xy_trans(x,y)
	
	def set_xyz_trans(self, x, y,z):
		self.rotation_sliders.set_xyz_trans(x,y,z)
	
	def perspective_clicked(self):
		self.target().set_perspective(True)
		
	def ortho_clicked(self):
		self.target().set_perspective(False)
Пример #8
0
class EMVolumeInspector(QtGui.QWidget):
	def __init__(self,target) :
		QtGui.QWidget.__init__(self,None)
		self.target=weakref.ref(target)
		self.setWindowIcon(QtGui.QIcon(get_image_directory() +"desktop.png"))
		self.rotation_sliders = EMTransformPanel(target,self)
		
		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")
		
		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(0)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		self.vbl.addLayout(self.hbl)
		
		self.hist = ImgHistogram(self)
		self.hist.setObjectName("hist")
		self.hbl.addWidget(self.hist)
		
		self.vbl2 = QtGui.QVBoxLayout()
		self.vbl2.setMargin(0)
		self.vbl2.setSpacing(6)
		self.vbl2.setObjectName("vbl2")
		self.hbl.addLayout(self.vbl2)
	
		self.cubetog = QtGui.QPushButton("Cube")
		self.cubetog.setCheckable(1)
		self.vbl2.addWidget(self.cubetog)
		
		self.defaults = QtGui.QPushButton("Defaults")
		self.vbl2.addWidget(self.defaults)
		
		self.tabwidget = QtGui.QTabWidget()
		
		self.tabwidget.addTab(self.get_main_tab(), "Main")
		self.tabwidget.addTab(self.get_GL_tab(),"GL")
		
		self.vbl.addWidget(self.tabwidget)
		
		self.n3_showing = False
		
		QtCore.QObject.connect(self.contrast, QtCore.SIGNAL("valueChanged"), target.set_contrast)
		QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"), target.set_GL_contrast)
		QtCore.QObject.connect(self.glbrightness, QtCore.SIGNAL("valueChanged"), target.set_GL_brightness)
		QtCore.QObject.connect(self.bright, QtCore.SIGNAL("valueChanged"), target.set_brightness)
		QtCore.QObject.connect(self.cubetog, QtCore.SIGNAL("toggled(bool)"), target.toggle_cube)
		QtCore.QObject.connect(self.defaults, QtCore.SIGNAL("clicked(bool)"), self.set_defaults)
		QtCore.QObject.connect(self.smp, QtCore.SIGNAL("valueChanged(int)"), target.set_texture_sample)
	
	def update_rotations(self,t3d):
		self.rotation_sliders.update_rotations(t3d)
	
	def set_scale(self,val):
		self.rotation_sliders.set_scale(val)
	
	def set_xy_trans(self, x, y):
		self.rotation_sliders.set_xy_trans(x,y)
	
	def set_xyz_trans(self,x,y,z):
		self.rotation_sliders.set_xyz_trans(x,y,z)	
		
	def get_transform_layout(self):
		return self.maintab.vbl
	
	def get_GL_tab(self):
		self.gltab = QtGui.QWidget()
		gltab = self.gltab
		
		gltab.vbl = QtGui.QVBoxLayout(self.gltab )
		gltab.vbl.setMargin(0)
		gltab.vbl.setSpacing(6)
		gltab.vbl.setObjectName("Main")
		
		self.glcontrast = ValSlider(gltab,(1.0,5.0),"GLShd:")
		self.glcontrast.setObjectName("GLShade")
		self.glcontrast.setValue(1.0)
		gltab.vbl.addWidget(self.glcontrast)
		
		self.glbrightness = ValSlider(gltab,(-1.0,0.0),"GLBst:")
		self.glbrightness.setObjectName("GLBoost")
		self.glbrightness.setValue(0.1)
		self.glbrightness.setValue(0.0)
		gltab.vbl.addWidget(self.glbrightness)
	
		return gltab
	
	def get_main_tab(self):
	
		self.maintab = QtGui.QWidget()
		maintab = self.maintab
		maintab.vbl = QtGui.QVBoxLayout(self.maintab)
		maintab.vbl.setMargin(0)
		maintab.vbl.setSpacing(6)
		maintab.vbl.setObjectName("Main")
			
		self.contrast = ValSlider(maintab,(0.0,20.0),"Cont:")
		self.contrast.setObjectName("contrast")
		self.contrast.setValue(1.0)
		maintab.vbl.addWidget(self.contrast)

		self.bright = ValSlider(maintab,(-5.0,5.0),"Brt:")
		self.bright.setObjectName("bright")
		self.bright.setValue(0.1)
		self.bright.setValue(0.0)
		maintab.vbl.addWidget(self.bright)

		self.hbl_smp = QtGui.QHBoxLayout()
		self.hbl_smp.setMargin(0)
		self.hbl_smp.setSpacing(6)
		self.hbl_smp.setObjectName("Texture Oversampling")
		maintab.vbl.addLayout(self.hbl_smp)
		
		self.smp_label = QtGui.QLabel()
		self.smp_label.setText('Texture Oversampling')
		self.hbl_smp.addWidget(self.smp_label)
		
		self.smp = QtGui.QSpinBox(maintab)
		self.smp.setMaximum(10)
		self.smp.setMinimum(1)
		self.smp.setValue(1)
		self.hbl_smp.addWidget(self.smp)

		self.lowlim=0
		self.highlim=1.0
		self.busy=0

		self.rotation_sliders.addWidgets(maintab.vbl)

		return maintab
	
	def set_defaults(self):
		self.contrast.setValue(1.0)
		self.bright.setValue(0.0)
		self.glcontrast.setValue(1.0)
		self.glbrightness.setValue(0.0)
		self.rotation_sliders.set_defaults()
	
	def slider_rotate(self):
		self.target().load_rotation(self.get_current_rotation())
	
	def set_hist(self,hist,minden,maxden):
		self.hist.set_data(hist,minden,maxden)
Пример #9
0
class EM3DSliceInspector(QtGui.QWidget):
    def __init__(self, target):
        self.busy = False
        QtGui.QWidget.__init__(self, None)
        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "desktop.png"))
        self.transform_panel = EMTransformPanel(target, self)
        self.target = weakref.ref(target)

        self.vbl = QtGui.QVBoxLayout(self)
        self.vbl.setMargin(0)
        self.vbl.setSpacing(6)
        self.vbl.setObjectName("vbl")

        self.hbl = QtGui.QHBoxLayout()
        self.hbl.setMargin(0)
        self.hbl.setSpacing(6)
        self.hbl.setObjectName("hbl")
        self.vbl.addLayout(self.hbl)

        self.hist = ImgHistogram(self)
        self.hist.setObjectName("hist")
        self.hbl.addWidget(self.hist)

        self.vbl2 = QtGui.QVBoxLayout()
        self.vbl2.setMargin(0)
        self.vbl2.setSpacing(6)
        self.vbl2.setObjectName("vbl2")
        self.hbl.addLayout(self.vbl2)

        self.cubetog = QtGui.QPushButton("Cube")
        self.cubetog.setCheckable(1)
        self.vbl2.addWidget(self.cubetog)

        self.defaults = QtGui.QPushButton("Defaults")
        self.vbl2.addWidget(self.defaults)

        self.vbl.addWidget(self.get_main_tab())

        self.n3_showing = False

        #		self.current_src = EULER_EMAN

        QtCore.QObject.connect(self.slice, QtCore.SIGNAL("valueChanged"),
                               target.set_slice)
        QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"),
                               target.set_GL_contrast)
        QtCore.QObject.connect(self.glbrightness,
                               QtCore.SIGNAL("valueChanged"),
                               target.set_GL_brightness)
        QtCore.QObject.connect(self.axisCombo,
                               QtCore.SIGNAL("currentIndexChanged(QString)"),
                               target.setAxis)
        QtCore.QObject.connect(self.cubetog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_cube)
        QtCore.QObject.connect(self.defaults, QtCore.SIGNAL("clicked(bool)"),
                               self.set_defaults)
        QtCore.QObject.connect(self.contrast, QtCore.SIGNAL("valueChanged"),
                               self.on_contrast_changed)
        QtCore.QObject.connect(self.bright, QtCore.SIGNAL("valueChanged"),
                               self.on_brightness_changed)

    def on_contrast_changed(self, val):
        if self.busy: return
        self.target().set_contrast(val)

    def on_brightness_changed(self, val):
        if self.busy: return
        self.target().set_brightness(val)

    def set_contrast_bright(self, c, b):
        self.busy = True
        self.contrast.setValue(c)
        self.bright.setValue(b)
        self.busy = False

    def update_rotations(self, t3d):
        self.transform_panel.update_rotations(t3d)

    def set_scale(self, val):
        self.transform_panel.set_scale(val)

    def set_xy_trans(self, x, y):
        self.transform_panel.set_xy_trans(x, y)

    def set_xyz_trans(self, x, y, z):
        self.transform_panel.set_xyz_trans(x, y, z)

    def get_transform_layout(self):
        return self.maintab.vbl

    def set_defaults(self):
        self.target().set_default_contrast_settings()
        self.set_contrast_bright(self.target().contrast, self.target().bright)
        self.glcontrast.setValue(1.0)
        self.glbrightness.setValue(0.0)
        self.transform_panel.set_defaults()

        self.target().generate_current_display_list()
        self.target().updateGL()

    def get_main_tab(self):

        self.maintab = QtGui.QWidget()
        maintab = self.maintab
        maintab.vbl = QtGui.QVBoxLayout(self.maintab)
        maintab.vbl.setMargin(0)
        maintab.vbl.setSpacing(6)
        maintab.vbl.setObjectName("Main")

        self.hbl_slice = QtGui.QHBoxLayout()
        self.hbl_slice.setMargin(0)
        self.hbl_slice.setSpacing(6)
        self.hbl_slice.setObjectName("Axis")
        maintab.vbl.addLayout(self.hbl_slice)

        self.slice = ValSlider(maintab, (0.0, 10.0), "Slice:")
        self.slice.setObjectName("slice")
        self.slice.setValue(1.0)
        self.hbl_slice.addWidget(self.slice)

        self.axisCombo = QtGui.QComboBox(maintab)
        self.axisCombo.addItem(' z ')
        self.axisCombo.addItem(' y ')
        self.axisCombo.addItem(' x ')
        self.axisCombo.addItem(' track ')
        self.hbl_slice.addWidget(self.axisCombo)

        self.contrast = ValSlider(maintab, (0.0, 20.0), "Cont:")
        self.contrast.setObjectName("contrast")
        self.contrast.setValue(1.0)
        maintab.vbl.addWidget(self.contrast)

        self.bright = ValSlider(maintab, (-5.0, 5.0), "Brt:")
        self.bright.setObjectName("bright")
        self.bright.setValue(0.1)
        self.bright.setValue(0.0)
        maintab.vbl.addWidget(self.bright)

        self.glcontrast = ValSlider(maintab, (1.0, 5.0), "GLShd:")
        self.glcontrast.setObjectName("GLShade")
        self.glcontrast.setValue(1.0)
        maintab.vbl.addWidget(self.glcontrast)

        self.glbrightness = ValSlider(maintab, (-1.0, 0.0), "GLBst:")
        self.glbrightness.setObjectName("GLBoost")
        self.glbrightness.setValue(0.1)
        self.glbrightness.setValue(0.0)
        maintab.vbl.addWidget(self.glbrightness)

        self.transform_panel.addWidgets(maintab.vbl)

        return maintab

    def slider_rotate(self):
        self.target().load_rotation(self.get_current_rotation())

    def set_hist(self, hist, minden, maxden):
        self.hist.set_data(hist, minden, maxden)

    def set_slice(self, val):
        self.slice.setValue(val)

    def set_sliceRange(self, min, max):
        self.slice.setRange(min, max)
Пример #10
0
class EMFontInspector(QtGui.QWidget, EMLightsInspectorBase):
	def __init__(self,target) :
		QtGui.QWidget.__init__(self,None)
		EMLightsInspectorBase.__init__(self)
		self.target=weakref.ref(target)
		self.transform_panel = EMTransformPanel(target,self)
		self.transform_vbl = None # This will eventually be a vertical box layout for the transform panel
		self.init_fonts()

		self.vbl = QtGui.QVBoxLayout(self)
		self.vbl.setMargin(0)
		self.vbl.setSpacing(6)
		self.vbl.setObjectName("vbl")

		self.hbl = QtGui.QHBoxLayout()
		self.hbl.setMargin(0)
		self.hbl.setSpacing(6)
		self.hbl.setObjectName("hbl")
		self.vbl.addLayout(self.hbl)

		self.vbl2 = QtGui.QVBoxLayout()
		self.vbl2.setMargin(0)
		self.vbl2.setSpacing(6)
		self.vbl2.setObjectName("vbl2")
		self.hbl.addLayout(self.vbl2)

		self.wiretog = QtGui.QPushButton("Wire")
		self.wiretog.setCheckable(1)
		self.vbl2.addWidget(self.wiretog)

		self.lighttog = QtGui.QPushButton("Light")
		self.lighttog.setCheckable(1)
		self.vbl2.addWidget(self.lighttog)

		self.tabwidget2 = QtGui.QTabWidget()
		self.maintab = None
		self.tabwidget2.addTab(self.get_main_tab(), "Main")
		#self.tabwidget2.addTab(self.get_GL_tab(),"GL")
		self.tabwidget2.addTab(self.get_format_tab(),"Formatting")
		self.tabwidget2.addTab(self.get_light_tab(), "Lights")
		self.vbl.addWidget(self.tabwidget2)
		self.n3_showing = False

		QtCore.QObject.connect(self.cbb, QtCore.SIGNAL("currentIndexChanged(QString)"), target.setColor)
		QtCore.QObject.connect(self.wiretog, QtCore.SIGNAL("toggled(bool)"), target.toggle_wire)
		QtCore.QObject.connect(self.lighttog, QtCore.SIGNAL("toggled(bool)"), target.toggle_light)
		QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"), target.set_GL_contrast)
		QtCore.QObject.connect(self.glbrightness, QtCore.SIGNAL("valueChanged"), target.set_GL_brightness)
		QtCore.QObject.connect(self.combo, QtCore.SIGNAL("currentIndexChanged (const QString&)"), self.on_combo_change)
		QtCore.QObject.connect(self.text, QtCore.SIGNAL("textChanged(const QString&)"), self.on_text_change)
		QtCore.QObject.connect(self.lspacing, QtCore.SIGNAL("valueChanged"), self.set_GL_lspacing)
		QtCore.QObject.connect(self.length, QtCore.SIGNAL("valueChanged"), self.set_GL_length)
		QtCore.QObject.connect(self.tsize, QtCore.SIGNAL("valueChanged(int)"), self.set_GL_tsize)
		QtCore.QObject.connect(self.Dfont, QtCore.SIGNAL("currentIndexChanged (const QString&)"), self.on_Dfont_change)
		QtCore.QObject.connect(self.bgR, QtCore.SIGNAL("valueChanged"), self.set_GL_bgR)
		QtCore.QObject.connect(self.bgG, QtCore.SIGNAL("valueChanged"), self.set_GL_bgG)
		QtCore.QObject.connect(self.bgB, QtCore.SIGNAL("valueChanged"), self.set_GL_bgB)
		QtCore.QObject.connect(self.bg_a, QtCore.SIGNAL("valueChanged"), self.set_GL_bg_a)
	
	def get_transform_layout(self):
		return self.transform_vbl
		
	def set_GL_bgR(self,bgR):
		self.target().set_bg_r(bgR)
		self.target().updateGL()

	def set_GL_bgG(self,bgG):
		self.target().set_bg_g(bgG)
		self.target().updateGL()

	def set_GL_bgB(self,bgB):
		self.target().set_bg_b(bgB)
		self.target().updateGL()

	def set_GL_bg_a(self,bg_a):
		self.target().set_bg_a(bg_a)
		self.target().updateGL()

	def init_fonts(self):
		self.d = {}
		self.l = []
		platform = get_platform()
		if platform == "Linux":
			f_dir = "/usr/share/fonts/"
		elif platform == "Windows" or platform == "win32":
			f_dir = ":/windows/fonts/"
		elif platform in ["Apple", "Darwin"]:
			f_dir = "/Library/Fonts/"
		else:
			raise RuntimeError("Platform %s is not supported" %platform )
		
		for root, dirs, files in os.walk(f_dir):
			for name in files:
				if name.find("ttf")!=-1:
					filename = os.path.join(root, name)
					self.d[name] = filename
					self.l.extend([name])
		return self.l, self.d

	def on_Dfont_change(self,Dfont):
		self.target().font_renderer.set_font_file_name(self.d[str(Dfont)])
		self.target().updateGL()

	def set_GL_lspacing(self,lspacing):
		self.target().set_lspacing(lspacing)
		#THE FOLLOWING IF STATEMENT DOES IS NOT EFFECTIVE
		if len(self.target().render_string.split("\n")) != 1:
			self.lspacing.setEnabled(True)
		else:
			self.lspacing.setEnabled(False)
		self.target().updateGL()

	def set_GL_length(self,length):
		self.target().font_renderer.set_depth(int(length))	
		self.target().updateGL()

	def set_GL_tsize(self,tsize):
		self.target().font_renderer.set_face_size(tsize)
		self.target().updateGL()

	def on_text_change(self,text):
		try:
			evalt=str(eval(str(text)))
			self.target().set_render_string(evalt)
		except:
			self.target().set_render_string(str(text))
			
		if len(self.target().render_string.split("\n")) != 1:
			self.lspacing.setEnabled(True)
		else:
			self.lspacing.setEnabled(False)
		self.target().updateGL()

	def on_combo_change(self,mode):
		d = {}
		d["Extrude"] = FTGLFontMode.EXTRUDE
		d["Pixmap"] = FTGLFontMode.PIXMAP
		d["Bitmap"] = FTGLFontMode.BITMAP
		d["Polygon"] = FTGLFontMode.POLYGON
		d["Outline"] = FTGLFontMode.OUTLINE
		d["Texture"] = FTGLFontMode.TEXTURE
		self.target().font_renderer.set_font_mode(d[str(mode)])
		if mode == "Extrude":
			self.length.setEnabled(True)
		else:
			self.length.setEnabled(False)
		self.target().updateGL()

	def update_rotations(self,t3d):
		self.transform_panel.update_rotations(t3d)

	def set_scale(self,val):
		self.transform_panel.set_scale(val)

	def set_xy_trans(self, x, y):
		self.transform_panel.set_xy_trans(x,y)

	def set_xyz_trans(self,x,y,z):
		self.transform_panel.set_xyz_trans(x,y,z)	

	def get_GL_tab(self):
		self.gltab = QtGui.QWidget()
		gltab = self.gltab

		gltab.vbl = QtGui.QVBoxLayout(self.gltab)
		gltab.vbl.setMargin(0)
		gltab.vbl.setSpacing(6)
		gltab.vbl.setObjectName("Main")

		self.glcontrast = ValSlider(gltab,(1.0,5.0),"GLShd:")
		self.glcontrast.setObjectName("GLShade")
		self.glcontrast.setValue(1.0)
		gltab.vbl.addWidget(self.glcontrast)

		self.glbrightness = ValSlider(gltab,(-1.0,0.0),"GLBst:")
		self.glbrightness.setObjectName("GLBoost")
		self.glbrightness.setValue(0.1)
		self.glbrightness.setValue(0.0)
		gltab.vbl.addWidget(self.glbrightness)

		return gltab

	def get_main_tab(self):
		if ( self.maintab == None ):
			self.maintab = QtGui.QWidget()
			maintab = self.maintab
			maintab.vbl = QtGui.QVBoxLayout(self.maintab)
			maintab.vbl.setMargin(0)
			maintab.vbl.setSpacing(6)
			maintab.vbl.setObjectName("Main")
			
			self.transform_vbl = QtGui.QVBoxLayout()
			self.transform_panel.addWidgets(self.transform_vbl)
			maintab.vbl.addLayout(self.transform_vbl)
			self.glwidget = QtGui.QTabWidget()
			self.glwidget.addTab(self.get_GL_tab(),"GL")
			maintab.vbl.addWidget(self.glwidget)

		return maintab

	def get_format_tab(self):
		self.formattab = QtGui.QWidget()
		formattab = self.formattab
		formattab.vbl = QtGui.QVBoxLayout(self.formattab)
		formattab.vbl.setMargin(0)
		formattab.vbl.setSpacing(6)
		formattab.vbl.setObjectName("Format")

		self.hbl1 = QtGui.QHBoxLayout()
		self.text = QtGui.QLineEdit()
		self.text.setText("hello world")
		text_label = QtGui.QLabel("Enter Text:",self)
		text_label.setToolTip("Enters quotes to evaluate new line e.g. \"hello\\nworld\". Evaluates numerical expressions e.g. 9*9 (with out quotes)")
		self.hbl1.addWidget(text_label)
		self.hbl1.addWidget(self.text)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.Dfont = QtGui.QComboBox()
		for k in self.l: self.Dfont.addItem(k)
		self.hbl1.addWidget(QtGui.QLabel("Fonts:",self))
		self.hbl1.addWidget(self.Dfont)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.tsize = QtGui.QSpinBox()
		self.tsize.setRange(0,500)
		self.tsize.setValue(32)
		self.hbl1.addWidget(QtGui.QLabel("Size:",self),Qt.AlignLeft)
		self.hbl1.addWidget(self.tsize,Qt.AlignRight)
		self.combo = QtGui.QComboBox()
		self.items = ["Extrude","Pixmap","Bitmap","Polygon","Outline","Texture"]
		for k in self.items: self.combo.addItem(k)
		self.hbl1.addWidget(QtGui.QLabel("Style:",self),Qt.AlignLeft)
		self.hbl1.addWidget(self.combo,Qt.AlignRight)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.lspacing = ValSlider(self,(-100.0,100.0),"Line Spacing:")
		self.lspacing.setObjectName("Length")
		self.lspacing.setValue(75.0)
		self.lspacing.setEnabled(False)
		self.hbl1.addWidget(self.lspacing)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.length = ValSlider(self,(0.0,500.0),"Length:")
		self.length.setObjectName("Length")
		self.length.setValue(75.0)
		self.hbl1.addWidget(self.length)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.cbb = QtGui.QComboBox()
		self.hbl1.addWidget(QtGui.QLabel("Material:",self))
		self.hbl1.addWidget(self.cbb)
		formattab.vbl.addLayout(self.hbl1)

		self.hbl1 = QtGui.QHBoxLayout()
		self.bgtabwidget = QtGui.QTabWidget()
		self.maintab = None
		self.bgtabwidget.addTab(self.get_bgRGB_tab(), "BG RGB")
		self.hbl1.addWidget(self.bgtabwidget)
		self.n3_showing = False
		formattab.vbl.addLayout(self.hbl1)

		return formattab

	def get_bgRGB_tab(self):
		self.bgRGBtab = QtGui.QWidget()
		bgRGBtab = self.bgRGBtab
		bgRGBtab.vbl2 = QtGui.QVBoxLayout(self.bgRGBtab)
		bgRGBtab.vbl2.setMargin(0)
		bgRGBtab.vbl2.setSpacing(6)
		bgRGBtab.vbl2.setObjectName("BG RGB")

		self.hbl2 = QtGui.QHBoxLayout()
		self.bgR = ValSlider(self,(0,1),"R:")
		self.bgR.setObjectName("R")
		self.bgR.setValue(0.5)
		self.hbl2.addWidget(self.bgR)
		bgRGBtab.vbl2.addLayout(self.hbl2)

		self.hbl2 = QtGui.QHBoxLayout()
		self.bgG = ValSlider(self,(0,1),"G:")
		self.bgG.setObjectName("G")
		self.bgG.setValue(0.5)
		self.hbl2.addWidget(self.bgG)
		bgRGBtab.vbl2.addLayout(self.hbl2)

		self.hbl2 = QtGui.QHBoxLayout()
		self.bgB = ValSlider(self,(0,1),"B:")
		self.bgB.setObjectName("B")
		self.bgB.setValue(0.5)
		self.hbl2.addWidget(self.bgB)
		bgRGBtab.vbl2.addLayout(self.hbl2)		

		self.hbl2 = QtGui.QHBoxLayout()
		self.bg_a = ValSlider(self,(0,1),"Alpha:")
		self.bg_a.setObjectName("Alpha")
		self.bg_a.setValue(1.0)
		self.hbl2.addWidget(self.bg_a)
		bgRGBtab.vbl2.addLayout(self.hbl2)

		return bgRGBtab

#	def slider_rotate(self):
#		self.target.load_rotation(self.get_current_rotation())

#	def set_xy_trans(self, x, y):
#		self.x_trans.setValue(x)
#		self.y_trans.setValue(y)

#	def set_translate_scale(self, xscale,yscale,zscale):
#		self.x_trans.setSingleStep(xscale)
#		self.y_trans.setSingleStep(yscale)
#		self.z_trans.setSingleStep(zscale)

#	def update_rotations(self,t3d):
#		rot = t3d.get_rotation(self.src_map[str(self.src.itemText(self.src.currentIndex()))])
#		
#		convention = self.src.currentText()
#		if ( self.src_map[str(convention)] == EULER_SPIN ):
#			self.n3.setValue(rot[self.n3.getLabel()],True)
#		
#		self.az.setValue(rot[self.az.getLabel()],True)
#		self.alt.setValue(rot[self.alt.getLabel()],True)
#		self.phi.setValue(rot[self.phi.getLabel()],True)

#	def slider_rotate(self):
#		self.target.load_rotation(self.get_current_rotation())

#	def get_current_rotation(self):
#		convention = self.src.currentText()
#		rot = {}
#		if ( self.current_src == EULER_SPIN ):
#			rot[self.az.getLabel()] = self.az.getValue()
#			
#			n1 = self.alt.getValue()
#			n2 = self.phi.getValue()
#			n3 = self.n3.getValue()
#			
#			norm = sqrt(n1*n1 + n2*n2 + n3*n3)
#			
#			n1 /= norm
#			n2 /= norm
#			n3 /= norm
#			
#			rot[self.alt.getLabel()] = n1
#			rot[self.phi.getLabel()] = n2
#			rot[self.n3.getLabel()] = n3
#
#		else:
#			rot[self.az.getLabel()] = self.az.getValue()
#			rot[self.alt.getLabel()] = self.alt.getValue()
#			rot[self.phi.getLabel()] = self.phi.getValue()
#		
#		return Transform(self.current_src, rot)

	def setColors(self,colors,current_color):
		a = 0
		for i in colors:
			self.cbb.addItem(i)
			if ( i == current_color):
				self.cbb.setCurrentIndex(a)
			a += 1
Пример #11
0
class EMFontInspector(QtGui.QWidget, EMLightsInspectorBase):
    def __init__(self, target):
        QtGui.QWidget.__init__(self, None)
        EMLightsInspectorBase.__init__(self)
        self.target = weakref.ref(target)
        self.transform_panel = EMTransformPanel(target, self)
        self.transform_vbl = None  # This will eventually be a vertical box layout for the transform panel
        self.init_fonts()

        self.vbl = QtGui.QVBoxLayout(self)
        self.vbl.setMargin(0)
        self.vbl.setSpacing(6)
        self.vbl.setObjectName("vbl")

        self.hbl = QtGui.QHBoxLayout()
        self.hbl.setMargin(0)
        self.hbl.setSpacing(6)
        self.hbl.setObjectName("hbl")
        self.vbl.addLayout(self.hbl)

        self.vbl2 = QtGui.QVBoxLayout()
        self.vbl2.setMargin(0)
        self.vbl2.setSpacing(6)
        self.vbl2.setObjectName("vbl2")
        self.hbl.addLayout(self.vbl2)

        self.wiretog = QtGui.QPushButton("Wire")
        self.wiretog.setCheckable(1)
        self.vbl2.addWidget(self.wiretog)

        self.lighttog = QtGui.QPushButton("Light")
        self.lighttog.setCheckable(1)
        self.vbl2.addWidget(self.lighttog)

        self.tabwidget2 = QtGui.QTabWidget()
        self.maintab = None
        self.tabwidget2.addTab(self.get_main_tab(), "Main")
        #self.tabwidget2.addTab(self.get_GL_tab(),"GL")
        self.tabwidget2.addTab(self.get_format_tab(), "Formatting")
        self.tabwidget2.addTab(self.get_light_tab(), "Lights")
        self.vbl.addWidget(self.tabwidget2)
        self.n3_showing = False

        QtCore.QObject.connect(self.cbb,
                               QtCore.SIGNAL("currentIndexChanged(QString)"),
                               target.setColor)
        QtCore.QObject.connect(self.wiretog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_wire)
        QtCore.QObject.connect(self.lighttog, QtCore.SIGNAL("toggled(bool)"),
                               target.toggle_light)
        QtCore.QObject.connect(self.glcontrast, QtCore.SIGNAL("valueChanged"),
                               target.set_GL_contrast)
        QtCore.QObject.connect(self.glbrightness,
                               QtCore.SIGNAL("valueChanged"),
                               target.set_GL_brightness)
        QtCore.QObject.connect(
            self.combo, QtCore.SIGNAL("currentIndexChanged (const QString&)"),
            self.on_combo_change)
        QtCore.QObject.connect(self.text,
                               QtCore.SIGNAL("textChanged(const QString&)"),
                               self.on_text_change)
        QtCore.QObject.connect(self.lspacing, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_lspacing)
        QtCore.QObject.connect(self.length, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_length)
        QtCore.QObject.connect(self.tsize, QtCore.SIGNAL("valueChanged(int)"),
                               self.set_GL_tsize)
        QtCore.QObject.connect(
            self.Dfont, QtCore.SIGNAL("currentIndexChanged (const QString&)"),
            self.on_Dfont_change)
        QtCore.QObject.connect(self.bgR, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_bgR)
        QtCore.QObject.connect(self.bgG, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_bgG)
        QtCore.QObject.connect(self.bgB, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_bgB)
        QtCore.QObject.connect(self.bg_a, QtCore.SIGNAL("valueChanged"),
                               self.set_GL_bg_a)

    def get_transform_layout(self):
        return self.transform_vbl

    def set_GL_bgR(self, bgR):
        self.target().set_bg_r(bgR)
        self.target().updateGL()

    def set_GL_bgG(self, bgG):
        self.target().set_bg_g(bgG)
        self.target().updateGL()

    def set_GL_bgB(self, bgB):
        self.target().set_bg_b(bgB)
        self.target().updateGL()

    def set_GL_bg_a(self, bg_a):
        self.target().set_bg_a(bg_a)
        self.target().updateGL()

    def init_fonts(self):
        self.d = {}
        self.l = []
        platform = get_platform()
        if platform == "Linux":
            f_dir = "/usr/share/fonts/"
        elif platform == "Windows" or platform == "win32":
            f_dir = ":/windows/fonts/"
        elif platform in ["Apple", "Darwin"]:
            f_dir = "/Library/Fonts/"
        else:
            raise RuntimeError("Platform %s is not supported" % platform)

        for root, dirs, files in os.walk(f_dir):
            for name in files:
                if name.find("ttf") != -1:
                    filename = os.path.join(root, name)
                    self.d[name] = filename
                    self.l.extend([name])
        return self.l, self.d

    def on_Dfont_change(self, Dfont):
        self.target().font_renderer.set_font_file_name(self.d[str(Dfont)])
        self.target().updateGL()

    def set_GL_lspacing(self, lspacing):
        self.target().set_lspacing(lspacing)
        #THE FOLLOWING IF STATEMENT DOES IS NOT EFFECTIVE
        if len(self.target().render_string.split("\n")) != 1:
            self.lspacing.setEnabled(True)
        else:
            self.lspacing.setEnabled(False)
        self.target().updateGL()

    def set_GL_length(self, length):
        self.target().font_renderer.set_depth(int(length))
        self.target().updateGL()

    def set_GL_tsize(self, tsize):
        self.target().font_renderer.set_face_size(tsize)
        self.target().updateGL()

    def on_text_change(self, text):
        try:
            evalt = str(eval(str(text)))
            self.target().set_render_string(evalt)
        except:
            self.target().set_render_string(str(text))

        if len(self.target().render_string.split("\n")) != 1:
            self.lspacing.setEnabled(True)
        else:
            self.lspacing.setEnabled(False)
        self.target().updateGL()

    def on_combo_change(self, mode):
        d = {}
        d["Extrude"] = FTGLFontMode.EXTRUDE
        d["Pixmap"] = FTGLFontMode.PIXMAP
        d["Bitmap"] = FTGLFontMode.BITMAP
        d["Polygon"] = FTGLFontMode.POLYGON
        d["Outline"] = FTGLFontMode.OUTLINE
        d["Texture"] = FTGLFontMode.TEXTURE
        self.target().font_renderer.set_font_mode(d[str(mode)])
        if mode == "Extrude":
            self.length.setEnabled(True)
        else:
            self.length.setEnabled(False)
        self.target().updateGL()

    def update_rotations(self, t3d):
        self.transform_panel.update_rotations(t3d)

    def set_scale(self, val):
        self.transform_panel.set_scale(val)

    def set_xy_trans(self, x, y):
        self.transform_panel.set_xy_trans(x, y)

    def set_xyz_trans(self, x, y, z):
        self.transform_panel.set_xyz_trans(x, y, z)

    def get_GL_tab(self):
        self.gltab = QtGui.QWidget()
        gltab = self.gltab

        gltab.vbl = QtGui.QVBoxLayout(self.gltab)
        gltab.vbl.setMargin(0)
        gltab.vbl.setSpacing(6)
        gltab.vbl.setObjectName("Main")

        self.glcontrast = ValSlider(gltab, (1.0, 5.0), "GLShd:")
        self.glcontrast.setObjectName("GLShade")
        self.glcontrast.setValue(1.0)
        gltab.vbl.addWidget(self.glcontrast)

        self.glbrightness = ValSlider(gltab, (-1.0, 0.0), "GLBst:")
        self.glbrightness.setObjectName("GLBoost")
        self.glbrightness.setValue(0.1)
        self.glbrightness.setValue(0.0)
        gltab.vbl.addWidget(self.glbrightness)

        return gltab

    def get_main_tab(self):
        if (self.maintab == None):
            self.maintab = QtGui.QWidget()
            maintab = self.maintab
            maintab.vbl = QtGui.QVBoxLayout(self.maintab)
            maintab.vbl.setMargin(0)
            maintab.vbl.setSpacing(6)
            maintab.vbl.setObjectName("Main")

            self.transform_vbl = QtGui.QVBoxLayout()
            self.transform_panel.addWidgets(self.transform_vbl)
            maintab.vbl.addLayout(self.transform_vbl)
            self.glwidget = QtGui.QTabWidget()
            self.glwidget.addTab(self.get_GL_tab(), "GL")
            maintab.vbl.addWidget(self.glwidget)

        return maintab

    def get_format_tab(self):
        self.formattab = QtGui.QWidget()
        formattab = self.formattab
        formattab.vbl = QtGui.QVBoxLayout(self.formattab)
        formattab.vbl.setMargin(0)
        formattab.vbl.setSpacing(6)
        formattab.vbl.setObjectName("Format")

        self.hbl1 = QtGui.QHBoxLayout()
        self.text = QtGui.QLineEdit()
        self.text.setText("hello world")
        text_label = QtGui.QLabel("Enter Text:", self)
        text_label.setToolTip(
            "Enters quotes to evaluate new line e.g. \"hello\\nworld\". Evaluates numerical expressions e.g. 9*9 (with out quotes)"
        )
        self.hbl1.addWidget(text_label)
        self.hbl1.addWidget(self.text)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.Dfont = QtGui.QComboBox()
        for k in self.l:
            self.Dfont.addItem(k)
        self.hbl1.addWidget(QtGui.QLabel("Fonts:", self))
        self.hbl1.addWidget(self.Dfont)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.tsize = QtGui.QSpinBox()
        self.tsize.setRange(0, 500)
        self.tsize.setValue(32)
        self.hbl1.addWidget(QtGui.QLabel("Size:", self), Qt.AlignLeft)
        self.hbl1.addWidget(self.tsize, Qt.AlignRight)
        self.combo = QtGui.QComboBox()
        self.items = [
            "Extrude", "Pixmap", "Bitmap", "Polygon", "Outline", "Texture"
        ]
        for k in self.items:
            self.combo.addItem(k)
        self.hbl1.addWidget(QtGui.QLabel("Style:", self), Qt.AlignLeft)
        self.hbl1.addWidget(self.combo, Qt.AlignRight)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.lspacing = ValSlider(self, (-100.0, 100.0), "Line Spacing:")
        self.lspacing.setObjectName("Length")
        self.lspacing.setValue(75.0)
        self.lspacing.setEnabled(False)
        self.hbl1.addWidget(self.lspacing)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.length = ValSlider(self, (0.0, 500.0), "Length:")
        self.length.setObjectName("Length")
        self.length.setValue(75.0)
        self.hbl1.addWidget(self.length)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.cbb = QtGui.QComboBox()
        self.hbl1.addWidget(QtGui.QLabel("Material:", self))
        self.hbl1.addWidget(self.cbb)
        formattab.vbl.addLayout(self.hbl1)

        self.hbl1 = QtGui.QHBoxLayout()
        self.bgtabwidget = QtGui.QTabWidget()
        self.maintab = None
        self.bgtabwidget.addTab(self.get_bgRGB_tab(), "BG RGB")
        self.hbl1.addWidget(self.bgtabwidget)
        self.n3_showing = False
        formattab.vbl.addLayout(self.hbl1)

        return formattab

    def get_bgRGB_tab(self):
        self.bgRGBtab = QtGui.QWidget()
        bgRGBtab = self.bgRGBtab
        bgRGBtab.vbl2 = QtGui.QVBoxLayout(self.bgRGBtab)
        bgRGBtab.vbl2.setMargin(0)
        bgRGBtab.vbl2.setSpacing(6)
        bgRGBtab.vbl2.setObjectName("BG RGB")

        self.hbl2 = QtGui.QHBoxLayout()
        self.bgR = ValSlider(self, (0, 1), "R:")
        self.bgR.setObjectName("R")
        self.bgR.setValue(0.5)
        self.hbl2.addWidget(self.bgR)
        bgRGBtab.vbl2.addLayout(self.hbl2)

        self.hbl2 = QtGui.QHBoxLayout()
        self.bgG = ValSlider(self, (0, 1), "G:")
        self.bgG.setObjectName("G")
        self.bgG.setValue(0.5)
        self.hbl2.addWidget(self.bgG)
        bgRGBtab.vbl2.addLayout(self.hbl2)

        self.hbl2 = QtGui.QHBoxLayout()
        self.bgB = ValSlider(self, (0, 1), "B:")
        self.bgB.setObjectName("B")
        self.bgB.setValue(0.5)
        self.hbl2.addWidget(self.bgB)
        bgRGBtab.vbl2.addLayout(self.hbl2)

        self.hbl2 = QtGui.QHBoxLayout()
        self.bg_a = ValSlider(self, (0, 1), "Alpha:")
        self.bg_a.setObjectName("Alpha")
        self.bg_a.setValue(1.0)
        self.hbl2.addWidget(self.bg_a)
        bgRGBtab.vbl2.addLayout(self.hbl2)

        return bgRGBtab

#	def slider_rotate(self):
#		self.target.load_rotation(self.get_current_rotation())

#	def set_xy_trans(self, x, y):
#		self.x_trans.setValue(x)
#		self.y_trans.setValue(y)

#	def set_translate_scale(self, xscale,yscale,zscale):
#		self.x_trans.setSingleStep(xscale)
#		self.y_trans.setSingleStep(yscale)
#		self.z_trans.setSingleStep(zscale)

#	def update_rotations(self,t3d):
#		rot = t3d.get_rotation(self.src_map[str(self.src.itemText(self.src.currentIndex()))])
#
#		convention = self.src.currentText()
#		if ( self.src_map[str(convention)] == EULER_SPIN ):
#			self.n3.setValue(rot[self.n3.getLabel()],True)
#
#		self.az.setValue(rot[self.az.getLabel()],True)
#		self.alt.setValue(rot[self.alt.getLabel()],True)
#		self.phi.setValue(rot[self.phi.getLabel()],True)

#	def slider_rotate(self):
#		self.target.load_rotation(self.get_current_rotation())

#	def get_current_rotation(self):
#		convention = self.src.currentText()
#		rot = {}
#		if ( self.current_src == EULER_SPIN ):
#			rot[self.az.getLabel()] = self.az.getValue()
#
#			n1 = self.alt.getValue()
#			n2 = self.phi.getValue()
#			n3 = self.n3.getValue()
#
#			norm = sqrt(n1*n1 + n2*n2 + n3*n3)
#
#			n1 /= norm
#			n2 /= norm
#			n3 /= norm
#
#			rot[self.alt.getLabel()] = n1
#			rot[self.phi.getLabel()] = n2
#			rot[self.n3.getLabel()] = n3
#
#		else:
#			rot[self.az.getLabel()] = self.az.getValue()
#			rot[self.alt.getLabel()] = self.alt.getValue()
#			rot[self.phi.getLabel()] = self.phi.getValue()
#
#		return Transform(self.current_src, rot)

    def setColors(self, colors, current_color):
        a = 0
        for i in colors:
            self.cbb.addItem(i)
            if (i == current_color):
                self.cbb.setCurrentIndex(a)
            a += 1