forked from Absolute-Tinkerer/Generative-Art
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
62 lines (50 loc) · 1.41 KB
/
gui.py
File metadata and controls
62 lines (50 loc) · 1.41 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
"""
@author: cemysf
"""
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from gui_experiments import FUNCTION_IN_USE, ArtFuncExperiment
GUI_WIDTH = 800
GUI_HEIGHT = 600
class Canvas(QLabel):
def mousePressEvent(self, event):
self.parentWidget().generateArtwork()
self.parentWidget().showArtwork()
class App(QWidget):
def __init__(self, artFunc: ArtFuncExperiment):
super().__init__()
self.width = GUI_WIDTH
self.height = GUI_HEIGHT
self.left = 10
self.top = 10
self.artFunc = artFunc
self.initUI()
def generateArtwork(self):
self.artwork = self.artFunc.use(GUI_WIDTH, GUI_HEIGHT)
def showArtwork(self):
pixmap = self.artwork.getImage()
self.canvas.setPixmap(pixmap)
def initUI(self):
self.setGeometry(self.left, self.top, self.width, self.height)
self.canvas = Canvas(self)
self.generateArtwork()
self.showArtwork()
# self.resize(pixmap.width(),pixmap.height())
self.show()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Q:
self.close()
def printInfo():
print(
"""
##### GUI #####
print q to exit
mouse click: create new image
###############
""")
if __name__ == '__main__':
printInfo()
app = QApplication(sys.argv)
ex = App(FUNCTION_IN_USE)
sys.exit(app.exec_())