Commit 4581260a authored by André Anjos's avatar André Anjos 💬

[gui] Use buttons to make job a bit easier to learn

parent 72e8baea
Pipeline #26445 passed with stages
in 14 minutes and 36 seconds
......@@ -39,7 +39,7 @@ m : toogle current object between "polygon" and "line" modes
c : creates a new (annotation) object
D : deletes all annotated points on the currently active object
D : deletes current (annotation) object
X : deletes all annotated objects
......@@ -124,14 +124,15 @@ class HelpDialog(tkinter.Toplevel):
# Now build the dialog geometry
buttonbox = tkinter.Frame(body, height=20)
buttonbox.pack(side=tkinter.BOTTOM)
w = tkinter.Button(buttonbox, text="Dismiss", command=self.on_dismiss,
default=tkinter.ACTIVE)
w.pack(side=tkinter.RIGHT)
self.bind("<Return>", self.on_dismiss)
self.bind("<Escape>", self.on_dismiss)
buttonbox.pack(side=tkinter.BOTTOM)
textbox = tkinter.Frame(body, height=380)
textbox.pack(side=tkinter.TOP)
self.initial_focus = t = tkinter.Text(textbox)
t.insert(tkinter.INSERT, message) #fill in contents
scrollbar = tkinter.Scrollbar(textbox)
......@@ -141,7 +142,6 @@ class HelpDialog(tkinter.Toplevel):
t.config(state=tkinter.DISABLED)
t.pack(side=tkinter.TOP)
textbox.pack(side=tkinter.TOP)
body.pack(padx=5, pady=5)
......@@ -296,7 +296,74 @@ class AnnotatorApp(tkinter.Tk):
if self.canvas is None:
# creates the image canvas
self.frames = {}
self.buttons = {}
self.labels = {}
self.variables = {}
f = self.frames['left'] = tkinter.Frame(self)
f.pack(side=tkinter.LEFT, padx=5, pady=5, fill=tkinter.BOTH, expand=True)
# creates a little panel for information and buttons, on the left
f = self.frames['image-selector'] = tkinter.LabelFrame(f, text="Images",
padx=5, pady=5)
f.grid(row=0)
b = self.buttons['previous-frame'] = tkinter.Button(f, text="← (p)",
command=self.previous_frame)
b.grid(row=0, column=0)
b = self.buttons['next-frame'] = tkinter.Button(f, text="→ (n)",
command=self.next_frame)
b.grid(row=0, column=1)
v = self.variables['image-progress'] = tkinter.StringVar()
v.set('[progress]')
l = self.labels['image-progress'] = tkinter.Label(f, textvariable=v)
l.grid(row=2, columnspan=2)
f = self.frames['annotations'] = tkinter.LabelFrame(self.frames['left'],
text="Objects", padx=5, pady=5)
f.grid(row=1)
b = self.buttons['previous-annotation'] = \
tkinter.Button(f, text="← (O)",
command=self.activate_previous_annotation)
b.grid(row=0, column=0)
b = self.buttons['next-annotation'] = tkinter.Button(f,
text="→ (o)", command=self.activate_next_annotation)
b.grid(row=0, column=1)
b = self.buttons['create-object'] = tkinter.Button(f,
text="✚ (c)", command=self.create_new_annotation)
b.grid(row=1, column=0)
b = self.buttons['delete-object'] = tkinter.Button(f,
text="✖ (D)", command=self.remove_active_annotation)
b.grid(row=1, column=1)
b = self.buttons['toggle-mode'] = \
tkinter.Button(f, text="mode (m)",
command=self.toggle_active_annotation_mode)
b.grid(row=2, columnspan=2)
v = self.variables['annotation-numpoints'] = tkinter.StringVar()
v.set('points')
l = self.labels['annotation-numpoints'] = tkinter.Label(f, textvariable=v)
l.grid(row=3, columnspan=2)
v = self.variables['annotation-progress'] = tkinter.StringVar()
v.set('[progress]')
l = self.labels['annotation-progress'] = tkinter.Label(f, textvariable=v)
l.grid(row=4, columnspan=2)
v = self.variables['annotation-mode'] = tkinter.StringVar()
v.set('mode...')
l = self.labels['annotation-mode'] = tkinter.Label(f, textvariable=v)
l.grid(row=5, columnspan=2)
# creates the image canvas on the root window
self.canvas = tkinter.Canvas(self, width=self.image.width,
height=self.image.height)
self.canvas.pack(side=tkinter.TOP)
......@@ -367,21 +434,20 @@ class AnnotatorApp(tkinter.Tk):
def _update_status_bar(self):
# updates the status bar
if not self.annotation:
annotated = '(0 objects annotated)'
else:
annotated = '(%d object(s); [%s] annotations)' % (
len(self.annotation),
','.join([str(len(k)) for k in self.annotation]))
self.variables['image-progress'].set('#%d out of %d' % (self.curr_pos+1,
len(self.filelist)))
self.variables['annotation-numpoints'].set('%d points' % \
len(self.curr_annotation))
self.variables['annotation-progress'].set('#%d out of %d' % (
self.annotation.index(self.curr_annotation)+1, len(self.annotation)))
self.variables['annotation-mode'].set('%s: %s' % (
'View' if self.readonly else 'Edit', self.default_mode.upper()))
basename = os.path.basename(self.filelist[self.curr_pos])
mode = 'View' if self.readonly else 'Edit'
mode = '%s (%s)' % (mode, self.default_mode)
stem = os.path.relpath(self.filelist[self.curr_pos], self.basedir)
self.title("annotate: %s (%d/%d)" % (stem, self.curr_pos+1,
len(self.filelist)))
y, x = self.unzoom_point(self._current_mouse_position())
self.text_status.set('%s %s (%03d/%03d) - %s || press ? for help ' \
'|| [x, y] = [%d, %d]' % \
(mode, basename, self.curr_pos+1, len(self.filelist), annotated, x, y))
self.text_status.set('press ? for help || [x, y] = [%d, %d]' % (x, y))
def save(self, *args, **kwargs):
......@@ -440,29 +506,24 @@ class AnnotatorApp(tkinter.Tk):
dialog = HelpDialog(self, __doc__, self.canvas)
def change_frame(self, event):
"""Advances to the next or rewinds to the previous frame"""
move = 0
def previous_frame(self, event=None):
"""Rewinds to the previous frame, wraps around if needed"""
self.save()
self.curr_pos -= 1
if self.curr_pos < 0:
self.curr_pos = len(self.filelist)-1
self._update_image()
if event.keysym in ('n', 'N') or event.num in (5,):
self.curr_pos += 1
logger.debug('Advancing to next image...')
if self.curr_pos >= len(self.filelist):
self.curr_pos = len(self.filelist) - 1
self.text_status.set('[warning] cannot go beyond end')
return
if event.keysym in ('p', 'P') or event.num in (4,):
self.curr_pos -= 1
logger.debug('Reversing to previous image...')
if self.curr_pos < 0:
self.text_status.set('[warning] cannot go beyond first image')
self.curr_pos = 0
return
def next_frame(self, event=None):
"""Advances to the next frame, wraps around if needed"""
self.save()
self.curr_pos += 1
logger.debug('Advancing to next image...')
if self.curr_pos >= len(self.filelist):
self.curr_pos = 0
self._update_image()
......@@ -577,6 +638,7 @@ class AnnotatorApp(tkinter.Tk):
current += 1
self.curr_annotation = self.annotation[current]
self.curr_annotation.activate()
self._update_status_bar()
def activate_previous_annotation(self, event=None):
......@@ -591,6 +653,7 @@ class AnnotatorApp(tkinter.Tk):
current -= 1
self.curr_annotation = self.annotation[current]
self.curr_annotation.activate()
self._update_status_bar()
def create_new_annotation(self, event=None):
......@@ -636,12 +699,12 @@ class AnnotatorApp(tkinter.Tk):
self.bind("o", self.activate_next_annotation)
self.bind("O", self.activate_previous_annotation)
self.bind("m", self.toggle_active_annotation_mode)
self.bind("n", self.change_frame)
self.bind("p", self.change_frame)
self.bind("N", self.change_frame)
self.bind("P", self.change_frame)
self.bind("<Button-4>", self.change_frame)
self.bind("<Button-5>", self.change_frame)
self.bind("n", self.next_frame)
self.bind("p", self.previous_frame)
self.bind("N", self.next_frame)
self.bind("P", self.previous_frame)
self.bind("<Button-4>", self.previous_frame)
self.bind("<Button-5>", self.next_frame)
# keeps track of mouse coordinates
self.bind("<Motion>", self.on_mouse_motion)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment