Esempio n. 1
0
    def get_init_path_list(self):
        """get path list when first launch (double click or from cmd)"""
        # if init_path is a folder, try to get the first image
        if os.path.isdir(self.init_path):
            self.init_path = sorted(
                list(
                    itertools.chain(
                        *(glob.glob(os.path.join(self.init_path, f'*{ext}'))
                          for ext in FORMATS))))[0]

        # fix the path pattern passed from windows system when double click
        self.init_path = self.init_path.replace('\\', '/')

        if self.init_path.endswith(FORMATS):
            folder = os.path.dirname(self.init_path)
            self.folder_list[0] = folder
            # get path list
            self.path_list[0] = get_img_list(folder, self._include_names,
                                             self._exclude_names)
            self.file_size_list[0] = [None] * len(self.path_list[0])
            # get current pidx
            try:
                self._pidx = self.path_list[0].index(self.init_path)
            except ValueError:
                # self.init_path may not in self.path_list after refreshing
                self._pidx = 0
            # save open file history
            self.save_open_history()
        else:
            show_msg('Critical', 'Critical',
                     f'Wrong init path! {self.init_path}')
Esempio n. 2
0
 def switch_preview_canvas(self):
     show_msg(
         'Information',
         '^_^',
         text=
         ('Has not implemented yet.\nContributions are welcome!\n尚未实现, 欢迎贡献!'
          ))
Esempio n. 3
0
 def get_color_type(self, path=None, fidx=None, pidx=None):
     path = self.get_path(path, fidx, pidx)[0]
     try:
         with Image.open(path) as lazy_img:
             color_type = lazy_img.mode
     except FileNotFoundError:
         show_msg('Critical', 'Critical', f'Cannot open {path}')
     return color_type
Esempio n. 4
0
 def get_shape(self, path=None, fidx=None, pidx=None):
     path = self.get_path(path, fidx, pidx)[0]
     try:
         with Image.open(path) as lazy_img:
             width, height = lazy_img.size
     except FileNotFoundError:
         show_msg('Critical', 'Critical', f'Cannot open {path}')
     return width, height
Esempio n. 5
0
 def update_path_list(self):
     is_same_len, img_len_list = self.db.update_path_list()
     show_str = 'Comparison:\n # for each folder:\n\t' + '\n\t'.join(
         map(str, img_len_list))
     self.comparison_label.setText(show_str)
     if is_same_len is False:
         msg = f'Comparison folders have differnet number of images.\n{show_str}'
         show_msg('Warning', 'Warning!', msg)
Esempio n. 6
0
 def add_cmp_folder(self, cmp_path):
     is_same_len, img_len_list = self.db.add_cmp_folder(cmp_path)
     show_str = 'Number for each folder:\n\t' + '\n\t'.join(
         map(str, img_len_list))
     self.comparison_label.setText(show_str)
     if is_same_len is False:
         msg = ('Comparison folders have differnet number of images.\n'
                f'{show_str}')
         show_msg('Warning', 'Warning!', msg)
Esempio n. 7
0
    def get_init_path_list(self):
        """get path list when first launch (double click or from cmd)"""
        # if init_path is a folder, try to get the first image
        if os.path.isdir(self.init_path):
            self.recursive_scan_folder = True
            self.path_list[0] = list(
                scandir(self.init_path,
                        suffix=FORMATS,
                        recursive=True,
                        full_path=True))
            self.init_path = self.path_list[0][0]
        else:
            self.recursive_scan_folder = False

        # fix the path pattern passed from windows system when double click
        self.init_path = self.init_path.replace('\\', '/')

        if self.init_path.endswith(FORMATS):
            folder = os.path.dirname(self.init_path)
            self.folder_list[0] = folder
            # get path list
            if self.recursive_scan_folder is False:
                self.path_list[0] = get_img_list(folder, self._include_names,
                                                 self._exclude_names,
                                                 self._exact_exclude_names)
            self.file_size_list[0] = [None] * len(self.path_list[0])
            self.md5_list[0] = [None] * len(self.path_list[0])
            self.phash_list[0] = [None] * len(self.path_list[0])
            # get current pidx
            try:
                self._pidx = self.path_list[0].index(self.init_path)
            except ValueError:
                # self.init_path may not in self.path_list after refreshing
                self._pidx = 0
            # save open file history
            self.save_open_history()
        else:
            show_msg('Critical', 'Critical',
                     f'Wrong init path! {self.init_path}')
Esempio n. 8
0
    def switch_compare_canvas(self):
        if self.canvas_type != 'compare':
            num_compare = self.hvdb.get_folder_len()
            if num_compare == 1:
                num_view, ok = QInputDialog.getText(
                    self, 'Compare Canvas',
                    '# Compare Columns: (options: 2, 3, 4)', QLineEdit.Normal,
                    '2')
                if ok:
                    try:
                        num_view = int(num_view)
                    except Exception:
                        show_msg(icon='Warning',
                                 title='Warning',
                                 text='# Compare Columns should be int.')
                    if num_view > 4 or num_view < 2:
                        show_msg(icon='Warning',
                                 title='Warning',
                                 text='# Compare Columns should be 2, 3, 4.')
                    self.hvdb.interval = num_view - 1
                else:  # when press the 'Cancellation' button
                    self.hvdb.interval = 1
                    num_view = 1
            else:  # for comparing mode
                if not self.hvdb.is_same_len:
                    show_msg('Critical', 'Warning',
                             ('Compare folders have different length, \n'
                              'It may introduce misalignment and errors.'))
                self.hvdb.fidx = 0
                num_view = min(self.hvdb.get_folder_len(), 4)
                show_msg(
                    'Information', 'Compare Canvas',
                    f'Comparsion folder mode.\n # Compare Columns: {num_view}.'
                )

            if num_view > 1:
                self.dock_info.close()
                self.center_canvas.canvas = Canvas(self,
                                                   self.hvdb,
                                                   num_view=num_view)
                self.setCentralWidget(self.center_canvas.canvas)
                self.canvas_type = 'compare'
Esempio n. 9
0
    def switch_compare_canvas(self):
        if self.canvas_type != 'compare':
            num_compare = self.hvdb.get_folder_len()
            if num_compare == 1:
                num_view, ok = QInputDialog.getText(
                    self, 'Compare Canvas',
                    '# Compare Columns: (options: 2, 3, 4)', QLineEdit.Normal,
                    '2')
                if ok:
                    try:
                        num_view = int(num_view)
                    except Exception:
                        show_msg(icon='Warning',
                                 title='Warning',
                                 text='# Compare Columns should be int.')
                    if num_view > 4 or num_view < 2:
                        show_msg(icon='Warning',
                                 title='Warning',
                                 text='# Compare Columns should be 2, 3, 4.')
                    self.hvdb.interval = num_view - 1
                else:  # default value
                    self.hvdb.interval = 1
                    num_view = 2
            else:
                if not self.hvdb.is_same_len:
                    show_msg('Critical', 'Error',
                             ('Compare folders have different length, \n'
                              'Cannot enter compare canvas.'))
                    return
                self.hvdb.fidx = 0
                num_view = min(self.hvdb.get_folder_len(), 4)
                show_msg(
                    'Information', 'Compare Canvas',
                    f'Comparsion folder mode.\n # Compare Columns: {num_view}.'
                )

            self.dock_info.close()
            self.canvas = Canvas(self, self.hvdb, num_view=num_view)
            self.setCentralWidget(self.canvas)
            self.canvas_type = 'compare'