peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

CustomColour does not work on all widgets #208

Closed jabdoa2 closed 5 years ago

jabdoa2 commented 5 years ago

Describe the bug CustomColour only works on certain widgets. For example Labels always use the "label" color.

To Reproduce

from asciimatics.scene import Scene
from time import sleep
from asciimatics.screen import Screen
from asciimatics.widgets import Frame, Layout, Label

screen = Screen.open()
frame = Frame(screen, screen.height, screen.width, has_border=False)
title_layout = Layout([1])
frame.add_layout(title_layout)
title_text = Label("MPF Framework v1.2.3", align="^")
title_layout.add_widget(title_text)
title_text.custom_colour = "title"
frame.fix()
scene = Scene([frame], -1)
screen.set_scenes([scene], start_scene=scene)
screen.draw_next_frame()
sleep(1)
screen.close()

Expected behavior Label Text should use "title" color.

Actual behavior Label Text uses "label" color.

System details (please complete the following information):

peterbrittain commented 5 years ago

Yeah - looks like some widgets still pick from the palette directly. Should be an easy fix to use a suitable lookup function instead.

peterbrittain commented 5 years ago

Just looking at this one now... It would appear that the only widget that totally fails to do this is the Label widget. All the rest will use a hard-coded "label" colour if they also have a label and so the UI is consistent.

The basic scheme is as follows:

I am perfectly happy that the Frame and ScrollBars are out of the user's control - there are no settings to allow them to change this. The only question is what to do about Labels, which straddle two worlds - being a Label widget in their own right and being a component of another Widget.

The simple fix (that I imagined before looking at this in more detail) was that we just fix up any rogue widgets to draw in the custom colour. However, that then leaves the question of how to handle labels that are embedded within another widget (by setting the label property).

I could (a) ignore the issue and still have them drawn with a hard-coded "label" colour, or (b) refactor the packge to treat them as fully formed widgets in their own right.

The latter is more effort and so only something I want to do if you have an explicit need for it. Your example only needs (a). Can you please confirm that you don't also need (b)?

jabdoa2 commented 5 years ago

I only need a currently. Those are my current hacks: https://github.com/missionpinball/mpf/pull/1339/files