Coverage for src/robotide/widgets/button.py: 95%

32 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

1# Copyright 2008-2015 Nokia Networks 

2# Copyright 2016- Robot Framework Foundation 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15 

16import os 1ad

17import wx 1ad

18from wx import Colour, BitmapBundle 1ad

19 

20 

21class ButtonWithHandler(wx.Button): 1ad

22 

23 def __init__(self, parent, label, mk_handler=None, handler=None, width=-1, bitmap=None, 1ad

24 height=25, color_secondary_foreground='black', color_secondary_background='light grey', fsize=10): 

25 fsize = max(8, fsize) 1acb

26 bt_image = None 1acb

27 style = 0 1acb

28 name = label 1acb

29 if bitmap is not None and isinstance(bitmap, str): 1acb

30 img_path = os.path.join(os.path.dirname(__file__), bitmap) 1ab

31 bt_image = BitmapBundle.FromFiles(img_path) 1ab

32 label = 'config_panel' 1ab

33 width = height 1ab

34 style = wx.BU_EXACTFIT | wx.BU_NOTEXT | wx.BORDER_NONE 1ab

35 if width == -1: 1acb

36 width = len(label) * fsize 1ac

37 size = wx.Size(width, height) 1acb

38 wx.Button.__init__(self, parent, label=label, size=size, style=style, name=name) 1acb

39 if bt_image is not None: 1acb

40 self.SetBitmap(bt_image) 1ab

41 self.SetBitmapLabel(bt_image) 1ab

42 self.SetToolTip(name) 1ab

43 self.SetBackgroundColour(Colour(color_secondary_background)) 1acb

44 self.SetOwnBackgroundColour(Colour(color_secondary_background)) 1acb

45 self.SetForegroundColour(Colour(color_secondary_foreground)) 1acb

46 # self.SetOwnForegroundColour(Colour(color_secondary_foreground)) 

47 if not handler or mk_handler: 1acb

48 if not mk_handler: 48 ↛ 49line 48 didn't jump to line 49 because the condition on line 48 was never true1ac

49 name = 'on_%s' % label.strip().replace(' ', '_').lower() 

50 else: 

51 name = 'on_%s' % mk_handler.strip().replace(' ', '_').lower() 1ac

52 handler = getattr(parent, name) 1ac

53 parent.Bind(wx.EVT_BUTTON, handler, self) 1acb