Ejemplo n.º 1
0
 def restart(self):
     dialog = QtWidgets.QFileDialog(directory=self.starting_directory)
     path = dialog.getExistingDirectory()
     if not path:
         if self.verbose:
             print("No path given")
         self.quit()
         return
     self.starting_directory = path
     os.chdir(path)
     self.files_list = self.get_files(path)
     print(f"Found {len(self.files_list)} files")
     self.slide_number = -1
     self.sort(self.sort_kind)
     self.next_slide()  # show_slide resets the timer.
Ejemplo n.º 2
0
 def move_to(self):
     """Issue a prompt and move the file if the user agrees."""
     file_name = self.files_list[self.slide_number]
     path: str = QtWidgets.QFileDialog().getExistingDirectory()
     if path:
         new_path = os.path.join(path, os.path.basename(file_name))
         if os.path.exists(new_path):
             print("File exists:", new_path)
             pathlib.Path(file_name).unlink(new_path)  # type:ignore
         else:
             pathlib.Path(file_name).rename(new_path)
         del self.files_list[self.slide_number]
         self.slide_number = max(0, self.slide_number - 1)
         self.next_slide()
         self.raise_()
 def run(
         self,
         extensions=None,  # List of file extensions.
         hash_size=8,  # Size of compressed image.
         height=None,  # Window height (default 1500 pixels) when not in full screen mode.
         path=None,  # Root directory.
         starting_directory=None,  # Starting directory for file dialog if no path given.
 ):
     """
     Preprecess the files and show the first duplicates.
     Return True if any duplicates were found.
     """
     # Init ivars.
     self.extensions = extensions or ['.jpeg', '.jpg', '.png']
     self.hash_size = hash_size or 8
     self.starting_directory = starting_directory or os.getcwd()
     self.window_height = height or 900
     # Get the directory.
     if not path:
         dialog = QtWidgets.QFileDialog(directory=self.starting_directory)
         path = dialog.getExistingDirectory()
     if not path:
         print("No path given")
         return False
     # Get the files.
     filenames = self.get_files(path)
     if not filenames:
         print(f"No pictures found in {path!r}")
         return False
     print(f"{len(filenames)} file{g.plural(len(filenames))} in {path}")
     print(
         f"\nPreprocessing with hash size {self.hash_size}. This may take awhile..."
     )
     # Compute the hash dicts.
     self.compute_dicts(filenames)
     # Find the duplicates.
     self.duplicates = self.find_duplicates()
     g.es_print(f"{len(self.duplicates)} duplicate sets")
     ok = bool(self.duplicates)  # Do this before calling next_window.
     if self.duplicates:
         self.next_window()
     return ok
Ejemplo n.º 4
0
 def run(
     self,
     background_color=None,  # Default background color.
     delay=None,  # Delay between slides, in seconds. Default 100.
     extensions=None,  # List of file extensions.
     full_screen=False,  # True: start in full-screen mode.
     height=None,  # Window height (default 1500 pixels) when not in full screen mode.
     path=None,  # Root directory.
     scale=None,  # Initial scale factor. Default 1.0
     reset_zoom=True,  # True: reset zoom factor when changing slides.
     sort_kind=None,  # 'date', 'name', 'none', 'random', or 'size'.  Default is 'random'.
     starting_directory=None,  # Starting directory for file dialogs.
     verbose=False,  # True, print info messages.
     width=None,  # Window width (default 1500 pixels) when not in full screen mode.
 ):
     """
     Create the widgets and run the slideshow.
     Return True if any pictures were found.
     """
     # Keep a reference to this class!
     global gWidget
     gWidget = self
     # Init ivars.
     w = self
     self.background_color = background_color or "black"
     self.delay = delay or 100
     self.extensions = extensions or ['.jpeg', '.jpg', '.png']
     self.full_screen = False
     self.reset_zoom = reset_zoom
     self.scale = scale or 1.0
     self.sort_kind = sort_kind or 'random'
     self.starting_directory = starting_directory or os.getcwd()
     self.verbose = verbose
     # Careful: width and height are QWidget methods.
     self._height = height or 900
     self._width = width or 1500
     # Compute the files list.
     if not path:
         dialog = QtWidgets.QFileDialog(
             directory=self.starting_directory)
         path = dialog.getExistingDirectory()
     if not path:
         if self.verbose:
             print("No path given")
         return False
     self.files_list = self.get_files(path)
     if not self.files_list:
         print(f"No slides found in {path!r}")
         return False
     print(f"Found {len(self.files_list)} files")
     self.starting_directory = path
     os.chdir(path)
     n = len(self.files_list)
     if self.verbose:
         print(f"Found {n} picture{g.plural(n)} in {path}")
     # Init the widget.
     w.make_widgets()
     # Center the widget
     qtRectangle = w.frameGeometry()
     centerPoint = QtGui.QGuiApplication.primaryScreen(
     ).availableGeometry().center()
     qtRectangle.moveCenter(centerPoint)
     w.move(qtRectangle.topLeft())
     # Show the widget.
     w.showNormal()
     if full_screen:  # Not self.full_screen.
         w.toggle_full_screen()
     # Show the next slide.
     self.sort(sort_kind)
     self.next_slide()  # show_slide resets the timer.
     return True