summaryrefslogtreecommitdiff
path: root/gr-qtgui/apps/plot_form.py
blob: 2fb19d72b8aaab7ad0da6dc4e3c7ae3b48636b64 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
#
# Copyright 2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

try:
    from PyQt4 import QtGui, QtCore
    import sip
except ImportError:
    print "Error: Program requires PyQt4."
    sys.exit(1)

class dialog_box(QtGui.QWidget):
    def __init__(self, top_block, title=''):
        QtGui.QWidget.__init__(self, None)

        self._start = 0
        self._end = 0

        self.top_block = top_block
        
        self.setWindowTitle(title)

        self.size_val = QtGui.QIntValidator(0, top_block._max_nsamps, self)

        self.start_form = QtGui.QFormLayout()
        self.start_edit = QtGui.QLineEdit(self)
        self.start_edit.setMinimumWidth(100)
        self.start_edit.setText(QtCore.QString("%1").arg(top_block._start))
        self.start_edit.setValidator(self.size_val)
        self.start_form.addRow("Start:", self.start_edit)
        self.connect(self.start_edit, QtCore.SIGNAL("returnPressed()"),
                     self.update_points)

        end = top_block._start + top_block._nsamps
        self.end_form = QtGui.QFormLayout()
        self.end_edit = QtGui.QLineEdit(self)
        self.end_edit.setMinimumWidth(100)
        self.end_edit.setText(QtCore.QString("%1").arg(end))
        self.end_edit.setValidator(self.size_val)
        self.end_form.addRow("End:", self.end_edit)
        self.connect(self.end_edit, QtCore.SIGNAL("returnPressed()"),
                     self.update_points)

        self.layout = QtGui.QGridLayout(self)
        self.layout.addWidget(top_block.get_gui(), 0,0,1,2)
        self.layout.addLayout(self.start_form, 1,0,1,1)
        self.layout.addLayout(self.end_form, 1,1,1,1)

        self.resize(800, 500)

    def update_points(self):
        newstart = self.start_edit.text().toUInt()[0]
        newend = self.end_edit.text().toUInt()[0]
        if(newstart != self._start or newend != self._end):
            if(newend < newstart):
                QtGui.QMessageBox.information(
                    self, "Warning",
                    "End sample is less than start sample.",
                    QtGui.QMessageBox.Ok);
            else:
                newnsamps = newend - newstart
                self.top_block.reset(newstart, newnsamps)
        self._start = newstart
        self._end = newend