          for command in ('extract', 'train', 'convert'):
              commandtab = CommandTab(self, notebook, command)
              commandtab.build_tab()
  
  # All pages stuff
      def menu(self):
          ''' Menu bar for loading and saving configs '''
          menubar = tk.Menu(self.gui)
          filemenu = tk.Menu(menubar, tearoff=0)
          filemenu.add_command(label='Load full config...', command=self.load_config)
          filemenu.add_command(label='Save full config...', command=self.save_config)
          filemenu.add_separator()
          filemenu.add_command(label='Reset all to default', command=self.reset_config)
          filemenu.add_command(label='Clear all', command=self.clear_config)
          filemenu.add_separator()
          filemenu.add_command(label='Quit', command=self.gui.quit)
          menubar.add_cascade(label="File", menu=filemenu)
          self.gui.config(menu=menubar)
  
      def load_config(self, command=None):
          ''' Load a saved config file '''
          cfgfile = filedialog.askopenfile(mode='r', filetypes=self.filetypes)
          if not cfgfile:
 
</s> remove         # Commands explicitly stated to ensure consistent ordering
        for command in ('extract', 'train', 'convert'):
            commandtab = CommandTab(self, notebook, command)
            commandtab.build_tab()
 </s> add         self.previewloc = os.path.join(PATHSCRIPT, '.gui_preview.png') </s> remove         ''' Load a saved config file '''
 </s> add         """ Load a saved config file """ </s> remove     def build_gui(self):
        ''' Build the GUI '''
        self.gui.title('faceswap.py')
        self.menu()
        notebook = ttk.Notebook(self.gui)
        notebook.pack(fill=tk.BOTH, expand=True)
 </s> add         self.task = FaceswapControl(self, calling_file=calling_file)
        self.runningtask = False </s> remove         ''' Save the current GUI state to a config file in json format '''
        cfgfile = filedialog.asksaveasfile( mode='w',
                                            filetypes=self.filetypes, 
                                            defaultextension='.fsw')
 </s> add         """ Save the current GUI state to a config file in json format """
        cfgfile = filedialog.asksaveasfile(mode='w',
                                           filetypes=self.filetypes,
                                           defaultextension='.fsw') </s> remove     def add_util_buttons(self, frame):
        ''' Add the section utility buttons '''
        utlframe = tk.Frame(frame)
        utlframe.pack(side=tk.TOP, pady=(5,0))
 </s> add     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)

        # 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

class FaceswapGui(object):
    """ The Graphical User Interface """

    def __init__(self, utils, calling_file='faceswap.py'):
        self.gui = tk.Tk()
        self.utils = utils
        self.calling_file = calling_file
        self.utils.delete_preview()
        self.utils.init_tk()
        self.gui.protocol('WM_DELETE_WINDOW', self.close_app)

    def build_gui(self):
        """ Build the GUI """
        self.gui.title(self.calling_file)
        self.menu()

        container = tk.PanedWindow(self.gui,
                                   sashrelief=tk.RAISED,
                                   orient=tk.VERTICAL)
        container.pack(fill=tk.BOTH, expand=True)

        topcontainer = tk.PanedWindow(container,
                                      sashrelief=tk.RAISED,
                                      orient=tk.HORIZONTAL)
        container.add(topcontainer)

        bottomcontainer = ttk.Frame(container, height=150)
        container.add(bottomcontainer)

        optsnotebook = ttk.Notebook(topcontainer, width=400, height=500)
        topcontainer.add(optsnotebook)

        if self.calling_file == 'faceswap.py':
            # Commands explicitly stated to ensure consistent ordering
            cmdlist = ('extract', 'train', 'convert')
        else:
            cmdlist = self.utils.opts.keys()

        for command in cmdlist:
            commandtab = CommandTab(self.utils, optsnotebook, command)
            commandtab.build_tab()

        dspnotebook = ttk.Notebook(topcontainer, width=780)
        topcontainer.add(dspnotebook)

        for display in ('graph', 'preview'):
            displaytab = DisplayTab(self.utils, dspnotebook, display)
            displaytab.build_tab()

        self.add_console(bottomcontainer)
        self.add_status_bar(bottomcontainer)

    def menu(self):
        """ Menu bar for loading and saving configs """
        menubar = tk.Menu(self.gui)
        filemenu = tk.Menu(menubar, tearoff=0)
        filemenu.add_command(label='Load full config...',
                             command=self.utils.load_config)
        filemenu.add_command(label='Save full config...',
                             command=self.utils.save_config)
        filemenu.add_separator()
        filemenu.add_command(label='Reset all to default',
                             command=self.utils.reset_config)
        filemenu.add_command(label='Clear all',
                             command=self.utils.clear_config)
        filemenu.add_separator()
        filemenu.add_command(label='Quit', command=self.close_app)
        menubar.add_cascade(label="File", menu=filemenu)
        self.gui.config(menu=menubar)

    def add_console(self, frame):
        """ Build the output console """
        consoleframe = ttk.Frame(frame)
        consoleframe.pack(side=tk.TOP, anchor=tk.W, padx=10, pady=(2, 0),
                          fill=tk.BOTH, expand=True)
        console = ConsoleOut(consoleframe, self.utils)
        console.build_console()

    def add_status_bar(self, frame):
        """ Build the info text section page """
        statusframe = ttk.Frame(frame)
        statusframe.pack(side=tk.BOTTOM, anchor=tk.W, padx=10, pady=2,
                         fill=tk.X, expand=False)

        lbltitle = ttk.Label(statusframe, text='Status:', width=6, anchor=tk.W)
        lbltitle.pack(side=tk.LEFT, expand=False)
        self.utils.guitext['status'].set('Ready')
        lblstatus = ttk.Label(statusframe,
                              width=20,
                              textvariable=self.utils.guitext['status'],
                              anchor=tk.W)
        lblstatus.pack(side=tk.LEFT, anchor=tk.W, fill=tk.X, expand=True)

    def close_app(self):
        """ Close Python. This is here because the graph animation function
        continues to
            run even when tkinter has gone away """
        confirm = messagebox.askokcancel
        confirmtxt = 'Processes are still running. Are you sure...?'
        if self.utils.runningtask and not confirm('Close', confirmtxt):
            return
        if self.utils.runningtask:
            self.utils.task.terminate()
        self.utils.delete_preview()
        self.gui.quit()
        exit()

