jarvisteach / appJar

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

Would like to set disabled bg on buttons #579

Open tnsolley opened 5 years ago

tnsolley commented 5 years ago

Bug Report


Context


Attempting to make Enabled and Disabled buttons more visually distinct than the default (which is a Fg change only)

Expected Behaviour


All Button items listed, on Disable, will be a different color than the default, with no errors or warnings.

Actual Behaviour


AppJar throws WARNINGs for each and every app.setButtonDisabledBg() call, and not for the app.setButtonDisabledFg() call.

Any error messages produced by appJar


Terminal output as below:

2019-04-23 11:57:28,267 appJar:WARNING [Line 13458->3063/configureWidget]: Error configuring Submit: unknown option "-disabledbackground"
2019-04-23 11:57:29,696 appJar:WARNING [Line 13499->3063/configureWidget]: Error configuring Clear BIV Fields: unknown option "-disabledbackground"
2019-04-23 11:57:29,739 appJar:WARNING [Line 13501->3063/configureWidget]: Error configuring Submit BIV: unknown option "-disabledbackground"
2019-04-23 11:57:30,179 appJar:WARNING [Line 13511->3063/configureWidget]: Error configuring GET: unknown option "-disabledbackground"
2019-04-23 11:57:31,158 appJar:WARNING [Line 13528->3063/configureWidget]: Error configuring Choose Setup File: unknown option "-disabledbackground"
2019-04-23 11:57:35,604 appJar:WARNING [Line 13622->3063/configureWidget]: Error configuring Clear Setup Fields: unknown option "-disabledbackground"
2019-04-23 11:57:35,652 appJar:WARNING [Line 13624->3063/configureWidget]: Error configuring Import Setup: unknown option "-disabledbackground"
2019-04-23 11:57:36,002 appJar:WARNING [Line 13636->3063/configureWidget]: Error configuring Ready!: unknown option "-disabledbackground"
2019-04-23 11:57:36,402 appJar:WARNING [Line 13653->3063/configureWidget]: Error configuring Confirm: unknown option "-disabledbackground"
2019-04-23 11:57:36,444 appJar:WARNING [Line 13655->3063/configureWidget]: Error configuring Deny: unknown option "-disabledbackground"
2019-04-23 11:57:36,953 appJar:WARNING [Line 13679->3063/configureWidget]: Error configuring ok1: unknown option "-disabledbackground"
2019-04-23 11:57:37,459 appJar:WARNING [Line 13694->3063/configureWidget]: Error configuring cl2: unknown option "-disabledbackground"
2019-04-23 11:57:37,559 appJar:WARNING [Line 13698->3063/configureWidget]: Error configuring sm2: unknown option "-disabledbackground"
2019-04-23 11:57:37,763 appJar:WARNING [Line 13713->3063/configureWidget]: Error configuring pr4: unknown option "-disabledbackground"
2019-04-23 11:57:37,828 appJar:WARNING [Line 13716->3063/configureWidget]: Error configuring pr7: unknown option "-disabledbackground"
2019-04-23 11:57:40,530 appJar:WARNING [Line 13854->3063/configureWidget]: Error configuring pr1: unknown option "-disabledbackground"
2019-04-23 11:57:40,596 appJar:WARNING [Line 13857->3063/configureWidget]: Error configuring pr3: unknown option "-disabledbackground"
2019-04-23 11:57:40,660 appJar:WARNING [Line 13860->3063/configureWidget]: Error configuring pr2: unknown option "-disabledbackground"
2019-04-23 11:57:40,726 appJar:WARNING [Line 13863->3063/configureWidget]: Error configuring pr5: unknown option "-disabledbackground"
2019-04-23 11:57:40,937 appJar:WARNING [Line 13878->3063/configureWidget]: Error configuring er4: unknown option "-disabledbackground"
2019-04-23 11:57:41,001 appJar:WARNING [Line 13881->3063/configureWidget]: Error configuring er7: unknown option "-disabledbackground"
2019-04-23 11:57:58,771 appJar:WARNING [Line 14515->3063/configureWidget]: Error configuring er1: unknown option "-disabledbackground"
2019-04-23 11:57:58,870 appJar:WARNING [Line 14518->3063/configureWidget]: Error configuring er3: unknown option "-disabledbackground"
2019-04-23 11:57:58,968 appJar:WARNING [Line 14521->3063/configureWidget]: Error configuring er2: unknown option "-disabledbackground"
2019-04-23 11:57:59,063 appJar:WARNING [Line 14524->3063/configureWidget]: Error configuring er5: unknown option "-disabledbackground"
2019-04-23 11:57:59,782 appJar:WARNING [Line 14550->3063/configureWidget]: Error configuring ok4: unknown option "-disabledbackground"
2019-04-23 11:58:00,541 appJar:WARNING [Line 14574->3063/configureWidget]: Error configuring ok2: unknown option "-disabledbackground"
2019-04-23 11:58:01,250 appJar:WARNING [Line 14598->3063/configureWidget]: Error configuring ok3: unknown option "-disabledbackground"
2019-04-23 11:58:02,200 appJar:WARNING [Line 14633->3063/configureWidget]: Error configuring ok5: unknown option "-disabledbackground"
2019-04-23 11:58:03,091 appJar:WARNING [Line 14650->3063/configureWidget]: Error configuring Start Session: unknown option "-disabledbackground"
2019-04-23 11:58:03,148 appJar:WARNING [Line 14652->3063/configureWidget]: Error configuring Send: unknown option "-disabledbackground"
2019-04-23 11:58:03,206 appJar:WARNING [Line 14654->3063/configureWidget]: Error configuring Clear Val: unknown option "-disabledbackground"
2019-04-23 11:58:03,994 appJar:WARNING [Line 14681->3063/configureWidget]: Error configuring Update: unknown option "-disabledbackground"

