def _setup(self, width=None, dragsize=None): if width is None: width = style.LIFT_BUTTON_SIZE[0] if dragsize is None: dragsize = style.LIFT_DRAG_SIZE self._drag_element = DraggerLiftY(self) self._height = width painter = functions.obtain_valid_painter( painterstyle.DEF_PAINTER, pressed=True, color=style.DEF_COLOR2, size=( width, self._length + dragsize[1] + style.LIFT_MARGINS[1] + 1)) self.set_painter(painter) self._drag_element.set_painter( painterstyle.DEF_PAINTER( size=dragsize), autopress=False) try: self._drag_element.set_center((self.get_fus_center()[0], None)) except AttributeError: # state is ghost state, and has no fusionner self._drag_element.set_center((self.get_ghost_center()[0], None)) self._drag_element.set_free(y=False) Ghost.fit_children(self)
def __init__(self, text="", elements=None, normal_params=None, press_params=None, finish=True): """Pressable element.""" self.press_params = init_params(press_params) super(Pressable, self).__init__(text, elements, normal_params, finish=False) # painters if not press_params or not "painter" in press_params: painter = copy(self.normal_params.params.get("painter")) if not painter: painter = painterstyle.DEF_PAINTER(size=style.SIZE) painter.pressed = True self.press_params.params["painter"] = painter ## self.set_painter(painterstyle.DEF_PAINTER(size=style.SIZE)) # reactions self._set_press_reaction(parameters.BUTTON_PRESS_EVENT, {"button": parameters.LEFT_CLICK_BUTTON}) self._set_unpress_reaction(parameters.BUTTON_UNPRESS_EVENT, {"button": parameters.LEFT_CLICK_BUTTON}) if finish: self.finish()
def get_painter(self, painter=None): if "painter" in self.params: painter = self.params["painter"] elif not painter: painter = painterstyle.DEF_PAINTER(size=style.SIZE) paint_size = self.params.get("painter size") if paint_size: painter.size = paint_size return painter
def _add_buttons(self, size=None): size = style.SMALL_SIZE if size is None else size # _plus self._plus = Plus(text="+") self._plus.set_painter(painterstyle.DEF_PAINTER(size=size)) self._plus.finish() self._plus.drag = self._drag_element reac_plus = ConstantReaction(constants.THORPY_EVENT, self._plus._reaction_time, {"name": constants.EVENT_TIME}, name=constants.REAC_MOUSE_REPEAT) self.add_reaction(reac_plus) # _minus self._minus = Minus(text="-") self._minus.set_painter(painterstyle.DEF_PAINTER(size=size)) self._minus.finish() self._minus.drag = self._drag_element reac_minus = ConstantReaction(constants.THORPY_EVENT, self._plus._reaction_time, {"name": constants.EVENT_TIME}, name=constants.REAC_MOUSE_REPEAT + 0.1) self.add_reaction(reac_minus) self.add_elements([self._plus, self._minus]) # reactions to mouse _press (!= reactions to key _press): self._plus.reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction( constants.THORPY_EVENT, self._drag_element.shift, { "name": constants.EVENT_PRESS, "el": self.plus }) self._minus.reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction( constants.THORPY_EVENT, self._drag_element.shift, { "name": constants.EVENT_PRESS, "el": self.minus }, {"sign": -1}) self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction( constants.THORPY_EVENT, self._drag_element.shift, { "name": constants.EVENT_PRESS, "el": self.plus }) self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction( constants.THORPY_EVENT, self._drag_element.shift, { "name": constants.EVENT_PRESS, "el": self.minus }, {"sign": -1})
def __init__(self, text="", elements=None, normal_params=None, press_params=None): """To modify _press and _unpress reaction, assign new self._reaction_press and self._reaction_unpress functions !""" self.press_params = init_params(press_params) super(Pressable, self).__init__(text, elements, normal_params) # fusionner self.set_painter(painterstyle.DEF_PAINTER(size=style.SIZE)) # reactions self._set_press_reaction(parameters.BUTTON_PRESS_EVENT, {"button": parameters.LEFT_CLICK_BUTTON}) self._set_unpress_reaction(parameters.BUTTON_UNPRESS_EVENT, {"button": parameters.LEFT_CLICK_BUTTON})
def _setup(self, width=None, dragsize=None): width = style.LIFT_BUTTON_SIZE[0] if width is None else width dragsize = style.LIFT_DRAG_SIZE if dragsize is None else dragsize self._drag_element = DraggerDirViewerY(self) self._height = width painter = functions.obtain_valid_painter( painterstyle.DEF_PAINTER, color=style.DEF_COLOR2, pressed=True, size=(width, self._length + dragsize[1] + style.LIFT_MARGINS[1] + 1)) self.set_painter(painter) self._drag_element.set_painter(painterstyle.DEF_PAINTER(size=dragsize), autopress=False) self.current_state.ghost_rect.height = self._length try: self._drag_element.set_center((self.get_fus_center()[0], None)) except AttributeError: # state is ghost state, and has no fusionner self._drag_element.set_center((self.get_ghost_center()[0], None)) self._drag_element.set_free(y=False) self.englobe_childrens()