summaryrefslogtreecommitdiff
path: root/gr-wxgui/src/python/slider.py
blob: e8cdcfcaca029d7577e9f4291d2ed82f3021c038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python

import wx

def slider(parent, min, max, callback):
    """
    Return a wx.Slider object.

    @param min: minimum slider value
    @type min: float
    @param max: maximum slider value
    @type max: float
    @param callback: function of one arg invoked when slider moves.
    @rtype: wx.Slider
    """
    new_id = wx.NewId()
    s = wx.Slider(parent, new_id, (max+min)/2, min, max, wx.DefaultPosition,
                  wx.Size(250,-1), wx.SL_HORIZONTAL | wx.SL_LABELS)
    wx.EVT_COMMAND_SCROLL(parent, new_id,
                          lambda evt : callback(evt.GetInt()))
    return s


# ----------------------------------------------------------------
# 		             Demo app
# ----------------------------------------------------------------
if __name__ == '__main__':

    from gnuradio.wxgui import stdgui

    class demo_graph(stdgui.gui_flow_graph):

        def __init__(self, frame, panel, vbox, argv):
            stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)

            vbox.Add(slider(panel, 23, 47, self.my_callback1), 1, wx.ALIGN_CENTER)
            vbox.Add(slider(panel, -100, 100, self.my_callback2), 1, wx.ALIGN_CENTER)

        def my_callback1(self, val):
            print "cb1 = ", val

        def my_callback2(self, val):
            print "cb2 = ", val

    def main ():
        app = stdgui.stdapp (demo_graph, "Slider Demo")
        app.MainLoop ()

    main ()