Next/Previous button, and checkbox / bool like button? #942
-
I am currently trying to create a plot where I can cycle through a set of meshs iteratively, showing each one at a time with a previous/next button. As this is for screening a number of meshs, the idea would be to be able to also have a button each time which can be pressed to say, for example, this mesh is good (or bad) then move to the next one, in order to screen the quality of a large number of objects by eye. I've looked through the button examples, but haven't been able to figure this out! Is this something that would be possible? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi, you can try something like this: from vedo import *
def func(evt):
global index
if evt.actor and evt.actor.name == "ok_button":
if evt.actor not in goods:
i = (index+1) % len(meshes)
printc("GOOD! adding", meshes[i-1].name, c='g')
goods.append(meshes[i-1])
txt.text("that was good!").c('g')
plt.remove(meshes[i-1]).add(meshes[i])
plt.reset_camera()
index += 1
if evt.actor and evt.actor.name == "ko_button":
if evt.actor not in bads:
i = (index+1) % len(meshes)
printc("BAD! adding", meshes[i-1].name, c='r')
bads.append(meshes[i-1])
txt.text("that was bad!").c('r')
plt.remove(meshes[i-1]).add(meshes[i])
plt.reset_camera()
index += 1
# load some meshes
m1 = Mesh(dataurl+'bunny.obj').normalize().c('green5')
m2 = Mesh(dataurl+'apple.ply').normalize().c('red5')
m3 = Mesh(dataurl+'beethoven.ply').normalize().c('blue5')
m1.name = "a bunny"
m2.name = "an apple"
m3.name = "mr. beethoven"
index = 0 # init global index
meshes = [m1, m2, m3]
goods, bads = [], []
plt = Plotter()
bu = plt.add_button(
func,
pos=(0.2, 0.05), # x,y fraction from bottom left corner
states=["Good"], # text for each state
c=["w"], # font color for each state
bc=["dg"], # background color for each state
font="Courier", # font type
size=40, # font size
bold=True, # bold font
name="ok_button", # button name
)
bu = plt.add_button(
func,
pos=(0.8, 0.05), # x,y fraction from bottom left corner
states=["Bad"], # text for each state
c=["w"], # font color for each state
bc=["dr"], # background color for each state
font="Courier", # font type
size=40, # font size
bold=True, # bold font
name="ko_button", # button name
)
txt = Text2D(meshes[0].name, font="Courier", s=1.5, c='k')
plt += txt
plt.show(meshes[0]).close()
print("List of good ones", goods) Note that I just found a small bug.. (the callback function is called twice for some reason) so I add a tag to remind myself to look into it.. |
Beta Was this translation helpful? Give feedback.
-
Hi, I made some modifications to
then from vedo import *
def scroll_left(obj, ename):
global index
i = (index - 1) % len(meshes)
txt.text(meshes[i].name).c("k")
plt.remove(meshes[index]).add(meshes[i])
plt.reset_camera()
index = i
def scroll_right(obj, ename):
global index
i = (index + 1) % len(meshes)
txt.text(meshes[i].name).c("k")
plt.remove(meshes[index]).add(meshes[i])
plt.reset_camera()
index = i
def flag(obj, ename):
global index
txt.text("Flag Button Pressed!").c("r")
plt.reset_camera()
# load some meshes
m1 = Mesh(dataurl + "bunny.obj").c("green5")
m2 = Mesh(dataurl + "apple.ply").c("red5")
m3 = Mesh(dataurl + "beethoven.ply").c("blue5")
m1.name = "a bunny"
m2.name = "an apple"
m3.name = "mr. beethoven"
meshes = [m1, m2, m3]
txt = Text2D(meshes[0].name, font="Courier", pos="top-center", s=1.5)
plt = Plotter()
bu = plt.add_button(
scroll_right,
pos=(0.8, 0.06), # x,y fraction from bottom left corner
states=[">"], # text for each state
c=["w"], # font color for each state
bc=["k5"], # background color for each state
size=40, # font size
)
bu = plt.add_button(
scroll_left,
pos=(0.2, 0.06), # x,y fraction from bottom left corner
states=["<"], # text for each state
c=["w"], # font color for each state
bc=["k5"], # background color for each state
size=40, # font size
)
bu = plt.add_button(
flag,
pos=(0.5, 0.06),
states=["Flag"],
c=["w"],
bc=["r"],
size=40,
)
index = 0 # init global index
plt += txt
plt.show(meshes[0]).close() |
Beta Was this translation helpful? Give feedback.
Hi, I made some modifications to
Button
class, trythen