LtqxWYEG / ShitStuckToYourMouse

Draws mouse-cursor-following particles, text, cursor coordinates, color of pixel under cursor, pictures or a clock - for when you really need to keep an eye on the time. Uses PyGame for low resource usage. Works by creating a transparent full-screen window that is click-through, on top of the z-order.
18 stars 1 forks source link

Trouble with image... #1

Closed PySimpleGUI closed 4 weeks ago

PySimpleGUI commented 3 years ago

I gavew it a go and ran into 2 problems.

The first was the import of CREATE_NO_WINDOW which isn't in the 3.6 version I tried on first.

from subprocess import Popen, PIPE, CREATE_NO_WINDOW

So, I went with 3.9 and got further. I tried a number of things to try to get the settings right to find the py.png file that's in the images folder, but I couldn't figure it out.
image

I'm sure I'm missing something stupid that I failed to do but wasn't able to figure it out.... a little help?

File "E:\DownloadsE\ShitStuckToYourMouse-main\ShitStuckToYourMouse-main\main.pyw", line 549, in <module>
  main(config)
File "E:\DownloadsE\ShitStuckToYourMouse-main\ShitStuckToYourMouse-main\main.pyw", line 316, in main
  window = make_window('Dark')
File "E:\DownloadsE\ShitStuckToYourMouse-main\ShitStuckToYourMouse-main\main.pyw", line 295, in make_window
  [sg.Image(data = get_img_data(imagePath, first = True), k = 'image')]]
File "E:\DownloadsE\ShitStuckToYourMouse-main\ShitStuckToYourMouse-main\main.pyw", line 171, in get_img_data
  img = Image.open(f)
File "x:\Python\python3.9\Lib\site-packages\PIL\Image.py", line 2904, in open
  fp = builtins.open(filename, "rb")

builtins.FileNotFoundError: [Errno 2] No such file or directory: 'py.png'
LtqxWYEG commented 3 years ago

Hi, thank you for trying my first project :)

The first was the import of CREATE_NO_WINDOW which isn't in the 3.6 version I tried on first.

Is that also not available if I'd change it to "import subprocess"? I don't yet know how to respect other Python versions peculiarities. Could one upgrade the subprocess packet to the current version in py 3.6?

I tried a number of things to try to get the settings right to find the py.png file that's in the images folder, but I couldn't figure it out.

The image in the images folder is not used, but instead the py.png in the root folder. (Which I forgot to include in the source folder.. xD) I think I'll delete the images folder here on github. It does not add anything but confusion. However it should work perfectly fine if you choose a file via the browse button.

On that regard: I changed how the input line works. You can now enter a path and click save/run without crashing the program. It also checks if the file exists now - I totally forgot that. :)

And you can now run the main.pyw without changing it first. I did not update the release yet

PySimpleGUI commented 3 years ago

For small images.... for me that means all images... can be turned into base64 and included in the source code itself which removes the possibility of this problem happening. May be a technique you can utilize :-)

Your first Issue? Really? Ever? That's SO cool!

py_image = b'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAZM0lEQVRYCQEoGdfmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqv8JgNX/Ev///wz/AAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+/gAzM//8Pqqr/CQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+qBgABVvoAAAAAAAAAAAAAAAAAAAAAH6P/GR0KAAkS9gAC9AIA+75bAOoAAAH3AAAAAAAAAAAAAAAAAP+ABgABgPoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAIAAQD+AAr/GYm+AHgtEwBICgYAJRYVAAEQCQAABwAAAAEAAAD9AAAA8vkAAO3xAADz9wDp3PAAv2dcAHYA1AHjAP8AAwABAP0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/4AGAAGA+hmU/3CQSQCPIRoAAOfpAAASBQAAAf8A9fz8APb8AAD/AAAAAAMAAAEBAwAEAw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AA/wAACQEAAPcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//6oJ/9WAEgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAG/6pVEgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJELlWVMk86AAAAABJRU5ErkJggg=='
LtqxWYEG commented 3 years ago

For small images.... for me that means all images... can be turned into base64 and included in the source code itself which removes the possibility of this problem happening. May be a technique you can utilize :-)

py_image = b'AAAAAAAAAAAAAAAAAAAAAAAAAAAA=='

Ah, I keep that in mind! Thanks! The py.png is only an example - and now I realize it should be the poop emoji, one moment ...

Your first Issue? Really? Ever? That's SO cool!

Yea 😁

PySimpleGUI commented 3 years ago

We've got some forward progress.......

X:\Python\python3.9\python.exe "C:/Python/PycharmProjects/PSG/User Submitted Programs/ShitStuckToYourMouse-main/main.pyw"
Traceback (most recent call last):
  File "C:\Python\PycharmProjects\PSG\User Submitted Programs\ShitStuckToYourMouse-main\main.pyw", line 565, in <module>
    main(config)
  File "C:\Python\PycharmProjects\PSG\User Submitted Programs\ShitStuckToYourMouse-main\main.pyw", line 319, in main
    getVariablesFromConfig(window)
  File "C:\Python\PycharmProjects\PSG\User Submitted Programs\ShitStuckToYourMouse-main\main.pyw", line 97, in getVariablesFromConfig
    window['randomMod'].update(int(config.get("SPARKLES", "randomMod")))
ValueError: invalid literal for int() with base 10: '5.50'

Process finished with exit code 1

Longer-term question - I'm wondering if your code could have benefited from using the User Settings and the Exec APIs in PySimpleGUI. Curious what yo think of them since you're using similar capabilities by calling Popen for example.

EDIT - I think what I should have asked was..... what do you think about using JSON versus Config files. Could be that PySimpleGUI should support both formats.

LtqxWYEG commented 3 years ago

oh that's because you use either the config or default.ini from the release that hasn't been updated. Download the default.ini from the source and it should work fine. (or open it and just change that value to an integer)

EDIT - I think what I should have asked was..... what do you think about using JSON versus Config files. Could be that PySimpleGUI should support both formats.

Hm, I chose a config - before the GUI existed - because I wanted to easily have explanations of the values visible to the user. (That was only me though) And I didn't like JSON cause you can't include comments in it that don't look like values. I guess now that every explanation is in the GUI, I could change to JSON. I'll take a look at your User Settings solution. Thank you again :)

Exec APIs in PySimpleGUI

I didn't know that existed. I've had so many issues trying to kill the processes I spawned... no solution worked!! I tried maybe ten different ways and none could kill the processes. Except the rudimentary and bad "Popen(taskkill...)" which I don't like because it takes so much time. So, yeah, I'll definitely use your API if it can kill my processes! :)

PySimpleGUI commented 3 years ago

I tried maybe ten different ways and none could kill the processes.

Oh... uhh..... KILLING a process.... now that would have been a fantastic thing for the Exec APIs to have....

image

The Subprocess ID is returned when you call execute_py_file or execute_command_subprocess... so you can work with the subprocess using the normal Python subprocessing methods. I just don't have anything shown on how to use that to "kill" a subprocess.

I use psutil to kill prcoesses in a general kind of way.

Thanks for the comments about config files! Really good points. Similar to layouts in some ways because you can use comments inside of layouts.

LtqxWYEG commented 3 years ago

the normal Python subprocessing methods. I use psutil to kill prcoesses in a general kind of way.

I tried using subprocess-method with pip and without. (.kill(), .terminate()) Also psutil and all that. I tried getting the process ID with psutil. It just wouldn't work! Googled for hours and went insane

Oh... uhh..... KILLING a process.... now that would have been a fantastic thing for the Exec APIs to have....

Oh, yea xD (At least for the spawned processes)

LtqxWYEG commented 3 years ago

I had to change the name. Getting another perspective on it showed me that it was too vulgar xD

PySimpleGUI commented 3 years ago

I think I'm using the straight demo programs from the PySimpleGUI Repo to kill processes:

image

https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_psutil_Kill_Python_Processes.py https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_psutil_Kill_Processes.py

I use some version of them to kill all of the running PySimpleGUI programs on my system so I can run batch tests. I think it's able to kill tasks pretty well. I'm not sure of anything though.

