Skip to content

Commit 77867d1

Browse files
committed
Adding Context menu buttons
1 parent 18c466d commit 77867d1

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

app/components.py

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def __init__(self, text, id = None, signal=None, parent=None,
9797
self.signal = signal
9898
self.clicked.connect(self.click)
9999

100+
def update_text(self, new_text):
101+
self.setText(new_text)
102+
100103
def click(self):
101104

102105
if self.signal:

app/contextMenu.py

+40-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PySide2.QtCore import Qt, QTimer
55
from components import EyePilotButton
66

7+
import time
78
import random
89
import resources_rc # Import the compiled resource file
910
class ContextMenuBtn(QWidget):
@@ -37,14 +38,16 @@ def __init__(self,text,x,y):
3738

3839
self.setGeometry(x, y, self.width, self.height)
3940

40-
4141
self.to_y = y
4242
self.to_x = x
4343

4444
def setPosition(self,x,y):
4545
self.to_x = x - self.diameter/2
4646
self.to_y = y - self.diameter/2
4747

48+
def setText(self,text):
49+
self.btn.setText(text)
50+
4851
def setTransparency(self,transparency):
4952
self.transparency = transparency
5053
if self.transparency > 0:
@@ -56,14 +59,42 @@ def setTransparency(self,transparency):
5659

5760
self.setColor(self.brush_color.red(),self.brush_color.green(),self.brush_color.blue())
5861

62+
class ContextMenu(QWidget):
63+
64+
def __init__(self) -> None:
65+
self.btn1 = ContextMenuBtn("Lorem ipsum morem solem",100,100)
66+
self.btn2 = ContextMenuBtn("Lorem ipsum morem solem",150,300)
67+
self.btn3 = ContextMenuBtn("Lorem ipsum morem solem",200,500)
68+
self.btn4 = ContextMenuBtn("Lorem ipsum morem solem",300,700)
69+
70+
def show(self):
71+
self.btn1.show()
72+
self.btn2.show()
73+
self.btn3.show()
74+
self.btn4.show()
75+
76+
def hide(self):
77+
self.btn1.hide()
78+
self.btn2.hide()
79+
self.btn3.hide()
80+
self.btn4.hide()
81+
82+
def setText(self,t1,t2,t3,t4):
83+
self.btn1.setText(t1)
84+
self.btn2.setText(t2)
85+
self.btn3.setText(t3)
86+
self.btn4.setText(t4)
87+
88+
5989
if __name__ == "__main__":
6090
app = QApplication(sys.argv)
61-
btn1 = ContextMenuBtn("Lorem ipsum morem solem",100,100)
62-
btn1.show()
63-
btn2 = ContextMenuBtn("Lorem ipsum morem solem",150,300)
64-
btn2.show()
65-
btn3 = ContextMenuBtn("Lorem ipsum morem solem",200,500)
66-
btn3.show()
67-
btn4 = ContextMenuBtn("Lorem ipsum morem solem",300,700)
68-
btn4.show()
91+
menu = ContextMenu()
92+
93+
menu.show()
94+
menu.setText("Text1","Text2","Text3","Text4")
95+
# for n in range(10):
96+
# menu.hide()
97+
menu.show()
98+
menu.setText("Text1","Text2","Text3","LOL4")
99+
69100
sys.exit(app.exec_())

app/contextTracker.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import threading
88
import numpy as np
99
import time
10+
import re
1011

1112
class VisContext:
1213

@@ -21,7 +22,9 @@ def __init__(self,before = lambda : None ,after = lambda : None):
2122

2223
def getDescription(self):
2324
img, description = self.cursorTracker.getRichContext()
24-
return description
25+
pattern = r'(?<=\d\. )(.*?)(?=\n)'
26+
tokens = re.findall(pattern, description)
27+
return tokens
2528

2629
def before_scan(self):
2730
self.before()
@@ -142,7 +145,7 @@ def rescan(self,x,y,w,h):
142145
self.DSB.loadData(rectangles)
143146

144147
def getRichContext(self):
145-
description = ""
148+
description = "output: 0. Open .git\n1. Open Documents\n2. Open Downloads\n3. Open dist\n4. Open build\n5. Open Downloads" # test input
146149
# description = self.advisorModel.respond(self.rich_context.getPath(self))
147150
return (self.rich_context, description)
148151

app/main.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from contextTracker import VisContext
1616

1717
from dot import CircleWidget
18+
from contextMenu import ContextMenu
1819

1920
from tracker import Tracker
2021

@@ -128,6 +129,7 @@ def __init__(self):
128129
self.calibrationON = False
129130

130131
self.vizContext = VisContext()
132+
self.contextMenu = ContextMenu()
131133

132134
self.model = ModelSaver()
133135

@@ -171,11 +173,15 @@ def main_loop(self):
171173
self.fix_start = time.time()
172174
self.vizContext.start()
173175
self.vizContext.setPosition(point[0], point[1])
174-
self.vizContext.getDescription()
176+
description = self.vizContext.getDescription()
177+
print(description)
178+
self.contextMenu.show()
179+
self.contextMenu.setText(description[0],description[1],description[2],"Exit")
175180
elif not fix:
176181
self.vizContext.close()
177182

178183
if blink and fix:
184+
self.contextMenu.hide()
179185
x,y = self.vizContext.setPosition(point[0], point[1])
180186
self.press(x,y)
181187

0 commit comments

Comments
 (0)