示例#1
0
    def __init__(self, orientation, text, parent, value=0.0):
        QWidget.__init__(self, parent)
        self.d_label = QLabel(text, self)
        self.d_label.setFont(QFont("Helvetica", 10))

        self.d_thermo = Qwt.QwtThermo(self)
        self.d_thermo.setOrientation(orientation)
        self.d_thermo.setScale(0.0, 100.0)
        self.d_thermo.setValue(value)
        self.d_thermo.setFont(QFont("Helvetica", 8))
        self.d_thermo.setPipeWidth(6)
        self.d_thermo.setScaleMaxMajor(6)
        self.d_thermo.setScaleMaxMinor(5)
        self.d_thermo.setFillBrush(Qt.darkMagenta)

        #if 0
        colorMap = Qwt.QwtLinearColorMap(Qt.blue, Qt.red)

        colorMap.addColorStop(0.2, Qt.yellow)
        colorMap.addColorStop(0.3, Qt.cyan)
        colorMap.addColorStop(0.4, Qt.green)
        colorMap.addColorStop(0.5, Qt.magenta)
        colorMap.setMode(Qwt.QwtLinearColorMap.FixedColors)
        self.d_thermo.setColorMap(colorMap)
        #endif"""

        self.layout = QVBoxLayout(self)
        #self.layout.setCanvasMargin( 0 )
        self.layout.setSpacing(0)

        if (orientation == Qt.Horizontal):
            self.d_label.setAlignment(Qt.AlignCenter)
            self.d_thermo.setScalePosition(Qwt.QwtThermo.LeadingScale)
            self.layout.addWidget(self.d_label)
            self.layout.addWidget(self.d_thermo)
        else:
            self.d_label.setAlignment(Qt.AlignRight)
            self.d_thermo.setScalePosition(Qwt.QwtThermo.TrailingScale)
            self.layout.addWidget(self.d_thermo, 10, Qt.AlignHCenter)
            self.layout.addWidget(self.d_label, 0)
