Source code for sublime_music.ui.common.icon_button

from typing import Any, Optional

from gi.repository import Gtk


[docs]class IconButton(Gtk.Button):
[docs] def __init__( self, icon_name: Optional[str], tooltip_text: str = "", relief: bool = False, icon_size: Gtk.IconSize = Gtk.IconSize.BUTTON, label: str | None = None, **kwargs, ): Gtk.Button.__init__(self, **kwargs) self.icon_size = icon_size box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, name="icon-button-box") self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size) box.pack_start(self.image, False, False, 0) if label is not None: box.add(Gtk.Label(label=label)) if not relief: self.props.relief = Gtk.ReliefStyle.NONE self.add(box) self.set_tooltip_text(tooltip_text)
[docs] def set_icon(self, icon_name: Optional[str]): self.image.set_from_icon_name(icon_name, self.icon_size)
[docs]class IconToggleButton(Gtk.ToggleButton):
[docs] def __init__( self, icon_name: Optional[str], tooltip_text: str = "", relief: bool = False, icon_size: Gtk.IconSize = Gtk.IconSize.BUTTON, label: str | None = None, **kwargs, ): Gtk.ToggleButton.__init__(self, **kwargs) self.icon_size = icon_size box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, name="icon-button-box") self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size) box.add(self.image) if label is not None: box.add(Gtk.Label(label=label)) if not relief: self.props.relief = Gtk.ReliefStyle.NONE self.add(box) self.set_tooltip_text(tooltip_text)
[docs] def set_icon(self, icon_name: Optional[str]): self.image.set_from_icon_name(icon_name, self.icon_size)
[docs] def get_active(self) -> bool: return super().get_active()
[docs] def set_active(self, active: bool): super().set_active(active)
[docs]class IconMenuButton(Gtk.MenuButton):
[docs] def __init__( self, icon_name: Optional[str] = None, tooltip_text: str = "", relief: bool = True, icon_size: Gtk.IconSize = Gtk.IconSize.BUTTON, label: str | None = None, popover: Any = None, **kwargs, ): Gtk.MenuButton.__init__(self, **kwargs) if popover: self.set_use_popover(True) self.set_popover(popover) self.icon_size = icon_size box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, name="icon-button-box") self.image = Gtk.Image.new_from_icon_name(icon_name, self.icon_size) box.add(self.image) if label is not None: box.add(Gtk.Label(label=label)) self.props.relief = Gtk.ReliefStyle.NORMAL self.add(box) self.set_tooltip_text(tooltip_text)
[docs] def set_icon(self, icon_name: Optional[str]): self.image.set_from_icon_name(icon_name, self.icon_size)
[docs] def set_from_file(self, icon_file: Optional[str]): self.image.set_from_file(icon_file)