Esempio n. 1
0
    def setUp(self):
        # TODO: we need prf_map, prf_imgs and prf_eth_map
        self.rtfparser = RTF_Parser()
        shutil.copyfile("newganmanager/.user/default_cfg.json",
                        "newganmanager/testing/.user/cfg.json")
        self.pm = Profile_Manager("No Profile", "newganmanager/testing")
        self.mapper = Mapper("newganmanager/test/", self.pm)
        self.pm.prf_cfg["img_dir"] = "newganmanager/test/"
        # data: UID, first_nat, sec_nat, eth-code
        self.data_simple = self.rtfparser.parse_rtf(
            "newganmanager/test/test_simple.rtf")
        self.data_all_cases = self.rtfparser.parse_rtf(
            "newganmanager/test/test_allcases.rtf")
        self.data_subset1 = self.rtfparser.parse_rtf(
            "newganmanager/test/allcases_subset1.rtf")
        self.data_subset2 = self.rtfparser.parse_rtf(
            "newganmanager/test/allcases_subset2.rtf")
        self.data_exclusive = self.rtfparser.parse_rtf(
            "newganmanager/test/test_exclusive.rtf")

        for eth in [
                "African", "Asian", "EECA", "Italmed", "SAMed",
                "South American", "SpanMed", "YugoGreek", "MENA", "MESA",
                "Caucasian", "Central European", "Scandinavian", "Seasian"
        ]:
            map = [eth + str(i) for i in range(20)]
            self.mapper.eth_map[eth] = set(map)
Esempio n. 2
0
 def setUp(self):
     self.pm = Profile_Manager("No Profile", "newganmanager/testing/")
     self.pm.prf_cfg["img_dir"] = "newganmanager/test/"
     self.data = [
         ["African", "African1", "1915714540"],
         ["Caucasian", "Caucasian2", "1915576430"]
     ]
     self.xml_data = self.pm.write_xml(self.data)
Esempio n. 3
0
 def setUp(self):
     shutil.copyfile("newganmanager/.user/default_cfg.json", "newganmanager/testing/.user/cfg.json")
     self.pm = Profile_Manager("No Profile", "newganmanager/testing")
     self.pm.prf_cfg["img_dir"] = "newganmanager/test/"
     self.data = [
         ["African", "African1", "1915714540"],
         ["Caucasian", "Caucasian2", "1915576430"]
     ]
     self.xml_data = self.pm.write_xml(self.data)
