      ''' 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)
          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')
          self.helptext = tk.StringVar()
          self.statustext = tk.StringVar()
          self.serializer = JSONSerializer
          self.filetypes=(('Faceswap files', '*.fsw'),  ('All files', '*.*'))
         
 
</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.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() </s> remove class TKGui(object):
 </s> add # 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): </s> remove         lbl_title = tk.Label(statusframe, text='Status', width=15, anchor=tk.SW)
        lbl_title.pack(side=tk.TOP)
        self.statustext.set('Idle')
        lbl_status = tk.Label(statusframe, height=1, width=15, textvariable=self.statustext,  wraplength=120, justify=tk.LEFT, anchor=tk.NW, bg="gray90")
        lbl_status.pack(side=tk.BOTTOM, anchor=tk.N)

    def execute_script(self, command):
 </s> add         lbltitle = tk.Label(statusframe, text='Status', width=15, anchor=tk.SW)
        lbltitle.pack(side=tk.TOP)
        self.gui.statustext.set('Idle')
        lblstatus = tk.Label(   statusframe,
                                height=1,
                                width=15,
                                textvariable=self.gui.statustext,
                                wraplength=120,
                                justify=tk.LEFT,
                                anchor=tk.NW,
                                bg="gray90")
        lblstatus.pack(side=tk.BOTTOM, anchor=tk.N)

class CommandTab(object):
    ''' Tabs to hold the command options '''
    def __init__(self, gui, notebook, command):
        self.gui = gui
        self.notebook = notebook
        self.page = ttk.Frame(self.notebook)
        self.command = command
        self.title = command.title()

    def build_tab(self):
        ''' Build the tab '''
        actionframe = ActionFrame(self.gui, self.page, self.command)
        actionframe.build_frame()
        self.add_frame_seperator()
        opt_frame = self.add_right_frame() </s> remove     @staticmethod
    def add_frame_seperator(page):
        ''' Add a seperator between left and right frames '''
        separator = tk.Frame(page, width=2, bd=1, relief=tk.SUNKEN)
        separator.pack(fill=tk.Y, padx=5, side=tk.LEFT)

# Left Frame stuff
    def add_left_frame(self, page, title):
        ''' Add help display and execute button to the left frame of each page '''
        frame = tk.Frame(page)
 </s> add     def bind_help(self, control, helptext):
        ''' Controls the help text displayed on mouse hover '''
        for action in ('<Enter>', '<FocusIn>', '<Leave>', '<FocusOut>'):
            helptext = helptext if action in ('<Enter>', '<FocusIn>') else ''
            control.bind(action, lambda event, txt=helptext: self.helptext.set(txt))

    def execute_task(self, command):
        ''' Execute the task in Faceswap.py '''
        self.task.execute_script(self.opts, command, self.parser, self.statustext)

class ActionFrame(object):
    '''Action Frame - Displays information and action controls '''
    def __init__(self, gui, page, command):
        self.gui = gui
        self.page = page
        self.command = command
        self.title = command.title()

    def build_frame(self):
        ''' Add help display and Action buttons to the left frame of each page '''
        frame = tk.Frame(self.page)
        
        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'))

      ''' The Graphical User Interface '''
      def __init__(self, subparser, subparsers, parser, command, description='default'):
          self.root = tk.Tk()
          self.parser = parser
        
        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'))

        
        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'))

        
        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'))

        
        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'))

        
        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'))

        
        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'))

          self.helptext = tk.StringVar()
          self.statustext = tk.StringVar()
          self.serializer = JSONSerializer
          self.filetypes=(('Faceswap files', '*.fsw'),  ('All files', '*.*'))
         
keep keep keep keep replace replace replace replace replace 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