deviantfero / wpgtk

:flower_playing_cards: a colorscheme, wallpaper and template manager for *nix
http://deviantfero.github.io/wpgtk/
GNU General Public License v2.0
2.06k stars 48 forks source link

List index out of range #293

Closed GnikDroy closed 9 months ago

GnikDroy commented 11 months ago

Uses of [0] without verifying if the list is not-empty results in a few unhelpful messages.

Use wpg -a on the following image: sha256 918c1520567f09b863df055310bae8dcaabc5032e22506f6d2afac087041b47e

14

Traceback (most recent call last):
  File "/usr/bin/wpg", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 305, in main
    process_args(args)
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 222, in process_args
    add_action(glob.glob(x)[0])
  File "/usr/lib/python3.11/site-packages/wpgtk/data/themer.py", line 24, in create_theme
    return color.get_color_list(filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 52, in get_color_list
    color_list = auto_adjust(color_list)
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 150, in auto_adjust
    colors = smart_sort(colors)
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 130, in smart_sort
    closest_cds = [sorted_by_color[x][0] for x in range(8)]
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 130, in <listcomp>
    closest_cds = [sorted_by_color[x][0] for x in range(8)]
                   ~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Similarly,

wpg -a <invalid_path>

Traceback (most recent call last):
  File "/usr/bin/wpg", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 305, in main
    process_args(args)
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 221, in process_args
    if path.isfile(glob.glob(x)[0]):
                   ~~~~~~~~~~~~^^^
IndexError: list index out of range
deviantfero commented 11 months ago

Good catch I'll fix these soon

On Tue, Dec 5, 2023, 12:41 AM Gnik @.***> wrote:

Uses of [0] without verifying if the list is not-empty results in a few unhelpful messages.

Use wpg -a on this image

14.jpg (view on web) https://github.com/deviantfero/wpgtk/assets/30725674/bf6ce07f-3406-4aea-af78-e6148071982b

Traceback (most recent call last): File "/usr/bin/wpg", line 8, in sys.exit(main()) ^^^^^^ File "/usr/lib/python3.11/site-packages/wpgtk/main.py", line 305, in main process_args(args) File "/usr/lib/python3.11/site-packages/wpgtk/main.py", line 222, in process_args add_action(glob.glob(x)[0]) File "/usr/lib/python3.11/site-packages/wpgtk/data/themer.py", line 24, in create_theme return color.get_color_list(filename) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 52, in get_color_list color_list = auto_adjust(color_list) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 150, in auto_adjust colors = smart_sort(colors) ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 130, in smart_sort closest_cds = [sorted_by_color[x][0] for x in range(8)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/wpgtk/data/color.py", line 130, in closest_cds = [sorted_by_color[x][0] for x in range(8)]



Similarly,

wpg -a <invalid_path>

Traceback (most recent call last):
  File "/usr/bin/wpg", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 305, in main
    process_args(args)
  File "/usr/lib/python3.11/site-packages/wpgtk/__main__.py", line 221, in process_args
    if path.isfile(glob.glob(x)[0]):
                   ~~~~~~~~~~~~^^^IndexError: list index out of range

—
Reply to this email directly, view it on GitHub
<https://github.com/deviantfero/wpgtk/issues/293>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVCGSMWYOJZZ3KMMQEHKD3YH26YRAVCNFSM6AAAAABAHE76T6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGAZDKMZZGI2TMNQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
deviantfero commented 10 months ago

hey I was able to fix the glob issue, but I wasn't able to reproduce the first issue, even with the image you provided, could you provide more details? or maybe a video?

GnikDroy commented 10 months ago

I am using wpgtk-git from AUR, but the same issue from the more stable wpgtk package.

What does sorted_by_color look like for you in Line 130 of wpgtk/data/color.py?

The following is the result after wpg -a on the image. Item number 3 is an empty list so cannot be indexed by [0].

sorted_by_color = [
    [
        ("#040404", 6.928203230275509),
        ("#1690AA", 223.87496510329152),
        ("#AB47BB", 263.15584736045673),
        ("#AB47BB", 263.15584736045673),
        ("#E08A1C", 264.5826902879325),
        ("#18B2D2", 276.33313228782396),
        ("#7fbaec", 326.22231683316824),
        ("#FEEB00", 346.0361252817399),
    ],
    [
        ("#E08A1C", 144.183910336764),
        ("#AB47BB", 216.9469981354893),
        ("#AB47BB", 216.9469981354893),
        ("#FEEB00", 235.00212764994276),
        ("#040404", 251.06373692749816),
        ("#1690AA", 322.37400639629743),
        ("#7fbaec", 326.6129207487052),
        ("#18B2D2", 359.3674999217375),
    ],
    [],
    [
        ("#FEEB00", 20.024984394500787),
        ("#E08A1C", 124.23365083583433),
        ("#AB47BB", 275.4650613054222),
        ("#AB47BB", 275.4650613054222),
        ("#7fbaec", 277.2020923441957),
        ("#1690AA", 309.04692200376303),
        ("#18B2D2", 321.54315417996384),
        ("#040404", 354.99014070816105),
    ],
    [
        ("#1690AA", 168.65645555388622),
        ("#18B2D2", 185.16209115258988),
        ("#AB47BB", 197.24603925047518),
        ("#AB47BB", 197.24603925047518),
        ("#7fbaec", 226.02212281102044),
        ("#040404", 251.06373692749816),
        ("#E08A1C", 347.48956818874433),
        ("#FEEB00", 429.84415780605883),
    ],
    [
        ("#AB47BB", 129.30970574554718),
        ("#AB47BB", 129.30970574554718),
        ("#7fbaec", 226.58552469211267),
        ("#E08A1C", 267.4584079815028),
        ("#1690AA", 286.79260799399975),
        ("#18B2D2", 295.0762613291689),
        ("#FEEB00", 346.7722595594982),
        ("#040404", 354.99014070816105),
    ],
    [
        ("#18B2D2", 92.35799911215054),
        ("#1690AA", 141.52738250953416),
        ("#7fbaec", 145.7772273024837),
        ("#AB47BB", 260.2325882744127),
        ("#AB47BB", 260.2325882744127),
        ("#E08A1C", 339.69692374232653),
        ("#040404", 354.99014070816105),
        ("#FEEB00", 360.47329998212075),
    ],
    [
        ("#7fbaec", 146.64924138910504),
        ("#AB47BB", 213.39165869358624),
        ("#AB47BB", 213.39165869358624),
        ("#18B2D2", 247.61865842460256),
        ("#FEEB00", 255.78506602223672),
        ("#E08A1C", 257.25279395956034),
        ("#1690AA", 271.72596489846165),
        ("#040404", 434.7447526997882),
    ],
]

If you need more info, let me know.

Feel free to close this if not reproducible.

deviantfero commented 10 months ago

I think I've got this nearly fixed, it was a problem with the color sorting algorithm I wrote :sweat:

deviantfero commented 9 months ago

fixed on v6.6.0 :)