timerdialog.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 1997-2017 JDERobot Developers Team
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Library General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, see <http://www.gnu.org/licenses/>.
16 
17  Authors : Okan Asik (asik.okan@gmail.com)
18 
19  '''
20 import sys
21 from PyQt5.QtWidgets import QDialog, QGroupBox, \
22  QLineEdit, QVBoxLayout, QHBoxLayout, QPushButton, \
23  QWidget, QApplication, QMessageBox
24 from PyQt5.QtCore import pyqtSignal
25 from PyQt5.QtGui import QFontDatabase
26 
27 
28 class TimerDialog(QDialog):
29  timeChanged = pyqtSignal('int')
30 
31  def __init__(self, name, timeValue):
32  super(QDialog, self).__init__()
33  self.resize(300, 150)
34 
35  timeContainer = QGroupBox()
36  timeContainer.setTitle('Time (ms)')
37 
38  self.lineEdit = QLineEdit()
39  fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
40  self.lineEdit.setFont(fixedWidthFont)
41  self.lineEdit.setText(str(timeValue))
42  vLayout = QVBoxLayout()
43  vLayout.addWidget(self.lineEdit)
44 
45  self.cancelButton = QPushButton()
46  self.cancelButton.setText('Cancel')
47  self.cancelButton.clicked.connect(self.cancelClicked)
48 
49  self.acceptButton = QPushButton()
50  self.acceptButton.setText('Accept')
51  self.acceptButton.clicked.connect(self.acceptClicked)
52 
53  buttonContainer = QWidget()
54  hLayout = QHBoxLayout()
55  hLayout.addWidget(self.cancelButton)
56  hLayout.addWidget(self.acceptButton)
57  buttonContainer.setLayout(hLayout)
58  vLayout.addWidget(buttonContainer)
59  timeContainer.setLayout(vLayout)
60 
61  vLayout2 = QVBoxLayout()
62  vLayout2.addWidget(timeContainer)
63  self.setLayout(vLayout2)
64 
65  def cancelClicked(self):
66  self.close()
67 
68  def acceptClicked(self):
69  if self.lineEdit.text().isdigit():
70  self.timeChanged.emit(int(self.lineEdit.text()))
71  self.close()
72  else:
73  QMessageBox.warning(self, 'Input Error', 'Please input an integer in the box')
74  pass
75 
76 if __name__ == '__main__':
77  app = QApplication(sys.argv)
78  dialog = TimerDialog('Timer', 100)
79  dialog.exec_()


visualstates
Author(s):
autogenerated on Thu Apr 1 2021 02:42:20