Commit d8fafdba authored by André Anjos's avatar André Anjos 💬

[gui/widgets] Applies ttk styling so buttons now look-like working

parent ba89e7f9
Pipeline #26534 passed with stages
in 12 minutes and 55 seconds
......@@ -129,6 +129,7 @@ Pointer shortcuts
import os
import math
import tkinter
import tkinter.ttk
import tkinter.font
import functools
import warnings
......@@ -205,7 +206,6 @@ class AnnotatorApp(tkinter.Tk):
self.filter = False
# builds the application interface - buttons, frames and the image canvas
self.font = tkinter.font.Font(size=12)
self.frames = {}
self.buttons = {}
self.labels = {}
......@@ -213,62 +213,60 @@ class AnnotatorApp(tkinter.Tk):
self.tooltips = {}
self.canvas = None #where the image will be displayed
f = self.frames['left'] = tkinter.Frame(self)
f = self.frames['left'] = tkinter.ttk.Frame(self)
f.pack(side=tkinter.LEFT, padx=5, pady=5, fill=tkinter.Y, expand=False)
# 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, font=self.font)
f = self.frames['image-selector'] = tkinter.ttk.LabelFrame(f, text="Images")
f.grid(row=0, sticky=tkinter.NSEW)
v = self.variables['image-progress'] = tkinter.StringVar()
v.set('[progress]')
l = self.labels['image-progress'] = tkinter.Label(f, textvariable=v,
font=self.font)
l = self.labels['image-progress'] = tkinter.ttk.Label(f, textvariable=v)
l.grid(row=0, columnspan=2)
b = self.buttons['previous-frame'] = tkinter.Button(f, text="<< (p)",
command=self.previous_frame, font=self.font)
b = self.buttons['previous-frame'] = tkinter.ttk.Button(f, text="<< (p)",
command=self.previous_frame)
b.grid(row=1, column=0, sticky=tkinter.NSEW)
self.tooltips['previous-frame'] = \
widgets.Tooltip(b, text='Go to previous image (keyboard: p)')
b = self.buttons['next-frame'] = tkinter.Button(f, text=">> (n)",
command=self.next_frame, font=self.font)
b = self.buttons['next-frame'] = tkinter.ttk.Button(f, text=">> (n)",
command=self.next_frame)
b.grid(row=1, column=1, sticky=tkinter.NSEW)
self.tooltips['next-frame'] = \
widgets.Tooltip(b, text='Go to next image (keyboard: n)')
f = self.frames['annotations'] = tkinter.LabelFrame(self.frames['left'],
text="Objects", padx=5, pady=5, font=self.font)
f = self.frames['annotations'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Objects")
f.grid(row=1, sticky=tkinter.NSEW)
v = self.variables['annotation-progress'] = tkinter.StringVar()
v.set('[progress]')
l = self.labels['annotation-progress'] = tkinter.Label(f, textvariable=v,
font=self.font)
l = self.labels['annotation-progress'] = tkinter.ttk.Label(f,
textvariable=v)
l.grid(row=0, columnspan=2)
b = self.buttons['previous-annotation'] = \
tkinter.Button(f, text="<< (O)", font=self.font,
tkinter.ttk.Button(f, text="<< (O)",
command=self.activate_previous_annotation)
b.grid(row=1, column=0, sticky=tkinter.NSEW)
self.tooltips['previous-annotation'] = widgets.Tooltip(b,
text='Highlight (edit) previous object (keyboard: O)')
b = self.buttons['next-annotation'] = tkinter.Button(f, font=self.font,
text=">> (o)", command=self.activate_next_annotation)
b = self.buttons['next-annotation'] = tkinter.ttk.Button(f, text=">> (o)",
command=self.activate_next_annotation)
b.grid(row=1, column=1, sticky=tkinter.NSEW)
self.tooltips['next-annotation'] = widgets.Tooltip(b,
text='Highlight (edit) next object (keyboard: o)')
b = self.buttons['create-object'] = tkinter.Button(f, font=self.font,
b = self.buttons['create-object'] = tkinter.ttk.Button(f,
text="new (c)", command=self.create_new_annotation)
b.grid(row=2, column=0, sticky=tkinter.NSEW)
self.tooltips['create-object'] = widgets.Tooltip(b,
text='Annotate a new object (keyboard: c)')
b = self.buttons['delete-object'] = tkinter.Button(f, font=self.font,
b = self.buttons['delete-object'] = tkinter.ttk.Button(f,
text="del (D)", command=self.remove_active_annotation)
b.grid(row=2, column=1, sticky=tkinter.NSEW)
self.tooltips['create-object'] = widgets.Tooltip(b,
......@@ -276,9 +274,8 @@ class AnnotatorApp(tkinter.Tk):
v = self.variables['decoration-mode'] = tkinter.StringVar()
v.set('mode (m): %s' % self.default_mode[:4].upper())
b = self.buttons['toggle-mode'] = \
tkinter.Button(f, textvariable=v, font=self.font,
command=self.toggle_active_annotation_mode)
b = self.buttons['toggle-mode'] = tkinter.ttk.Button(f, textvariable=v,
command=self.toggle_active_annotation_mode)
b.grid(row=3, columnspan=2, sticky=tkinter.NSEW)
self.tooltips['decoration-mode'] = widgets.Tooltip(b,
text='Toggle between ALT decoration modes. This is no way ' \
......@@ -286,19 +283,21 @@ class AnnotatorApp(tkinter.Tk):
v = self.variables['annotation-numpoints'] = tkinter.StringVar()
v.set('points')
l = self.labels['annotation-numpoints'] = tkinter.Label(f,
textvariable=v, font=self.font)
l = self.labels['annotation-numpoints'] = tkinter.ttk.Label(f,
textvariable=v)
l.grid(row=4, columnspan=2)
self.tooltips['decoration-mode'] = widgets.Tooltip(l,
text='Displays the number of annotated points in the current ' \
'object being annotated (highlit)')
f = self.frames['filters'] = tkinter.LabelFrame(self.frames['left'],
text="Filters", padx=5, pady=5, font=self.font)
f = self.frames['filters'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Filters")
f.grid(row=2, sticky=tkinter.NSEW)
b = self.buttons['adaheq'] = tkinter.Checkbutton(f,
text="CLAHE", command=self.toggle_filter, font=self.font)
v = self.variables['adaheq'] = tkinter.IntVar()
v.set(0)
b = self.buttons['adaheq'] = tkinter.ttk.Checkbutton(f,
text="CLAHE", command=self.toggle_filter, variable=v)
b.grid(row=0, columnspan=3, sticky=tkinter.W)
self.tooltips['adaheq'] = widgets.Tooltip(b,
text='Applies Contrast Limited Adaptive Histogram Equalization ' \
......@@ -307,55 +306,51 @@ class AnnotatorApp(tkinter.Tk):
v = self.variables['adaheq-kernel-size'] = tkinter.IntVar()
v.set(18)
l = self.labels['adaheq-kernel-size'] = tkinter.Label(f, text='Kernel:',
font=self.font)
l.grid(row=1, column=1, sticky=tkinter.W)
b = self.buttons['adaheq-kernel-size'] = tkinter.Entry(f, textvariable=v,
width=4, font=self.font)
b.grid(row=1, column=2, sticky=tkinter.W)
l = self.labels['adaheq-kernel-size'] = tkinter.ttk.Label(f, text='Kernel:')
l.grid(row=1, column=1, sticky=tkinter.E)
b = self.buttons['adaheq-kernel-size'] = tkinter.ttk.Entry(f,
textvariable=v, width=4)
b.grid(row=1, column=2, sticky=tkinter.E)
v = self.variables['adaheq-clip'] = tkinter.DoubleVar()
v.set(0.02)
l = self.labels['adaheq-clip'] = tkinter.Label(f, text='Clip:',
font=self.font)
l = self.labels['adaheq-clip'] = tkinter.ttk.Label(f, text='Clip:')
l.grid(row=2, column=1, sticky=tkinter.W)
b = self.buttons['adaheq-clip'] = tkinter.Entry(f, textvariable=v,
width=4, font=self.font)
b = self.buttons['adaheq-clip'] = tkinter.ttk.Entry(f, textvariable=v,
width=4)
b.grid(row=2, column=2, sticky=tkinter.W)
f = self.frames['pointer'] = tkinter.LabelFrame(self.frames['left'],
text="Pointer [x, y]", padx=5, pady=5, font=self.font)
f = self.frames['pointer'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Pointer [x, y]")
f.grid(row=3, sticky=tkinter.NSEW)
v = self.variables['pointer-position'] = tkinter.StringVar()
v.set('(0, 0)')
l = self.labels['pointer-position'] = tkinter.Label(f, textvariable=v,
font=self.font)
l.grid(row=0, sticky=tkinter.W)
l = self.labels['pointer-position'] = tkinter.ttk.Label(f, textvariable=v)
l.grid(row=0, sticky=tkinter.E)
self.tooltips['pointer-position'] = widgets.Tooltip(l,
text='This box displays the current pointer position with respect ' \
'to the displayed image. Coordinates are displayed in true ' \
'image resolution')
f = self.frames['zoom'] = tkinter.LabelFrame(self.frames['left'],
text="Zoom", padx=5, pady=5, font=self.font)
f = self.frames['zoom'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Zoom")
f.grid(row=4, sticky=tkinter.NSEW)
v = self.variables['zoom'] = tkinter.StringVar()
v.set('%g' % self.zoom)
l = self.labels['zoom'] = tkinter.Label(f, textvariable=v, font=self.font)
l.grid(row=0, sticky=tkinter.W)
l = self.labels['zoom'] = tkinter.ttk.Label(f, textvariable=v)
l.grid(row=0, sticky=tkinter.E)
self.tooltips['zoom'] = widgets.Tooltip(l,
text='This box displays the current image zoom.')
f = self.frames['help'] = tkinter.LabelFrame(self.frames['left'],
text="Help", padx=5, pady=5, font=self.font)
f = self.frames['help'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Help")
f.grid(row=5, sticky=tkinter.NSEW)
b = self.buttons['display-help'] = \
tkinter.Button(f, text='help (?)', font=self.font,
command=self.on_help)
b.grid(row=0, sticky=tkinter.NSEW)
tkinter.ttk.Button(f, text='help (?)', command=self.on_help)
b.grid(row=0, sticky=tkinter.E)
self.tooltips['display-help'] = widgets.Tooltip(b,
text='Click on this button to display the help dialog and ' \
'learn more about keyboard and mouse-based shortcuts')
......@@ -678,7 +673,7 @@ class AnnotatorApp(tkinter.Tk):
def toggle_active_annotation_mode(self, event=None):
if self.curr_annotation: self.curr_annotation.toggle_mode()
for k in self.annotation: k.toggle_mode()
self.default_mode = 'line' if self.default_mode == 'polygon' else 'polygon'
self.variables['decoration-mode'].set('mode (m): %s' % \
self.default_mode[:4].upper())
......
......@@ -4,6 +4,8 @@
'''Widgets for easing the annotation of objects in the image'''
import tkinter
import tkinter.ttk
import warnings
import logging
logger = logging.getLogger(__name__)
......@@ -332,6 +334,8 @@ class Annotation(object):
def _create_decoration(self):
"""Creates decorations for the current object"""
color = COLOR_INACTIVE if self.active else COLOR_DESELECTED
if self.mode in ('polygon',): #create a connector line
if len(self.point) < 3: #cannot create a polygon with 2 points...
......@@ -340,7 +344,7 @@ class Annotation(object):
points = [k for c in zoom_points(self.zoom, self.point) \
for k in reversed(c)]
self.decoration.append(self.canvas.create_polygon(*points,
outline=COLOR_INACTIVE, fill=COLOR_INACTIVE, stipple="gray50",
outline=color, fill=color, stipple="gray50",
tags="mask", width=2.0, state=tkinter.HIDDEN))
else: #mode is line, create a connector between the points
......@@ -349,7 +353,7 @@ class Annotation(object):
points = zoom_point(self.zoom, (self.point[k][1], self.point[k][0],
self.point[k+1][1], self.point[k+1][0]))
self.decoration.append(self.canvas.create_line(*points,
fill=COLOR_INACTIVE, tags="mask", width=2.0, state=tkinter.HIDDEN))
fill=color, tags="mask", width=2.0, state=tkinter.HIDDEN))
def toggle_mode(self):
......@@ -629,9 +633,7 @@ class Tooltip(object):
# Leaves only the label and removes the app window
self.tw.wm_overrideredirect(True)
win = tkinter.Frame(self.tw,
background=bg,
borderwidth=0)
win = tkinter.Frame(self.tw, background=bg, borderwidth=0)
label = tkinter.Label(win,
text=self.text,
justify=tkinter.LEFT,
......@@ -899,12 +901,13 @@ class HelpDialog(Dialog):
self.grid_columnconfigure(0, weight=1)
# scrollbar for the help text
scrollbar = tkinter.Scrollbar(tbox)
scrollbar = tkinter.ttk.Scrollbar(tbox)
scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
tbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=tbox.yview)
tbox.config(state=tkinter.DISABLED)
# a single dismiss button
btn = tkinter.Button(self, text ="Dismiss", command=lambda: self.on_close())
btn = tkinter.ttk.Button(self, text ="Dismiss", command=lambda:
self.on_close())
btn.grid(row=1, column=0, sticky=tkinter.S)
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