Esempio n. 4
0
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        self.logger.info(
            "Starting Application\n------------------------------------------------"
        )
        self.logger.info(str(self.paths.app))
        self.facepack_dirs = set([
            "African", "Asian", "Caucasian", "Central European", "EECA",
            "Italmed", "MENA", "MESA", "SAMed", "Scandinavian", "Seasian",
            "South American", "SpanMed", "YugoGreek"
        ])
        self.mode_info = {
            "Overwrite": "Overwrites already replaced faces",
            "Preserve": "Preserves already replaced faces",
            "Generate": "Generates mapping from scratch."
        }
        os.makedirs(str(self.paths.app) + "/.config", exist_ok=True)
        if not os.path.isfile(str(self.paths.app) + "/.user/cfg.json"):
            shutil.copyfile(
                str(self.paths.app) + "/.user/default_cfg.json",
                str(self.paths.app) + "/.user/cfg.json")

        self.logger.info("Loading current profile")
        self.profile_manager = Profile_Manager(
            Config_Manager().get_latest_prf(
                str(self.paths.app) + "/.user/cfg.json"), str(self.paths.app))
        self.profile_manager.migrate_config()
        self.logger.info("Creating GUI")
        self.main_box = toga.Box()
        self.logger.info("Created main box")

        self.hook = "https://discord.com/api/webhooks/796137178328989768/ETMNtPVb-PHuZPayC5G5MZD24tdDi5jmG6jAgjZXg0FDOXjy-VIabATXPco05qLIr4ro"

        # CREATE MENUBAR
        troubleshooting = toga.Command(
            lambda e=None, u=
            "https://github.com/Maradonna90/NewGAN-Manager/wiki/Troubleshooting":
            self.open_link(u),
            label='Troubleshooting',
            group=toga.Group.HELP,
            section=1)
        usage = toga.Command(
            lambda e=None, u="https://www.youtube.com/watch?v=iJqZNp0nomM":
            self.open_link(u),
            label='User Guide',
            group=toga.Group.HELP,
            section=0)

        faq = toga.Command(
            lambda e=None, u=
            "https://github.com/Maradonna90/NewGAN-Manager/wiki/FAQ": self.
            open_link(u),
            label='FAQ',
            group=toga.Group.HELP,
            section=2)

        discord = toga.Command(
            lambda e=None, u="https://discord.gg/UfRpJVc": self.open_link(u),
            label='Discord',
            group=toga.Group.HELP,
            section=3)

        self.commands.add(discord, faq, troubleshooting, usage)

        label_width = 125
        # TOP Profiles
        prf_box = toga.Box()
        self.logger.info("Created prf_box")

        prf_inp = toga.TextInput()
        self.logger.info("Created prf_inp")

        self.prfsel_box = toga.Box()
        prf_lab = toga.Label(text="Create Profile: ")
        prf_lab.style.update(width=label_width)

        prfsel_lab = toga.Label(text="Select Profile: ")
        prfsel_lab.style.update(width=label_width)
        self.prfsel_lst = SourceSelection(items=list(
            self.profile_manager.config["Profile"].keys()),
                                          on_select=self._set_profile_status)
        self.prfsel_lst.value = self.profile_manager.cur_prf
        prfsel_btn = toga.Button(
            label="Delete",
            on_press=lambda e=None, c=self.prfsel_lst: self._delete_profile(c))
        prf_btn = toga.Button(label="Create",
                              on_press=lambda e=None, d=prf_inp, c=self.
                              prfsel_lst: self._create_profile(d, c))

        self.main_box.add(prf_box)
        prf_box.add(prf_lab)
        prf_box.add(prf_inp)
        prf_box.add(prf_btn)
        prf_lab.style.update(padding_top=7)
        prf_inp.style.update(direction=ROW, padding=(0, 20), flex=1)

        self.main_box.add(self.prfsel_box)
        self.prfsel_box.add(prfsel_lab)
        self.prfsel_box.add(self.prfsel_lst)
        self.prfsel_box.add(prfsel_btn)
        self.prfsel_lst.style.update(direction=ROW, padding=(0, 20), flex=1)
        prfsel_lab.style.update(padding_top=7)

        # MID Path selections
        dir_box = toga.Box()
        dir_lab = toga.Label(text="Select Image Directory: ")
        dir_lab.style.update(width=label_width)
        self.dir_inp = toga.TextInput(
            readonly=True, initial=self.profile_manager.prf_cfg['img_dir'])
        self.dir_inp.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.dir_btn = toga.Button(label="...",
                                   on_press=self.action_select_folder_dialog,
                                   enabled=False)

        rtf_box = toga.Box()
        rtf_lab = toga.Label(text="RTF File: ")
        rtf_lab.style.update(width=label_width)
        self.rtf_inp = toga.TextInput(
            readonly=True, initial=self.profile_manager.prf_cfg['rtf'])
        self.rtf_inp.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.rtf_btn = toga.Button(label="...",
                                   on_press=self.action_open_file_dialog,
                                   enabled=False)

        self.main_box.add(dir_box)
        self.main_box.add(rtf_box)
        dir_box.add(dir_lab)
        dir_box.add(self.dir_inp)
        dir_box.add(self.dir_btn)
        rtf_box.add(rtf_lab)
        rtf_box.add(self.rtf_inp)
        rtf_box.add(self.rtf_btn)
        dir_lab.style.update(padding_top=7)
        rtf_lab.style.update(padding_top=7)

        gen_mode_box = toga.Box()
        self.genmde_lab = toga.Label(text="Mode: ")
        self.genmde_lab.style.update(width=label_width)
        self.genmdeinfo_lab = toga.Label(text=self.mode_info["Generate"])
        self.gendup = toga.Switch(label="Allow Duplicates?")
        self.genmde_lst = SourceSelection(items=list(self.mode_info.keys()),
                                          on_select=self.update_label)
        self.genmde_lst.value = "Generate"
        self.genmde_lst.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.genmde_lab.style.update(padding_top=7)
        self.genmdeinfo_lab.style.update(padding_top=7)
        self.gendup.style.update(padding_top=7, padding_left=20)

        gen_mode_box.add(self.genmde_lab)
        gen_mode_box.add(self.genmde_lst)
        gen_mode_box.add(self.genmdeinfo_lab)
        gen_mode_box.add(self.gendup)
        self.main_box.add(gen_mode_box)
        # BOTTOM Generation
        gen_box = toga.Box()
        self.gen_btn = toga.Button(label="Replace Faces",
                                   on_press=self._replace_faces,
                                   enabled=False)
        self.gen_btn.style.update(padding_bottom=20)
        self.gen_lab = toga.Label(text="")

        # self.gen_prg = toga.ProgressBar(max=110)
        self.gen_prg = Progressbar(label=self.gen_lab)
        gen_box.add(self.gen_btn)
        gen_box.add(self.gen_lab)
        gen_box.add(self.gen_prg)
        self.main_box.add(gen_box)
        self.gen_prg.style.update(width=570, alignment="center")
        self.gen_lab.style.update(padding_top=20,
                                  padding_bottom=20,
                                  width=100,
                                  alignment="center")

        # Report bad image
        rep_box = toga.Box()
        self.rep_lab = toga.Label(text="Player UID: ")
        self.rep_lab.style.update(width=label_width)
        self.rep_inp = toga.TextInput(on_change=self.change_image)
        self.rep_img = toga.ImageView(toga.Image("resources/logo.png"))
        self.rep_img.style.update(height=180)
        self.rep_img.style.update(width=180)
        self.rep_btn = toga.Button(label="Report",
                                   on_press=self.send_report,
                                   enabled=False)

        rep_box.add(self.rep_lab)
        rep_box.add(self.rep_inp)
        rep_box.add(self.rep_img)
        rep_box.add(self.rep_btn)
        self.main_box.add(rep_box)
        self.rep_lab.style.update(padding_top=10)
        self.rep_inp.style.update(direction=ROW, padding=(0, 20), flex=1)

        # END config
        self.prfsel_box.style.update(padding_bottom=20)
        dir_box.style.update(padding_bottom=20)
        prf_box.style.update(padding_bottom=20)
        rtf_box.style.update(padding_bottom=20)
        gen_mode_box.style.update(padding_bottom=20)
        rep_box.style.update(padding_top=20)
        gen_box.style.update(direction=COLUMN, alignment='center')
        self.main_box.style.update(direction=COLUMN,
                                   padding=30,
                                   alignment='center')

        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(1000, 600))
        self.main_window.content = self.main_box
        self.main_window.show()

        self.check_for_update()
