jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

fileEntry disable doesn't completely work #590

Closed nighttardis closed 4 years ago

nighttardis commented 5 years ago

Bug Report


Context


I was trying to disable a FileEntry widget and get the following error:

2019-09-01 20:12:38,063 appJar:WARNING [Line 47->3191/configureWidget]: Error configuring ca: bad state "readonly": must be active, disabled, or normal

The entry box is disabled but the button still works and will still fill in the entry box. In my limited testing (just tested my use case don't know what other side effects this update may have) line 3084 would need to be updated to "disabled" instead of read-only. Enabling does seem to work correctly though.

Sample code, demonstrating the issue


from appJar import gui
app = gui()
app.addFileEntry(title="ca")
app.disableEntry(name="ca")

Version Information


python==3.7.4, appJar==0.94.0, tk==8.6.9.1-2

projectbtle commented 4 years ago

I had the same issue with a DirectoryEntry, and I think the problem is because the code uses the same state value for the associated button as well (I'm guessing buttons don't have a readonly state?)

I modified the code as follows (lines 3077 to 3095) and it seems to work:

elif option == 'state':
    # make entries readonly - can still copy/paste
    but = None
    btn_val = value
    if kind == WIDGET_NAMES.Entry:
        if value == "disabled" and hasattr(item, 'but'):
        but = item.but
        item.unbind("<Button-1>")
        value = "readonly"
    elif value == 'normal' and hasattr(item, 'but') and item.cget('state') != 'normal':
        but = item.but
        item.bind("<Button-1>", item.click_command, "+")

    if self.ttkFlag:
        gui.trace("%s configured with ttk state %s", name, value)
        item.state([value])
        if but is not None: but.state([btn_val])
    else:
        item.config(state=value)
        if but is not None: but.config(state=btn_val)

This keeps the original value of disabled for the button, while changing the state for the Entry field to readonly.

I don't know if this has the potential to break something further down the line, but the modified functionality is contained within this particular elif clause, so hopefully it shouldn't.

jarvisteach commented 4 years ago

I've implemented this in the next_release (see #583)