SliderDemo.py :  » GUI » PyQwt » PyQwt-5.2.0 » qt3examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » PyQwt 
PyQwt » PyQwt 5.2.0 » qt3examples » SliderDemo.py
#!/usr/bin/env python

# The Python version of qwt-*/examples/sliders

# for debugging, requires: python configure.py  --trace ...
if False:
    import sip
    sip.settracemask(0x3f)

import sys
import qt
import Qwt5 as Qwt


class Layout(qt.QBoxLayout):

    def __init__(self, orientation, parent=None):
        qt.QBoxLayout.__init__(self, parent, qt.QBoxLayout.LeftToRight)
        if orientation == qt.Qt.Vertical:
            self.setDirection(qt.QBoxLayout.TopToBottom)
        self.setSpacing(20)
        self.setMargin(0)

    # __init__()

# class Layout


class Slider(qt.QWidget):

    def __init__(self, parent, sliderType):
        qt.QWidget.__init__(self, parent)

        self.slider = self.createSlider(self, sliderType)
        assert(not self.slider is None)
        
        if self.slider.scalePosition() == Qwt.QwtSlider.NoScale:
            if self.slider.orientation() == qt.Qt.Horizontal:
                alignment = qt.Qt.AlignHCenter | qt.Qt.AlignTop
            else:
                alignment = qt.Qt.AlignVCenter | qt.Qt.AlignLeft
        elif self.slider.scalePosition() == Qwt.QwtSlider.LeftScale:
            alignment = qt.Qt.AlignVCenter | qt.Qt.AlignRight
        elif self.slider.scalePosition() == Qwt.QwtSlider.RightScale:
            alignment = qt.Qt.AlignVCenter | qt.Qt.AlignLeft
        elif self.slider.scalePosition() == Qwt.QwtSlider.TopScale:
            alignment = qt.Qt.AlignHCenter | qt.Qt.AlignBottom
        elif self.slider.scalePosition() == Qwt.QwtSlider.BottomScale:
            alignment = qt.Qt.AlignHCenter | qt.Qt.AlignTop

        self.label = qt.QLabel("0", self)
        self.label.setAlignment(alignment)
        self.label.setFixedWidth(self.label.fontMetrics().width('10000.9'))

        self.connect(self.slider,
                     qt.SIGNAL('valueChanged(double)'),
                     self.setNum)
        
        if self.slider.orientation() == qt.Qt.Horizontal:
            layout = qt.QHBoxLayout(self)
        else:
            layout = qt.QVBoxLayout(self)

        layout.addWidget(self.slider)
        layout.addWidget(self.label)
            
    # __init__ ()

    def createSlider(self, parent, sliderType):

        if sliderType == 0:
            slider = Qwt.QwtSlider(parent,
                                   qt.Qt.Horizontal,
                                   Qwt.QwtSlider.TopScale,
                                   Qwt.QwtSlider.BgTrough)
            slider.setThumbWidth(10)
            slider.setRange(-10.0, 10.0, 1.0, 0) # paging disabled
            return slider

        if sliderType == 1:
            slider = Qwt.QwtSlider(parent,
                                   qt.Qt.Horizontal,
                                   Qwt.QwtSlider.NoScale,
                                   Qwt.QwtSlider.BgBoth)
            slider.setRange(0.0, 1.0, 0.01, 5)
            return slider

        if sliderType == 2:
            slider = Qwt.QwtSlider(parent,
                                   qt.Qt.Horizontal,
                                   Qwt.QwtSlider.BottomScale,
                                   Qwt.QwtSlider.BgSlot)
            slider.setThumbWidth(25)
            slider.setThumbLength(12)
            slider.setRange(1000.0, 3000.0, 10.0, 10)
            return slider

        if sliderType == 3:
            slider = Qwt.QwtSlider(parent,
                                   qt.Qt.Vertical,
                                   Qwt.QwtSlider.LeftScale,
                                   Qwt.QwtSlider.BgSlot)
            slider.setRange(0.0, 100.0, 1.0, 5)
            slider.setScaleMaxMinor(5)
            return slider

        if sliderType == 4:
            slider = Qwt.QwtSlider(parent,
                                   qt.Qt.Vertical,
                                   Qwt.QwtSlider.NoScale,
                                   Qwt.QwtSlider.BgTrough)
            slider.setRange(0.0,100.0,1.0, 10)
            return slider

        if sliderType == 5:
            slider = Qwt.QwtSlider(parent, 
                                   qt.Qt.Vertical,
                                   Qwt.QwtSlider.RightScale,
                                   Qwt.QwtSlider.BgBoth)
            slider.setScaleEngine(Qwt.QwtLog10ScaleEngine())
            slider.setThumbWidth(20)
            slider.setBorderWidth(1)
            slider.setRange(0.0, 4.0, 0.01)
            slider.setScale(1.0, 1.0e4)
            slider.setScaleMaxMinor(10)
            return slider

        return None

    # createSlider()

    def setNum(self, value):
        if isinstance(self.slider.scaleEngine(), Qwt.QwtLog10ScaleEngine):
            value  = 10.0**value

        self.label.setText('%s' % value)

    # setNum()

# class(SliderWidget)


class SliderDemo(qt.QWidget):

    def __init__(self, *args):
        qt.QWidget.__init__(self, *args)

        hSliderLayout = Layout(qt.Qt.Vertical)
        for i in (0, 1, 2):
            hSliderLayout.addWidget(Slider(self, i))
        hSliderLayout.addStretch()

        vSliderLayout = Layout(qt.Qt.Horizontal)
        for i in (3, 4, 5):
            vSliderLayout.addWidget(Slider(self, i))

        vTitle = qt.QLabel("Vertical Sliders", self)
        vTitle.setFont(qt.QFont("Helvetica", 14, qt.QFont.Bold))
        vTitle.setAlignment(qt.Qt.AlignHCenter)

        layout1 = Layout(qt.Qt.Vertical)
        layout1.addWidget(vTitle, 0)
        layout1.addLayout(vSliderLayout, 10)
        
        hTitle = qt.QLabel("Horizontal Sliders", self)
        hTitle.setFont(vTitle.font())
        hTitle.setAlignment(qt.Qt.AlignHCenter)
        
        layout2 = Layout(qt.Qt.Vertical)
        layout2.addWidget(hTitle, 0)
        layout2.addLayout(hSliderLayout, 10)

        mainLayout = Layout(qt.Qt.Horizontal, self)
        mainLayout.addLayout(layout1)
        mainLayout.addLayout(layout2, 10)
 
    # __init__()

# class SliderDemo


def make():
    demo = SliderDemo()
    demo.show()
    return demo

# make()


def main(args):
    app = qt.QApplication(args)
    demo = make()
    app.setMainWidget(demo)
    sys.exit(app.exec_loop())

# main()


# Admire!
if __name__ == '__main__':
    main(sys.argv)

# Local Variables: ***
# mode: python ***
# End: ***
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.