<commit_before>import sys

import maptools

try:
    import easygui

    easygui_enabled = True
except ImportError:
    easygui_enabled = False

try:
    import argparse

    argparse_enabled = True
except ImportError:
    argparse_enabled = False


def main():
    if argparse_enabled:
        commandln()
    elif easygui_enabled:
        print "argparse not found, using GUI instead"
        gui()
    else:
        print "Neither argparse nor easygui was found, cannot continue. Please install one of the two."
        sys.exit()


def commandln():
    parser = argparse.ArgumentParser(description='Escapists Map Tools')
    parsegroup = parser.add_mutually_exclusive_group()
    parsegroup.add_argument("-dc", "--decompile", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Decompiles a map with a given encryption key")
    parsegroup.add_argument("-d", "--decrypt", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Decrypts a map with a given encryption key")
    parsegroup.add_argument("-e", "--encrypt", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Encrypts a map with a given encryption key")
    args = parser.parse_args()

    if args.decompile != None:
        maptools.decompilemap(args.decompile[0], args.decompile[1])
    elif args.decrypt != None:
        maptools.decryptmap(args.decrypt[0], args.decrypt[1])
    elif args.encrypt != None:
        maptools.encryptmap(args.encrypt[0], args.encrypt[1])
    elif easygui_enabled == False:
        print "Module easygui not installed. Only the command-line interface is available."
        parser.print_usage()
    else:
        print "No command line arguments, using GUI."
        gui()


def gui():
    option = easygui.buttonbox("Select an option.", "Escapists Map Tools",
                               ["Decompile a map", "Decrypt a map", "Encrypt a map"])
    if option == "Decompile a map":
        key = easygui.enterbox("Enter encryption key (Default: mothking)", option, "mothking")
        maptools.decompilemap(easygui.fileopenbox(), key)
    elif option == "Decrypt a map":
        key = easygui.enterbox("Enter encryption key (Default: mothking)", option, "mothking")
        maptools.decryptmap(easygui.fileopenbox(), key)
    elif option == "Encrypt a map":
        key = easygui.enterbox("Enter encryption key (Default: mothking)", option, "mothking")
        maptools.encryptmap(easygui.fileopenbox(), key)

<commit_msg>Remove the easygui dependency. Although it's a bit ugly it's better than having useless depends.<commit_after>import sys
import Tkinter
import tkFileDialog

import maptools

try:
    import argparse
    argparse_enabled = True
except ImportError:
    argparse_enabled = False


def main():
    if argparse_enabled:
        commandln()
    else:
        print "argparse not found, using GUI instead"
        gui()


def commandln():
    parser = argparse.ArgumentParser(description='Escapists Map Tools')
    parsegroup = parser.add_mutually_exclusive_group()
    parsegroup.add_argument("-dc", "--decompile", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Decompiles a map with a given encryption key")
    parsegroup.add_argument("-d", "--decrypt", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Decrypts a map with a given encryption key")
    parsegroup.add_argument("-e", "--encrypt", type=str, nargs=2, metavar=('map_file.map', 'encryption_key'),
                            help="Encrypts a map with a given encryption key")
    args = parser.parse_args()

    if args.decompile != None:
        maptools.decompilemap(args.decompile[0], args.decompile[1])
    elif args.decrypt != None:
        maptools.decryptmap(args.decrypt[0], args.decrypt[1])
    elif args.encrypt != None:
        maptools.encryptmap(args.encrypt[0], args.encrypt[1])
    else:
        print "No command line arguments, using GUI."
        gui()


class maptoolsgui:
    def __init__(self, winname):
        self.winname = winname
        winname.title("Escapists Map Tools")

        self.label = Tkinter.Label(winname, text="Select an action")
        self.label.pack(side="top")

        self.decompmap = Tkinter.Button(winname, text="Decompile a map", command=lambda: self.enterkey(1))
        self.decompmap.pack(side="left")

        self.dcryptmap = Tkinter.Button(winname, text="Decrypt a map", command=lambda: self.enterkey(2))
        self.dcryptmap.pack(side="left")

        self.ecryptmap = Tkinter.Button(winname, text="Encrypt a map", command=lambda: self.enterkey(3))
        self.ecryptmap.pack(side="left")

    def enterkey(self, somevariable):

        if somevariable == 1:
            self.action = 1
        elif somevariable == 2:
            self.action = 2
        elif somevariable == 3:
            self.action = 3

        self.keylevel = Tkinter.Toplevel()
        self.keylevel.title("Enter encryption key")
        self.keylevel.protocol("WM_DELETE_WINDOW", self.winname.destroy)
        self.keylevel.focus_set()
        self.winname.withdraw()

        self.label = Tkinter.Label(self.keylevel, text="Enter an encryption key (Default: mothking)")
        self.label.pack()

        self.entry = Tkinter.Entry(self.keylevel)
        self.entry.pack()
        self.entry.insert(0, "mothking")

        self.okay = Tkinter.Button(self.keylevel, text="OK", command=self.dotheactionyo)
        self.okay.pack(side="left")

        self.cancel = Tkinter.Button(self.keylevel, text="Cancel", command=sys.exit)
        self.cancel.pack(side="right")

    def dotheactionyo(self):
        self.encryptkey = self.entry.get()
        self.keylevel.destroy()
        print self.action
        print self.encryptkey
        self.filepath = tkFileDialog.askopenfilename(defaultextension=".map",
                                                     filetypes=[('Escapists map file', '*.map'),
                                                                ('Escapists project file', '*.proj'),
                                                                ('All files', '*.*')],
                                                     initialdir="C:\Program Files (x86)\Steam\SteamApps\common\The Escapists\Data\Maps")
        if not self.filepath:
            sys.exit()
        elif self.action == 1:
            maptools.decompilemap(self.filepath, self.encryptkey)
        elif self.action == 2:
            maptools.decryptmap(self.filepath, self.encryptkey)
        elif self.action == 3:
            maptools.encryptmap(self.filepath, self.encryptkey)


def gui():
    window = Tkinter.Tk()
    maptoolsgui(window)
    window.mainloop()


{'fraction_non_alphanumeric': 0.11872885096366044, 'fraction_numerical': 0.004855083124908048, 'mean_word_length': 2.525933609958506, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3028010', 'n_tokens_mistral': 2053, 'n_tokens_neox': 2015, 'n_words': 471}