summaryrefslogtreecommitdiff
path: root/cad/src/exprs/DraggableHandle_AlongCircle.py
blob: 66c5ab931f78d0d5f364e16e4219e5bddd517bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""
$Id$
"""

from utilities.constants import white

from exprs.attr_decl_macros import Instance, Option
from exprs.transforms import Translate
from exprs.Center import Center
from exprs.ExprsConstants import StateRef, Vector
from exprs.ExprsConstants import Point, Drawable
from exprs.ExprsConstants import ORIGIN, DX ##,DY
from exprs.Highlightable import Highlightable
from exprs.Rect import Rect
from exprs.Exprs import tuple_Expr
from exprs.__Symbols__ import _self
from exprs.instance_helpers import DelegatingInstanceOrExpr
from exprs.DragBehavior_AlongCircle import DragBehavior_AlongCircle
from exprs.Set import Action

class DraggableHandle_AlongCircle(DelegatingInstanceOrExpr):
    """
    A kind of draggable handle which can be dragged along a line
    to change the value of a single floating point parameter
    (representing position along the line, using a scale and origin
    determined by our arguments).

    ### TODO: add epydoc parameters to this docstring? not sure that will work for a class!
    Maybe we need to synthesize those (from the doc options below) into a fake __init__ method for its sake??
    """
    # == args and options

    # options for appearance of handle
    appearance = Option( Drawable,
                         Center(Rect(0.2, 0.2, white)),
                         doc = "appearance, when not highlighted")

    appearance_highlighted = Option( Drawable,
                                     appearance,
                                     doc = "appearance, when highlighted")

    sbar_text = Option(str,
                       "draggable handle along circle",
                       doc = "statusbar text on mouseover")

    # state variable controlled by dragging
    rotationDistanceRef = Option(StateRef,
                                doc = "stateref to a dragged disctance variable")


    # action options, for Highlightable to do after the ones that come from
    # DragBehavior_AlongLine [new feature of this and Highlightable, 080129]
    on_press = Option(Action)
    on_drag = Option(Action)
    on_release = Option(Action)
    on_release_in = Option(Action, on_release)
    on_release_out = Option(Action, on_release)
    on_doubleclick = Option(Action)

    #origin of the handle itself
    origin = Option( Point, ORIGIN)

    # Center of the circle whose perimeter serves as a path along which to
    # drag
    center = Option( Point, ORIGIN)

    #Axis of the circle.
    axis  = Option( Vector, DX, doc = "vector giving direction and scale")

    #radius Vector
    radiusVector = Option( Vector,
                           DX,
                           doc = "vector giving direction and scale")

    #angle range for the rotation
    range_for_rotation = Option(tuple_Expr,
                                None,
                                doc = "range limit of angle (tuple)")


    # == internal instances and formulae (modified from test_statearray_3.py)

    _drag_handler = Instance(
        DragBehavior_AlongCircle(
            _self._delegate,
            rotationDistanceRef,
            origin,
            center,
            axis,
            radiusVector,
            range_for_rotation = range_for_rotation))


    #QUESTION: Should the 'RotateTranslate' transform from exprs.transforms be
    #used here? -- Ninad 2008-02-13
    delegate = \
        Highlightable(
            Translate(
                appearance,
                _drag_handler._rotation #k ok?? only if that thing hangs around even in between drags, i guess!
                    #e #k not sure if this code-commoning is good, but it's tempting. hmm.
             ),
            highlighted = Translate(
                appearance_highlighted,
                _drag_handler._rotation
             ),
            sbar_text = sbar_text,
            behavior = _drag_handler,
            on_press = _self.on_press,
            on_drag = _self.on_drag,
            # (note: no need to pass on_release)
            on_release_in = _self.on_release_in,
            on_release_out = _self.on_release_out,
            on_doubleclick = _self.on_doubleclick,
         )


    pass # end of class