コード例 #1
0
ファイル: gui_test.py プロジェクト: nikyq/SickZil-Machine
def test_open_project_is_flat_imgdir_then_no_state_change(clear_state):
    flat_imgdir = str(Path('fixture/prj_3file_I', config.IMGDIR))
    dir_type = main_window.open_project(
        QUrl('file://' + os.path.abspath(flat_imgdir)))

    assert state.project() == ((), ())
    assert dir_type == config.FLAT_IMGDIR
コード例 #2
0
ファイル: gui.py プロジェクト: khdong0714/JMTrans
    def rm_txt_all(self): 
        ''' 
        Remove text of all image.
        NOTE: If image has previously saved masks, then use it.
        '''
        if state.now_image() is None: return None

        self.saveMask.emit(state.now_mask()) # save current edited mask
        no_mask_path_pairs = fp.lremove(
            lambda pair: Path(pair.mask).exists(),
            state.img_mask_pairs()
        )
        new_masks = fp.map(
            lambda p: imgpath2mask(p.img),
            no_mask_path_pairs
        )
        for mask,pair in tqdm(zip(new_masks, no_mask_path_pairs),
                              total=len(no_mask_path_pairs),
                              desc='Generate Masks'):
            io.save(pair.mask, mask)

        img_paths,mask_paths = state.project()
        images= fp.map(lambda p: io.load(p, io.IMAGE), img_paths)
        masks = fp.map(lambda p: io.load(p, io.MASK), mask_paths)
        inpainteds = fp.map(core.inpainted, images,masks)

        for ipath,inpainted in tqdm(zip(img_paths, inpainteds),
                                    total=len(img_paths),
                                    desc='  Remove Texts'):
            io.save(ipath, inpainted) 
        self.update_gui()
コード例 #3
0
    def update(self, img_paths=None, mask_paths=None):
        if (img_paths is None and mask_paths is None):
            img_paths, mask_paths = state.project()

        self.beginRemoveRows(#-----------------------
            QModelIndex(), 0, len(self.images) - 1)
        self.endRemoveRows() #-----------------------

        self.beginInsertRows(#-----------------------
            QModelIndex(), 0, len(img_paths) - 1)
        def content(path):
            p = Path(path)
            return str(Path( p.parent.name, p.name ))
        self.images= fp.lmap(content, img_paths)  # SET STATE!
        self.masks = fp.lmap(content, mask_paths) # SET STATE!
        self.endInsertRows() #-----------------------
コード例 #4
0
def test_open_project_with_prj3file_then_open_folder(clear_state):
    open_project('./fixture/prj_3file_I')

    expected_imgs = tuple(fp.map(
        posix_abspath,
        (fpath('fixture/prj_3file_I',consts.IMGDIR,'1'), 
         fpath('fixture/prj_3file_I',consts.IMGDIR,'2.png'), 
         fpath('fixture/prj_3file_I',consts.IMGDIR,'3.jpg'))
    ))
    expected_masks = tuple(fp.map(
        posix_abspath,
        (fpath('fixture/prj_3file_I',consts.MASKDIR,'1.png'), 
         fpath('fixture/prj_3file_I',consts.MASKDIR,'2.png'), 
         fpath('fixture/prj_3file_I',consts.MASKDIR,'3.png'))
    ))

    assert state.project() == (expected_imgs,expected_masks)
コード例 #5
0
ファイル: gui_test.py プロジェクト: nikyq/SickZil-Machine
def test_open_project_with_prj3file_then_open_folder(clear_state):
    dir_type = main_window.open_project(
        QUrl('file://' + os.path.abspath('./fixture/prj_3file_I')))

    def fpath(*ps):
        return str(Path(*ps))

    expected_imgs = tuple(
        fp.map(os.path.abspath,
               (fpath('fixture/prj_3file_I', config.IMGDIR, '1'),
                fpath('fixture/prj_3file_I', config.IMGDIR, '2.png'),
                fpath('fixture/prj_3file_I', config.IMGDIR, '3.jpg'))))
    expected_masks = tuple(
        fp.map(os.path.abspath,
               (fpath('fixture/prj_3file_I', config.MASKDIR, '1.png'),
                fpath('fixture/prj_3file_I', config.MASKDIR, '2.png'),
                fpath('fixture/prj_3file_I', config.MASKDIR, '3.png'))))

    assert state.project() == (expected_imgs, expected_masks)
    assert dir_type == config.PRJDIR
コード例 #6
0
def test_clear_all():
    state.set_project('fixture/prj_3file_I/')
    state.clear_all()
    assert state.project() == ((), ())
    assert state.cursor() == 0
コード例 #7
0
def test_open_project_is_flat_imgdir_then_no_state_change(clear_state):
    open_project('fixture/prj_3file_I/' + consts.IMGDIR)
    assert state.project() == ((),())
コード例 #8
0
def test_open_project_not_prjdir_nor_imgdir_then_no_state_change(clear_state):
    open_project('./fixture')
    assert state.project() == ((),())
コード例 #9
0
ファイル: gui_test.py プロジェクト: nikyq/SickZil-Machine
def test_open_project_not_prjdir_nor_imgdir_then_no_state_change(clear_state):
    dir_type = main_window.open_project(
        QUrl('file://' + os.path.abspath('./fixture')))
    assert state.project() == ((), ())
    assert dir_type == config.UNSUPPORT_DIR