roster/src/widgets/request_item.py

57 lines
1.8 KiB
Python

# request_item.py
#
# Copyright 2025 Pavel Baksy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
from gi.repository import Gtk, GObject
@Gtk.Template(resource_path='/cz/bugsy/roster/widgets/request-item.ui')
class RequestItem(Gtk.Box):
"""Widget for displaying a saved request."""
__gtype_name__ = 'RequestItem'
method_label = Gtk.Template.Child()
name_label = Gtk.Template.Child()
__gsignals__ = {
'load-requested': (GObject.SIGNAL_RUN_FIRST, None, ()),
'delete-requested': (GObject.SIGNAL_RUN_FIRST, None, ()),
}
def __init__(self, saved_request):
super().__init__()
self.saved_request = saved_request
self.method_label.set_text(saved_request.request.method)
self.name_label.set_text(saved_request.name)
# Add click gesture for loading
gesture = Gtk.GestureClick.new()
gesture.connect('released', self._on_clicked)
self.add_controller(gesture)
def _on_clicked(self, gesture, n_press, x, y):
"""Handle click to load request."""
self.emit('load-requested')
@Gtk.Template.Callback()
def on_delete_clicked(self, button):
"""Handle delete button click."""
self.emit('delete-requested')