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
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
def add_actions(self, parent): """ Add Actio Buttons """ logger.debug("Adding util buttons") frame = ttk.Frame(parent) frame.pack(padx=5, pady=(5, 10), side=tk.BOTTOM, fill=tk.X, anchor=tk.E) for utl in ("save", "clear", "reset"): logger.debug("Adding button: '%s'", utl) img = get_images().icons[utl] if utl == "save": text = "Save full config" action = self.config_tools.save_config elif utl == "clear": text = "Reset full config to default values" action = self.config_tools.reset_config_default elif utl == "reset": text = "Reset full config to saved values" action = self.config_tools.reset_config_saved btnutl = ttk.Button(frame, image=img, command=action) btnutl.pack(padx=2, side=tk.RIGHT) Tooltip(btnutl, text=text, wraplength=200) logger.debug("Added util buttons")
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
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
def initialize_tkinter(self): """ Initialize tkinter for standalone or GUI """ logger.debug("Initializing tkinter") pathscript = os.path.realpath(os.path.dirname(sys.argv[0])) pathcache = os.path.join(pathscript, "lib", "gui", ".cache") initialize_images(pathcache=pathcache) self.set_geometry() self.root.title("Faceswap.py - Convert Settings") self.root.tk.call("wm", "iconphoto", self.root._w, get_images().icons["favicon"]) # pylint:disable=protected-access logger.debug("Initialized tkinter")
def _set_initial_layout(self): """ Set the favicon and the bottom frame position to correct location to display full frame window. Notes ----- The favicon pops the tkinter GUI (without loaded elements) as soon as it is called, so this is set last. """ logger.debug("Setting initial layout") self.tk.call("wm", "iconphoto", self._w, get_images().icons["favicon"]) # pylint:disable=protected-access location = int(self.winfo_screenheight() // 1.5) self._containers["main"].sashpos(0, location) self.update_idletasks()
def _play(self, *args, frame_count=None): # pylint:disable=unused-argument """ Play the video file. """ start = time() is_playing = self._navigation.tk_is_playing.get() icon = "pause" if is_playing else "play" self._buttons["play"].config(image=get_images().icons[icon]) if not is_playing: logger.debug("Pause detected. Stopping.") return # Populate the filtered frames count on first frame frame_count = self._det_faces.filter.count if frame_count is None else frame_count self._navigation.increment_frame(frame_count=frame_count, is_playing=True) delay = 16 # Cap speed at approx 60fps max. Unlikely to hit, but just in case duration = int((time() - start) * 1000) delay = max(1, delay - duration) self.after(delay, lambda f=frame_count: self._play(f))
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()
def add_actions(self, parent, config_key): """ Add Actio Buttons """ logger.debug("Adding util buttons") title = config_key.split(".")[1].replace("_", " ").title() for utl in ("save", "clear", "reset"): logger.debug("Adding button: '%s'", utl) img = get_images().icons[utl] if utl == "save": text = "Save {} config".format(title) action = parent.config_tools.save_config elif utl == "clear": text = "Reset {} config to default values".format(title) action = parent.config_tools.reset_config_default elif utl == "reset": text = "Reset {} config to saved values".format(title) action = parent.config_tools.reset_config_saved btnutl = ttk.Button(self.action_frame, image=img, command=lambda cmd=action: cmd(config_key)) btnutl.pack(padx=2, side=tk.RIGHT) Tooltip(btnutl, text=text, wraplength=200) logger.debug("Added util buttons")