示例#2
0
    def createBox(self, orientation, typ):
        self.d_wheel = Qwt.QwtWheel()
        self.d_wheel.setValue(80)
        self.d_wheel.setWheelWidth(20)
        self.d_wheel.setMass(1.0)
        self.d_thermo = Qwt.QwtThermo()
        self.d_thermo.setOrientation(orientation)

        if (orientation == Qt.Horizontal):
            self.d_thermo.setScalePosition(Qwt.QwtThermo.LeadingScale)
            self.d_wheel.setOrientation(Qt.Vertical)
        else:
            self.d_thermo.setScalePosition(Qwt.QwtThermo.TrailingScale)
            self.d_wheel.setOrientation(Qt.Horizontal)
        if typ == 0:
            colorMap = Qwt.QwtLinearColorMap()
            colorMap.setColorInterval(Qt.blue, Qt.red)
            self.d_thermo.setColorMap(colorMap)
        elif typ == 1:
            colorMap = Qwt.QwtLinearColorMap()
            colorMap.setMode(Qwt.QwtLinearColorMap.FixedColors)
            idx = 4
            colorMap.setColorInterval(Qt.GlobalColor(idx),
                                      Qt.GlobalColor(idx + 10))
            for i in range(10):
                colorMap.addColorStop(i / 10.0, Qt.GlobalColor(idx + i))
            self.d_thermo.setColorMap(colorMap)
        elif typ == 2:
            self.d_wheel.setRange(10, 1000)
            self.d_wheel.setSingleStep(1.0)
            #self.d_thermo.setScaleEngine( Qwt.QwtLogScaleEngine )
            self.d_thermo.setScaleMaxMinor(10)
            self.d_thermo.setFillBrush(Qt.darkCyan)
            self.d_thermo.setAlarmBrush(Qt.magenta)
            self.d_thermo.setAlarmLevel(500.0)
            self.d_wheel.setValue(800)
        elif typ == 3:
            self.d_wheel.setRange(-1000, 1000)
            self.d_wheel.setSingleStep(1.0)
            #self.d_wheel.setPalette( QColor( "Tan" ) )

            #scaleEngine = Qwt.QwtLinearScaleEngine()
            #scaleEngine.setTransformation( Qwt.QwtPowerTransform( 2 ) )

            self.d_thermo.setScaleMaxMinor(5)
            #self.d_thermo.setScaleEngine( scaleEngine )

            pal = QPalette()
            pal.setColor(QPalette.Base, Qt.darkGray)
            #pal.setColor( QPalette.ButtonText, QColor( "darkKhaki" ) )

            self.d_thermo.setPalette(pal)
        elif typ == 4:
            self.d_wheel.setRange(-100, 300)
            self.d_wheel.setInverted(True)

            colorMap = Qwt.QwtLinearColorMap()
            colorMap.setColorInterval(Qt.darkCyan, Qt.yellow)
            self.d_thermo.setColorMap(colorMap)

            self.d_wheel.setValue(243)
        elif typ == 5:
            self.d_thermo.setFillBrush(Qt.darkCyan)
            self.d_thermo.setAlarmBrush(Qt.magenta)
            self.d_thermo.setAlarmLevel(60.0)
        elif typ == 6:
            self.d_thermo.setOriginMode(Qwt.QwtThermo.OriginMinimum)
            #self.d_thermo.setFillBrush( QBrush( "DarkSlateBlue" ) )
            #self.d_thermo.setAlarmBrush( QBrush( "DarkOrange" ) )
            self.d_thermo.setAlarmLevel(60.0)
        elif typ == 7:
            self.d_wheel.setRange(-100, 100)
            self.d_thermo.setOriginMode(Qwt.QwtThermo.OriginCustom)
            self.d_thermo.setOrigin(0.0)
            self.d_thermo.setFillBrush(Qt.darkBlue)

        dmin = self.d_wheel.minimum()
        dmax = self.d_wheel.maximum()

        #if ( self.d_wheel.isInverted() ):
        #    tmp = dmin
        #    dmin = dmax
        #    dmax = tmp
        #    #swap( dmin, dmax )
        self.d_thermo.setScale(dmin, dmax)
        self.d_thermo.setValue(self.d_wheel.value())
        self.d_wheel.valueChanged['double'].connect(self.d_thermo.setValue)

        box = QWidget()

        layout = None

        if (orientation == Qt.Horizontal):
            layout = QHBoxLayout(box)
        else:
            layout = QVBoxLayout(box)
        layout.addWidget(self.d_thermo, Qt.AlignCenter)
        layout.addWidget(self.d_wheel)
        return box
示例#3
0
    def __init__(self):
        super(MyApp, self).__init__()
        # Set up the user interface from Designer.
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)

