Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Color Selected Item #49

Closed
wdog opened this issue Apr 27, 2020 · 3 comments
Closed

Change Color Selected Item #49

wdog opened this issue Apr 27, 2020 · 3 comments
Labels
Colors Issue with Colors Widgets Add for issues having to do with widgets
Milestone

Comments

@wdog
Copy link
Contributor

wdog commented Apr 27, 2020

Hi!

how can i change the color of a selected line in a scroll_menu?
(and in general of a particular part of a widget? )

Bold is not enough, What I have to do if I want to use reverse colors GREEN_ON_BLACK and BLACK_ON_GREEN for example.

Can I add an object to the scroll_menu and use maybe __str__ for rendering, so to have a selected object and not a string get() or an int get_selected_item() ?

thanks a lot

@jwlodek
Copy link
Owner

jwlodek commented Apr 27, 2020

So the first question, at the moment the library does not give the ability to do this, though you could code it in to the renderer without too much trouble. Basically, you could add a new attribute like selected_item_color for the widget's class, and in the _draw function, check if the line number matches the selected item index, and tell the renderer to use that color instead of the standard one for that line.

The reason I haven't gotten this implemented yet is because I want to think about how to make it work reliably side-by-side with the current color rule system, though I haven't quite decided the best way to do it. I am planning to add that in one of the new versions though.

For the second question, someone had already suggested that, and the ability to add objects to menus will be included in v0.1.1 which should release in the next few days. The feature is already working on the v0.1.1-develop branch if you want to check it out. The original suggestion is here: #45, and the commit that adds the support is here: ae5bcef

@jwlodek jwlodek added Colors Issue with Colors Widgets Add for issues having to do with widgets labels Apr 27, 2020
@wdog
Copy link
Contributor Author

wdog commented Apr 28, 2020

So for the second question I'll wait next release, but for the first one can you provide me some more tips?

I'm trying to extend the PyCUI class and add a new method add_scroll_menu_extra which add and extended class of ScrollMenu with the colors I need... Am I on the right way?

By the way why can I change color to status_bar (public) and not to title_bar (private) ?

@jwlodek
Copy link
Owner

jwlodek commented Apr 28, 2020

Yeah thats what I would do. Just extend the ScrollMenu and override the _draw function, and then add a new method to an extension of the PyCUI class like you said. The _draw function can probably be almost identical, but instead of bolding the selected item, just set the renderer color mode to the selected color attribute you created. Something like this:

if line_counter == self._selected_item:
    self._renderer.set_color_mode(self._selected_color)
    self._renderer.draw_text(self, line, self._start_y + counter)
    self._renderer.unset_color_mode(self._selected_color)

You may need some extra logic to handle cases where you have a selected item you want to color that collides with a color rule, but what that could be I'm not sure.

As for the second point, good catch, the title bar attribute should be public, that will be changed in the next release as well.

@jwlodek jwlodek added this to the v0.1.3 milestone May 6, 2020
@jwlodek jwlodek closed this as completed Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Colors Issue with Colors Widgets Add for issues having to do with widgets
Projects
None yet
Development

No branches or pull requests

2 participants