[python-win32] Using win32com.shell to browse iphone photos | problem with pywebview

Bastian Schnitzler baschni at gmail.com
Wed May 11 02:58:30 EDT 2022


Hello,

I want to use win32com to transfer photos from my iphone to my
computer (I found a code snippet here, that worked for me:
https://gitlab.com/lassi.niemisto/iphone-photo-dump/).
In addition I would like to use pywebview to build a GUI.

Behaviour of the shell listing the resource "My computer" is
unexpected when I access the win32com functions through pywebview as
it is not showing my iphone then.

Here is a minimal working example (you may have to replace the String
== "Dieser PC" according to the language of your windows):

from win32com.shell import shell, shellcon
from webview import create_window, start, windows

class Api():
    def listFoldersDieserPC(self):

        folder = shell.SHGetDesktopFolder()
        for item in folder:
            print("loop: ", folder.GetDisplayNameOf(item,
shellcon.SHGDN_NORMAL))
            if folder.GetDisplayNameOf(item, shellcon.SHGDN_NORMAL) ==
"Dieser PC":
                new_folder = folder.BindToObject(item, None,
shell.IID_IShellFolder)
                break

        # list folders in Dieser PC/This Computer
        for item in new_folder:
            print("loop: ", new_folder.GetDisplayNameOf(item,
shellcon.SHGDN_NORMAL))


api = Api()
window = create_window('Test', 'index.html', js_api=api, min_size=(600, 450))
api.listFoldersDieserPC()
print("now from the browser")
start()

With index.html:
<button value="asdf"
onClick="window.pywebview.api.listFoldersDieserPC()">List
Folders</button>

The first time I call the function api.listFoldersDieserPC directly
from python, the second time through the button in the pywebview
browser window.

This is the output:

loop: Dieser PC
loop: Downloads
loop: Bilder
loop: Musik
loop: Desktop
loop: Dokumente
loop: Videos
loop: Apple iPhone
loop: Local Disk (C:)

now from the browser

loop: Dieser PC
loop: Downloads
loop: Bilder
loop: Musik
loop: Desktop
loop: Dokumente
loop: Videos
loop: Local Disk (C:)

Process finished with exit code 0

It is the same, except that the folder for Apple iPhone is missing on
the second go.

Why is the shell behaving differently here? Is this a bug in win32com
or is pywebview influencing it somehow? What can I do to make it work?

Kind regards


More information about the python-win32 mailing list