Esempio n. 1
0
    def createCompass(self, pos):
        palette0 = QPalette()
        for c in range(QPalette.NColorRoles):
            colorRole = QPalette.ColorRole(c)
            palette0.setColor(colorRole, QColor())

        #palette0.setColor( QPalette.Base, palette().color( QPalette.backgroundRole() ).light( 120 ) )
        palette0.setColor(QPalette.WindowText, palette0.color(QPalette.Base))

        compass = Qwt.QwtCompass(self)
        compass.setLineWidth(4)
        compass.setFrameShadow(Qwt.QwtCompass.Sunken)
        #    pos <= 2 ? QwtCompass.Sunken : QwtCompass.Raised )

        if pos == 0:
            #A compass with a rose and no needle. Scale and rose are rotating.
            compass.setMode(Qwt.QwtCompass.RotateScale)

            rose = Qwt.QwtSimpleCompassRose(16, 2)
            rose.setWidth(0.15)

            compass.setRose(rose)
        elif pos == 1:
            #A windrose, with a scale indicating the main directions only
            map = {}
            map[0.0] = "N"
            map[90.0] = "E"
            map[180.0] = "S"
            map[270.0] = "W"

            compass.setScaleDraw(Qwt.QwtCompassScaleDraw(map))

            rose = Qwt.QwtSimpleCompassRose(4, 1)
            compass.setRose(rose)

            compass.setNeedle(
                Qwt.QwtCompassWindArrow(Qwt.QwtCompassWindArrow.Style2))
            compass.setValue(60.0)
        elif pos == 2:
            #A compass with a rotating needle in darkBlue. Shows
            #a ticks for each degree.

            palette0.setColor(QPalette.Base, Qt.darkBlue)
            palette0.setColor(QPalette.WindowText,
                              QColor(Qt.darkBlue))  #.dark( 120 ) )
            palette0.setColor(QPalette.Text, Qt.white)

            scaleDraw = Qwt.QwtCompassScaleDraw()
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Ticks, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Labels, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone, False)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MinorTick, 1)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MediumTick, 1)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MajorTick, 3)

            compass.setScaleDraw(scaleDraw)

            compass.setScaleMaxMajor(36)
            compass.setScaleMaxMinor(5)

            compass.setNeedle(
                Qwt.QwtCompassMagnetNeedle(
                    Qwt.QwtCompassMagnetNeedle.ThinStyle))
            compass.setValue(220.0)
        elif pos == 3:
            #A compass without a frame, showing numbers as tick labels.
            #The origin is at 220.0
            palette0.setColor(QPalette.Base,
                              self.palette().color(self.backgroundRole()))
            palette0.setColor(QPalette.WindowText, Qt.blue)
            compass.setLineWidth(0)
            map = {}
            for d in range(0, 360, 60):
                map[d] = "%.0f" % (d * 1.0)

            scaleDraw = Qwt.QwtCompassScaleDraw(map)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Ticks, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Labels, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone, True)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MinorTick, 0)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MediumTick, 0)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MajorTick, 3)
            compass.setScaleDraw(scaleDraw)
            compass.setScaleMaxMajor(36)
            compass.setScaleMaxMinor(5)
            compass.setNeedle(
                Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Ray, True,
                                        Qt.white))
            compass.setOrigin(220.0)
            compass.setValue(20.0)
        elif pos == 4:
            #A compass showing another needle
            scaleDraw = Qwt.QwtCompassScaleDraw()
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Ticks, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Labels, True)
            scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone, False)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MinorTick, 0)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MediumTick, 0)
            scaleDraw.setTickLength(Qwt.QwtScaleDiv.MajorTick, 3)
            compass.setScaleDraw(scaleDraw)
            compass.setNeedle(
                Qwt.QwtCompassMagnetNeedle(
                    Qwt.QwtCompassMagnetNeedle.TriangleStyle, Qt.white,
                    Qt.red))
            compass.setValue(220.0)
        elif pos == 5:
            #A compass with a yellow on black ray
            palette0.setColor(QPalette.WindowText, Qt.black)
            compass.setNeedle(
                Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Ray, False,
                                        Qt.yellow))
            compass.setValue(315.0)

        newPalette = compass.palette()
        for c in range(QPalette.NColorRoles):
            colorRole = QPalette.ColorRole(c)
            if (palette0.color(colorRole).isValid()):
                newPalette.setColor(colorRole, palette0.color(colorRole))

        for i in range(QPalette.NColorGroups):
            colorGroup = QPalette.ColorGroup(i)
            light = newPalette.color(colorGroup, QPalette.Base)  #.light( 170 )
            dark = newPalette.color(colorGroup, QPalette.Base)  #.dark( 170 )
            #mid = compass.frameShadow() == QwtDial.Raised
            #    ? newPalette.color( colorGroup, QPalette.Base ).dark( 110 )
            #    : newPalette.color( colorGroup, QPalette.Base ).light( 110 )
            mid = newPalette.color(colorGroup, QPalette.Base)  #.dark( 110 )
            newPalette.setColor(colorGroup, QPalette.Dark, dark)
            newPalette.setColor(colorGroup, QPalette.Mid, mid)
            newPalette.setColor(colorGroup, QPalette.Light, light)
        compass.setPalette(newPalette)
        return compass
Esempio n. 2
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()