# ======= LOCAL WIDGET MODIFICATIONS ===============================================================

        spdMeter   = self.ui.SpeedDial
        spdLCD     = self.ui.SpeedLCD
        spdWheel   = self.ui.SpeedWheel
        thermo     = self.ui.Thermo
        thermSlide = self.ui.ThermoSlider
        compass    = self.ui.Compass
        counter    = self.ui.Counter
        global clk
        clk = self.ui.AnalogClock

        # SPEEDOMETER SETUP
        palette2 = QPalette()
        palette2.setColor(QPalette.Base, Qt.black)
        palette2.setColor(QPalette.WindowText, QColor(Qt.darkBlue))
        palette2.setColor(QPalette.Text, Qt.yellow)
        palette2.setColor(QPalette.Dark, Qt.darkGray)       # Bezel ring color 1
        palette2.setColor(QPalette.Light, Qt.lightGray)     # Bezel Ring Color 2
        spdMeter.setPalette(palette2)
        needle = Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Arrow, True, Qt.red, QtGui.QColor(Qt.gray))
        spdMeter.setNeedle(needle)

        # THERMO SETUP
        colorMap = Qwt.QwtLinearColorMap()
        colorMap.setColorInterval(Qt.blue, Qt.red)
        thermo.setColorMap(colorMap)

        # COMPASS SETUP
        palette0 = QPalette()
        palette0.setColor(QPalette.Base, Qt.darkBlue)
        palette0.setColor(QPalette.WindowText, QColor(Qt.darkBlue))
        palette0.setColor(QPalette.Text, Qt.yellow)
        palette0.setColor(QPalette.Dark, Qt.darkGray)       # Bezel ring color 1
        palette0.setColor(QPalette.Light, Qt.lightGray)     # Bezel Ring Color 2
        compass.setPalette(palette0)
        # Tick marks for each degree
        CompSclDrw = Qwt.QwtCompassScaleDraw()
        CompSclDrw.enableComponent(Qwt.QwtAbstractScaleDraw.Ticks, True)
        CompSclDrw.enableComponent(Qwt.QwtAbstractScaleDraw.Labels, True)
        CompSclDrw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone, False)
        CompSclDrw.setTickLength(Qwt.QwtScaleDiv.MinorTick, 0)
        CompSclDrw.setTickLength(Qwt.QwtScaleDiv.MediumTick, 0)
        CompSclDrw.setTickLength(Qwt.QwtScaleDiv.MajorTick, 5)
        compass.setScaleDraw(CompSclDrw)
        compass.setNeedle(Qwt.QwtCompassMagnetNeedle(Qwt.QwtCompassMagnetNeedle.ThinStyle, Qt.darkBlue, Qt.red))

        # ANALOG CLOCK SETUP
        palette1 = QPalette()
        palette1.setColor(QPalette.Base, Qt.black)           # Clock number ring background
        palette1.setColor(QPalette.Text, Qt.yellow)          # Clock numbers color
        palette1.setColor(QPalette.Foreground, Qt.darkBlue)  # Inner Ring Color
        palette1.setColor(QPalette.Dark, Qt.darkGray)        # Bezel ring color 1
        palette1.setColor(QPalette.Light, Qt.lightGray)      # Bezel Ring Color 2
        clk.setPalette(palette1)
        # Disable minor ticks
        ClkSclDrw = Qwt.QwtRoundScaleDraw()
        ClkSclDrw.setTickLength(Qwt.QwtScaleDiv.MinorTick, 0)
        # Set color of clock hands
        knobColor = QColor(Qt.gray)
        for i in range(clk.NHands):
            handColor = QColor(Qt.gray)
            width = 8
            if i == clk.SecondHand:
                handColor = Qt.red
                knobColor = QColor(Qt.darkRed)
                width = 5
            hand = Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Arrow, True, handColor, knobColor)
            hand.setWidth(width)
            clk.setHand(clk.Hand(i), hand)

# ======= WIDGET CONNECTIONS =======================================================================

        spdMeter.setValue(self.ui.SpeedWheel.value())
        spdWheel.valueChanged['double'].connect(spdMeter.setValue)
        spdWheel.valueChanged['double'].connect(spdLCD.display)
        thermSlide.valueChanged['double'].connect(thermo.setValue)
        counter.valueChanged['double'].connect(compass.setValue)

# =======  SINE WAVE PLOT SETUP ====================================================================

        global ampKnob, frqKnob, maxPts, n, angle, xData, yData, curve, plot, deg
        ampKnob = self.ui.AmpKnob                # Amplitude knob object
        frqKnob = self.ui.FreqKnob               # Frequency knob object
        maxPts = 250                             # X axis range for plots
        xData = np.zeros(1, dtype=np.uint16)     # Buffer for x data
        yData = np.zeros(1, dtype=np.float32)    # Buffer for y Data
        n = 0                                    # loop counter and base for frequency steps
        angle = 0                                # Rotation angle along X axis for plots
        deg = u'\N{DEGREE SIGN}'
        plot = self.ui.qwtPlot                   # Plot object
        # plot.setTitle("SINE WAVE PLOT")
        # plot.insertLegend(Qwt.QwtLegend())
        plot.setCanvasBackground(Qt.black)
        plot.setAxisScale(2, 0, maxPts, 50)      # X bottom axis
        plot.setAxisMaxMinor(2, 5)
        plot.setAxisScale(0, -10, 10, 2)         # Y Left Axis
        plot.setAxisMaxMinor(0, 2)
        grid = Qwt.QwtPlotGrid()
        grid.setPen(Qt.darkGray, 0, Qt.DotLine)
        grid.attach(plot)
        curve = Qwt.QwtPlotCurve()
        # curve.setTitle("Some Points")
        curve.attach(plot)
        curve.setPen(Qt.yellow, 2)
        curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased, True)
        # Start the loop function
        update()