Пример #1
0
class _GraphicalSlider(_Slider, Element):

    def __init__(self, length, limvals=None, text="", elements=None,
                 normal_params=None):
        limvals = parameters.LIMVALS if limvals is None else limvals
        self._plus = None
        self._minus = None
        Element.__init__(self, text, elements, normal_params)
        _Slider.__init__(self, length, limvals)
        self.current_state.autoghost = False
##        self._set_wheel_reaction(parameters.BUTTON_UNPRESS_EVENT,
##                                {"button": parameters.WHEELUP_BUTTON})
##        self._set_unwheel_reaction(parameters.BUTTON_PRESS_EVENT,
##                                  {"button": parameters.WHEELDOWN_BUTTON})
        self._setup()
        self.active_wheel = False


    def get_storer_rect(self):
        return self.get_family_rect(constants.STATE_NORMAL)

    def move(self, shift):
        value_before = self.get_value()
        Element.move(self, shift)
        if self.get_value() != value_before:
            self._drag_element.place_at(value_before)

##    def _set_wheel_reaction(self, type_, args=None):
##        if not args:
##            args = {}
##        reac_wheelup = Reaction(type_, self._reaction_wheel, args,
##                                reac_name=constants.REAC_WHEELUP)
##
##    def _set_unwheel_reaction(self, type_, args=None):
##        if not args:
##            args = {}
##        reac_wheeldown = Reaction(type_, self._reaction_unwheel, args,
##                                  reac_name=constants.REAC_WHEELDOWN)
##
##    def _reaction_wheel(self, event):
##        if self.active_wheel:
##            if self.collide(event.pos, self.current_state_key):
##                self._drag_element.shift(parameters.WHEEL_SLIDER_SHIFT)
##
##    def _reaction_unwheel(self, event):
##        if self.active_wheel:
##            if self.collide(event.pos, self.current_state_key):
##                self._drag_element.shift(-parameters.WHEEL_SLIDER_SHIFT)

    def _setup(self):
        pass

    def _press_plus(self):
        # change state, blit and update
        functions.keypress(self._plus, constants.STATE_PRESSED)
        self._drag_element.shift()

    def _press_minus(self):
        # change state, blit and update
        functions.keypress(self._minus, constants.STATE_PRESSED)
        self._drag_element.shift(-1)

    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,
                                     {"id":constants.EVENT_TIME},
                                     reac_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,
                                     {"id":constants.EVENT_TIME},
                                     reac_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,
            {"id":constants.EVENT_PRESS, "el": self.plus})
        self._minus.reactions[constants.REAC_PRESSED +0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.minus},
            {"sign":-1})
        self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.plus})
        self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.minus},
            {"sign":-1})

##    def _get_no_slide_rect(self):
##        """Returns size without slide_rect"""
##        wh_slide = self._get_slide_rect().size
##        wh = self.get_fus_rect().size
##        return (wh[0] - wh_slide[0], wh[1] - wh_slide[1])

    def get_dragger(self):
        return self._drag_element

    def set_value(self, value):
        self.get_dragger().place_at(value)
Пример #2
0
class _GraphicalSlider(_Slider, Element):

    def __init__(self, length, limvals=None, text="", elements=None,
                 normal_params=None):
        limvals = parameters.LIMVALS if limvals is None else limvals
        self._plus = None
        self._minus = None
        Element.__init__(self, text, elements, normal_params)
        _Slider.__init__(self, length, limvals)
        self.current_state.autoghost = False
##        self._set_wheel_reaction(parameters.BUTTON_UNPRESS_EVENT,
##                                {"button": parameters.WHEELUP_BUTTON})
##        self._set_unwheel_reaction(parameters.BUTTON_PRESS_EVENT,
##                                  {"button": parameters.WHEELDOWN_BUTTON})
        self._setup()
        self.active_wheel = False

    def get_storer_rect(self):
        return self.get_family_rect(constants.STATE_NORMAL)

    def move(self, shift):
        value_before = self.get_value()
        Element.move(self, shift)
        if self.get_value() != value_before:
            self._drag_element.place_at(value_before)

##    def _set_wheel_reaction(self, typ, args=None):
##        if not args:
##            args = {}
##        reac_wheelup = Reaction(typ, self._reaction_wheel, args,
##                                reac_name=constants.REAC_WHEELUP)
##
##    def _set_unwheel_reaction(self, typ, args=None):
##        if not args:
##            args = {}
##        reac_wheeldown = Reaction(typ, self._reaction_unwheel, args,
##                                  reac_name=constants.REAC_WHEELDOWN)
##
##    def _reaction_wheel(self, event):
##        if self.active_wheel:
##            if self.collide(event.pos, self.current_state_key):
##                self._drag_element.shift(parameters.WHEEL_SLIDER_SHIFT)
##
##    def _reaction_unwheel(self, event):
##        if self.active_wheel:
##            if self.collide(event.pos, self.current_state_key):
##                self._drag_element.shift(-parameters.WHEEL_SLIDER_SHIFT)

    def _setup(self):
        pass

    def _press_plus(self):
        # change state, blit and update
        functions.keypress(self._plus, constants.STATE_PRESSED)
        self._drag_element.shift()

    def _press_minus(self):
        # change state, blit and update
        functions.keypress(self._minus, constants.STATE_PRESSED)
        self._drag_element.shift(-1)

    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,
                                     {"id":constants.EVENT_TIME},
                                     reac_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,
                                     {"id":constants.EVENT_TIME},
                                     reac_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,
            {"id":constants.EVENT_PRESS, "el": self.plus})
        self._minus.reactions[constants.REAC_PRESSED +0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.minus},
            {"sign":-1})
        self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.plus})
        self._reactions[constants.REAC_PRESSED + 0.1] = ConstantReaction(
            constants.THORPY_EVENT,
            self._drag_element.shift,
            {"id":constants.EVENT_PRESS, "el": self.minus},
            {"sign":-1})

