From fbb4af9918f4d4abccd74ad93f2c42298184b4ca Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Tue, 27 Sep 2016 00:10:49 +0300 Subject: [PATCH] Add DoubleStageButton widget --- TODO | 1 - youtube_dl_gui/mainframe.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 2359178..653e86e 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ NEW_LAYOUT ========== * Create new button widget (groups, auto width) -* Create new button with two stages (like toggle) * Settings menu add "Statistics" * Swap some of the Error messages with Info * Add clear list button ? diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 01d1ef1..55c8d71 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -1190,3 +1190,36 @@ class ExtComboBox(wx.ComboBox): def LoadMultiple(self, items_list): for item in items_list: self.Append(item) + + +class DoubleStageButton(wx.Button): + + def __init__(self, parent, labels, bitmaps, bitmap_pos=wx.TOP, *args, **kwargs): + super(DoubleStageButton, self).__init__(parent, *args, **kwargs) + + assert isinstance(labels, tuple) and isinstance(bitmaps, tuple) + assert len(labels) == 2 + assert len(bitmaps) == 0 or len(bitmaps) == 2 + + self.labels = labels + self.bitmaps = bitmaps + self.bitmap_pos = bitmap_pos + + self._stage = 0 + self._set_layout() + + def _set_layout(self): + self.SetLabel(self.labels[self._stage]) + + if len(self.bitmaps): + self.SetBitmap(self.bitmaps[self._stage], self.bitmap_pos) + + def change_stage(self): + self._stage = 0 if self._stage else 1 + self._set_layout() + + def set_stage(self, new_stage): + assert new_stage == 0 or new_stage == 1 + + self._stage = new_stage + self._set_layout()