From 215f02bb8705f2d0f431fcf5a0a01b647fb8d3a5 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Tue, 11 Jan 2022 12:30:08 +0100 Subject: [PATCH] Implement channel list shrinking on cleanup --- gui.py | 15 ++++++++++++++- twitch.py | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gui.py b/gui.py index 96de7d3..9c0c3bd 100644 --- a/gui.py +++ b/gui.py @@ -583,6 +583,10 @@ class ChannelList: # we need this because columns have 9-10 pixels of padding that cuts text off return self._font.measure(text) + 10 + def _redraw(self): + # this forces a redraw that recalculates widget width + self._table.event_generate("<>") + def _adjust_width(self, column: str, value: str): # causes the column to expand if the value's width is greater than the current width if column in self._const_width: @@ -591,7 +595,16 @@ class ChannelList: curr_width = self._table.column(column, "width") if value_width > curr_width: self._table.column(column, minwidth=value_width, width=value_width) - self._table.event_generate("<>") # force redraw + self._redraw() + + def shrink(self): + # causes the columns to shrink back after long values have been removed from it + columns = self._table.cget("columns") + iids = self._table.get_children() + for column in columns: + width = max(self._measure(self._table.set(i, column)) for i in iids) + self._table.column(column, minwidth=width, width=width) + self._redraw() def _set(self, iid: str, column: str, value: str): self._table.set(iid, column, value) diff --git a/twitch.py b/twitch.py index 6bba8d6..9568ae4 100644 --- a/twitch.py +++ b/twitch.py @@ -212,6 +212,7 @@ class Twitch: for channel in to_remove: del self.channels[channel.id] channel.remove() + self.gui.channels.shrink() self.change_state(State.CHANNEL_FETCH) elif self._state is State.CHANNEL_FETCH: if selected_game is None: