Esempio n. 1
0
    def _add_buttons(self):
        """ Add the action buttons to the Display window.

        Returns
        -------
        dict:
            The action name and its associated button.
        """
        frame = ttk.Frame(self)
        frame.pack(side=tk.TOP, fill=tk.Y)
        buttons = dict()
        for action in self.key_bindings.values():
            if action == self._initial_action:
                btn_style = "actions_selected.TButton"
                state = (["pressed", "focus"])
            else:
                btn_style = "actions_deselected.TButton"
                state = (["!pressed", "!focus"])

            button = ttk.Button(frame,
                                image=get_images().icons[action.lower()],
                                command=lambda t=action: self.on_click(t),
                                style=btn_style)
            button.state(state)
            button.pack()
            Tooltip(button, text=self._helptext[action])
            buttons[action] = button
        return buttons
Esempio n. 2
0
    def _add_buttons(self):
        """ Add the display buttons to the Faces window.

        Returns
        -------
        dict
            The display name and its associated button.
        """
        frame = ttk.Frame(self)
        frame.pack(side=tk.TOP, fill=tk.Y)
        buttons = dict()
        for display in self.key_bindings.values():
            var = tk.BooleanVar()
            var.set(False)
            self._tk_vars[display] = var

            lookup = "landmarks" if display == "mesh" else display
            button = ttk.Button(frame,
                                image=get_images().icons[lookup],
                                command=lambda t=display: self.on_click(t),
                                style="display_deselected.TButton")
            button.state(["!pressed", "!focus"])
            button.pack()
            Tooltip(button, text=self._helptext[display])
            buttons[display] = button
        return buttons
Esempio n. 3
0
 def _add_transport(self):
     """ Add video transport controls """
     frame = ttk.Frame(self._transport_frame)
     frame.pack(side=tk.BOTTOM, fill=tk.X)
     icons = get_images().icons
     buttons = dict()
     for action in ("play", "beginning", "prev", "next", "end", "save",
                    "extract", "mode"):
         padx = (0, 6) if action in ("play", "prev", "mode") else (0, 0)
         side = tk.RIGHT if action in ("extract", "save",
                                       "mode") else tk.LEFT
         state = ["!disabled"] if action != "save" else ["disabled"]
         if action != "mode":
             icon = action if action != "extract" else "folder"
             wgt = ttk.Button(frame,
                              image=icons[icon],
                              command=self._btn_action[action])
             wgt.state(state)
         else:
             wgt = self._add_filter_mode_combo(frame)
         wgt.pack(side=side, padx=padx)
         Tooltip(wgt, text=self._helptext[action])
         buttons[action] = wgt
     logger.debug("Transport buttons: %s", buttons)
     return buttons
Esempio n. 4
0
 def _add_static_buttons(self):
     """ Add the buttons to copy alignments from previous and next frames """
     lookup = dict(copy_prev=("Previous", "C"), copy_next=("Next", "V"), reload=("", "R"))
     frame = ttk.Frame(self)
     frame.pack(side=tk.TOP, fill=tk.Y)
     sep = ttk.Frame(frame, height=2, relief=tk.RIDGE)
     sep.pack(fill=tk.X, pady=5, side=tk.TOP)
     buttons = dict()
     tk_frame_index = self._globals.tk_frame_index
     for action in ("copy_prev", "copy_next", "reload"):
         if action == "reload":
             icon = "reload3"
             cmd = lambda f=tk_frame_index: self._det_faces.revert_to_saved(f.get())  # noqa
             helptext = _("Revert to saved Alignments ({})").format(lookup[action][1])
         else:
             icon = action
             direction = action.replace("copy_", "")
             cmd = lambda f=tk_frame_index, d=direction: self._det_faces.update.copy(  # noqa
                 f.get(), d)
             helptext = _("Copy {} Alignments ({})").format(*lookup[action])
         state = ["!disabled"] if action == "copy_next" else ["disabled"]
         button = ttk.Button(frame,
                             image=get_images().icons[icon],
                             command=cmd,
                             style="actions_deselected.TButton")
         button.state(state)
         button.pack()
         Tooltip(button, text=helptext)
         buttons[action] = button
     self._globals.tk_frame_index.trace("w", self._disable_enable_copy_buttons)
     self._globals.tk_update.trace("w", self._disable_enable_reload_button)
     return buttons
Esempio n. 5
0
    def _add_filter_threshold_slider(self, frame):
        """ Add the optional filter threshold slider for misaligned filter to the filter frame.

        Parameters
        ----------
        frame: :class:`tkinter.ttk.Frame`
            The Filter Frame that holds the filter threshold slider
        """
        slider_frame = ttk.Frame(frame)
        tk_var = self._globals.tk_filter_distance

        min_max = (5, 20)
        ctl_frame = ttk.Frame(slider_frame)
        ctl_frame.pack(padx=2, side=tk.RIGHT)

        lbl = ttk.Label(ctl_frame, text="Distance:", anchor=tk.W)
        lbl.pack(side=tk.LEFT, anchor=tk.N, expand=True)

        tbox = ttk.Entry(ctl_frame, width=6, textvariable=tk_var, justify=tk.RIGHT)
        tbox.pack(padx=(0, 5), side=tk.RIGHT)

        ctl = ttk.Scale(
            ctl_frame,
            variable=tk_var,
            command=lambda val, var=tk_var, dt=int, rn=1, mm=min_max:
            set_slider_rounding(val, var, dt, rn, mm))
        ctl["from_"] = min_max[0]
        ctl["to"] = min_max[1]
        ctl.pack(padx=5, fill=tk.X, expand=True)
        for item in (tbox, ctl):
            Tooltip(item,
                    text=self._helptext["distance"],
                    wrap_length=200)
        tk_var.trace("w", self._navigation.nav_scale_callback)
        self._optional_widgets["distance_slider"] = slider_frame
Esempio n. 6
0
    def _add_filter_mode_combo(self, frame):
        """ Add the navigation mode combo box to the filter frame.

        Parameters
        ----------
        frame: :class:`tkinter.ttk.Frame`
            The Filter Frame that holds the filter combo box
        """
        self._globals.tk_filter_mode.set("All Frames")
        self._globals.tk_filter_mode.trace("w", self._navigation.nav_scale_callback)
        nav_frame = ttk.Frame(frame)
        lbl = ttk.Label(nav_frame, text="Filter:")
        lbl.pack(side=tk.LEFT, padx=(0, 5))
        combo = ttk.Combobox(
            nav_frame,
            textvariable=self._globals.tk_filter_mode,
            state="readonly",
            values=self._filter_modes)
        combo.pack(side=tk.RIGHT)
        Tooltip(nav_frame, text=self._helptext["mode"])
        nav_frame.pack(side=tk.RIGHT)
Esempio n. 7
0
    def add_optional_buttons(self, editors):
        """ Add the optional editor specific action buttons """
        for name, editor in editors.items():
            actions = editor.actions
            if not actions:
                self._optional_buttons[name] = None
                continue
            frame = ttk.Frame(self)
            sep = ttk.Frame(frame, height=2, relief=tk.RIDGE)
            sep.pack(fill=tk.X, pady=5, side=tk.TOP)
            seen_groups = set()
            for action in actions.values():
                group = action["group"]
                if group is not None and group not in seen_groups:
                    btn_style = "actions_selected.TButton"
                    state = (["pressed", "focus"])
                    action["tk_var"].set(True)
                    seen_groups.add(group)
                else:
                    btn_style = "actions_deselected.TButton"
                    state = (["!pressed", "!focus"])
                    action["tk_var"].set(False)
                button = ttk.Button(frame,
                                    image=get_images().icons[action["icon"]],
                                    style=btn_style)
                button.config(
                    command=lambda b=button: self._on_optional_click(b))
                button.state(state)
                button.pack()

                helptext = action["helptext"]
                hotkey = action["hotkey"]
                helptext += "" if hotkey is None else " ({})".format(
                    hotkey.upper())
                Tooltip(button, text=helptext)
                self._optional_buttons.setdefault(name, dict())[button] = dict(
                    hotkey=hotkey, group=group, tk_var=action["tk_var"])
            self._optional_buttons[name]["frame"] = frame
        self._display_optional_buttons()