66import datetime
77import math
88
9-
109shapes = {
1110 3 : 'Triangle' ,
1211 4 : 'Quadrilateral' ,
1716 9 : 'Enneagon' ,
1817 10 : 'Decagon'
1918}
19+
20+
2021class Graph (QtWidgets .QWidget ):
2122 """Class which defines the window of the application"""
2223
@@ -47,10 +48,10 @@ def __init__(self, ctx, surface, line_color):
4748
4849 # 'Draw' Button to draw the line using user-given coordinates
4950 drawButton = QtWidgets .QPushButton (self .tr ("Draw" ),
50- clicked = self .draw )
51+ clicked = self .draw )
5152 # 'Reset' Button to clear everything in the input boxes
5253 clearButton = QtWidgets .QPushButton (self .tr ("Reset" ),
53- clicked = self .clear )
54+ clicked = self .clear )
5455 # Save Button for saving the plotted graph with transparent background
5556 save = QtWidgets .QPushButton (self .tr ("Save this Graph" ),
5657 clicked = self .save )
@@ -73,22 +74,26 @@ def __init__(self, ctx, surface, line_color):
7374 self .line_color = line_color
7475
7576 def makeInputLayout (self ):
77+ text = 'Extra Info \N{Black Down-Pointing Triangle} '
7678 self .inputLayout = QtWidgets .QFormLayout ()
7779 self .coordLayout = QtWidgets .QFormLayout ()
7880 self .scrollArea = QtWidgets .QScrollArea ()
7981 self .widget = QtWidgets .QWidget ()
8082 self .str = QtWidgets .QLabel ('Geometric Figure:' )
8183 self .shapeName = QtWidgets .QLabel ('Line' )
82- self .extraInfo = QtWidgets .QPushButton (self .tr ('Extra Info \N{Black Down-Pointing Triangle} ' ), clicked = self .info )
83- self .extraInfo .setToolTip ('Show extra information for the line or shape' )
84+ self .extraInfo = QtWidgets .QPushButton (text , clicked = self .info )
85+ self .extraInfo .setToolTip (('Show extra information '
86+ 'for the line or shape' ))
8487 self .shapeInfo = ExtraInfo ()
8588 self .widget .setLayout (self .coordLayout )
8689 self .inputLayout .addRow (self .str , self .shapeName )
8790 self .inputLayout .addRow (self .extraInfo , QtWidgets .QWidget ())
8891 self .inputLayout .addRow (self .shapeInfo )
8992 self .scrollArea .setWidget (self .widget )
90- self .scrollArea .setVerticalScrollBarPolicy (QtCore .Qt .ScrollBarAsNeeded )
91- self .scrollArea .setHorizontalScrollBarPolicy (QtCore .Qt .ScrollBarAlwaysOff )
93+ self .scrollArea .setVerticalScrollBarPolicy (
94+ QtCore .Qt .ScrollBarAsNeeded )
95+ self .scrollArea .setHorizontalScrollBarPolicy (
96+ QtCore .Qt .ScrollBarAlwaysOff )
9297 self .scrollArea .setWidgetResizable (True )
9398 self .inputLayout .addRow (self .scrollArea )
9499
@@ -162,15 +167,21 @@ def paintEvent(self, e):
162167 p .setPen (pen )
163168 try :
164169 for i in range (0 , len (self .points )):
165- p1 = geometry .Point (int (self .points [i ][0 ].text ()), int (self .points [i ][1 ].text ()))
166- p2 = geometry .Point (int (self .points [i + 1 ][0 ].text ()), int (self .points [i + 1 ][1 ].text ()))
170+ p1 = geometry .Point (int (self .points [i ][0 ].text ()),
171+ int (self .points [i ][1 ].text ()))
172+ p2 = geometry .Point (int (self .points [i + 1 ][0 ].text ()),
173+ int (self .points [i + 1 ][1 ].text ()))
167174 p .drawLine (p1 .x (), p1 .y (), p2 .x (), p2 .y ())
168175 except IndexError :
169- p1 = geometry .Point (int (self .points [- 1 ][0 ].text ()), int (self .points [- 1 ][1 ].text ()))
170- p2 = geometry .Point (int (self .points [0 ][0 ].text ()), int (self .points [0 ][1 ].text ()))
176+ p1 = geometry .Point (int (self .points [- 1 ][0 ].text ()),
177+ int (self .points [- 1 ][1 ].text ()))
178+ p2 = geometry .Point (int (self .points [0 ][0 ].text ()),
179+ int (self .points [0 ][1 ].text ()))
171180 p .drawLine (p1 .x (), p1 .y (), p2 .x (), p2 .y ())
172181 p .end ()
173- self .shapeInfo .updateInfo (self .points , self .shapeName )
182+ self .shapeInfo .updateInfo (self .points ,
183+ self .shapeName ,
184+ self .pointNum )
174185 self .image .setPixmap (QtGui .QPixmap ().fromImage (graph1 ))
175186 self .graph1 = graph1
176187
@@ -188,24 +199,27 @@ def addPoint(self):
188199 self .points .append ([])
189200 index = len (self .points ) - 1
190201 self .points [index ].extend ([x1 , y1 ])
191- self .input = PointInput ('Point' + str (self .pointNum ), self .points [index ][0 ], self .points [index ][1 ])
202+ self .input = PointInput ('Point' + str (self .pointNum ),
203+ self .points [index ][0 ],
204+ self .points [index ][1 ])
192205 self .coordLayout .insertRow (self .coordLayout .rowCount (), self .input )
193206 self .shapeInfo .str1 .setText ('Length of the sides:' )
194207 self .shapeInfo .distance .setStyleSheet ('background:solid #F2F3f4' )
195208 self .pointNum += 1
196- self .shapeName .setText (shapes .get (index + 1 , 'Undefined shape with {} number of sides' .format (index + 1 )))
209+ self .shapeName .setText (shapes .get (index + 1 ,
210+ ('Undefined shape with {} number of '
211+ 'sides' ).format (index + 1 )))
197212
198213 def info (self ):
199- if not self .pressedOnce :
200- self .extraInfo .setText (self . tr ( 'Extra Info \N{Black Up-Pointing Triangle} ' ) )
214+ if not self .pressedOnce :
215+ self .extraInfo .setText ('Extra Info \N{Black Up-Pointing Triangle} ' )
201216 self .shapeInfo .show ()
202- self .extraInfo .setStyleSheet ('border: transparent' )
203217 self .pressedOnce = True
204218 else :
205219 self .shapeInfo .hide ()
206220 self .pressedOnce = False
207- self .extraInfo .setStyleSheet ( 'background:solid #F2F3f4' )
208- self . extraInfo . setText ( self . tr ( 'Extra Info \N{Black Down-Pointing Triangle} ' ))
221+ self .extraInfo .setText (( 'Extra Info'
222+ ' \N{Black Down-Pointing Triangle} ' ))
209223
210224 def dist (self ):
211225 x0 = int (self .points [0 ][0 ].text ())
@@ -240,8 +254,8 @@ def shapeType(self):
240254 for i in range (0 , len (self .points )):
241255 x0 = int (self .points [i ][0 ].text ())
242256 y0 = int (self .points [i ][1 ].text ())
243- x3 = int (self .points [i + 1 ][0 ].text ())
244- y3 = int (self .points [i + 1 ][1 ].text ())
257+ x3 = int (self .points [i + 1 ][0 ].text ())
258+ y3 = int (self .points [i + 1 ][1 ].text ())
245259 x1 = x0 if x0 >= x3 else x3
246260 y1 = y0 if y0 >= y3 else y3
247261 x2 = x0 if x0 < x3 else x3
@@ -260,3 +274,6 @@ def shapeType(self):
260274 distance = math .sqrt (((x1 - x2 ) ** 2 ) + ((y1 - y2 ) ** 2 ))
261275 dist .append (distance )
262276 return 'Regular' if len (set (dist )) == 1 else 'Irregular'
277+
278+ def closeEvent (self , e ):
279+ self .shapeInfo .sidesLength .close ()
0 commit comments