2025-12-28 19:53:05 -06:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
import gi
|
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TabWidget(Gtk.Box):
|
2026-02-16 17:11:30 -06:00
|
|
|
"""docstring for TabWidget"""
|
|
|
|
|
|
2025-12-28 19:53:05 -06:00
|
|
|
def __init__(self):
|
|
|
|
|
super(TabWidget, self).__init__()
|
|
|
|
|
|
2026-02-16 23:52:03 -06:00
|
|
|
self.file = None
|
|
|
|
|
|
|
|
|
|
self._handler_id = None
|
|
|
|
|
self._eve_handler_id = None
|
2025-12-28 19:53:05 -06:00
|
|
|
|
|
|
|
|
self._setup_styling()
|
|
|
|
|
self._setup_signals()
|
|
|
|
|
self._load_widgets()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_styling(self):
|
|
|
|
|
ctx = self.get_style_context()
|
|
|
|
|
ctx.add_class("tab-widget")
|
|
|
|
|
|
2026-02-16 17:11:30 -06:00
|
|
|
self.set_orientation(0)
|
|
|
|
|
self.set_hexpand(False)
|
2026-02-24 22:30:07 -06:00
|
|
|
self.set_vexpand(False)
|
|
|
|
|
self.set_size_request(-1, 12)
|
2025-12-28 19:53:05 -06:00
|
|
|
|
2026-02-16 17:11:30 -06:00
|
|
|
def _setup_signals(self):
|
2025-12-28 19:53:05 -06:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
def _load_widgets(self):
|
2026-02-16 23:52:03 -06:00
|
|
|
self.event_box = Gtk.EventBox()
|
|
|
|
|
self.label = Gtk.Label()
|
|
|
|
|
self.close_bttn = Gtk.Button()
|
|
|
|
|
icon = Gtk.Image(stock = Gtk.STOCK_CLOSE)
|
2025-12-28 19:53:05 -06:00
|
|
|
|
2026-02-16 23:52:03 -06:00
|
|
|
self.event_box.set_above_child(True)
|
2025-12-28 19:53:05 -06:00
|
|
|
ctx = self.label.get_style_context()
|
|
|
|
|
ctx.add_class("tab-label")
|
2026-02-16 23:52:03 -06:00
|
|
|
ctx = self.close_bttn.get_style_context()
|
2025-12-28 19:53:05 -06:00
|
|
|
ctx.add_class("tab-close-bttn")
|
|
|
|
|
|
2026-02-16 17:11:30 -06:00
|
|
|
self.label.set_xalign(0.0)
|
|
|
|
|
self.label.set_margin_left(25)
|
|
|
|
|
self.label.set_margin_right(25)
|
2025-12-28 19:53:05 -06:00
|
|
|
self.label.set_hexpand(True)
|
|
|
|
|
|
2026-02-16 23:52:03 -06:00
|
|
|
self.close_bttn.add(icon)
|
|
|
|
|
self.event_box.add(self.label)
|
|
|
|
|
self.add(self.event_box)
|
|
|
|
|
self.add(self.close_bttn)
|
2025-12-28 19:53:05 -06:00
|
|
|
|
2026-02-16 17:11:30 -06:00
|
|
|
self.show_all()
|
|
|
|
|
|
2026-01-03 21:57:37 -06:00
|
|
|
def clear_signals_and_data(self):
|
2026-02-16 23:52:03 -06:00
|
|
|
self.close_bttn.disconnect(self._handler_id)
|
|
|
|
|
self.event_box.disconnect(self._eve_handler_id)
|
|
|
|
|
self._handler_id = None
|
2025-12-28 22:44:44 -06:00
|
|
|
|
2026-02-16 17:11:30 -06:00
|
|
|
for child in self.get_children():
|
|
|
|
|
child.unparent()
|
|
|
|
|
child.run_dispose()
|
|
|
|
|
child.destroy()
|
2025-12-28 22:44:44 -06:00
|
|
|
|
|
|
|
|
def set_close_signal(self, callback):
|
2026-02-16 23:52:03 -06:00
|
|
|
self._handler_id = self.close_bttn.connect(
|
|
|
|
|
'clicked',
|
2026-02-16 17:11:30 -06:00
|
|
|
callback,
|
|
|
|
|
self.file
|
|
|
|
|
)
|