Source code for tangram.widget.widgets

# Copyright 2017 The Tangram Developers. See the AUTHORS file at the
# top-level directory of this distribution and at
# https://github.com/renatoGarcia/tangram/blob/master/AUTHORS.
#
# This file is part of Tangram.
#
# Tangram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Tangram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tangram in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.

from typing import Optional

from gi.repository import Gtk

from .._base import Base
from .._gui_thread import on_gtk_thread
from .._utility import Signal


[docs]class Vertical(Base):
[docs] @on_gtk_thread def __init__(self, *args, **kwargs): super().__init__(**kwargs) self._gtk_obj = Gtk.Grid() self._gtk_obj.set_orientation(Gtk.Orientation.VERTICAL) self._children = args for widget in self._children: self._gtk_obj.add(widget._gtk_obj)
[docs]class Horizontal(Base):
[docs] @on_gtk_thread def __init__(self, *args, spacing=5, **kwargs): super().__init__(**kwargs) self._gtk_obj = Gtk.Grid() self._gtk_obj.set_orientation(Gtk.Orientation.HORIZONTAL) self._gtk_obj.set_column_spacing(spacing) self._children = args for widget in self._children: self._gtk_obj.add(widget._gtk_obj)
[docs]class ToggleButton(Base): """ https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html Signals: :toggled(state): Emitted when the button is pressed. :argument state: bool, true if is active, false else. """
[docs] @on_gtk_thread def __init__(self, **kwargs): super().__init__(**kwargs) self._gtk_obj = Gtk.ToggleButton() self._image_record = Gtk.Image.new_from_icon_name('media-record', Gtk.IconSize.BUTTON) self._image_stop = Gtk.Image.new_from_icon_name('media-playback-stop', Gtk.IconSize.BUTTON) self._gtk_obj.set_image(self._image_record) self._gtk_obj.connect('toggled', self._on_toggled) self.toggled = Signal()
def _on_toggled(self, togglebutton): state = togglebutton.get_active() if state: self._gtk_obj.set_image(self._image_stop) else: self._gtk_obj.set_image(self._image_record) self.toggled.emit(state)
[docs]class Message(Base): """Shows a message composed by ``[title][text]``. Both ``title`` and ``text`` strings are optinal, and can contain *Pango Markup Format*[#pmf]_ tags. .. [#pmf] https://developer.gnome.org/pango/stable/PangoMarkupFormat.html """
[docs] @on_gtk_thread def __init__(self, *, title: Optional[str] = None, text: Optional[str] = None, name: Optional[str] = None) -> None: super().__init__(name=name) self._gtk_obj = Gtk.Grid() self._gtk_obj.set_orientation(Gtk.Orientation.HORIZONTAL) self._title = Gtk.Label(label=title) self._gtk_obj.add(self._title) self._text = Gtk.Label(label=text, use_markup=True) self._gtk_obj.add(self._text) self._gtk_obj.set_valign(Gtk.Align.CENTER)
def title(): doc = """Message title.""" @on_gtk_thread def fget(self): return self._title.get_label() @on_gtk_thread def fset(self, value): self._title.set_label(value) return locals() title = property(**title()) def text(): doc = """Message text.""" @on_gtk_thread def fget(self): return self._text.get_label() @on_gtk_thread def fset(self, value): self._text.set_label(value) return locals() text = property(**text())