def __init__(self, text: Text, size: Vector2D = None, position: Vector2D = Vector2D.zero(), color: Color = None, onclick=None): super(Button, self).__init__() # look self.text = text self.size = size if self.size is None: self.size = Vector2D(100, 35) self._position = position self.text.center(Vector2D.center(self.position, self.size)) # color if color is None: color = colors.TRANSPARENT self._mutable_color = color self._original_color = color # behaviour self.onhover = Hover(DIM_LIGHT, ORIGINAL_COLOR) self.onclick = onclick if self.onclick is None: self.onclick = lambda button: None
def __init__(self, text: Text, padding: Vector2D = Vector2D(20, 10), position: Vector2D = Vector2D.zero(), color: Color = None, onclick=None): super(Button, self).__init__() # look self.text = text self._position = position self.padding = padding self._size = Vector2D( self.text.rect.size[0] + self.padding.x, self.text.rect.size[1] + self.padding.y ) self.text.center(Vector2D.center(self.position, self.size)) # color if color is None: color = colors.TRANSPARENT self._mutable_color = color self._original_color = color # behaviour self.onhover = Hover(DIM_LIGHT, ORIGINAL_COLOR) self.onclick = onclick if self.onclick is None: self.onclick = lambda button: None # used to draw self.surface = self.make()
def position(self, value): self._position = value self.text.center(Vector2D.center(self.position, self.size))
# sorta = InsertionSort(bars.sizes[:]) # sorta = CycleSort(bars.sizes[:]) # sorta = QuickSort(bars.sizes[:], 0, len(bars.sizes) - 1) sorta = algorithms.MergeSort(bars.sizes[:]) # limit queue size to be safe ac = AlgorithmController(sorta, maxsize=10000) ac.start() # button to control algorithm flow flip_button = Button(Text('', color=colors.WHITE), size=Vector2D(70, 25), color=Color(0, 0, 0, 0), onclick=lambda _: should_sort.flip()) flip_button.position = Vector2D( Vector2D.center(screen.get_rect(), screen.get_rect().size).x - (flip_button.size.x / 2), 0) flip_button.onhover = Hover(BLACK_TEXT_WHITE_BACKGROUND, WHITE_TEXT_TRANSPARENT_BACKGROUND) def fbflip(val): flip_button.text.text = 'RUNNING' if val else 'STOPPED' fbflip(should_sort.get()) should_sort.on_flip = fbflip manager = WidgetManager([flip_button]) fc = FrameRate(limit=60) while True: