Kalmat / PyWinCtl

Cross-Platform module to get info on and control windows on screen
Other
179 stars 19 forks source link

missing value not evaluated correctly #70

Closed yjmd2222 closed 1 year ago

yjmd2222 commented 1 year ago

Hi. I'm trying to use pywinctl on macOS Ventura, but I encountered a problem which I believe is due to "missing value" not being evaluated correctly. I think the issue occurs when a window does not have a valid title which would be translated to "missing value," but this very "missing value" is not interpreted as a valid single object, hence the SyntaxError: forgot a comma.

import pywinctl

print(pywinctl.getAllTitles())
Traceback (most recent call last):
  File "/Users/hacpro/Documents/GitHub/fake-attendance/test.py", line 3, in <module>
    print(pywinctl.getAllTitles())
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hacpro/anaconda3/envs/testingpywinctl/lib/python3.11/site-packages/pywinctl/_pywinctl_macos.py", line 200, in getAllTitles
    res = ast.literal_eval(ret)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hacpro/anaconda3/envs/testingpywinctl/lib/python3.11/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hacpro/anaconda3/envs/testingpywinctl/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    [[["비밀번호를 저장하시겠습니까?", "New Issue · Kalmat/PyWinCtl - Chrome"], ["test.py — fake-attendance"], ["src", "다운로드"], [missing value, "Zoom 회의", "Zoom"]]]
                                                                                                                    ^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Kalmat commented 1 year ago

Hi! Sorry for the late reply. I was out and with limited access to my mail.

To be honest, I didn't expect a "missing value" in the window title (empty is ok, but... missing?). Anyway you are totally right, it shouldn't crash. Thank you so much for pointing out this issue! I will upload a new version solving this as soon as I can (by next week, I hope). Just curious, which app/window is the one returning "missing value" as title?

yjmd2222 commented 1 year ago

Hi, there. It's great to hear that you are fixing this issue. I got the job done using AppleScript, but I might come back to pywinctl because I'm still confused with AppleScript. Most of zoom.us/Zoom Meetings app's window titles/names return "missing value" like "Zoom Meeting" shadow window (Something empty gets created when I start or join a new meeting), "Agree to recording", and "Update needed." They have their respective proper title in Windows. Anyways, "missing value" seemed to be a very common placeholder in AppleScript when I Googled it; it may go in the title or other props. I don't know anything else though.

Kalmat commented 1 year ago

Hi! I have prepared a new version that hopefully solves this issue. If you want to give it a try, you can find it here. Anyway, I will upload it to PyPi in a few days, as soon as I finish all required, intensive tests.

Thank you again!