heartcase / csv_input_uploader

CSV Files Uploader using PySimpleGUI, Requests
0 stars 0 forks source link

Clever extension of the year award #1

Open MikeTheWatchGuy opened 6 years ago

MikeTheWatchGuy commented 6 years ago

It took copying, pasting and playing with your code to figure out what it was you were doing messing with button.ChangeSubmits... especially when there IS no button.ChangeSubmits. I could tell right away something was amiss. Few people reach behind the SDK, and it's usually to get to some tkinter variable.

I don't believe you've finished hooking it up, but it would appear as if you're going to populate the listbox with the filenames immediately after they are chosen.

You must have really studied the code to find your way through to this hack. What are the chances that I would leave that kind of door open?? I was lazy, clearly, then I added the try statement, leaving the change submits off of the button element.

Somehow you've implemented a feature that I'm not so sure I would have immediately implemented. It would make the Button Element's parameters a bit messy and difficult to explain to a newbie.

I will certainly document the method you've used and I'm adding the official ChangeSubmits variable to the Button class.

I need to think about adding the change_submits to buttons. It may make sense because almost all other elements have that flag, so why not a button too.

heartcase commented 6 years ago

Thanks Mike! This library is amazing! It saved lots of time for me as a very beginner in python!
I am so excited to find your comments here! Have a great day!

MikeTheWatchGuy commented 6 years ago

Very beginner?? Really? That hack you implemented was pretty advanced looking. Did you really get lucky or did you read my code to figure out what to do. I don't think I could have come up with that hack and it's my code.

heartcase commented 6 years ago

Probably just get lucky.
I tired to use the target to update the list, but it seems cause exceptions on Multiline, not like what it does on Text. Then with the help from pyCharm, i found the callback function and saw the flag right there. Its name already suggests that it is what I was looking for. I can change the field of an instance in python freely, i know it is a little risky to do so, and probably is never a good practice. I have searched the usage of this filed, i think at least it won't blow the whole things up, and to my surprise it does the job and no bad things happen so far!

MikeTheWatchGuy commented 6 years ago

If you upgrade to the latest PySimpleGUI you’ll find a new flag for buttons so that you don’t need to do the hack anymore. You can set the flag as a parameter to the file button.

MikeTheWatchGuy commented 6 years ago
import PySimpleGUI as sg
layout = [
    [sg.Text('Select some files')],
    [sg.FilesBrowse('Select Files', change_submits=True, target='_FILES_', key='_FILES_')],
    [sg.Multiline(size=(60,8), key='_MULTI_')],
    [sg.Listbox([], size=(60,6), key='_LIST_')],
    [sg.Button('Read')]
        ]

window = sg.Window('Main').Layout(layout)
while True:
    event, values = window.Read()
    print(event, values)
    if event is None:
        break
    if event == '_FILES_':
        window.FindElement('_MULTI_').Update('\n'.join((values['_FILES_'].split(';'))))
        window.FindElement('_LIST_').Update((values['_FILES_'].split(';')))

Try this code to see if it's something like what you're seeking.