mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-09 04:36:50 -04:00
* GUI version 3 (#411) GUI version 3.0a * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Add OriginalHighRes 128 update to gui branch (#421) * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Dev gui (#420) * reduce singletons * Fix tooltips and screen boundaries on popup * Remove dpi fix. Fix context filebrowsers * fix tools.py execution and context filebrowser bugs * Bugfixes (#422) * Bump matplotlib requirement. Fix polyfit. Fix TQDM on sort * Fixed memory usage at 6GB cards. (#423) - Switched default encoder to ORIGINAL - Fixed memory consumption. Tested with geforce gtx 9800 ti with 6Gb; batch_size 8 no OOM or memory warnings now. * Staging (#426) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Add DPI Scaling (#428) * Add dpi scaling * Hotfix for effmpeg. (#429) effmpeg fixed so it works both in cli and gui. Initial work done to add previewing feature to effmpeg (currently does nothing). Some small spacing changes in other files to improve PEP8 conformity. * PEP8 Linting (#430) * pep8 linting * Requirements version bump (#432) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Requirements version bump (#431) This bumps the versions of: scandir h5py Keras opencv-python to their latest vesions. Virtual Environment will need to be setup again to make use of these. * High DPI Fixes (#433) * dpi scaling * DPI Fixes * Fix and improve context manager. (#434) effmpeg tool: Context manager for GUI fixed. Context manager in general: Functionality extended to allow configuring the context with both: command -> action command -> variable (cli argument) -> action * Change epoch option to iterations * Change epochs to iterations
165 lines
5.1 KiB
Python
Executable file
165 lines
5.1 KiB
Python
Executable file
#!/usr/bin python3
|
|
""" Tooltip. Pops up help messages for the GUI """
|
|
import platform
|
|
import tkinter as tk
|
|
|
|
|
|
class Tooltip:
|
|
"""
|
|
Create a tooltip for a given widget as the mouse goes on it.
|
|
|
|
Adapted from StackOverflow:
|
|
|
|
http://stackoverflow.com/questions/3221956/
|
|
what-is-the-simplest-way-to-make-tooltips-
|
|
in-tkinter/36221216#36221216
|
|
|
|
http://www.daniweb.com/programming/software-development/
|
|
code/484591/a-tooltip-class-for-tkinter
|
|
|
|
- Originally written by vegaseat on 2014.09.09.
|
|
|
|
- Modified to include a delay time by Victor Zaccardo on 2016.03.25.
|
|
|
|
- Modified
|
|
- to correct extreme right and extreme bottom behavior,
|
|
- to stay inside the screen whenever the tooltip might go out on
|
|
the top but still the screen is higher than the tooltip,
|
|
- to use the more flexible mouse positioning,
|
|
- to add customizable background color, padding, waittime and
|
|
wraplength on creation
|
|
by Alberto Vassena on 2016.11.05.
|
|
|
|
Tested on Ubuntu 16.04/16.10, running Python 3.5.2
|
|
|
|
"""
|
|
|
|
def __init__(self, widget,
|
|
*,
|
|
background="#FFFFEA",
|
|
pad=(5, 3, 5, 3),
|
|
text="widget info",
|
|
waittime=400,
|
|
wraplength=250):
|
|
|
|
self.waittime = waittime # in miliseconds, originally 500
|
|
self.wraplength = wraplength # in pixels, originally 180
|
|
self.widget = widget
|
|
self.text = text
|
|
self.widget.bind("<Enter>", self.on_enter)
|
|
self.widget.bind("<Leave>", self.on_leave)
|
|
self.widget.bind("<ButtonPress>", self.on_leave)
|
|
self.background = background
|
|
self.pad = pad
|
|
self.ident = None
|
|
self.topwidget = None
|
|
|
|
def on_enter(self, event=None):
|
|
""" Schedule on an enter event """
|
|
self.schedule()
|
|
|
|
def on_leave(self, event=None):
|
|
""" Unschedule on a leave event """
|
|
self.unschedule()
|
|
self.hide()
|
|
|
|
def schedule(self):
|
|
""" Show the tooltip after wait period """
|
|
self.unschedule()
|
|
self.ident = self.widget.after(self.waittime, self.show)
|
|
|
|
def unschedule(self):
|
|
""" Hide the tooltip """
|
|
id_ = self.ident
|
|
self.ident = None
|
|
if id_:
|
|
self.widget.after_cancel(id_)
|
|
|
|
def show(self):
|
|
""" Show the tooltip """
|
|
def tip_pos_calculator(widget, label,
|
|
*,
|
|
tip_delta=(10, 5), pad=(5, 3, 5, 3)):
|
|
""" Calculate the tooltip position """
|
|
|
|
s_width, s_height = widget.winfo_screenwidth(), widget.winfo_screenheight()
|
|
|
|
width, height = (pad[0] + label.winfo_reqwidth() + pad[2],
|
|
pad[1] + label.winfo_reqheight() + pad[3])
|
|
|
|
mouse_x, mouse_y = widget.winfo_pointerxy()
|
|
|
|
x_1, y_1 = mouse_x + tip_delta[0], mouse_y + tip_delta[1]
|
|
x_2, y_2 = x_1 + width, y_1 + height
|
|
|
|
x_delta = x_2 - s_width
|
|
if x_delta < 0:
|
|
x_delta = 0
|
|
y_delta = y_2 - s_height
|
|
if y_delta < 0:
|
|
y_delta = 0
|
|
|
|
offscreen = (x_delta, y_delta) != (0, 0)
|
|
|
|
if offscreen:
|
|
|
|
if x_delta:
|
|
x_1 = mouse_x - tip_delta[0] - width
|
|
|
|
if y_delta:
|
|
y_1 = mouse_y - tip_delta[1] - height
|
|
|
|
offscreen_again = y_1 < 0 # out on the top
|
|
|
|
if offscreen_again:
|
|
# No further checks will be done.
|
|
|
|
# TIP:
|
|
# A further mod might automagically augment the
|
|
# wraplength when the tooltip is too high to be
|
|
# kept inside the screen.
|
|
y_1 = 0
|
|
|
|
return x_1, y_1
|
|
|
|
background = self.background
|
|
pad = self.pad
|
|
widget = self.widget
|
|
|
|
# creates a toplevel window
|
|
self.topwidget = tk.Toplevel(widget)
|
|
if platform.system() == "Darwin":
|
|
# For Mac OS
|
|
self.topwidget.tk.call("::tk::unsupported::MacWindowStyle",
|
|
"style", self.topwidget._w,
|
|
"help", "none")
|
|
|
|
# Leaves only the label and removes the app window
|
|
self.topwidget.wm_overrideredirect(True)
|
|
|
|
win = tk.Frame(self.topwidget,
|
|
background=background,
|
|
borderwidth=0)
|
|
label = tk.Label(win,
|
|
text=self.text,
|
|
justify=tk.LEFT,
|
|
background=background,
|
|
relief=tk.SOLID,
|
|
borderwidth=0,
|
|
wraplength=self.wraplength)
|
|
|
|
label.grid(padx=(pad[0], pad[2]),
|
|
pady=(pad[1], pad[3]),
|
|
sticky=tk.NSEW)
|
|
win.grid()
|
|
|
|
xpos, ypos = tip_pos_calculator(widget, label)
|
|
|
|
self.topwidget.wm_geometry("+%d+%d" % (xpos, ypos))
|
|
|
|
def hide(self):
|
|
""" Hide the tooltip """
|
|
topwidget = self.topwidget
|
|
if topwidget:
|
|
topwidget.destroy()
|
|
self.topwidget = None
|