def contextMenuEvent(self, event):
try:
if self.cursor_mode:
if self.click_box!=None and self.bboxes!=None:
#print(self.bboxes)
for index, b in enumerate(self.bboxes):
if b[0].x()<self.click_box.x()<b[1].x() and \
b[0].y()<self.click_box.y()<b[1].y():
#print(index,b)
actionSet = []
for key, value in self.ind_to_class.items():
if 'prod' in value:
menu_opt = menu.addMenu(value)
for i in range(1, 21):
if 'prod' in b[2]:
btwo = b[2].rsplit('_')
type_prod = btwo[1]
prod_num = btwo[2]
#print(btwo, type_prod, prod_num)
if int(prod_num) == i and type_prod in value:
color1 = str(self.gt_color[key][0])
color2 = str(self.gt_color[key][1])
color3 = str(self.gt_color[key][2])
label
= QtWidgets.
QLabel(b
[2]) label.setStyleSheet("QLabel { color: " + self.text_color[
key] + "; background-color: rgb(" + color1 + "," + color2 + "," + color3 + "); padding: 5px 25px 5px 25px; } QLabel:hover { color: rgb(255,255,255); background-color: #00457d;}")
action_high.setDefaultWidget(label)
action_high.setText(b[2])
menu_opt.addAction(action_high)
else:
menu_opt.addAction(str(value) + '_' + str(i))
else:
menu_opt.addAction(str(value) + '_' + str(i))
else:
if value == b[2]:
color1 = str(self.gt_color[key][0])
color2 = str(self.gt_color[key][1])
color3 = str(self.gt_color[key][2])
label
= QtWidgets.
QLabel(value
) label.setStyleSheet("QLabel { color: " + self.text_color[key] + "; background-color: rgb(" + color1 + "," + color2 + "," + color3 + "); padding: 5px 25px 5px 25px; } QLabel:hover { color: rgb(255,255,255); background-color: #00457d;}")
action_high.setDefaultWidget(label)
action_high.setText(value)
menu.addAction(action_high)
else:
menu.addAction(value)
actionSet.append(menu)
action = menu.exec_(event.screenPos())
if action:
self.bboxes[index][2] = action.text()
elif not self.cursor_mode:
#print(self.click_boxes)
if len(self.click_boxes) > 0 and self.bboxes!=None:
actionSet = []
for key, value in self.ind_to_class.items():
##########actionSet.append(menu.addAction(value))
if 'prod' in value:
menu_opt = menu.addMenu(value)
for i in range(1, 21):
menu_opt.addAction(str(value) + '_' + str(i))
else:
menu.addAction(value)
actionSet.append(menu)
action = menu.exec_(event.screenPos())
ind_sel = None
#for indi, vali in enumerate(actionSet):
# if action == vali:
# ind_sel = indi
#print("Class selected: "+str(ind_sel))
for index, b in enumerate(self.click_boxes):
self.bboxes[b[4]-1][2] = action.text()#self.ind_to_class[ind_sel]
self.click_boxes = []
self.draw_box = False
self.click = 0
except:
print('Problem')
if self.print_callback != None:
self.print_callback(self.bboxes)
def contextMenuEvent(self, event):
try:
if self.cursor_mode:
if self.click_box!=None and self.bboxes!=None:
#print(self.bboxes)
for index, b in enumerate(self.bboxes):
if b[0].x()<self.click_box.x()<b[1].x() and \
b[0].y()<self.click_box.y()<b[1].y():
#print(index,b)
menu = QMenu()
actionSet = []
for key, value in self.ind_to_class.items():
if 'prod' in value:
menu_opt = menu.addMenu(value)
for i in range(1, 21):
if 'prod' in b[2]:
btwo = b[2].rsplit('_')
type_prod = btwo[1]
prod_num = btwo[2]
#print(btwo, type_prod, prod_num)
if int(prod_num) == i and type_prod in value:
color1 = str(self.gt_color[key][0])
color2 = str(self.gt_color[key][1])
color3 = str(self.gt_color[key][2])
action_high = QtWidgets.QWidgetAction(menu)
label = QtWidgets.QLabel(b[2])
label.setStyleSheet("QLabel { color: " + self.text_color[
key] + "; background-color: rgb(" + color1 + "," + color2 + "," + color3 + "); padding: 5px 25px 5px 25px; } QLabel:hover { color: rgb(255,255,255); background-color: #00457d;}")
action_high.setDefaultWidget(label)
action_high.setText(b[2])
menu_opt.addAction(action_high)
else:
menu_opt.addAction(str(value) + '_' + str(i))
else:
menu_opt.addAction(str(value) + '_' + str(i))
else:
if value == b[2]:
color1 = str(self.gt_color[key][0])
color2 = str(self.gt_color[key][1])
color3 = str(self.gt_color[key][2])
action_high = QtWidgets.QWidgetAction(menu)
label = QtWidgets.QLabel(value)
label.setStyleSheet("QLabel { color: " + self.text_color[key] + "; background-color: rgb(" + color1 + "," + color2 + "," + color3 + "); padding: 5px 25px 5px 25px; } QLabel:hover { color: rgb(255,255,255); background-color: #00457d;}")
action_high.setDefaultWidget(label)
action_high.setText(value)
menu.addAction(action_high)
else:
menu.addAction(value)
actionSet.append(menu)
action = menu.exec_(event.screenPos())
if action:
self.bboxes[index][2] = action.text()
elif not self.cursor_mode:
#print(self.click_boxes)
if len(self.click_boxes) > 0 and self.bboxes!=None:
menu = QMenu()
actionSet = []
for key, value in self.ind_to_class.items():
##########actionSet.append(menu.addAction(value))
if 'prod' in value:
menu_opt = menu.addMenu(value)
for i in range(1, 21):
menu_opt.addAction(str(value) + '_' + str(i))
else:
menu.addAction(value)
actionSet.append(menu)
action = menu.exec_(event.screenPos())
ind_sel = None
#for indi, vali in enumerate(actionSet):
# if action == vali:
# ind_sel = indi
#print("Class selected: "+str(ind_sel))
for index, b in enumerate(self.click_boxes):
self.bboxes[b[4]-1][2] = action.text()#self.ind_to_class[ind_sel]
self.click_boxes = []
self.draw_box = False
self.click = 0
except:
print('Problem')
if self.print_callback != None:
self.print_callback(self.bboxes)
To copy to clipboard, switch view to plain text mode
Thanks!
Bookmarks