##    def _get_no_slide_rect(self):
##        """Returns size without slide_rect"""
##        wh_slide = self._get_slide_rect().size
##        wh = self.get_fus_rect().size
##        return (wh[0] - wh_slide[0], wh[1] - wh_slide[1])

    def get_dragger(self):
        return self._drag_element

    def set_value(self, value):
        self.get_dragger().place_at(value)
Пример #3
0
class LiftY(SliderY):

    def __init__(self,
                 link,
                 text="",
                 elements=None,
                 dragsize=style.LIFT_DRAG_SIZE,
                 buttonsize=style.LIFT_BUTTON_SIZE,
                 normal_params=None):
        """<link> is the element affected by the lift"""
        dragsize = style.LIFT_DRAG_SIZE if dragsize is None else dragsize
        buttonsize=style.LIFT_BUTTON_SIZE if buttonsize is None else buttonsize
        link_h = link.get_fus_size()[1]  # get height of the linked element
        # set maxval to link height !!!! not link_h, but link_h - self_h
        limvals = (0, link_h)
        surplus_h = self._get_theo_size(buttonsize, dragsize, link_h,
                                       surplus=True)[1]
        length = link.get_fus_size()[1] - surplus_h  # compute proper height
        super(LiftY, self).__init__(length, limvals, text, elements,
                                    normal_params)
        self._add_buttons()
        self._linked = link
        self.finish()
        e_right = link.get_fus_rect().right
        l_width = self.get_fus_size()[0]
        x = e_right - l_width - style.LIFT_MARGINS[0]
        y = link.get_fus_rect().top + style.LIFT_MARGINS[1]
        self.set_topleft((x, y))
        self._drag_element.place_at(self.limvals[0])

    def _reaction_wheel(self, event):
        if self.active_wheel:
            if self.father.collide(event.pos, self.father.current_state_key):
                self._drag_element.shift(parameters.WHEEL_LIFT_SHIFT)

    def _reaction_unwheel(self, event):
        if self.active_wheel:
            if self.father.collide(event.pos, self.father.current_state_key):
                self._drag_element.shift(-parameters.WHEEL_LIFT_SHIFT)

    def get_value(self):
        return int(SliderY.get_value(self))

    def finish(self):
        SliderY.finish(self)
        self._finish_add()

    def misc_refresh(self):
        SliderY.misc_refresh(self)
        self._refresh_limvals()

    def _refresh_limvals(self, fact=1.):
        linked_family = fact * self._linked.get_family_rect().height
        selfh = self.get_fus_size()[1]
        uplim = max(1, linked_family - selfh)
        self.limvals = (0, uplim)

    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 _add_buttons(self, size=None):
        size = style.SMALL_SIZE if size is None else size
        self._plus = Plus()
        self._minus = Minus()
        self._plus.finish()
        self._minus.finish()
        self._plus.drag = self._drag_element
        self._minus.drag = self._drag_element
        reac_plus_time = ConstantReaction(constants.THORPY_EVENT,
                                     self._plus._reaction_time,
                                     {"id":constants.EVENT_TIME},
                                     reac_name=constants.REAC_MOUSE_REPEAT)
        self.add_reaction(reac_plus_time)
        reac_minus_time = ConstantReaction(constants.THORPY_EVENT,
                                     self._minus._reaction_time,
                                     {"id":constants.EVENT_TIME},
                                     reac_name=constants.REAC_MOUSE_REPEAT+0.1)
        self.add_reaction(reac_minus_time)
        self.add_elements([self._plus, self._minus])
        # reactions to mouse press:
        reac_pluspress2 = ConstantReaction(constants.THORPY_EVENT,
                                       self._drag_element.shift,
                                       {"el": self._plus,
                                        "id": constants.EVENT_PRESS},
                                       {"sign":parameters.CLICK_LIFT_SHIFT},
                                       reac_name=constants.REAC_PRESSED2)
        self.add_reaction(reac_pluspress2)
        reac_minuspress2 = ConstantReaction(constants.THORPY_EVENT,
                                    self._drag_element.shift,
                                    {"el": self._minus,
                                     "id": constants.EVENT_PRESS},
                                    {"sign":-parameters.CLICK_LIFT_SHIFT},
                                    reac_name=constants.REAC_PRESSED2+0.1)
        self.add_reaction(reac_minuspress2)

    def _finish_add(self, size=None):
        size = style.LIFT_BUTTON_SIZE if size is None else size
        rect = self.get_fus_rect()
        pos = (rect.centerx, rect.bottom + style.BUTTON_MARGINS[1] + size[1]/2)
        self._minus.set_center(pos)
        pos = (rect.centerx, rect.top - style.BUTTON_MARGINS[1] - size[1]/2)
        self._plus.set_center(pos)
        Ghost.fit_children(self)
        self._add_buttons_reactions()
