Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: help users use rclip with image viewers on Windows #141

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions rclip/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import itertools
import os
import subprocess
import re
import sys
import threading
from typing import Iterable, List, NamedTuple, Optional, Tuple, TypedDict, cast

import numpy as np

from tqdm import tqdm
import PIL
from PIL import Image, ImageFile
Expand All @@ -27,9 +29,10 @@ class ImageMeta(TypedDict):
PathMetaVector = Tuple[str, ImageMeta, model.FeatureVector]


def get_image_meta(entry: os.DirEntry) -> ImageMeta:
stat = entry.stat()
return ImageMeta(modified_at=stat.st_mtime, size=stat.st_size)
def get_image_meta(entry: os.DirEntry[str]) -> ImageMeta:
stat = entry.stat()
return ImageMeta(modified_at=stat.st_mtime, size=stat.st_size)



def is_image_meta_equal(image: db.Image, meta: ImageMeta) -> bool:
Expand Down Expand Up @@ -216,7 +219,7 @@ def main():
args.exclude_dir,
args.no_indexing,
)

XNVIEW_PATH = "C:\\Program Files\\XnViewMP\\xnviewmp.exe"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What if I have xnview installed to a different path?
  2. What if I don't have xnview installed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why xnview? What about other image viewers.

try:
result = rclip.search(args.query, current_directory, args.top, args.add, args.subtract)
if args.filepath_only:
Expand All @@ -228,6 +231,13 @@ def main():
print(f'{r.score:.3f}\t"{r.filepath}"')
if args.preview:
preview(r.filepath, args.preview_height)
if os.path.exists(XNVIEW_PATH):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this always try to open the xnview?

  1. What if I am on Linux/macOS?
  2. What if I don't want to open xnview?

try:
subprocess.run([XNVIEW_PATH, r.filepath])
except Exception as e:
print(f"Failed to open XnView for {r.filepath}: {e}")
else:
print(f"XnView not found at {XNVIEW_PATH}")
except Exception as e:
raise e
finally:
Expand Down