Sample code, demonstrating the issue


# Thomas Solley
# 4/23/2019

# <http://appjar.info/pythonWidgetOptions/>
# Showcase error with `set XXX DisabledBg` method

from appJar import gui

# Globals
disBg = "gray"
disFg = "light grey"

# Return True
### Also hide and disable stuff here!
# function to login the user
def login(btn):
  global Username
  global accessLevel

  if btn == "Clear Login Fields":
    app.entry("username", "")
    app.setEntryFocus("username")
    app.entry("password", "")
    return app.enableButton("Submit")
  elif btn == "Submit":
    app.disableButton("Submit")
    Username = app.getEntry("username")
    password = app.getEntry("password")
    if(Username=="Tester" and password=="tester"):
      accessLevel = "Tester"
      app.queueFunction(app.infoBox, "Success", "Access granted")
      app.disableButton("Clear Login Fields")      
      app.setToolbarEnabled()
      app.setToolbarPinned()      
      return True
    else:
      message = ("401 Incorrect Login: %s, %s, try again..." % (Username, password))
      print(message)
      app.queueFunction(app.errorBox, "Error", message)
      app.setFocus("username")
      return app.clearEntry("password")
    # End if-else  
  # End if-elif
# End <login()>

# Called by pmin1() on "Enter"
# Return True
# Perform variant of "login"
def pmin2():
  global Username
  global screenMode
  global accessLevel  

  if app.getFocus()=="password":     
    Username = app.getEntry("username")
    password = app.getEntry("password")
    if(Username=="Tester" and password=="tester"):
      app.disableEnter()
      accessLevel = "Tester"
      app.queueFunction(app.infoBox, "Success", "Access granted")
      app.disableButton("Clear Login Fields")
      app.setToolbarEnabled()
      app.setToolbarPinned()
      return True
    else:
      message = ("401 Incorrect Login: %s, %s, try again..." % (Username, password))
      print(message)
      app.queueFunction(app.errorBox, "Error", message)
      app.setFocus("username")
      app.clearEntry("password")
      return app.enableEnter(pmin2)
    # End if-else
  # End if-case  
# End <pmin2()>

# Call pmin2() on "Enter"
# Move cursor to "password" from "operator", if applicable
def pmin1():
  app.disableEnter()
  if app.getFocus()=="username":
    app.setFocus("password")
  elif app.getFocus()=="password":
    pass
  # End if-elif  
  app.enableEnter(pmin2)
  ##timeCatch()                                                                 # _--------
# End <pmin1()>

# function to get a help message on log-in page
def helpMe(nbtn):
  app.queueFunction(app.infoBox, "Login Help", "Tester")
# End <helpMe()>  

with gui("Test One") as app:
  with app.tabbedFrame("Tabs"):
    with app.tab("Login", bg="light slate gray", sticky="n"):
      with app.labelFrame("Login Form", sticky="news"):
        app.label("username", "Username:")
        app.setLabelBg("username", "dodger blue")
        app.setLabelFg("username", "gray15")
        app.entry("username", pos=('p', 1), focus=True)
        app.label("password", "Password:")
        app.setLabelBg("password", "cornflower blue")
        app.setLabelFg("password", "gray15")
        app.entry("password", pos=('p', 1), secret=True)
        app.buttons(["Clear Login Fields"], login, row=2, column=1)
        app.setButtonDisabledBg("Clear Login Fields",disBg)
        app.setButtonDisabledFg("Clear Login Fields",disFg)        
        app.separator(column=0, colspan=2, sticky="news")
        app.buttons(["Submit"], login, column=1, rowspan=2, sticky="e")
        app.setButtonDisabledBg("Submit",disBg)
        app.setButtonDisabledFg("Submit",disFg)
        app.link("help", helpMe, column=0, sticky="w")
        app.enableEnter(pmin1)       
      # End with-statement
    # End with-statement   
  # End with-statement
# End with-statement

# EOL

What steps are needed to reproduce the bug


Add app.setButtonDisabledBg() method to any button.

Version Information


Windows 10 SP1, Python 3.7.2, appJar 0.9.3

jarvisteach commented 5 years ago

Looking at the docs, the tkinter button doesn't support disabledbackground: http://effbot.org/tkinterbook/button.htm

So I don't think this is possible, you could try changing the background colour when you enable/disable buttons see if that works?

If it does, we could look at adding that in as a feature - when someone sets a disabled bg colour on a button, we can store it, then use it as a bg colour when the button is disabled...

tnsolley commented 5 years ago

@jarvisteach Yes, this works (though gets cumbersome with extensive usage). Essentially every app.enableButton(name) must be accompanied-with a app.setButtonBg(name, enableBg) call (to "reset" the color), and every app.disableButton(name) with its own app.setButtonBg(disableBg) call (to set the button disabled).

At the moment I'm using the appjar.py values for Disabled and Active Tabs (Fg, Bg) as the appropriate enableBg and disableBg colors, that is

disBg = "darkGray"
disFg = "gray"
enaBg = "#F6F6F6"
enaFg = "#000000"    # For posterity

If a user changes the Tab-colors, I'd suggest the Buttons inherit those values as default, unless override is given... or maybe add a second & third parameter to app.enableButton() and app.disableButton() which lets the users explicitly enter their own overrides for Bg and Fg?

jarvisteach commented 4 years ago

Now have the disabledBg being stored in the button and applied when the button is disabled, with the original bg being applied when the button is enabled.

Need to do testing on other platforms & check other states.