Reworking some tab logic to omit adding a label widget
This commit is contained in:
parent
be7be00f78
commit
44ef6ea2bb
|
@ -20,7 +20,7 @@ def run():
|
|||
locale.setlocale(locale.LC_NUMERIC, 'C')
|
||||
|
||||
setproctitle(f"{app_name}")
|
||||
faulthandler.enable() # For better debug info
|
||||
# faulthandler.enable() # For better debug info
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
# Add long and short arguments
|
||||
|
|
|
@ -34,6 +34,7 @@ class GridMixin:
|
|||
|
||||
dir = tab.get_current_directory()
|
||||
files = tab.get_files()
|
||||
store.clear()
|
||||
|
||||
for file in files:
|
||||
store.append([None, file[0]])
|
||||
|
@ -84,8 +85,8 @@ class GridMixin:
|
|||
Gtk.main_iteration()
|
||||
return False
|
||||
|
||||
def create_tab_widget(self, tab):
|
||||
return TabHeaderWidget(tab, self.close_tab)
|
||||
def create_tab_widget(self):
|
||||
return TabHeaderWidget(self.close_tab)
|
||||
|
||||
def create_scroll_and_store(self, tab, wid, use_tree_view = False):
|
||||
scroll = Gtk.ScrolledWindow()
|
||||
|
|
|
@ -34,7 +34,7 @@ class TabMixin(GridMixin):
|
|||
else:
|
||||
tab.set_path(path)
|
||||
|
||||
tab_widget = self.create_tab_widget(tab)
|
||||
tab_widget = self.get_tab_widget(tab)
|
||||
scroll, store = self.create_scroll_and_store(tab, wid)
|
||||
index = notebook.append_page(scroll, tab_widget)
|
||||
notebook.set_tab_detachable(scroll, True)
|
||||
|
@ -51,6 +51,14 @@ class TabMixin(GridMixin):
|
|||
self.set_window_title()
|
||||
self.set_file_watcher(tab)
|
||||
|
||||
def get_tab_widget(self, tab):
|
||||
tab_widget = self.create_tab_widget()
|
||||
tab_widget.tab = tab
|
||||
|
||||
tab_widget.label.set_label(f"{tab.get_end_of_path()}")
|
||||
tab_widget.label.set_width_chars(len(tab.get_end_of_path()))
|
||||
|
||||
return tab_widget
|
||||
|
||||
def close_tab(self, button, eve = None):
|
||||
notebook = button.get_parent().get_parent()
|
||||
|
@ -84,12 +92,13 @@ class TabMixin(GridMixin):
|
|||
del watcher
|
||||
del tab
|
||||
|
||||
gc.collect()
|
||||
if not settings_manager.is_trace_debug():
|
||||
self.fm_controller.save_state()
|
||||
|
||||
self.set_window_title()
|
||||
|
||||
gc.collect()
|
||||
|
||||
# NOTE: Not actually getting called even tho set in the glade file...
|
||||
def on_tab_dnded(self, notebook, page, x, y):
|
||||
...
|
||||
|
@ -114,12 +123,13 @@ class TabMixin(GridMixin):
|
|||
def on_tab_switch_update(self, notebook, content = None, index = None):
|
||||
self.selected_files.clear()
|
||||
wid, tid = content.get_children()[0].get_name().split("|")
|
||||
|
||||
self.fm_controller.set_wid_and_tid(wid, tid)
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
def get_id_from_tab_box(self, tab_box):
|
||||
return tab_box.get_children()[2].get_text()
|
||||
return tab_box.tab.get_id()
|
||||
|
||||
def get_tab_label(self, notebook, icon_grid):
|
||||
return notebook.get_tab_label(icon_grid.get_parent()).get_children()[0]
|
||||
|
|
|
@ -84,8 +84,8 @@ class GridMixin:
|
|||
Gtk.main_iteration()
|
||||
return False
|
||||
|
||||
def create_tab_widget(self, tab):
|
||||
return TabHeaderWidget(tab, self.close_tab)
|
||||
def create_tab_widget(self):
|
||||
return TabHeaderWidget(self.close_tab)
|
||||
|
||||
def create_scroll_and_store(self, tab, wid, use_tree_view = False):
|
||||
scroll = Gtk.ScrolledWindow()
|
||||
|
|
|
@ -34,7 +34,7 @@ class TabMixin(GridMixin):
|
|||
else:
|
||||
tab.set_path(path)
|
||||
|
||||
tab_widget = self.create_tab_widget(tab)
|
||||
tab_widget = self.get_tab_widget(tab)
|
||||
scroll, store = self.create_scroll_and_store(tab, wid)
|
||||
index = notebook.append_page(scroll, tab_widget)
|
||||
notebook.set_tab_detachable(scroll, True)
|
||||
|
@ -53,6 +53,14 @@ class TabMixin(GridMixin):
|
|||
event_system.emit("set_window_title", (tab.get_current_directory(),))
|
||||
self.set_file_watcher(tab)
|
||||
|
||||
def get_tab_widget(self, tab):
|
||||
tab_widget = self.create_tab_widget()
|
||||
tab_widget.tab_id = tab.get_id()
|
||||
|
||||
tab_widget.label.set_label(f"{tab.get_end_of_path()}")
|
||||
tab_widget.label.set_width_chars(len(tab.get_end_of_path()))
|
||||
|
||||
return tab_widget
|
||||
|
||||
def close_tab(self, button, eve = None):
|
||||
notebook = button.get_parent().get_parent()
|
||||
|
@ -90,12 +98,13 @@ class TabMixin(GridMixin):
|
|||
del watcher
|
||||
del tab
|
||||
|
||||
gc.collect()
|
||||
if not settings_manager.is_trace_debug():
|
||||
self.fm_controller.save_state()
|
||||
|
||||
self.set_window_title()
|
||||
|
||||
gc.collect()
|
||||
|
||||
# NOTE: Not actually getting called even tho set in the glade file...
|
||||
def on_tab_dnded(self, notebook, page, x, y):
|
||||
...
|
||||
|
@ -119,13 +128,13 @@ class TabMixin(GridMixin):
|
|||
|
||||
def on_tab_switch_update(self, notebook, content = None, index = None):
|
||||
self.selected_files.clear()
|
||||
wid, tid = content.get_children()[0].get_name().split("|")
|
||||
wid, tid = content.get_children()[0].tab.get_name().split("|")
|
||||
self.fm_controller.set_wid_and_tid(wid, tid)
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
def get_id_from_tab_box(self, tab_box):
|
||||
return tab_box.get_children()[2].get_text()
|
||||
return tab_box.tab.get_id()
|
||||
|
||||
def get_tab_label(self, notebook, icon_grid):
|
||||
return notebook.get_tab_label(icon_grid.get_parent()).get_children()[0]
|
||||
|
|
|
@ -103,7 +103,7 @@ class MessagePopupWidget(Gtk.Popover):
|
|||
self.popup()
|
||||
self.hide_message_timeout(seconds)
|
||||
|
||||
@threaded
|
||||
@daemon_threaded
|
||||
def hide_message_timeout(self, seconds=3):
|
||||
time.sleep(seconds)
|
||||
GLib.idle_add(event_system.emit, ("hide_messages_popup"))
|
||||
|
|
|
@ -9,14 +9,12 @@ from gi.repository import Gtk
|
|||
|
||||
|
||||
|
||||
|
||||
class TabHeaderWidget(Gtk.Box):
|
||||
"""docstring for TabHeaderWidget"""
|
||||
|
||||
def __init__(self, tab, close_tab):
|
||||
def __init__(self, close_tab):
|
||||
super(TabHeaderWidget, self).__init__()
|
||||
|
||||
self._tab = tab
|
||||
self._close_tab = close_tab # NOTE: Close method in tab_mixin
|
||||
|
||||
self._setup_styling()
|
||||
|
@ -32,25 +30,19 @@ class TabHeaderWidget(Gtk.Box):
|
|||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
label = Gtk.Label()
|
||||
tid = Gtk.Label()
|
||||
self.label = Gtk.Label()
|
||||
close = Gtk.Button()
|
||||
icon = Gtk.Image(stock=Gtk.STOCK_CLOSE)
|
||||
|
||||
label.set_label(f"{self._tab.get_end_of_path()}")
|
||||
label.set_width_chars(len(self._tab.get_end_of_path()))
|
||||
label.set_xalign(0.0)
|
||||
label.set_margin_left(25)
|
||||
label.set_margin_right(25)
|
||||
label.set_hexpand(True)
|
||||
tid.set_label(f"{self._tab.get_id()}")
|
||||
self.label.set_xalign(0.0)
|
||||
self.label.set_margin_left(25)
|
||||
self.label.set_margin_right(25)
|
||||
self.label.set_hexpand(True)
|
||||
|
||||
close.connect("released", self._close_tab)
|
||||
|
||||
close.add(icon)
|
||||
self.add(label)
|
||||
self.add(self.label)
|
||||
self.add(close)
|
||||
self.add(tid)
|
||||
|
||||
self.show_all()
|
||||
tid.hide()
|
||||
|
|
Loading…
Reference in New Issue