14
$\begingroup$

Background: I want to split graphics in a Manipulate in several parts in a tabview control. But the tabview somehow interferes with the locators as in the following simplified example:

 Manipulate[
  TabView[{aa -> Graphics[Line[{{0, 0}, p}], PlotRange -> 1], 
    bb -> 1}] , {{p, {1, 1}}, Locator}]

Question: How to use Locators on a graphic in a tabview. ( How to get the snippet above working ? )

EDIT:

I left out too much in the previous example, this is a better description.

  Manipulate[
   pts1 = pts;
  TabView[{
    a -> Graphics[Line[pts1]],
    b -> Graphics[Line[pts]]}],
  {{pts, ptsI}, Locator, LocatorAutoCreate -> All}, 
  Initialization -> {pts = {{0, 0.5}, {0, 0.6}}}]

So, there is one set of data, in this example pts. In one part of the display (A) the data is modified, the data is then shown on ( B ). -

$\endgroup$

4 Answers 4

20
$\begingroup$

Maybe something like

pltrng = {{-1, 1}, {-1, 1}};

Manipulate[pnts = LocatorPane[Dynamic[p], 
   Dynamic @ Graphics[Point[p], PlotRange -> pltrng], 
   LocatorAutoCreate -> True];
 tbl = Dynamic @ Grid[MapIndexed[{#2[[1]], #} &, p]];
 ln = Dynamic @  Graphics[{Red, Thick, Line[p]}, PlotRange -> pltrng]; 
 bzc = Dynamic @ Graphics[{Blue, BezierCurve[p]}, PlotRange -> pltrng];
 dsk = Dynamic @ Graphics[{Orange, Disk[#, .1] & /@ p}, PlotRange -> pltrng];
 plygn = Dynamic@ Graphics[{Green, Polygon[p]}, PlotRange -> pltrng];
 allviews =  Grid[{{pnts, tbl, dsk}, {ln, bzc, plygn}}, Dividers -> {All, All}];
 Dynamic @ TabView[{"locators" -> pnts, "table" -> tbl, "line" -> ln, 
   "beziercurve" -> bzc, "disks" -> dsk, "polygon" -> plygn, "all" -> allviews}, 
   Alignment -> Center], 
 {{p, {{-.5, -0.5}, {-.25, .5}, {.6, 0.6}}}, None}]

enter image description here

$\endgroup$
9
  • $\begingroup$ Very nice! I think this is exactly what he had in mind. However, the LocatorAutoCreate doesn't work as expected for me... Instead of creating a new one, it simply moves the previously selected one. $\endgroup$
    – rm -rf
    Commented May 14, 2012 at 2:45
  • $\begingroup$ @R.M Works OK for me. Remember to press "Alt - Mouse Click" instead of just "Mouse Click" to create a Locator $\endgroup$ Commented May 14, 2012 at 3:49
  • $\begingroup$ @R.M and belisarius thank you for the votes. I had to change the setting for LocatorAutoCreate to True from All in OP's question. With this setting, as belisarius notes, one needs to use Alt-Click to create a new locator. $\endgroup$
    – kglr
    Commented May 14, 2012 at 4:24
  • 1
    $\begingroup$ @ndroock1, glad it worked for you. $\endgroup$
    – kglr
    Commented May 14, 2012 at 6:31
  • 1
    $\begingroup$ @kglr In your last edit, you removed the assignment pts1 = p but didn't update all the instances where pts1 occur. $\endgroup$
    – Michael E2
    Commented Dec 13, 2020 at 20:08
9
$\begingroup$

One way to get it working is to do something like

Manipulate[TabView[{
   aa -> LocatorPane[Dynamic[p], Dynamic@Graphics[Line[{{0, 0}, p}], PlotRange -> 1]], 
   bb -> 1}], 
 {{p, {1, 1}}, None}]
$\endgroup$
3
  • 1
    $\begingroup$ This one has the additional benefit of allowing the usage of Dynamic[p] on the second tab $\endgroup$ Commented May 13, 2012 at 19:05
  • $\begingroup$ This works Heike, it may or may not be a solution to my problem but it definitely gives me something to study and work on. I just need a LOT of screen real estate to display graphics and manipulate it with controls. The best way to handle this is with tabs in my opinion and a lot of programs work like that. $\endgroup$ Commented May 13, 2012 at 19:09
  • $\begingroup$ I have edited ( improved ) the question. Your solution did not work ( immediately ) but I am still working with your idea. $\endgroup$ Commented May 13, 2012 at 19:34
5
$\begingroup$

You can move the TabView outside the Manipulate and it works:

TabView[{
    aa -> Manipulate[Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator}], 
    bb -> 1}
]

enter image description here enter image description here

$\endgroup$
5
  • $\begingroup$ Damn ... by 10 seconds :) $\endgroup$ Commented May 13, 2012 at 18:58
  • $\begingroup$ @belisarius :-D $\endgroup$
    – rm -rf
    Commented May 13, 2012 at 18:59
  • $\begingroup$ I have Manipulates per tabview at the moment and that causes a lot of sync problems. $\endgroup$ Commented May 13, 2012 at 19:03
  • $\begingroup$ @ndroock1 I don't quite understand what you mean by "manipulates per tabview" $\endgroup$
    – rm -rf
    Commented May 13, 2012 at 19:04
  • $\begingroup$ @R.M - Like TabView[a->Manipulate[],b->Manipulate[],...] that works somewhat with an outer Manipulate but it is infact a workaround for the problem proposed in this question. $\endgroup$ Commented May 13, 2012 at 20:54
-1
$\begingroup$

This works for me if I change parameter list name coherently:

pltrng = {{-1, 1}, {-1, 1}};

Manipulate[
 pnts = LocatorPane[Dynamic[p], 
   Dynamic@Graphics[Point[p], PlotRange -> pltrng], 
   LocatorAutoCreate -> True];
 tbl = Dynamic@Grid[MapIndexed[{#2[[1]], #} &, p]];
 ln = Dynamic@Graphics[{Red, Thick, Line[p]}, PlotRange -> pltrng];
 bzc = Dynamic@Graphics[{Blue, BezierCurve[p]}, PlotRange -> pltrng];
 dsk = Dynamic@
   Graphics[{Orange, Disk[#, .1] & /@ p}, PlotRange -> pltrng];
 plygn = Dynamic@Graphics[{Green, Polygon[p]}, PlotRange -> pltrng];
 allviews = 
  Grid[{{pnts, tbl, dsk}, {ln, bzc, plygn}}, Dividers -> {All, All}];
 Dynamic@TabView[{"locators" -> pnts, "table" -> tbl, "line" -> ln, 
    "beziercurve" -> bzc, "disks" -> dsk, "polygon" -> plygn, 
    "all" -> allviews}, 
   Alignment -> Center], {{p, {{-.5, -0.5}, {-.25, .5}, {.6, 0.6}}}, 
  None}]

enter image description here

This shows that LocatorAutoCreate works brilliantly. Press Mac-button on MacOS and the Windows-button in addition and simultaneous with the positioning click, right-click.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.