  
  from lib.cli import FullPaths
  from lib.Serializer import JSONSerializer
  
  class TKGui(object):
      ''' The Graphical User Interface '''
      def __init__(self, subparser, subparsers, parser, command, description='default'):
          self.root = tk.Tk()
          self.parser = parser
          self.opts = self.extract_options(subparsers)
 
</s> remove     def __init__(self, subparser, subparsers, parser, command, description='default'):
        self.root = tk.Tk()
 </s> add     def __init__(self, options, parser):
        self.gui = tk.Tk()
        self.opts = options </s> remove         self.opts = self.extract_options(subparsers)
        self.icofolder = tk.PhotoImage(file='icons/open_folder.png')
        self.icofile = tk.PhotoImage(file='icons/open_file.png')
        self.icosave = tk.PhotoImage(file='icons/save.png')
        self.icoreset = tk.PhotoImage(file='icons/reset.png')
        self.icoclear = tk.PhotoImage(file='icons/clear.png')
 </s> add         
        pathscript = path.realpath(path.dirname(sys.argv[0]))
        pathicons = path.join(pathscript, 'icons')
        self.icofolder = tk.PhotoImage(file=path.join(pathicons,'open_folder.png'))
        self.icoload = tk.PhotoImage(file=path.join(pathicons,'open_file.png'))
        self.icosave = tk.PhotoImage(file=path.join(pathicons,'save.png'))
        self.icoreset = tk.PhotoImage(file=path.join(pathicons,'reset.png'))
        self.icoclear = tk.PhotoImage(file=path.join(pathicons,'clear.png'))
 </s> remove from tkinter import ttk
from tkinter import filedialog
 </s> add from os import environ, path
from threading import Thread </s> remove from threading import Thread
import tkinter as tk
 </s> add  </s> remove        
        self.parse_arguments(description, subparser, command)

    def bad_args(self, args):
        self.parser.print_help()
        exit(0)

    def extract_options(self, subparsers):
        ''' Extract the existing ArgParse Options '''
        options = {command: subparsers[command].argument_list + subparsers[command].optional_arguments for command in subparsers.keys()}
        for command in options.values():
            for option in command:
                option['control_title'] = self.set_control_title(option.get('opts',''))
                option['control_type'] = self.set_control_type(option)
        return options

    @staticmethod
    def set_control_title(opts):
        ''' Take the option switch and format it nicely '''
        ctl_title = opts[0]
        if len(opts) == 2:
            ctl_title = opts[1]
        ctl_title = ctl_title.replace('-',' ').replace('_',' ')
        ctl_title = ctl_title.title().strip()
        return ctl_title
 
    @staticmethod
    def set_control_type(option):
        ''' Set what control type we should use for an option based on existence of various variables '''
        if option.get('dest', '') == 'alignments_path':
            ctl_type = 'filechooser'
        elif option.get('action', '') == FullPaths:
            ctl_type = 'folderchooser'
        elif option.get('choices', '') != '':
            ctl_type = 'combobox'
        elif option.get('type', '') in (str, float, int):
            ctl_type = 'entrybox'
        elif option.get('action', '') == 'store_true':
            ctl_type = 'checkbox'
        return ctl_type

    def parse_arguments(self, description, subparser, command):
        parser = subparser.add_parser(
            command,
            help="This Launches a GUI for Faceswap.",
            description=description,
            epilog="Questions and feedback: \
            https://github.com/deepfakes/faceswap-playground"
        )
        parser.set_defaults(func=self.process)
 </s> add         self.task = FaceswapControl()
# Users without tkinter distrubtion packages or without an X-Console will error out
# importing tkinter. Therefore run a check on these and only import if required 
tk = None
ttk = None
filedialog = None

def import_tkinter(command):
    ''' Perform checks when importing tkinter module to ensure that GUI will load '''
    global tk
    global ttk
    global filedialog
    try:
        import tkinter
        from tkinter import ttk
        from tkinter import filedialog
        tk = tkinter
    except ImportError:
        if 'gui' in command:
            print(  'It looks like TkInter isn''t installed for your OS, so the GUI has been '
                    'disabled. To enable the GUI please install the TkInter application.\n'
                    'You can try:\n'
                    '  Windows/macOS:      Install ActiveTcl Community Edition from '
                    'www.activestate.com\n'
                    '  Ubuntu/Mint/Debian: sudo apt install python3-tk\n'
                    '  Arch:               sudo pacman -S tk\n'
                    '  CentOS/Redhat:      sudo yum install tkinter\n'
                    '  Fedora:             sudo dnf install python3-tkinter\n')
        return False
    return True    

def check_display(command):
    # Check whether there is a display to output the GUI '''
    if not environ.get('DISPLAY', None):
        if 'gui' in command:
            print ('Could not detect a display. The GUI has been disabled')
        return False
    return True

class FaceswapGui(object):
  
  from lib.cli import FullPaths
  from lib.Serializer import JSONSerializer
  
# Users without tkinter distrubtion packages or without an X-Console will error out
# importing tkinter. Therefore run a check on these and only import if required 
tk = None
ttk = None
filedialog = None

def import_tkinter(command):
    ''' Perform checks when importing tkinter module to ensure that GUI will load '''
    global tk
    global ttk
    global filedialog
    try:
        import tkinter
        from tkinter import ttk
        from tkinter import filedialog
        tk = tkinter
    except ImportError:
        if 'gui' in command:
            print(  'It looks like TkInter isn''t installed for your OS, so the GUI has been '
                    'disabled. To enable the GUI please install the TkInter application.\n'
                    'You can try:\n'
                    '  Windows/macOS:      Install ActiveTcl Community Edition from '
                    'www.activestate.com\n'
                    '  Ubuntu/Mint/Debian: sudo apt install python3-tk\n'
                    '  Arch:               sudo pacman -S tk\n'
                    '  CentOS/Redhat:      sudo yum install tkinter\n'
                    '  Fedora:             sudo dnf install python3-tkinter\n')
        return False
    return True    

def check_display(command):
    # Check whether there is a display to output the GUI '''
    if not environ.get('DISPLAY', None):
        if 'gui' in command:
            print ('Could not detect a display. The GUI has been disabled')
        return False
    return True

class FaceswapGui(object):
      ''' The Graphical User Interface '''
      def __init__(self, subparser, subparsers, parser, command, description='default'):
          self.root = tk.Tk()
          self.parser = parser
          self.opts = self.extract_options(subparsers)
keep keep keep keep replace keep keep keep keep keep
 GUI v0.1.0a (#336)

* Code clean up

* Code refactor

* bugfix: Find paths to icons when launched from outside faceswap dir

* Bugfix: Disable GUI if TkInter app not available

* BugFix: Disable GUI if $DISPLAY not detected

* Minor code ammends

* Code Refactor

* DISPLAY check fix 
scripts/gui.py