Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

Commit

Permalink
Some major changes -
Browse files Browse the repository at this point in the history
1) Fixed some problems with the point system
2) Added a dialog for choosing where to save the graph
  • Loading branch information
sumagnadas committed May 4, 2020
1 parent 811124b commit b34e5d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions modules/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Point(QPoint):

def __init__(self, x=0, y=0):
x *= 14.85
x += 300
x += 299
y *= 14.85
y = -y + 300
y = -y + 299
super().__init__(x, y)


Expand Down
50 changes: 36 additions & 14 deletions modules/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from PySide2 import QtWidgets, QtGui, QtCore
from PySide2.QtWidgets import QFileDialog, QDialog
from .input import NumInput, ShapeList, PointInput
from .info import ExtraInfo
import os.path as pt
from os.path import abspath
from modules import geometry
import datetime
import math
Expand All @@ -24,6 +25,7 @@ class Graph(QtWidgets.QWidget):
def __init__(self, ctx, surface, line_color):
super().__init__()

self.errorSaving = QtWidgets.QDialog()
self.fileDir = ''
self.save_call = False
self.draw_call = False
Expand Down Expand Up @@ -91,15 +93,28 @@ def makeInputLayout(self):
self.inputLayout.addRow(self.shapeInfo)
self.scrollArea.setWidget(self.widget)
self.scrollArea.setVerticalScrollBarPolicy(
QtCore.Qt.ScrollBarAsNeeded)
QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarAlwaysOff)
QtCore.Qt.ScrollBarAlwaysOff)
self.scrollArea.setWidgetResizable(True)
self.inputLayout.addRow(self.scrollArea)

def makeErrorDialog(self):
imageObj = QtGui.QImage('resources/error_symbol.ico')
caption = self.tr('Graph has to be drawn before saving')
image = QtWidgets.QLabel()
image.setPixmap(QtGui.QPixmap().fromImage(imageObj))
label = QtWidgets.QLabel(caption)
errorLayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
errorLayout.addWidget(image)
errorLayout.addWidget(label)
self.errorSaving.setLayout(errorLayout)
self.errorSaving.setModal(True)

def makeWindowLayout(self, buttonBox):
'''Make the layout of the window'''

self.makeErrorDialog()
self.pointinput = QtWidgets.QFormLayout()
input1 = PointInput('Point1', self.points[0][0], self.points[0][1])
input2 = PointInput("Point2", self.points[1][0], self.points[1][1])
Expand All @@ -119,7 +134,7 @@ def makeWindowLayout(self, buttonBox):
def setImage(self, filename):
'''Set the image for the graph'''

self.graph_image = QtGui.QImage(pt.abspath(filename))
self.graph_image = QtGui.QImage(abspath(filename))
self.image.setPixmap(QtGui.QPixmap().fromImage(self.graph_image))

def draw(self):
Expand All @@ -145,8 +160,19 @@ def clear(self):
self.image.setPixmap("resources/graph.png")

def save(self):
self.save_call = True
self.image.update()
if hasattr(self, 'graph1'):
caption = self.tr('Choose a filename for saving the graph')
currentDT = datetime.datetime.now()
currentTime = currentDT.strftime("%H:%M:%S")
defaultFilename = self.fileDir + "graph-" + currentTime + ".png"
filename = QFileDialog.getSaveFileName(self,
caption,
abspath('./untitled.png'),
self.tr('Images (*.png)'))
name = filename[0] if len(filename[0]) > 1 else defaultFilename
self.graph1.save(name, "PNG")
else:
self.errorSaving.show()

def check(self):
for i in self.points:
Expand Down Expand Up @@ -185,13 +211,6 @@ def paintEvent(self, e):
self.image.setPixmap(QtGui.QPixmap().fromImage(graph1))
self.graph1 = graph1

elif self.save_call:
self.save_call = False
currentDT = datetime.datetime.now()
currentTime = currentDT.strftime("%H:%M:%S")
filename = self.fileDir + "graph-" + currentTime + ".png"
self.graph1.save(filename, "PNG")

def addPoint(self):
x1 = NumInput()
y1 = NumInput()
Expand Down Expand Up @@ -276,4 +295,7 @@ def shapeType(self):
return 'Regular' if len(set(dist)) == 1 else 'Irregular'

def closeEvent(self, e):
self.shapeInfo.sidesLength.close()
if hasattr(self.shapeInfo, 'sidesLength'):
self.shapeInfo.sidesLength.close()
else:
e.accept()
Binary file added resources/error_symbol.ico
Binary file not shown.

0 comments on commit b34e5d9

Please sign in to comment.