Merge pull request #2613 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2020-02-18 20:44:35 -05:00 committed by GitHub
commit 109b874712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View File

@ -1633,12 +1633,14 @@ class Checkbox(Element):
"""
return self.TKIntVar.get()
def Update(self, value=None, disabled=None, visible=None):
def Update(self, value=None, background_color=None, text_color=None, disabled=None, visible=None):
"""
Changes some of the settings for the Checkbox Element. Must call `Window.Read` or `Window.Finalize` prior.
Note that changing visibility may cause element to change locations when made visible after invisible
:param value: (bool) if True checks the checkbox, False clears it
:param background_color: (str) color of background
:param text_color: (str) color of the text. Note this also changes the color of the checkmark
:param disabled: (bool) disable or enable element
:param visible: (bool) control visibility of element
"""
@ -1656,6 +1658,30 @@ class Checkbox(Element):
self.TKCheckbutton.configure(state='disabled')
elif disabled == False:
self.TKCheckbutton.configure(state='normal')
if background_color is not None:
self.TKCheckbutton.configure(background=background_color)
self.BackgroundColor = background_color
if text_color is not None:
self.TKCheckbutton.configure(fg=text_color)
self.TextColor = text_color
if self.TextColor is not None and self.BackgroundColor is not None and self.TextColor.startswith('#') and self.BackgroundColor.startswith('#'):
# ---- compute color of circle background ---
# try: # something in here will fail if a color is not specified in Hex
text_hsl = _hex_to_hsl(self.TextColor)
background_hsl = _hex_to_hsl(self.BackgroundColor if self.BackgroundColor else theme_background_color())
# print(f'backgroundHSL = {background_hsl}')
l_delta = abs(text_hsl[2] - background_hsl[2])/10
if text_hsl[2] > background_hsl[2]: # if the text is "lighter" than the background then make background darker
bg_rbg = _hsl_to_rgb(background_hsl[0], background_hsl[1], background_hsl[2]-l_delta)
else:
bg_rbg = _hsl_to_rgb(background_hsl[0], background_hsl[1],background_hsl[2]+l_delta)
self.CheckboxBackgroundColor = RGB(*bg_rbg)
# except Exception as e:
# self.CheckboxBackgroundColor = self.BackgroundColor if self.BackgroundColor else theme_background_color()
# print(f'Update exception {e}')
print(f'Setting checkbox background = {self.CheckboxBackgroundColor}')
self.TKCheckbutton.configure(selectcolor=self.CheckboxBackgroundColor) # The background of the checkbox
if visible is False:
self.TKCheckbutton.pack_forget()
elif visible is True:
@ -9180,7 +9206,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKRightClickMenu = top_menu
element.TKText.bind('<Button-3>', element._RightClickMenuCallback)
# row_should_expand = True
# ------------------------- CHECKBOX element ------------------------- #
# ------------------------- CHECKBOX pleacement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_CHECKBOX:
element = element # type: Checkbox
width = 0 if auto_size_text else element_size[0]

View File

@ -1,6 +1,6 @@
#usr/bin/python3
version = __version__ = "0.35.0 Released 16-Jan-2020"
version = __version__ = "0.35.1 Unreleased fix for Text element after Remi update"
port = 'PySimpleGUIWeb'
@ -19,7 +19,7 @@ import base64, binascii
import mimetypes
from random import randint
from typing import List, Any, Union, Tuple, Dict # For doing types in comments
# from typing import List, Any, Union, Tuple, Dict # For doing types in comments
try:
@ -4203,7 +4203,6 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
elif element_type == ELEM_TYPE_TEXT:
element = element # type: Text
element.Widget = remi.gui.Label(element.DisplayText)
element.Widget.set_layout_orientation(True)
do_font_and_color(element.Widget)
if auto_size_text and element.Size == (None, None):
del(element.Widget.style['width'])