Пример #4
0
class LiftY(SliderY):

    def __init__(self,
                 link,
                 text="",
                 elements=None,
                 dragsize=style.LIFT_DRAG_SIZE,
                 buttonsize=style.LIFT_BUTTON_SIZE,
                 normal_params=None):
        """<link> is the element affected by the lift"""
        dragsize = style.LIFT_DRAG_SIZE if dragsize is None else dragsize
        buttonsize=style.LIFT_BUTTON_SIZE if buttonsize is None else buttonsize
        link_h = link.get_fus_size()[1]  # get height of the linked element
        # set maxval to link height !!!! not link_h, but link_h - self_h
        limvals = (0, link_h)
        surplus_h = self._get_theo_size(buttonsize, dragsize, link_h,
                                       surplus=True)[1]
        length = link.get_fus_size()[1] - surplus_h  # compute proper height
        super(LiftY, self).__init__(length, limvals, text, elements,
                                    normal_params)
        self._add_buttons()
        self._linked = link
        self.finish()
        e_right = link.get_fus_rect().right
        l_width = self.get_fus_size()[0]
        x = e_right - l_width - style.LIFT_MARGINS[0]
        y = link.get_fus_rect().top + style.LIFT_MARGINS[1]
        self.set_topleft((x, y))
        self._drag_element.place_at(self._limvals[0])

    def _reaction_wheel(self, event):
        if self.active_wheel:
            if self.father.collide(event.pos, self.father.current_state_key):
                self._drag_element.shift(parameters.WHEEL_LIFT_SHIFT)

    def _reaction_unwheel(self, event):
        if self.active_wheel:
            if self.father.collide(event.pos, self.father.current_state_key):
                self._drag_element.shift(-parameters.WHEEL_LIFT_SHIFT)

    def get_value(self):
        return int(SliderY.get_value(self))

    def finish(self):
        SliderY.finish(self)
        self._finish_add()

    def misc_refresh(self):
        SliderY.misc_refresh(self)
        self._refresh_limvals()

    def _refresh_limvals(self, fact=1.):
        linked_family = fact * self._linked.get_family_rect().height
        selfh = self.get_fus_size()[1]
        uplim = max(1, linked_family - selfh)
        self._limvals = (0, uplim)

    def _setup(self, width=style.LIFT_BUTTON_SIZE[0],
              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)
        self.englobe_childrens()

    def _add_buttons(self, size=None):
        size = style.SMALL_SIZE if size is None else size
        self._plus = Plus()
        self._minus = Minus()
        self._plus.finish()
        self._minus.finish()
        self._plus.drag = self._drag_element
        self._minus.drag = self._drag_element
        reac_plus_time = ConstantReaction(constants.THORPY_EVENT,
                                     self._plus._reaction_time,
                                     {"id":constants.EVENT_TIME},
                                     reac_name=constants.REAC_MOUSE_REPEAT)
        self.add_reaction(reac_plus_time)
        reac_minus_time = ConstantReaction(constants.THORPY_EVENT,
                                     self._minus._reaction_time,
                                     {"id":constants.EVENT_TIME},
                                     reac_name=constants.REAC_MOUSE_REPEAT+0.1)
        self.add_reaction(reac_minus_time)
        self.add_elements([self._plus, self._minus])
        # reactions to mouse press:
        reac_pluspress2 = ConstantReaction(constants.THORPY_EVENT,
                                       self._drag_element.shift,
                                       {"el": self._plus,
                                        "id": constants.EVENT_PRESS},
                                       {"sign":parameters.CLICK_LIFT_SHIFT},
                                       reac_name=constants.REAC_PRESSED2)
        self.add_reaction(reac_pluspress2)
        reac_minuspress2 = ConstantReaction(constants.THORPY_EVENT,
                                    self._drag_element.shift,
                                    {"el": self._minus,
                                     "id": constants.EVENT_PRESS},
                                    {"sign":-parameters.CLICK_LIFT_SHIFT},
                                    reac_name=constants.REAC_PRESSED2+0.1)
        self.add_reaction(reac_minuspress2)

    def _finish_add(self, size=None):
        size = style.LIFT_BUTTON_SIZE if size is None else size
        rect = self.get_fus_rect()
        pos = (rect.centerx, rect.bottom + style.BUTTON_MARGINS[1] + size[1]/2)
        self._minus.set_center(pos)
        pos = (rect.centerx, rect.top - style.BUTTON_MARGINS[1] - size[1]/2)
        self._plus.set_center(pos)
        self.englobe_childrens()
        self._add_buttons_reactions()