LtqxWYEG commented 3 years ago

Thank you! I tested it with a compiled exe and it works. I have no idea why and what I may have done wrong using the other methods I tried, but now I'm happy! :)

PySimpleGUI commented 3 years ago

FYI - I'm almost done with the first part of the UserSettings support of config files. The UserSettings object interface is pretty much done. Next will be the function APIs.

I made the interface for the config files look like this to users:

    settings = sg.UserSettings(r'C:\Python\PycharmProjects\PSG\User Submitted Programs\ShitStuckToYourMouse-main\config.ini', use_config_file=True, autosave=False)
    print(settings['SPARKLES']['randomMod'])
    settings['SPARKLES']['randomMod'] = '**** changed randomMod12343  ****'
    settings['SPARKL']['nbad'] = '+++ NEW VALUE +++'            # Make a new section and value!
    settings.save('config2.ini')

It's double indexed

settings[section][key] = value

After running the code on your ini file, the new ini file looks like this:

[SPARKLES]
transparentColor = #000000
particleSize = 2
particleAge = 60
ageBrightnessMod = 5.049
ageBrightnessNoise = 12
velocityMod = 0.75
velocityClamp = 200
GRAVITY = 0.0, 0.03
drag = 0.85
FPS = 60
interpolateMouseMovement = True
useOffset = False
offsetX = 20
offsetY = 10
markPosition = False
numParticles = 2
randomMod = **** changed randomMod12343  ****
particleColor = #ff00ff
particleColorRandom = False
ageColor = True
ageColorSpeed = -2.75
ageColorSlope = False
ageColorSlopeConcavity = 0.3
ageColorNoise = 60
ageColorNoiseMod = 0.75
dynamic = True
randomModDynamic = 0.23
printMouseSpeed = False
levelVelocity = 15, 30, 60, 120
levelNumParticles = 5, 8, 14, 20

[OTHeR]
fontColor = None
fontSize = 10
showColor = False
showClock = True
showCPU = True
showRAM = False
showImage = False
imagePath = py.png

[SPARKL]
nbad = +++ NEW VALUE +++

EDIT

Oh... I changed your [OTHER] section to be [OTHeR] for testing. It wasn't modified by PySimpleGUI... it was me.
image

PySimpleGUI commented 3 years ago

The only problem I'm seeing so far is that comments are stripped. I've not looked into it further to see if the config parser has a setting for this. If not, I'll code up whatever it takes to preserve the comments.

PySimpleGUI commented 3 years ago

image

OK, well, this answers if there is an option to not strip comments.

PySimpleGUI commented 3 years ago

I add a "preserve comments" option. I won't be able to preserve the comments on the setting itself, but the single-line comments I will. It's just code.....

LtqxWYEG commented 3 years ago

FYI - I'm almost done with the first part of the UserSettings support of config files. The UserSettings object interface is pretty much done. Next will be the function APIs.

I made the interface for the config files look like this to users:

    settings = sg.UserSettings(r'C:\Python\PycharmProjects\PSG\User Submitted Programs\ShitStuckToYourMouse-main\config.ini', use_config_file=True, autosave=False)
    print(settings['SPARKLES']['randomMod'])
    settings['SPARKLES']['randomMod'] = '**** changed randomMod12343  ****'
    settings['SPARKL']['nbad'] = '+++ NEW VALUE +++'            # Make a new section and value!
    settings.save('config2.ini')

Uh, nice. I'm curious how it turns out. :) So, usage it will be identical to the "values" variable? No need for writing the lists of settings in code?

A problem I have with configparser is that I needed to define if a setting is string, boolean, float or integer. COULD this be interpreted instead of defined? (-I don't think it would be an issue to require strings to be in " " marks, if they are not included in the read string. There is \" for if a string requires " inside, so no problem, I guess? -Integers are just numbers -Floats will be interpreted because of the dot. -Boolean because they are either exactly "False" or "True", as I don't think there are many use cases where one need these two words as a string)

