-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphGUI.py
More file actions
153 lines (118 loc) · 4.38 KB
/
Copy pathGraphGUI.py
File metadata and controls
153 lines (118 loc) · 4.38 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import PyQt5
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QWidget, QPushButton, QLabel, QHBoxLayout, QSlider, QMenuBar)
from PyQt5.QtGui import QFont
from Graph import Graph
from Calculator import Calculator
import sys
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
class GraphGUI(QWidget):
def __init__(self, functions):
super().__init__()
self.setWindowTitle('Graph')
self.setGeometry(300, 100, 865, 515)
self.setObjectName('GraphGUI')
self.functions = functions
self.sliders = dict()
self.old_z_value: str = '1'
self.__init__GUI()
self.__init__Graph()
self.connect_buttons()
def __init__GUI(self):
self.zoom = 1
header = QFont("Calibre")
header.setPointSize(14)
header.setBold(True)
font = QFont("Calibre")
font.setPointSize(16)
self.zoom_label = QLabel('Zoom', self)
self.increase = QPushButton('+', self)
self.decrease = QPushButton('−', self)
self.zoom_label.setFont(header)
self.increase.setFont(font)
self.decrease.setFont(font)
self.zoom_label.move(585, 30)
self.increase.move(555, 70)
self.decrease.move(620, 70)
self.increase.resize(50, 50)
self.decrease.resize(50, 50)
self.header = QLabel('Transparency', self)
self.header.setFont(header)
self.header.adjustSize()
self.header.move(647, 150)
self.z_axis_label = QLabel('Z-Axis', self)
self.z_axis_label.move(745, 30)
self.z_axis_label.setFont(header)
self.z_axis_slider = QSlider(Qt.Horizontal, self)
self.z_axis_slider.setGeometry(720, 80, 110, 15)
self.z_axis_slider.setRange(0, 500)
self.z_axis_slider.setValue(250)
function_labels = dict()
self.sliders = dict()
horizontal_shift = 0
vertical_shift = 0
for i, function in enumerate(self.functions):
if i > 3:
horizontal_shift = 150
vertical_shift = -320
without_html = Calculator.translate(function)
without_html = without_html.replace(' (', '')
without_html = without_html.replace(') ', '')
font.setPointSizeF(14 - (len(without_html) / 4))
function_labels[function] = QLabel(function, self)
function_labels[function].setFont(font)
function_labels[function].setWordWrap(True)
function_labels[function].move(575 + horizontal_shift, 190 + vertical_shift + (i * 80))
self.sliders[function] = QSlider(Qt.Horizontal, self)
self.sliders[function].setGeometry(560 + horizontal_shift, 230 + vertical_shift + (i * 80), 100, 10)
self.sliders[function].setSingleStep(100)
change_opacity = self.change_opacity_closed(function)
self.sliders[function].setRange(0, 250)
self.sliders[function].setInvertedAppearance(True)
self.sliders[function].setValue(250)
self.sliders[function].valueChanged[int].connect(change_opacity)
def __init__Graph(self):
self.graph = Graph(self.functions, 1)
self.graph.setGeometry(500, 100, 500, 500)
self.graph.setFixedSize(500, 500)
horizontal_box = QHBoxLayout()
horizontal_box.setAlignment(QtCore.Qt.AlignLeft)
horizontal_box.setAlignment(QtCore.Qt.AlignBottom)
horizontal_box.stretch(1)
horizontal_box.addWidget(self.graph)
self.setLayout(horizontal_box)
def connect_buttons(self):
self.increase.clicked.connect(lambda: self.increase_zoom())
self.decrease.clicked.connect(lambda: self.decrease_zoom())
self.z_axis_slider.valueChanged[int].connect(self.change_z_axis)
def change_z_axis(self, value):
value = str((value * -1 + 250) / 100)
self.graph.change_z_axis(value)
#def make_transparency_visible(self):
#self.transparency
def change_opacity_closed(self, function):
def change_opacity(value):
self.graph.change_opacity(function, value)
return change_opacity
def increase_zoom(self):
if not self.zoom <= 0:
self.zoom -= 1
self.graph.change_zoom(self.zoom)
def decrease_zoom(self):
if not self.zoom >= 4:
self.zoom += 1
self.graph.change_zoom(self.zoom)
if __name__ == '__main__':
app = QtWidgets.QApplication([])
# functions = ['2 ^ x', 'x ^ 2 - 0.2', 'x <sup> 3 </sup>', '√ x']
# functions = ['x * z ^ 3 - z * x ^ 3']
functions = ['-1 ÷ ( x ^ 2 + z ^ 2 ) ', 'x * z ^ 3 - z * x ^ 3', ' ( x ^ 4 ) ÷ ( z ^ 3 ) ', 'x + z', '3']
# '3x', '2 ^ x']
graph_GUI = GraphGUI(functions)
graph_GUI.show()
sys.exit(app.exec_())