Repository navigation
Expand file tree
/
Copy pathGUI for opencv.py
More file actions
241 lines (181 loc) · 7.71 KB
/
Copy pathGUI for opencv.py
File metadata and controls
241 lines (181 loc) · 7.71 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from PySide.QtGui import *
from PySide.QtCore import *
from utilities import *
import controller
class QFrameEfekto1(QFrame):
def __init__(self, parent = None):
super(QFrameEfekto1, self).__init__(parent)
self.name = 'Effect1'
control.set_effect_to_control(self.name)
self.start_stop_button = QPushButton(text = "Start")
grid = QGridLayout()
grid.addWidget(self.start_stop_button, 1, 0)
self.setLayout(grid)
self.connect(self.start_stop_button, SIGNAL("clicked()"), self.start_stop_pressed)
def start_stop_pressed(self):
if self.start_stop_button.text() == "Start":
self.start_stop_button.setText("Cancel")
control.start()
else:
self.start_stop_button.setText("Start")
control.stop()
class QFrameEfekto2(QFrame):
def __init__(self, parent = None):
super(QFrameEfekto2, self).__init__(parent)
self.name = 'Effect2'
control.set_effect_to_control(self.name)
#Radio buttons
self.normal_radio_button = QRadioButton(text = "No filter")
self.grey_radio_button = QRadioButton(text = "Greyscale")
self.sepia_radio_button = QRadioButton(text = "Sepia")
filtro_radio_buttons = QGroupBox('Filters')
vbox = QVBoxLayout()
vbox.addWidget(self.normal_radio_button)
vbox.addWidget(self.grey_radio_button)
vbox.addWidget(self.sepia_radio_button)
filtro_radio_buttons.setLayout(vbox)
self.normal_radio_button.setChecked(True)
#Buttons
self.start_stop_button = QPushButton(text = "Start")
#Spinbox and Dial
self.checkbox = QCheckBox(text = u"Enable")
self.dial = QDial() #kinda like speedometer of car
self.dial.setNotchesVisible(True)
self.dial.setMaximum(30)
self.spinbox = QSpinBox()
self.spinbox.setMaximum(30)
layout_dial = QHBoxLayout()
layout_dial.addWidget(self.checkbox)
layout_dial.addWidget(self.dial)
layout_dial.addWidget(self.spinbox)
gaussian_blur = QGroupBox('Gaussian blur')
gaussian_blur.setLayout(layout_dial)
#watermark
self.watermark_checkbox = QCheckBox(text = u"Enable")
self.watermark_checkbox.setChecked(True)
watermark_layout = QHBoxLayout()
watermark_layout.addWidget(self.watermark_checkbox)
watermark = QGroupBox('Logo')
watermark.setLayout(watermark_layout)
grid = QGridLayout()
grid.addWidget(filtro_radio_buttons, 0, 0)
grid.addWidget(gaussian_blur, 1, 0)
grid.addWidget(watermark, 2, 0)
grid.addWidget(self.start_stop_button, 3, 0)
self.setLayout(grid)
self.connect(self.start_stop_button, SIGNAL("clicked()"), self.start_stop_pressed)
self.connect(self.grey_radio_button, SIGNAL("pressed()"), control.convert_to_grayscale)
self.connect(self.normal_radio_button, SIGNAL("pressed()"), control.normal_colours)
self.connect(self.sepia_radio_button, SIGNAL("pressed()"), control.convert_to_sepia)
self.connect(self.dial, SIGNAL("valueChanged(int)"), self.dial_change) #calls a predifined method in spinbox and in dial
self.connect(self.spinbox, SIGNAL("valueChanged(int)"), self.spinbox_change) #vienas kit? kei?ia(pa?i?r?ti paleidus)
self.connect(self.checkbox, SIGNAL("clicked()"), self.gaussian_blur_enable)
self.connect(self.watermark_checkbox, SIGNAL("clicked()"), self.watermark_changed)
def watermark_changed(self):
if self.watermark_checkbox.isChecked():
control.enable_watermark()
return
else:
control.disable_watermark()
def gaussian_blur_enable(self):
if self.checkbox.isChecked():
control.enable_gaussian_blur()
return
else:
control.disable_gaussian_blur()
def dial_change(self, int): #int gauna i? SIGNAL
self.checkbox.setChecked(True)
self.gaussian_blur_enable()
self.spinbox.setValue(int)
control.set_gaussian_blur(int)
def spinbox_change(self, int):
self.dial.setValue(int)
control.set_gaussian_blur(int)
def start_stop_pressed(self):
if self.start_stop_button.text() == "Start":
self.start_stop_button.setText("Cancel")
control.start()
else:
self.start_stop_button.setText("Start")
control.stop()
class QFrameEfekto3(QFrame):
def __init__(self, parent = None):
super(QFrameEfekto3, self).__init__(parent)
self.name = 'Effect3'
self.runs = False
control.set_effect_to_control(self.name)
#Buttons
self.start_stop_button = QPushButton(text = "Start")
self.saugoti_button = QPushButton(text = "Save")
#Tekstas
self.negalima_saugoti = QLabel()
#saugojimo layout
saugojimo_layout = QVBoxLayout()
saugojimo_layout.addWidget(self.saugoti_button)
saugojimo_layout.addWidget(self.negalima_saugoti)
saugojimas = QGroupBox(u'Save Image')
saugojimas.setLayout(saugojimo_layout)
#Dropbox
self.dropbox = QComboBox()
self.populate_dropbox()
dropbox_layout = QHBoxLayout()
dropbox_layout.addWidget(self.dropbox)
paveikslelis = QGroupBox('Select Image')
paveikslelis.setLayout(dropbox_layout)
#Grid
grid = QGridLayout()
grid.addWidget(paveikslelis, 1, 0)
grid.addWidget(saugojimas, 2, 0)
grid.addWidget(self.start_stop_button, 3, 0)
self.setLayout(grid)
self.connect(self.start_stop_button, SIGNAL("clicked()"), self.start_stop_pressed)
self.dropbox.currentIndexChanged.connect(self.dropbox_changed)
self.connect(self.saugoti_button, SIGNAL("clicked()"), self.saugoti)
def saugoti(self):
if not self.runs:
self.negalima_saugoti.setText('First start the program')
return
fil_dir = QFileDialog.getSaveFileName(self, 'Save file', '', '.jpg')
if fil_dir[0] == '':
return
control.issaugoti_paveiksleli(fil_dir)
def dropbox_changed(self, index):
control.keisti_paveiksleli(self.dropbox.itemText(index))
def populate_dropbox(self):
path = os.path.dirname(os.path.realpath(__file__)) + '\\img' #gets file directory
img_list = get_imlist(path, 'png')
for n, img in enumerate(img_list):
name = img[img.rfind('\\') + 1:-4]
self.dropbox.insertItem(n, name, img)
def start_stop_pressed(self):
if self.start_stop_button.text() == "Start":
self.negalima_saugoti.setText('')
self.start_stop_button.setText("Cancel")
self.runs = True
control.start()
else:
self.start_stop_button.setText("Start")
self.runs = False
control.stop()
class Tabs(QTabWidget):
def __init__(self, parent = None):
super(Tabs, self).__init__(parent)
tab1 = QFrameEfekto1()
tab2 = QFrameEfekto2()
tab3 = QFrameEfekto3()
self.addTab(tab2, "Effect1")
self.addTab(tab3, "Effect2")
self.currentChanged.connect(self.tabswitch)
def tabswitch(self):
self.currentWidget().start_stop_button.setText("Start") #nustato text button ? 'start' pakeitus tab
control.stop()
control.set_effect_to_control(self.currentWidget().name)
app = QApplication(sys.argv) #Create a Qt application
control = controller.Control() #creates controler
gui = Tabs()
gui.show()
app.exec_() #enter the Qt main loop and start to execute the Qt code