-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication1.py
218 lines (171 loc) · 7.95 KB
/
application1.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
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
####################################
# #
# File name: application1.py #
# Author: Prajwal Rao #
# Date created: 26/6/2018 #
# Date last modified: 6/07/2018 #
# Tested on Python Version: 3.5 #
# Version: "0.9.0 (Beta)" #
# #
####################################
__author__ = "Prajwal Rao"
__email__ = ["[email protected]", "[email protected]"]
__version__ = "0.9.0"
__status__ = "Beta"
__maintainer__ = "Prajwal Rao"
from ImageBlock import ImageWindow
from ButtonBlock import ButtonWindow
from DataDisplayBlock import DataDisplayWindow
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QMessageBox, \
QVBoxLayout, QStatusBar, QLabel, QWidget, QFileDialog, QHBoxLayout
import os
import sys
from counter import count
import logging
import json
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(50, 50, 1920, 1080)
self.setWindowTitle("Ground Truthing")
# self.setWindowIcon(QtGui.QIcon('pythonlogo.png'))
self.frame_counter = self.images_handler()
# self.statusbar_init()
LOGGER.info("initialised status bar")
# menubar_init()
vboxlayout = QVBoxLayout()
hboxlayout = QHBoxLayout()
# vboxlayout.addStretch(2)
# vboxlayout.setStretch(1,2)
self.topwid = ImageWindow()
self.topwid.resize(self.topwid.sizeHint())
self.botwid = ButtonWindow()
self.botwid.resize(self.botwid.sizeHint())
self.printer = DataDisplayWindow()
self.topwid.image(self.frame_counter, self.printer)
self.botwid.gridstruct(self.frame_counter, self.printer)
self.printer.show_data(self.frame_counter)
self.wid = QWidget(self)
extractAction = QAction("Exit", self)
extractAction.setShortcut("Ctrl+Q")
extractAction.setStatusTip('Leave The App')
extractAction.triggered.connect(self.close_application)
saveFile = QAction("Save", self)
saveFile.setShortcut("Ctrl+S")
saveFile.setStatusTip('Save To Location')
saveFile.triggered.connect(self.save_application)
LOGGER.debug("frame Length = " + str(len(self.frame_counter.display_all())))
extractNextImage = QAction("Next Frame", self)
# extractNextImage.setShortcut("Alt+n")
extractNextImage.setShortcut("Right")
extractNextImage.setStatusTip("Next Frame...")
extractNextImage.triggered.connect(lambda: self.topwid.changeimage("n", self.frame_counter, self.printer))
extractPrevImage = QAction("Previous Frame", self)
# extractPrevImage.setShortcut("Alt+b")
extractPrevImage.setShortcut("Left")
extractPrevImage.setStatusTip("Previous Frame...")
extractPrevImage.triggered.connect(lambda: self.topwid.changeimage("b", self.frame_counter, self.printer))
getshortcuts = QAction("Shortcuts", self)
getshortcuts.setShortcut("Ctrl+K")
getshortcuts.setStatusTip("Shortcuts List")
getshortcuts.triggered.connect(lambda: self.short())
reportBugs = QAction("Report", self)
reportBugs.setShortcut("Ctrl+R")
reportBugs.setStatusTip("Please report bugs")
reportBugs.triggered.connect(lambda: self.bugreport())
author = QLabel("Prajwal Rao\[email protected]")
author.setStyleSheet("color : grey")
self.statusBar = QStatusBar()
self.statusBar.addPermanentWidget(author)
self.setStatusBar(self.statusBar)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
helpMenu = mainMenu.addMenu('&Help')
fileMenu.addAction(extractNextImage)
fileMenu.addAction(extractPrevImage)
fileMenu.addAction(saveFile)
fileMenu.addAction(extractAction)
helpMenu.addAction(getshortcuts)
helpMenu.addAction(reportBugs)
self.setCentralWidget(self.wid)
# vboxlayout.setAlignment(QtCore.Qt.AlignCenter)
hboxlayout.addWidget(self.topwid)
hboxlayout.addWidget(self.printer)
vboxlayout.addLayout(hboxlayout)
# vboxlayout.addWidget(self.topwid)
# print("vbox size hint: ",vboxlayout.sizeHint())
vboxlayout.addWidget(self.botwid.groupbox)
self.wid.setLayout(vboxlayout)
LOGGER.info("initialised menubar")
# self.home()
self.show()
# def get_frame(self, images):
# imgs = sorted(images, key=lambda x: int(x[6]))
def images_handler(self):
image_path = QFileDialog.getExistingDirectory(self, "Select Image Directory")
# image_path = input("Enter Image Path:")
imag = os.listdir(image_path)
images = [os.path.join(image_path, t) for t in imag]
# pprint(images)
# images = self.get_frame(images)
self.frame_counter = count()
# images = sorted(images, key=lambda x: int(x[6]))
for image in images:
self.frame_counter.set(image)
self.frame_counter.set_target_as_zero()
# self.frame_counter.sort_dict()
# pprint(self.frame_counter.display_all())
return self.frame_counter
def bugreport(self):
reporttext = 'Please report all bugs to <a href="mailto:[email protected]">[email protected]</a>' \
+ ' or <a href="mailto:[email protected]">[email protected]</a>'
QMessageBox.about(QWidget(), "Report", reporttext)
# reportmessage.setIcon(QMessageBox.Information)
# reportmessage.setText('Please report all bugs to <a href="mailto:[email protected]">[email protected]</a>'
# + ' or <a href="mailto:[email protected]">[email protected]</a>')
def short(self):
self.key_bindings = "Ctrl+S\t\t\tSave File as JSON\n" \
+ "Ctrl+Q\t\t\tQuit\n" \
+ "Right Arrow\t\t\tNext Frame\n" \
+ "Left Arrow\t\t\tPrevious Frame\n" \
+ "1\t\t\tAdd Small Car\n" \
+ "Shift+1\t\t\tRemove Small Car\n" \
+ "2\t\t\tAdd Big Car\n" \
+ "Shift+2\t\t\tRemove Big Car\n" \
+ "3\t\t\tAdd Bus\n" \
+ "Shift+3\t\t\tRemove Bus\n" \
+ "4\t\t\tAdd Two Wheeler\n" \
+ "Shift+4\t\t\tRemove Two Wheeler\n" \
+ "Q\t\t\tAdd Three Wheeler\n" \
+ "Shift+Q\t\t\tRemove Three Wheeler\n" \
+ "W\t\t\tAdd LCV\n" \
+ "Shift+W\t\t\tRemove LCV\n" \
+ "E\t\t\tAdd Truck\n" \
+ "Shift+E\t\t\tRemove Truck\n" \
+ "R\t\t\tAdd Bicycle\n" \
+ "Shift+R\t\t\tRemove Bicycle\n\n" \
+ "Ctrl+K\t\t\tShow Key Bindings\n" \
+ "Ctrl+R\t\t\tReport Bugs\n"
QMessageBox.about(QWidget(), "Shortcuts", self.key_bindings)
def save_application(self):
save_location = QFileDialog.getSaveFileName(self, "Save File")
LOGGER.info(save_location)
if not save_location[0].endswith(".json"):
save_location[0]+=".json"
with open(save_location[0], "w+") as file:
writedata = self.frame_counter.display_all()
json.dump(writedata, file)
def close_application(self):
choice = QMessageBox.question(self, 'Extract!',
"Do you really want to quit?",
QMessageBox.Yes | QMessageBox.No)
LOGGER.info("Quit")
sys.exit()
def run():
app = QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
App = QApplication(sys.argv)
run()