class ConsoleOut(object):
    """ The Console out tab of the Display section """

    def __init__(self, frame, utils):
        self.frame = frame
        utils.console = tk.Text(self.frame)
        self.console = utils.console
        self.debug = utils.debugconsole

    def build_console(self):
        """ Build and place the console """
        self.console.config(width=100, height=6, bg='gray90', fg='black')
        self.console.pack(side=tk.LEFT, anchor=tk.N, fill=tk.BOTH, expand=True)

        scrollbar = ttk.Scrollbar(self.frame, command=self.console.yview)
        scrollbar.pack(side=tk.LEFT, fill='y')
        self.console.configure(yscrollcommand=scrollbar.set)

        if self.debug:
            print('Console debug activated. Outputting to main terminal')
        else:
            sys.stdout = SysOutRouter(console=self.console, out_type="stdout")
            sys.stderr = SysOutRouter(console=self.console, out_type="stderr")


class SysOutRouter(object):
    """ Route stdout/stderr to the console window """

    def __init__(self, console=None, out_type=None):
        self.console = console
        self.out_type = out_type
        self.color = ("black" if out_type == "stdout" else "red")

    def write(self, string):
        """ Capture stdout/stderr """
        self.console.insert(tk.END, string, self.out_type)
        self.console.tag_config(self.out_type, foreground=self.color)
        self.console.see(tk.END)

    @staticmethod
    def flush():
        """ If flush is forced, send it to normal terminal """
        sys.__stdout__.flush()
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
          for command in ('extract', 'train', 'convert'):
              commandtab = CommandTab(self, notebook, command)
              commandtab.build_tab()
  
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
        self.lossdict = dict()

    def init_tk(self):
        """ TK System must be on prior to setting tk variables,
        so initialised from GUI """
        pathicons = os.path.join(PATHSCRIPT, 'icons')
        self.icons['folder'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_folder.png'))
        self.icons['load'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'open_file.png'))
        self.icons['save'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'save.png'))
        self.icons['reset'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'reset.png'))
        self.icons['clear'] = tk.PhotoImage(
            file=os.path.join(pathicons, 'clear.png'))

        self.guitext['help'] = tk.StringVar()
        self.guitext['status'] = tk.StringVar()

    def action_command(self, command):
        """ The action to perform when the action button is pressed """
        if self.runningtask:
            self.action_terminate()
        else:
            self.action_execute(command)

    def action_execute(self, command):
        """ Execute the task in Faceswap.py """
        self.clear_console()
        self.task.prepare(self.opts, command)
        self.task.execute_script()

    def action_terminate(self):
        """ Terminate the subprocess Faceswap.py task """
        self.task.terminate()
        self.runningtask = False
        self.clear_display_panel()
        self.change_action_button()

    def clear_display_panel(self):
        ''' Clear the preview window and graph '''
        self.delete_preview()
        self.lossdict = dict()

    def change_action_button(self):
        """ Change the action button to relevant control """
        for cmd in self.actionbtns.keys():
            btnact = self.actionbtns[cmd]
            if self.runningtask:
                ttl = 'Terminate'
                hlp = 'Exit the running process'
            else:
                ttl = cmd.title()
                hlp = 'Run the {} script'.format(cmd.title())
            btnact.config(text=ttl)
            Tooltip(btnact, text=hlp, wraplength=200)

    def clear_console(self):
        """ Clear the console output screen """
        self.console.delete(1.0, tk.END)
  
      def load_config(self, command=None):
          ''' Load a saved config file '''
          cfgfile = filedialog.askopenfile(mode='r', filetypes=self.filetypes)
          if not cfgfile:
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 GUI v0.2.1b (#352)

* Code refactor

* Console Added

* Add graphing with matplotlib

* Add GUI preview support

* Improve import handling.

* Add GUI integration for tools.py (Launch tools.py with the gui command)

* Reformat to conform to PEP8.

* Add Tooltips, 

* Make panels user adjustable

* Fix convert.py Sharpen default value 
scripts/gui.py