-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQt_GUI.py
176 lines (139 loc) · 5.64 KB
/
Qt_GUI.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from PyQt5.QtWidgets import QHBoxLayout, QComboBox, QColorDialog
from Colors import *
from Img_dailogbox import *
from Palette_Item import *
from Palette_generator import *
from Save_file import *
class App(QWidget):
def __init__(self):
super().__init__()
self.uploader = AppDemo()
self.title = 'Color Palette Generator'
self.setWindowIcon(QIcon("./Images/windowpalette.png"))
self.left = 50
self.top = 50
self.width = 1200
self.height = 900
self.panel_btns = []
self.mode = 0
self.layout_palette = QHBoxLayout()
self.layout_palette.setContentsMargins(0, 0, 0, 0)
self.layout_palette.setSpacing(0)
self.color_selected = ""
self.palette = []
self.grid_layout()
self.initUI()
def grid_layout(self):
layout = QGridLayout()
frametop = QFrame()
self.top_frame(frametop)
# frame.setGeometry()
framebottom = QFrame()
framebottom.setStyleSheet('background-color: ' + framebottomcolor + ";")
self.down_frame(framebottom)
layout.addWidget(frametop, 0, 0, 7, 1)
layout.addWidget(framebottom, 7, 0, 1, 1)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# Set the layout on the application's window
self.setLayout(layout)
def down_frame(self, framebottom):
layout = QGridLayout()
frameleft = QFrame()
self.UiComponents(frameleft)
frameright = QFrame()
self.btn_right(frameright)
layout.addWidget(frameleft, 0, 0, 1, 3)
layout.addWidget(frameright, 0, 3, 1, 1)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
framebottom.setLayout(layout)
def top_frame(self, frametop):
frametop.setLayout(self.layout_palette)
def update_palette(self, palette):
for i in reversed(range(self.layout_palette.count())):
widgetToRemove = self.layout_palette.itemAt(i).widget()
self.layout_palette.removeWidget(widgetToRemove)
widgetToRemove.setParent(None)
for color in palette:
self.layout_palette.addWidget(Palette_item(color))
def generate_palette(self):
palette = get_general_palette()
if self.color_selected != "" and self.mode == 1:
palette = get_light_palette(self.color_selected)
if self.color_selected != "" and self.mode == 2:
palette = get_dark_palette(self.color_selected)
if self.uploader.filepath != "":
palette = generate_Kmeans_palette(self.uploader.filepath, 10)
self.palette = palette
self.update_palette(palette)
def create_btn(self, name, function, img, layout):
button = QPushButton(name)
button.clicked.connect(function)
button.setIcon(QIcon(img))
button.setFont(QFont('Trebuchet MS', 12))
button.setIconSize(QSize(30, 30))
button.setStyleSheet("QPushButton"
"{"
"background-color : transparent;"
"color: white; "
"}"
"QPushButton::pressed"
"{"
"background-color : " + blue + ";"
"}"
)
self.panel_btns.append(button)
layout.addWidget(button)
def UiComponents(self, frameleft):
layout = QHBoxLayout()
self.create_btn("Color Picker", self.on_click, "./Images/color-picker.png", layout)
self.create_btn("Upload Image", self.img_uploader, "./Images/upload-img.png", layout)
# self.create_btn("View", self.clickme, "./Images/view.png", layout)
self.create_btn("Export", self.export, "./Images/share.png", layout)
self.dropdown(layout)
frameleft.setLayout(layout)
def export(self):
filepath = 'C:/Users/Kadari Sadhvika/Downloads/color-palette.txt'
savefile(filepath, self.palette)
def btn_right(self, frameright):
layout = QHBoxLayout()
self.create_btn("Generate Palette", self.generate_palette, "./Images/color-palette.png", layout)
frameright.setLayout(layout)
# action method
def clickme(self):
print("pressed")
def img_uploader(self):
self.uploader.show()
def openColorDialog(self):
color = QColorDialog.getColor()
if color.isValid():
self.color_selected = color.name()
self.uploader.filepath = ""
self.panel_btns[0].setStyleSheet(
"QPushButton"
"{"
"background-color : " + color.name() + ";"
"color: white; "
"}"
)
def on_click(self):
self.openColorDialog()
def dropdown(self, layout):
combo_box = QComboBox()
combo_box.setStyleSheet("color: white;")
combo_box.setMaximumWidth(250)
combo_box.setFont(QFont('Trebuchet MS', 12))
drop_list = ["Select Mode", "Same Shade Light Combo", "Same Shade Dark Combo"]
combo_box.setEditable(False)
combo_box.addItems(drop_list)
combo_box.currentIndexChanged.connect(self.mode_click)
view = combo_box.view()
view.setRowHidden(0, True)
layout.addWidget(combo_box)
def mode_click(self, i):
self.mode = i
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()