Пример #1
0
    def __init__(self, ui: UserInterface.UserInterface, text: str) -> None:
        column_widget = ui.create_column_widget()
        super().__init__(column_widget)
        self.on_button_clicked: typing.Optional[typing.Callable[[],
                                                                None]] = None
        font = "normal 11px serif"
        font_metrics = ui.get_font_metrics(font, text)
        text_button_canvas_item = TextButtonCanvasItem(text)
        text_button_canvas_item.update_sizing(
            text_button_canvas_item.sizing.with_fixed_size(
                Geometry.IntSize(height=font_metrics.height + 6,
                                 width=font_metrics.width + 6)))

        def button_clicked() -> None:
            if callable(self.on_button_clicked):
                self.on_button_clicked()

        text_button_canvas_item.on_button_clicked = button_clicked

        text_button_canvas_widget = ui.create_canvas_widget(properties={
            "height": 20,
            "width": 20
        })
        text_button_canvas_widget.canvas_item.add_canvas_item(
            text_button_canvas_item)
        # ugh. this is a partially working stop-gap when a canvas item is in a widget it will not get mouse exited reliably
        root_container = text_button_canvas_item.root_container
        if root_container:
            text_button_canvas_widget.on_mouse_exited = root_container.canvas_widget.on_mouse_exited

        column_widget.add(text_button_canvas_widget)
Пример #2
0
 def construct(self, d_type: str, ui: UserInterface.UserInterface, window: typing.Optional[Window.Window],
               d: Declarative.UIDescription, handler: Declarative.HandlerLike,
               finishes: typing.List[typing.Callable[[], None]]) -> typing.Optional[UserInterface.Widget]:
     if d_type == "notification_char_button":
         font = "normal 13px serif"
         text = d["text"]
         fm = ui.get_font_metrics(font, text)
         canvas_item = CharButtonCanvasItem(text)
         widget = ui.create_canvas_widget(properties={"height": fm.height + 4, "width": fm.width + 4})
         widget.canvas_item.add_canvas_item(canvas_item)
         if handler:
             Declarative.connect_name(widget, d, handler)
             Declarative.connect_attributes(widget, d, handler, finishes)
             Declarative.connect_event(widget, canvas_item, d, handler, "on_clicked", [])
         return widget
     return None