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

Make an animated widgetbutton #63

Open
kociak opened this issue Dec 1, 2022 · 0 comments
Open

Make an animated widgetbutton #63

kociak opened this issue Dec 1, 2022 · 0 comments
Labels
audience - user affects users effort - few days a few days good first issue good for newcomers impact - high has difficult or onerous workaround reach - medium affects several users weekly skill - ui skill tag skill level - medium skill level tag

Comments

@kociak
Copy link

kociak commented Dec 1, 2022

For some cases, it would be nice to have a button who's icon is animated. This can be because you want to notify to the user a transient state (in my case, something is moving) or attract their attention for an action (in my case, a fault that needs to be fixed manually).

I have made a blinkable button using a thread that regularly fires an Event.Event(). This works nicely (see at the end a rough example), but I don't like this design which is quite twisted. I guess the button widget itself should handle animation.

As I see it, the easiest would be a Animatedwidgetbutton who could have among its parameters a icon|List[icon] and a transition_time. The List[icon] would store the different animated frames of the button, that would be animated at a transition_time rate. If icon is fed rather than a List[icon], then the button is not animated.
How to do it might be through a thread mechanism as in my example (but not in the Converter, of course), but here this is outside of my expertise to give an advice.

example of a blinkable button using a Converter:

class StateToIconConverterBlinkable():
    def __init__(self, instrument:  MonchActuatorDevice):
        self.__instrument = instrument
        data1 = pkgutil.get_data(__name__, 'resources/icon1.png')
        data2 = pkgutil.get_data(__name__, 'resources/icon2.png')
        data3 = pkgutil.get_data(__name__, 'resources/icon3.png')
        self.__icon1 = CanvasItem.load_rgba_data_from_bytes(data1, "png")
        self.__icon2 = CanvasItem.load_rgba_data_from_bytes(data2, "png")
        self.__icon3 = CanvasItem.load_rgba_data_from_bytes(data3, "png")
        self.icon = self.__icon1
        self.__first_pass = True
        self.kill_blink_event = threading.Event()

    def convert(self, value:typing.Optional[MonchActuatorDevice.State]):
        if self.__instrument.state is MonchActuatorDevice.State.Observemove:
            self.ThreadedUpdate()
        else:
            self.kill_blink_event.is_set()
            self.icon = self.__icon3
            self.kill_blink_event.clear()

        return self.icon

    def ThreadedUpdate(self):
        threading.Thread(target = self.update).start()

    def update(self):
        time.sleep(0.3)
        if self.icon is self.__icon1:
            self.icon = self.__icon2
        else:
            self.icon = self.__icon1
        self.__instrument.property_changed_event.fire("state")
        if self.kill_blink_event.is_set():
            return


@cmeyer cmeyer self-assigned this Dec 2, 2022
@cmeyer cmeyer removed their assignment Dec 13, 2022
@cmeyer cmeyer added audience - user affects users good first issue good for newcomers impact - high has difficult or onerous workaround reach - medium affects several users weekly effort - few days a few days skill level - medium skill level tag skill - ui skill tag labels Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audience - user affects users effort - few days a few days good first issue good for newcomers impact - high has difficult or onerous workaround reach - medium affects several users weekly skill - ui skill tag skill level - medium skill level tag
Projects
None yet
Development

No branches or pull requests

2 participants