damonlynch / showinfilemanager

Platform independent Python module to open the system file manager and select files in it
MIT License
21 stars 1 forks source link

TypeError: None is not a valid ITEMIDLIST in this context #7

Closed etherealxx closed 11 months ago

etherealxx commented 1 year ago

Btw that file in "global_imagepath" exist so idk what's wrong in this. It works before.

PS C:\Users\Ethereal\Documents\GitHub\promptlocker-ecosystem> python -u "c:\Users\Ethereal\Documents\GitHub\promptlocker-ecosystem\promptlocker-eco.py"
debug global_imagepath: C:/Users/Ethereal/Downloads/testxxxx1.png
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Ethereal\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "c:\Users\Ethereal\Documents\GitHub\promptlocker-ecosystem\promptlocker-eco.py", line 291, in open_explorer
    show_in_file_manager(global_imagepath)
  File "C:\Users\Ethereal\AppData\Local\Programs\Python\Python310\lib\site-packages\showinfm\showinfm.py", line 348, in show_in_file_manager
    windows.launch_file_explorer(uris_and_paths, verbose)
  File "C:\Users\Ethereal\AppData\Local\Programs\Python\Python310\lib\site-packages\showinfm\system\windows.py", line 85, in launch_file_explorer
    shell_folder = desktop.BindToObject(
TypeError: None is not a valid ITEMIDLIST in this context

Just ask anything to me if you need more context.

damonlynch commented 1 year ago

I have never seen that problem, which means I have no way of replicating it on my system. Can you fix the problem yourself, and submit some code that contains the fix?

etherealxx commented 1 year ago

This is the shortest recreation of my code. i was able to replicate it. My device is windows (10 AND 11), python 3.10.6.

import tkinter as tk
from tkinter import filedialog
import os
from showinfm import show_in_file_manager

global_imagepath = ""

def open_file_dialog():
    global global_imagepath
    path = filedialog.askopenfilename(filetypes=[("Image Files", "*.png")])

    if path:
        if os.path.isfile(path):
            global_imagepath = path

def open_explorer():
    if not global_imagepath:
        open_file_dialog()
        print("current global_imagepath: " + global_imagepath)
        openthisimagebutton.config(text="View on Explorer")
    else:
        if os.path.exists(global_imagepath):
                show_in_file_manager(global_imagepath)

window = tk.Tk()
openthisimagebutton = tk.Button(window, text="Select a file", command=open_explorer)
openthisimagebutton.pack(padx=20, pady=20)
window.mainloop()
etherealxx commented 12 months ago

found something.

from the code i sent before, if i change show_in_file_manager(global_imagepath) to show_in_file_manager(global_imagepath.replace("/", os.sep)) or show_in_file_manager(os.path.normpath(global_imagepath)), the module works fine.

i think the problem lies in filedialog.askopenfilename() (from tkinter) that saves the path with slash instead of backlash in windows.

You can close this issue, or maybe implementing a feature on your module to fix this scenario, probably useful in the future.👀

damonlynch commented 11 months ago

Thanks for the update. I will close the issue.