/
area_dialog.py
67 lines (59 loc) · 2.08 KB
/
area_dialog.py
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
# -*- coding: utf-8 -*-
"""
.. module:: area_dialog
:platform: Linux, Windows
:synopsis: GUI for area division
.. moduleauthor: Zoltan Siki <siki@agt.bme.hu>
"""
from PyQt4.QtGui import QDialog, QMessageBox
from area_div import Ui_AreaDivDialog
from base_classes import tr
class AreaDialog(QDialog):
""" Class for area division dialog
"""
def __init__(self, total_area, div_area, rotate):
""" Initialize dialog data and event handlers
:param log: log instance for log messages
"""
super(AreaDialog, self).__init__()
self.total_area = int(total_area + 0.5)
self.div_area = int(div_area + 0.5)
self.rotate = rotate
self.ui = Ui_AreaDivDialog()
self.ui.setupUi(self)
self.ui.CancelButton.clicked.connect(self.onCancelButton)
self.ui.DivideButton.clicked.connect(self.onDivideButton)
def showEvent(self, event):
""" Set up initial state of dialog widgets
:param event: NOT USED
"""
self.reset()
def reset(self):
""" Reset dialog to initial state
"""
self.ui.AreaLineEdit.setText(str(self.div_area))
self.ui.TotalLineEdit.setText(str(self.total_area))
self.ui.TwoPointRadio.setChecked(True)
if self.rotate:
self.ui.OnePointRadio.setEnabled(True)
else:
self.ui.OnePointRadio.setEnabled(False)
def onDivideButton(self):
""" Check input and accept dialog
"""
try:
a = float(self.ui.AreaLineEdit.text())
except ValueError:
QMessageBox.warning(self, tr("Warning"), tr("Invalid area value"))
return
if a <= 0:
QMessageBox.warning(self, tr("Warning"), tr("Invalid area value"))
return
if not self.ui.OnePointRadio.isChecked() and not self.ui.TwoPointRadio.isChecked():
QMessageBox.warning(self, tr("Warning"), tr("Select division method"))
return
self.accept()
def onCancelButton(self):
""" Reject dialog
"""
self.reject()