Exemplo n.º 1
0
    def __init__(self, parent=None, name="Elements Info"):
        qt.QWidget.__init__(self, parent)
        self.setWindowTitle(name)

        layout = qt.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.energyValue = None
        self.splitter = qt.QSplitter(self)
        layout.addWidget(self.splitter)
        self.splitter.setOrientation(qt.Qt.Horizontal)
        self.table = QPeriodicTable(self.splitter)
        self.html = ElementHtml.ElementHtml()
        self.infoWidget = None
        self.table.setMinimumSize(500, 400)

        self.table.sigElementClicked.connect(self.elementClicked)

        self.lastElement = None
        Elements.registerUpdate(self._updateCallback)
Exemplo n.º 2
0
 def __init__(self, parent=None, name="Elements Info"):
     qt.QWidget.__init__(self, parent)
     self.setWindowTitle(name)
         
     layout = qt.QVBoxLayout(self)
     layout.setContentsMargins(0, 0, 0, 0)
     layout.setSpacing(0)
     self.energyValue = None
     self.splitter = qt.QSplitter(self)
     layout.addWidget(self.splitter)
     self.splitter.setOrientation(qt.Qt.Horizontal)
     self.table = QPeriodicTable(self.splitter)
     self.html  = ElementHtml.ElementHtml()
     self.infoWidget = None
     self.table.setMinimumSize(500,
                               400)
                               
     self.table.sigElementClicked.connect(self.elementClicked)
         
     self.lastElement = None
     Elements.registerUpdate(self._updateCallback)
