jwlodek / py_cui

A python library for intuitively creating CUI/TUI interfaces with widgets, inspired by gocui.
https://jwlodek.github.io/py_cui-docs
BSD 3-Clause "New" or "Revised" License
759 stars 42 forks source link

[not-a-bug][help-wanted] How to change border colors of selected buttons #173

Open strawberry-code opened 2 years ago

strawberry-code commented 2 years ago

I am trying to change the color of the borders of the button which the cursor is pointing on.

I am trying by this without success:

  def render(self):
        for key in self.master.get_widgets().keys():
            if self.master.get_widgets()[key].is_selected():
                self.master.get_widgets()[key].set_color(py_cui.RED_ON_BLACK)
            else:
                self.master.get_widgets()[key].set_color(py_cui.CYAN_ON_BLACK)

I kindly ask for little help here. What's wrong? If it is possibile to achieve it...

In the picture below I would the button "Show Yes No Popup" be colored in RED_ON_BLACK.

Schermata 2022-02-01 alle 19 22 12
jwlodek commented 2 years ago

How are you calling the above function? By default, py_cui interfaces will only re-draw when an action is performed (key press, mouse press). If you want that function to be run periodically, you can use the set_on_draw_update_func() to run the render function on every draw call, and then unlock periodic re-draw of the screen with set_refresh_timeout(). Note that the function set with set_on_draw_update_func() is fired at the start of the draw loop, before the new widget is considered selected.

It may be worthwhile to allow for setting a function to fire per draw call both at the start and end - that would simplify this