Also, Currently I need to juggle tuples or lists like this:

GET:
    string = config.getlistfloat("SPARKLES", "GRAVITY")
    window['GRAVITY_X'].update(string[0])
    window['GRAVITY_Y'].update(string[1])

    string = config.getlistint("SPARKLES", "levelVelocity")
    window['levelVelocity_1'].update(string[0])
    window['levelVelocity_2'].update(string[1])
    window['levelVelocity_3'].update(string[2])
    window['levelVelocity_4'].update(string[3])
    string = config.getlistint("SPARKLES", "levelNumParticles")
    window['levelNumParticles_1'].update(string[0])
    window['levelNumParticles_2'].update(string[1])
    window['levelNumParticles_3'].update(string[2])
    window['levelNumParticles_4'].update(string[3])

WRITE:
    string = [str(values['GRAVITY_X']), ', ', str(values['GRAVITY_Y'])]
    GRAVITYStr = "".join(string)
    config.set("SPARKLES", "GRAVITY", GRAVITYStr)

    string = [str(values['levelVelocity_1']), ', ', str(values['levelVelocity_2']), ', ', str(values['levelVelocity_3']), ', ', str(values['levelVelocity_4'])]
    levelVelocityStr = "".join(string)
    config.set("SPARKLES", "levelVelocity", levelVelocityStr)
    string = [str(values['levelNumParticles_1']), ', ', str(values['levelNumParticles_2']), ', ', str(values['levelNumParticles_3']), ', ', str(values['levelNumParticles_4'])]
    levelNumParticlesStr = "".join(string)

(As you probably know already) I'm not sure if there already is a better solution, but if not, maybe you could think of one? :) I.e. -Lists are interpreted as the above mentioned rules separated by comma: "string", True, 69, 4.20 --Maybe also in typical python-grammar: [("strong", False), (420, .69)]. This could be required or not. Imagine right now, where if I wanted a tuple of lists full of tuples with tuples, I'd have to bash my head so hard against the wall, I'd have to install a new window...

Yea... I dream of this config working:

[SADTINGS]
invisibleColor = "#000000"
matrixColorForSomeReason = (("#B00B15", "#B000000B"), ("#B0B0B0", "#BEBEBE"))  # Can include alpha values
particlePatricleness = False
particleLeetness = 1337.80085  # Warning: If over 9000.00, particle can no longer be removed from container and will persist forever on screen as stuck pixels!
# DANGER: If particleLeetness falls below 1337.00, the particle becomes pathetic!!
sanityLoss = (["hahaha", (["oh", "god", (((["please", "no", ["haha", ((((((12,10), ("omg", "no!")), "PLEASE"), "dangerous-"), True), ["too", "much", "to", "handle"]), (["imagine", "this", "in"], ["default", "configparser", "."]), ("yea", "nah"), ("yea", "nah"), ("yea", "nah"), "nope"], ["this", "must", "make"]]), "people"), "insane"), True, False, True, True], [True, True, True]), ("I", "mean"), ("come", "on")], ["pure", ["effing", "insanity", "-!-", " !"], [" ! ", "1", "1", "1"]])

Hm... actually, it might have been a nightmare. 😬

Thank you!

PySimpleGUI commented 3 years ago

It's checked into github now as 4.49.0.10.

I have not yet created and posted a matching demo file.

If you're familiar with the PySimpleGUI UserSettings APIs, then this will be an easy thing to get. If not, then this will be an easy thing to get.

Only the object interface is using config files at the moment.

You star by making a UserSettings Object that has config file indicated:

    settings = sg.UserSettings(r'C:\Python\PycharmProjects\PSG\MikesDemos\UserSettings Config File\config.ini', use_config_file=True)

Then you can access it as:

settings[section][key]

Get, set, and delete values as well as delete section are done.

Adding a section is easy to:

    settings['NEW section']['newKey'] = False

Oh, there's a flag that converts bools and None from text to actual True/False/None. The default is on. So be aware. Otherwise you're dealing with all strings.

That's the quick tutorial. There are other ways of doing this too but I don't have them in the demo program yet.