Esempio n. 5
0
 def setUp(self):
     self.pm = Profile_Manager("No Profile", "newganmanager/testing/")
Esempio n. 6
0
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        self.logger.info(
            "Starting Application\n------------------------------------------------"
        )
        self.logger.info(str(self.paths.app))

        self.mode_info = {
            "Overwrite": "Overwrites already replaced faces",
            "Preserve": "Preserves already replaced faces",
            "Generate": "Generates mapping from scratch."
        }
        os.makedirs(str(self.paths.app) + "/.config", exist_ok=True)

        self.logger.info("Loading current profile")
        self.profile_manager = Profile_Manager(
            Config_Manager().get_latest_prf(
                str(self.paths.app) + "/.user/cfg.json"), str(self.paths.app))
        self.profile_manager.migrate_config()
        self.logger.info("Creating GUI")
        self.main_box = toga.Box()
        self.logger.info("Created main box")

        label_width = 125
        # TOP Profiles
        prf_box = toga.Box()
        self.logger.info("Created prf_box")

        prf_inp = toga.TextInput()
        self.logger.info("Created prf_inp")

        self.prfsel_box = toga.Box()
        prf_lab = toga.Label(text="Create Profile: ")
        prf_lab.style.update(width=label_width)

        prfsel_lab = toga.Label(text="Select Profile: ")
        prfsel_lab.style.update(width=label_width)
        self.prfsel_lst = SourceSelection(items=list(
            self.profile_manager.config["Profile"].keys()),
                                          on_select=self._set_profile_status)
        self.prfsel_lst.value = self.profile_manager.cur_prf
        prfsel_btn = toga.Button(
            label="Delete",
            on_press=lambda e=None, c=self.prfsel_lst: self._delete_profile(c))
        prf_btn = toga.Button(label="Create",
                              on_press=lambda e=None, d=prf_inp, c=self.
                              prfsel_lst: self._create_profile(d, c))

        self.main_box.add(prf_box)
        prf_box.add(prf_lab)
        prf_box.add(prf_inp)
        prf_box.add(prf_btn)
        prf_lab.style.update(padding_top=7)
        prf_inp.style.update(direction=ROW, padding=(0, 20), flex=1)

        self.main_box.add(self.prfsel_box)
        self.prfsel_box.add(prfsel_lab)
        self.prfsel_box.add(self.prfsel_lst)
        self.prfsel_box.add(prfsel_btn)
        self.prfsel_lst.style.update(direction=ROW, padding=(0, 20), flex=1)
        prfsel_lab.style.update(padding_top=7)

        # MID Path selections
        dir_box = toga.Box()
        dir_lab = toga.Label(text="Select Image Directory: ")
        dir_lab.style.update(width=label_width)
        self.dir_inp = toga.TextInput(
            readonly=True, initial=self.profile_manager.prf_cfg['img_dir'])
        self.dir_inp.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.dir_btn = toga.Button(label="...",
                                   on_press=self.action_select_folder_dialog,
                                   enabled=False)

        rtf_box = toga.Box()
        rtf_lab = toga.Label(text="RTF File: ")
        rtf_lab.style.update(width=label_width)
        self.rtf_inp = toga.TextInput(
            readonly=True, initial=self.profile_manager.prf_cfg['rtf'])
        self.rtf_inp.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.rtf_btn = toga.Button(label="...",
                                   on_press=self.action_open_file_dialog,
                                   enabled=False)

        self.main_box.add(dir_box)
        self.main_box.add(rtf_box)
        dir_box.add(dir_lab)
        dir_box.add(self.dir_inp)
        dir_box.add(self.dir_btn)
        rtf_box.add(rtf_lab)
        rtf_box.add(self.rtf_inp)
        rtf_box.add(self.rtf_btn)
        dir_lab.style.update(padding_top=7)
        rtf_lab.style.update(padding_top=7)

        gen_mode_box = toga.Box()
        self.genmde_lab = toga.Label(text="Mode: ")
        self.genmde_lab.style.update(width=label_width)
        self.genmdeinfo_lab = toga.Label(text=self.mode_info["Generate"])
        self.genmde_lst = SourceSelection(items=list(self.mode_info.keys()),
                                          on_select=self.update_label)
        self.genmde_lst.value = "Generate"
        self.genmde_lst.style.update(direction=ROW, padding=(0, 20), flex=1)
        self.genmde_lab.style.update(padding_top=7)
        self.genmdeinfo_lab.style.update(padding_top=7)

        gen_mode_box.add(self.genmde_lab)
        gen_mode_box.add(self.genmde_lst)
        gen_mode_box.add(self.genmdeinfo_lab)
        self.main_box.add(gen_mode_box)
        # BOTTOM Generation
        gen_box = toga.Box()
        self.gen_btn = toga.Button(label="Replace Faces",
                                   on_press=self._replace_faces,
                                   enabled=False)
        self.gen_btn.style.update(padding_bottom=20)
        self.gen_lab = toga.Label(text="")

        # self.gen_prg = toga.ProgressBar(max=110)
        self.gen_prg = Progressbar(label=self.gen_lab)
        gen_box.add(self.gen_btn)
        gen_box.add(self.gen_lab)
        gen_box.add(self.gen_prg)
        self.main_box.add(gen_box)
        self.gen_prg.style.update(width=570, alignment="center")
        self.gen_lab.style.update(padding_top=20,
                                  padding_bottom=20,
                                  width=100,
                                  alignment="center")

        # Report bad image
        rep_box = toga.Box()
        self.rep_lab = toga.Label(text="Player UID: ")
        self.rep_lab.style.update(width=label_width)
        self.rep_inp = toga.TextInput(on_change=self.change_image)
        self.rep_img = toga.ImageView(toga.Image("resources/logo.png"))
        self.rep_img.style.update(height=180)
        self.rep_img.style.update(width=180)
        self.rep_btn = toga.Button(label="Report",
                                   on_press=self.send_report,
                                   enabled=False)

        rep_box.add(self.rep_lab)
        rep_box.add(self.rep_inp)
        rep_box.add(self.rep_img)
        rep_box.add(self.rep_btn)
        self.main_box.add(rep_box)
        self.rep_lab.style.update(padding_top=10)
        self.rep_inp.style.update(direction=ROW, padding=(0, 20), flex=1)

        # END config
        self.prfsel_box.style.update(padding_bottom=20)
        dir_box.style.update(padding_bottom=20)
        prf_box.style.update(padding_bottom=20)
        rtf_box.style.update(padding_bottom=20)
        gen_mode_box.style.update(padding_bottom=20)
        rep_box.style.update(padding_top=20)
        gen_box.style.update(direction=COLUMN, alignment='center')
        self.main_box.style.update(direction=COLUMN,
                                   padding=30,
                                   alignment='center')

        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(1000, 600))
        self.main_window.content = self.main_box
        self.main_window.show()
Esempio n. 7
0
 def setUp(self):
     shutil.copyfile("newganmanager/.user/default_cfg.json", "newganmanager/testing/.user/cfg.json")
     self.pm = Profile_Manager("No Profile", "newganmanager/testing")