Coverage for skcvideo/button_widget.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-02 14:10 +0200

1import cv2 

2 

3from skcvideo.colors import WHITE 

4from skcvideo.core import Button 

5from skcvideo.utils import put_text 

6 

7 

8class ButtonWidget: 

9 def __init__(self, box, text, callback, data=None, color=WHITE, pressed_color=None): 

10 self.box = box 

11 self.text = text 

12 self._callback = callback 

13 self._is_pressed = False 

14 self.default_color = color 

15 if pressed_color is None: 

16 self.pressed_color = color 

17 else: 

18 self.pressed_color = pressed_color 

19 self.buttons = [Button(box, callback, data=data)] 

20 

21 @property 

22 def is_pressed(self): 

23 return self._is_pressed 

24 

25 def build(self, im): 

26 x1, y1, x2, y2 = self.box 

27 xc, yc = (x1 + x2) // 2, (y1 + y2) // 2 

28 

29 if self.is_pressed: 

30 color = self.pressed_color 

31 thickness = 2 

32 else: 

33 color = self.default_color 

34 thickness = 1 

35 

36 im = cv2.rectangle(im, (x1, y1), (x2, y2), color, thickness) 

37 put_text(im, self.text, (xc, yc), color=color) 

38 return im 

39 

40 def refresh(self, image, frame): 

41 pass 

42 

43 def callback(self, *args, **kwargs): 

44 self._is_pressed = not self._is_pressed 

45 return self._callback(*args, **kwargs)