From 2f68c7c6d8e3957cb112cd19b970e57296167aa2 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 8 Jun 2020 06:49:27 -0500 Subject: [PATCH 1/5] Reduce item.GetState() calls to 1 With a toolbar(s) with x amount of buttons reduce the number of calls from possibly 3-6 each iteration down to 1. --- wx/lib/agw/aui/auibar.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index df1d75a1..e6303485 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -1007,27 +1007,28 @@ class AuiDefaultToolBarArt(object): bmp_rect, text_rect = self.GetToolsPosition(dc, item, rect) - if not item.GetState() & AUI_BUTTON_STATE_DISABLED: + item_state = item.GetState() + if not item_state & AUI_BUTTON_STATE_DISABLED: - if item.GetState() & AUI_BUTTON_STATE_PRESSED: + if item_state & AUI_BUTTON_STATE_PRESSED: dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 150))) dc.DrawRectangle(rect) - elif item.GetState() & AUI_BUTTON_STATE_HOVER or item.IsSticky(): + elif item_state & AUI_BUTTON_STATE_HOVER or item.IsSticky(): dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) # draw an even lighter background for checked item hovers (since # the hover background is the same colour as the check background) - if item.GetState() & AUI_BUTTON_STATE_CHECKED: + if item_state & AUI_BUTTON_STATE_CHECKED: dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 180))) dc.DrawRectangle(rect) - elif item.GetState() & AUI_BUTTON_STATE_CHECKED: + elif item_state & AUI_BUTTON_STATE_CHECKED: # it's important to put this code in an else statment after the # hover, otherwise hovers won't draw properly for checked items @@ -1035,10 +1036,9 @@ class AuiDefaultToolBarArt(object): dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) dc.DrawRectangle(rect) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: bmp = item.GetDisabledBitmap() - elif item.GetState() & AUI_BUTTON_STATE_HOVER or \ - item.GetState() & AUI_BUTTON_STATE_PRESSED: + elif item_state & AUI_BUTTON_STATE_HOVER or item_state & AUI_BUTTON_STATE_PRESSED: bmp = item.GetHoverBitmap() if not bmp: bmp = item.GetBitmap() @@ -1050,7 +1050,7 @@ class AuiDefaultToolBarArt(object): # set the item's text colour based on if it is disabled dc.SetTextForeground(wx.BLACK) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: dc.SetTextForeground(DISABLED_TEXT_COLOUR) if self._agwFlags & AUI_TB_TEXT and item.GetLabel() != "": From 861e0511c0d16b425b86befa01b941ddc700cfa1 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 8 Jun 2020 07:00:54 -0500 Subject: [PATCH 2/5] Reduce item.GetState() calls --- wx/lib/agw/aui/auibar.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index e6303485..ca7faa41 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -1093,21 +1093,22 @@ class AuiDefaultToolBarArt(object): bmp_rect, text_rect = self.GetToolsPosition(dc, item, button_rect) - if item.GetState() & AUI_BUTTON_STATE_PRESSED: + item_state = item.GetState() + if item_state & AUI_BUTTON_STATE_PRESSED: dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 140))) dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - elif item.GetState() & AUI_BUTTON_STATE_HOVER or item.IsSticky(): + elif item_state & AUI_BUTTON_STATE_HOVER or item.IsSticky(): dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - elif item.GetState() & AUI_BUTTON_STATE_CHECKED: + elif item_state & AUI_BUTTON_STATE_CHECKED: # it's important to put this code in an else statment after the # hover, otherwise hovers won't draw properly for checked items dc.SetPen(wx.Pen(self._highlight_colour)) @@ -1115,7 +1116,7 @@ class AuiDefaultToolBarArt(object): dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: bmp = item.GetDisabledBitmap() dropbmp = self._disabled_button_dropdown_bmp @@ -1125,8 +1126,10 @@ class AuiDefaultToolBarArt(object): bmp = item.GetBitmap() dropbmp = self._button_dropdown_bmp - if bmp.IsOk(): - dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) + if not bmp.IsOk(): + return + + dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) if horizontal: dc.DrawBitmap(dropbmp, dropbmp_x, dropbmp_y, True) else: @@ -1135,7 +1138,7 @@ class AuiDefaultToolBarArt(object): # set the item's text colour based on if it is disabled dc.SetTextForeground(wx.BLACK) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: dc.SetTextForeground(DISABLED_TEXT_COLOUR) if self._agwFlags & AUI_TB_TEXT and item.GetLabel() != "": From fe028d7dad571bbe8cc8a466edfbfd84f9d76935 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 8 Jun 2020 07:03:11 -0500 Subject: [PATCH 3/5] revert mistaked line --- wx/lib/agw/aui/auibar.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index ca7faa41..688a3027 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -1127,9 +1127,8 @@ class AuiDefaultToolBarArt(object): dropbmp = self._button_dropdown_bmp if not bmp.IsOk(): - return + dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) - dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) if horizontal: dc.DrawBitmap(dropbmp, dropbmp_x, dropbmp_y, True) else: From 1dcd1772cd64aab42afd89c5380bb44f3f2f5db3 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 8 Jun 2020 07:04:17 -0500 Subject: [PATCH 4/5] revert mistaked line again --- wx/lib/agw/aui/auibar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index 688a3027..0c18268d 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -1126,7 +1126,7 @@ class AuiDefaultToolBarArt(object): bmp = item.GetBitmap() dropbmp = self._button_dropdown_bmp - if not bmp.IsOk(): + if bmp.IsOk(): dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) if horizontal: From d710c0ffcc8f0d1d36a0dc985c3befaf0ee29706 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 8 Jun 2020 06:49:27 -0500 Subject: [PATCH 5/5] Reduce item.GetState() calls to 1 With a toolbar(s) with x amount of buttons reduce the number of calls from possibly 3-6 each iteration down to 1. --- wx/lib/agw/aui/auibar.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/wx/lib/agw/aui/auibar.py b/wx/lib/agw/aui/auibar.py index df1d75a1..0c18268d 100644 --- a/wx/lib/agw/aui/auibar.py +++ b/wx/lib/agw/aui/auibar.py @@ -1007,27 +1007,28 @@ class AuiDefaultToolBarArt(object): bmp_rect, text_rect = self.GetToolsPosition(dc, item, rect) - if not item.GetState() & AUI_BUTTON_STATE_DISABLED: + item_state = item.GetState() + if not item_state & AUI_BUTTON_STATE_DISABLED: - if item.GetState() & AUI_BUTTON_STATE_PRESSED: + if item_state & AUI_BUTTON_STATE_PRESSED: dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 150))) dc.DrawRectangle(rect) - elif item.GetState() & AUI_BUTTON_STATE_HOVER or item.IsSticky(): + elif item_state & AUI_BUTTON_STATE_HOVER or item.IsSticky(): dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) # draw an even lighter background for checked item hovers (since # the hover background is the same colour as the check background) - if item.GetState() & AUI_BUTTON_STATE_CHECKED: + if item_state & AUI_BUTTON_STATE_CHECKED: dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 180))) dc.DrawRectangle(rect) - elif item.GetState() & AUI_BUTTON_STATE_CHECKED: + elif item_state & AUI_BUTTON_STATE_CHECKED: # it's important to put this code in an else statment after the # hover, otherwise hovers won't draw properly for checked items @@ -1035,10 +1036,9 @@ class AuiDefaultToolBarArt(object): dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) dc.DrawRectangle(rect) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: bmp = item.GetDisabledBitmap() - elif item.GetState() & AUI_BUTTON_STATE_HOVER or \ - item.GetState() & AUI_BUTTON_STATE_PRESSED: + elif item_state & AUI_BUTTON_STATE_HOVER or item_state & AUI_BUTTON_STATE_PRESSED: bmp = item.GetHoverBitmap() if not bmp: bmp = item.GetBitmap() @@ -1050,7 +1050,7 @@ class AuiDefaultToolBarArt(object): # set the item's text colour based on if it is disabled dc.SetTextForeground(wx.BLACK) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: dc.SetTextForeground(DISABLED_TEXT_COLOUR) if self._agwFlags & AUI_TB_TEXT and item.GetLabel() != "": @@ -1093,21 +1093,22 @@ class AuiDefaultToolBarArt(object): bmp_rect, text_rect = self.GetToolsPosition(dc, item, button_rect) - if item.GetState() & AUI_BUTTON_STATE_PRESSED: + item_state = item.GetState() + if item_state & AUI_BUTTON_STATE_PRESSED: dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 140))) dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - elif item.GetState() & AUI_BUTTON_STATE_HOVER or item.IsSticky(): + elif item_state & AUI_BUTTON_STATE_HOVER or item.IsSticky(): dc.SetPen(wx.Pen(self._highlight_colour)) dc.SetBrush(wx.Brush(StepColour(self._highlight_colour, 170))) dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - elif item.GetState() & AUI_BUTTON_STATE_CHECKED: + elif item_state & AUI_BUTTON_STATE_CHECKED: # it's important to put this code in an else statment after the # hover, otherwise hovers won't draw properly for checked items dc.SetPen(wx.Pen(self._highlight_colour)) @@ -1115,7 +1116,7 @@ class AuiDefaultToolBarArt(object): dc.DrawRectangle(button_rect) dc.DrawRectangle(dropdown_rect) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: bmp = item.GetDisabledBitmap() dropbmp = self._disabled_button_dropdown_bmp @@ -1127,6 +1128,7 @@ class AuiDefaultToolBarArt(object): if bmp.IsOk(): dc.DrawBitmap(bmp, bmp_rect.x, bmp_rect.y, True) + if horizontal: dc.DrawBitmap(dropbmp, dropbmp_x, dropbmp_y, True) else: @@ -1135,7 +1137,7 @@ class AuiDefaultToolBarArt(object): # set the item's text colour based on if it is disabled dc.SetTextForeground(wx.BLACK) - if item.GetState() & AUI_BUTTON_STATE_DISABLED: + if item_state & AUI_BUTTON_STATE_DISABLED: dc.SetTextForeground(DISABLED_TEXT_COLOUR) if self._agwFlags & AUI_TB_TEXT and item.GetLabel() != "":