Exemplo n.º 3
0
class ElementsInfo(qt.QWidget):
    def __init__(self, parent=None, name="Elements Info"):
        qt.QWidget.__init__(self, parent)
        self.setWindowTitle(name)
            
        layout = qt.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.energyValue = None
        self.splitter = qt.QSplitter(self)
        layout.addWidget(self.splitter)
        self.splitter.setOrientation(qt.Qt.Horizontal)
        self.table = QPeriodicTable(self.splitter)
        self.html  = ElementHtml.ElementHtml()
        self.infoWidget = None
        self.table.setMinimumSize(500,
                                  400)
                                  
        self.table.sigElementClicked.connect(self.elementClicked)
            
        self.lastElement = None
        Elements.registerUpdate(self._updateCallback)
        
    def elementClicked(self, symbol):
        if self.infoWidget is None:
            self.__createInfoWidget(symbol)
        else:
            self.infoText.clear()
            self.infoText.insertHtml(self.html.gethtml(symbol))
        if self.infoWidget.isHidden():
            self.infoWidget.show()
        self.lastElement = symbol
        self.infoWidget.setWindowTitle(symbol)
        self.infoWidget.raise_()
        
    def __createInfoWidget(self,symbol=""):
        #Dock window like widget
        frame = qt.QWidget(self.splitter)
        layout = qt.QVBoxLayout(frame)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        #The dock functionnality
        toolbar = qt.QWidget(frame)
        layout.addWidget(toolbar)
        layout1       = qt.QHBoxLayout(toolbar)
        layout1.setContentsMargins(0, 0, 0, 0)
        layout1.setSpacing(0)

        # --- the line
        self.line1 = Line(toolbar)
        self.line1.setFrameShape(qt.QFrame.HLine)
        self.line1.setFrameShadow(qt.QFrame.Sunken)
        self.line1.setFrameShape(qt.QFrame.HLine)
        layout1.addWidget(self.line1)
        
        # --- the close button
        self.closelabel = PixmapLabel(toolbar)
        self.closelabel.setPixmap(qt.QPixmap(CLOSE_ICON))
        layout1.addWidget(self.closelabel)
        self.closelabel.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed))

        # --- connections
        self.line1.sigLineDoubleClickEvent.connect(self.infoReparent)
        self.closelabel.sigPixmapLabelMousePressEvent.connect(self.infoToggle)

        # --- The text edit widget
        w= qt.QWidget(frame)
        layout.addWidget(w)
        l=qt.QVBoxLayout(w)
        l.setContentsMargins(0, 0, 0, 0)
        l.setSpacing(0)
        
        hbox = qt.QWidget(w)
        hbox.layout = qt.QHBoxLayout(hbox)
        hbox.layout.setContentsMargins(0, 0, 0, 0)
        hbox.layout.setSpacing(0)
        l.addWidget(hbox)
        hbox.layout.addWidget(qt.HorizontalSpacer(hbox))
        l1=qt.QLabel(hbox)
        l1.setText('<b><nobr>Excitation Energy (keV)</nobr></b>')
        self.energy=MyQLineEdit(hbox)
        self.energy.setFixedWidth(self.energy.fontMetrics().width('#####.###'))
        self.energy.setText("")
        hbox.layout.addWidget(l1)
        hbox.layout.addWidget(self.energy)
        hbox.layout.addWidget(qt.HorizontalSpacer(hbox))
        self.energy.editingFinished[()].connect(self._energySlot)

        #if both signals are emitted and there is an error then we are in an
        #endless loop
        #self.connect(self.energy, qt.SIGNAL('focusOut'), self._energySlot)
        
        self.infoText = qt.QTextEdit(w)
        self.infoText.setReadOnly(1)
        self.infoText.clear()
        self.infoText.insertHtml(self.html.gethtml(symbol))
        l.addWidget(self.infoText)
        w.show()
        self.infoWidget=frame
        frame.show()
        
    def infoReparent(self):
        if self.infoWidget.parent() is not None:
            self.infoWidget.setParent(None)
            self.infoWidget.move(self.cursor().pos())
            self.infoWidget.show()
            #,self.cursor().pos(),1)
        else:
            self.infoWidget.setParent(self.splitter)
            self.splitter.insertWidget(1,self.infoWidget)
            #,qt.QPoint(),1)
            #self.splitter.moveToFirst(self.sourceFrame)
        self.infoWidget.setFocus()
    
    def infoToggle(self,**kw):
        if DEBUG:
            print("toggleSource called")
        if self.infoWidget.isHidden():
            self.infoWidget.show()
            self.infoWidget.raiseW()
        else:
            self.infoWidget.hide()

    def _energySlot(self):
        string = str(self.energy.text())
        if len(string):
            try:
                value = float(string)
            except:
                msg=qt.QMessageBox(self.energy)
                msg.setIcon(qt.QMessageBox.Critical)
                msg.setText("Invalid Float")
                msg.exec_()
                self.energy.setFocus()
                return
            if self.energyValue is not None:
                if value != self.energyValue:
                    self.energyValue = value
                    Elements.updateDict(energy=value)
            else:
                self.energyValue = value
                Elements.updateDict(energy=value)
            self.energy.setPaletteBackgroundColor(qt.QColor('white'))
            self.infoWidget.setFocus()
        else:
            self.energyValue = None
            self.energy.setText("")

            
    def _updateCallback(self):
        if self.lastElement is not None:
            self.elementClicked(self.lastElement)
            if Elements.Element[self.lastElement]['buildparameters']['energy'] is not None:
                self.energy.setText("%.3f" % Elements.Element[self.lastElement]['buildparameters']['energy'])
            else:
                self.energy.setText("")
Exemplo n.º 4
0
class ElementsInfo(qt.QWidget):
    def __init__(self, parent=None, name="Elements Info"):
        qt.QWidget.__init__(self, parent)
        self.setWindowTitle(name)

        layout = qt.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.energyValue = None
        self.splitter = qt.QSplitter(self)
        layout.addWidget(self.splitter)
        self.splitter.setOrientation(qt.Qt.Horizontal)
        self.table = QPeriodicTable(self.splitter)
        self.html = ElementHtml.ElementHtml()
        self.infoWidget = None
        self.table.setMinimumSize(500, 400)

        self.table.sigElementClicked.connect(self.elementClicked)

        self.lastElement = None
        Elements.registerUpdate(self._updateCallback)

    def elementClicked(self, symbol):
        if self.infoWidget is None:
            self.__createInfoWidget(symbol)
        else:
            self.infoText.clear()
            self.infoText.insertHtml(self.html.gethtml(symbol))
        if self.infoWidget.isHidden():
            self.infoWidget.show()
        self.lastElement = symbol
        self.infoWidget.setWindowTitle(symbol)
        self.infoWidget.raise_()

    def __createInfoWidget(self, symbol=""):
        #Dock window like widget
        frame = qt.QWidget(self.splitter)
        layout = qt.QVBoxLayout(frame)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        #The dock functionnality
        toolbar = qt.QWidget(frame)
        layout.addWidget(toolbar)
        layout1 = qt.QHBoxLayout(toolbar)
        layout1.setContentsMargins(0, 0, 0, 0)
        layout1.setSpacing(0)

        # --- the line
        self.line1 = Line(toolbar)
        self.line1.setFrameShape(qt.QFrame.HLine)
        self.line1.setFrameShadow(qt.QFrame.Sunken)
        self.line1.setFrameShape(qt.QFrame.HLine)
        layout1.addWidget(self.line1)

        # --- the close button
        self.closelabel = PixmapLabel(toolbar)
        self.closelabel.setPixmap(qt.QPixmap(CLOSE_ICON))
        layout1.addWidget(self.closelabel)
        self.closelabel.setSizePolicy(
            qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed))

        # --- connections
        self.line1.sigLineDoubleClickEvent.connect(self.infoReparent)
        self.closelabel.sigPixmapLabelMousePressEvent.connect(self.infoToggle)

        # --- The text edit widget
        w = qt.QWidget(frame)
        layout.addWidget(w)
        l = qt.QVBoxLayout(w)
        l.setContentsMargins(0, 0, 0, 0)
        l.setSpacing(0)

        hbox = qt.QWidget(w)
        hbox.layout = qt.QHBoxLayout(hbox)
        hbox.layout.setContentsMargins(0, 0, 0, 0)
        hbox.layout.setSpacing(0)
        l.addWidget(hbox)
        hbox.layout.addWidget(qt.HorizontalSpacer(hbox))
        l1 = qt.QLabel(hbox)
        l1.setText('<b><nobr>Excitation Energy (keV)</nobr></b>')
        self.energy = MyQLineEdit(hbox)
        self.energy.setFixedWidth(self.energy.fontMetrics().width('#####.###'))
        self.energy.setText("")
        hbox.layout.addWidget(l1)
        hbox.layout.addWidget(self.energy)
        hbox.layout.addWidget(qt.HorizontalSpacer(hbox))
        self.energy.editingFinished[()].connect(self._energySlot)

        #if both signals are emitted and there is an error then we are in an
        #endless loop
        #self.connect(self.energy, qt.SIGNAL('focusOut'), self._energySlot)

        self.infoText = qt.QTextEdit(w)
        self.infoText.setReadOnly(1)
        self.infoText.clear()
        self.infoText.insertHtml(self.html.gethtml(symbol))
        l.addWidget(self.infoText)
        w.show()
        self.infoWidget = frame
        frame.show()

    def infoReparent(self):
        if self.infoWidget.parent() is not None:
            self.infoWidget.setParent(None)
            self.infoWidget.move(self.cursor().pos())
            self.infoWidget.show()
            #,self.cursor().pos(),1)
        else:
            self.infoWidget.setParent(self.splitter)
            self.splitter.insertWidget(1, self.infoWidget)
            #,qt.QPoint(),1)
            #self.splitter.moveToFirst(self.sourceFrame)
        self.infoWidget.setFocus()

    def infoToggle(self, **kw):
        _logger.debug("toggleSource called")
        if self.infoWidget.isHidden():
            self.infoWidget.show()
            self.infoWidget.raiseW()
        else:
            self.infoWidget.hide()

    def _energySlot(self):
        string = str(self.energy.text())
        if len(string):
            try:
                value = float(string)
            except:
                msg = qt.QMessageBox(self.energy)
                msg.setIcon(qt.QMessageBox.Critical)
                msg.setText("Invalid Float")
                msg.exec_()
                self.energy.setFocus()
                return
            if self.energyValue is not None:
                if value != self.energyValue:
                    self.energyValue = value
                    Elements.updateDict(energy=value)
            else:
                self.energyValue = value
                Elements.updateDict(energy=value)
            self.energy.setPaletteBackgroundColor(qt.QColor('white'))
            self.infoWidget.setFocus()
        else:
            self.energyValue = None
            self.energy.setText("")

    def _updateCallback(self):
        if self.lastElement is not None:
            self.elementClicked(self.lastElement)
            if Elements.Element[
                    self.lastElement]['buildparameters']['energy'] is not None:
                self.energy.setText("%.3f" % Elements.Element[self.lastElement]
                                    ['buildparameters']['energy'])
            else:
                self.energy.setText("")