summaryrefslogtreecommitdiff
path: root/cad/src/exprs/outtakes/ToggleShow-outtakes.py
blob: 915bd1dd5caeeaea2364d8d1d002af0caea874e2 (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

# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details.
$Id$


old code for ToggleShow [nim], taken from testdraw2_cannib.py

# types
##ImageWidget = Widget # not sure if we want this to be a definite subtype
# could it be renamed to Image? possible name conflict (probably ok): import Image # from the PIL library
# I'll rename it.


# == ToggleAction

from __Symbols__ import stateref

ToggleAction = NamedLambda( ###e need to initialize the state if not there? NO, that's the job of the stateref (formula) itself!
    'ToggleAction',
    ((stateref, StateRef),),
    Set(stateref, not stateref) ### will 'not' be capturable by a formula?
        ## [update 061204: lhs and rhs are both wrong now, see Set.py -- lhs must be lval, rhs must be not stateref.value or so [nim]]
    )

# == ToggleButton

from __Symbols__ import stateref, false_icon, true_icon

ToggleButton = NamedLambda(
    'ToggleButton',
    ((stateref, StateRef),
     (false_icon, Image), #e add a default
     (true_icon, Image, false_icon), # same as false_icon, by default (default is a formula which can use prior symbols)
    ),
    Button(
        # plain image
        If(stateref,
           Overlay(Hidden(false_icon),Centered(true_icon)), # get the size of false_icon but the look of true_icon
               #e possible bugs: Centered might not work right if false_icon is not centered too; see also wrap/align options
               #e Overlay might work better outside, if otherwise something thinks the layout depends on the stateref state
           false_icon
        ),
        # highlighted image - ###e make this a lighter version of the plain image
        #e or a blue rect outlining the plain image -- I forget if Button assumes/implems the plain image always drawn under it...
        ###@@@ put this in somehow; missing things include my recollecting arg order of RectFrame, pixel units, dims of the icon, etc
        # actions -- for now, just do it immediately when pressed
        on_press = ToggleAction(stateref)
    ))

# == ToggleShow

ToggleFalseIcon = Rect(1,1,black) # stub
ToggleTrueIcon = Rect(1,1,gray) # stub

#e define default ToggleShow_stateref or StateRef value, in case env doesn't have one...

from __Symbols__ import thing, label, stateref

ToggleShow = NamedLambda(
    'ToggleShow',
    ((thing, Widget),
     (label, Widget, None),
     (stateref, StateRef, Automatic)),
        #e or should we specify a default stateref more explicitly? letting env override it as a feature of NamedLambda?
    Column( Row( ToggleButton(stateref, ToggleFalseIcon, ToggleTrueIcon),
                 label ),
            If( stateref, #k can you just plop in a stateref in place of asking for its value as a boolean? I guess so... it's a formula
                thing )
    ))

test_ToggleShow = ToggleShow( Rect(3,3,lightblue), "test_ToggleShow's label" )

#print test_ToggleShow