Skip to content

Commit

Permalink
Ensure flash labels stay correct #7
Browse files Browse the repository at this point in the history
Keep a copy of original FG/BG in flash label, that way if they are
changed, the flash label will keep the right combination

Also, made TINT user configurable, with additional parameter to setBg
  • Loading branch information
jarvisteach committed Jul 31, 2017
1 parent 4923058 commit 7419efe
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions appJar/appjar.py
Expand Up @@ -1842,7 +1842,7 @@ def setFg(self, colour, override=False):
# self.tb = Frame, at top of appWindow
# self.container = Frame, at bottom of appWindow => C_ROOT container
# self.bglabel = Label, filling all of container
def setBg(self, colour, override=False):
def setBg(self, colour, override=False, tint=False):
if self.containerStack[-1]['type'] == self.C_ROOT:
self.appWindow.config(background=colour)
self.bgLabel.config(background=colour)
Expand All @@ -1851,7 +1851,7 @@ def setBg(self, colour, override=False):

for child in self.containerStack[-1]['container'].winfo_children():
if not self.__isWidgetContainer(child):
gui.SET_WIDGET_BG(child, colour, override)
gui.SET_WIDGET_BG(child, colour, override, tint)

@staticmethod
def __isWidgetContainer(widget):
Expand Down Expand Up @@ -2826,6 +2826,11 @@ def SET_WIDGET_FG(widget, fg, external=False):
gui.SET_WIDGET_FG(widget.lb, fg, external)
elif widgType in ["PieChart", "MicroBitSimulator", "Scrollbar"]:
pass
elif widgType == "Label":
widget.config(fg=fg)
widget.origFg=fg
try: widget.config(bg=widget.origBg)
except: pass # not a flash label
else:
try:
widget.config(fg=fg)
Expand Down Expand Up @@ -2854,7 +2859,7 @@ def TINT(widget, colour):

# convenience method to set a widget's bg
@staticmethod
def SET_WIDGET_BG(widget, bg, external=False, tint=True):
def SET_WIDGET_BG(widget, bg, external=False, tint=False):

if bg is None: # ignore empty colours
return
Expand Down Expand Up @@ -2918,6 +2923,12 @@ def SET_WIDGET_BG(widget, bg, external=False, tint=True):
widget.config(bg=bg)
if widgType == "OptionMenu":
widget["menu"].config(bg=bg)
# deal with flash labels
elif widgType == "Label":
widget.config(bg=bg)
widget.origBg=bg
try: widget.config(fg=widget.origFg)
except: pass # not a flash label
# otherwise only colour un-excluded widgets
elif widgType not in noBg:
widget.config(bg=bg)
Expand Down Expand Up @@ -2961,8 +2972,8 @@ def __positionWidget(
sticky=W + E):
# allow item to be added to container
container = self.getContainer()
gui.SET_WIDGET_BG(widget, self.__getContainerBg())
gui.SET_WIDGET_FG(widget, self.__getContainerFg())
gui.SET_WIDGET_BG(widget, self.__getContainerBg())

# alpha paned window placement
if self.containerStack[-1]['type'] == self.C_PANEDFRAME:
Expand Down Expand Up @@ -5341,11 +5352,11 @@ def addRadioButton(
text=name,
variable=var,
value=name,
anchor=W,
background=self.__getContainerBg(),
activebackground=self.__getContainerBg(),
font=self.rbFont,
indicatoron = 1)
rb.config(anchor = W)
rb.bind("<Button-1>", self.__grabFocus)
rb.DEFAULT_TEXT = name

Expand Down Expand Up @@ -5954,10 +5965,13 @@ def addLabel(
lab.DEFAULT_TEXT = text
else:
lab.DEFAULT_TEXT = ""

lab.origBg = self.__getContainerBg()

lab.config(
justify=LEFT,
font=self.labelFont,
background=self.__getContainerBg())
background=lab.origBg)
self.n_labels[title] = lab

self.__positionWidget(lab, row, column, colspan, rowspan)
Expand Down

0 comments on commit 7419efe

Please sign in to comment.