14

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 ). -

nilo de roock
  • 9,657
  • 3
  • 35
  • 77

4 Answers4

20

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

kglr
  • 394,356
  • 18
  • 477
  • 896
  • 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. – rm -rf May 14 '12 at 02:45
  • @R.M Works OK for me. Remember to press "Alt - Mouse Click" instead of just "Mouse Click" to create a Locator – Dr. belisarius May 14 '12 at 03:49
  • @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. – kglr May 14 '12 at 04:24
  • @belisarius Ah, thanks. Cmd-click for me. Indeed, it was because of what kguler says in his comment... I tried the OP's code which had All and created locators with a simple click and tried that here too :) – rm -rf May 14 '12 at 04:30
  • Exactly what I was looking for. Thank you very much!! – nilo de roock May 14 '12 at 06:28
  • 1
    @ndroock1, glad it worked for you. – kglr May 14 '12 at 06:31
  • LocatorAutoCreate requires an additional button to be pressed. On MacOS this is the Mac-Button next to the Spacebar. Look up the documentation for LocatorAutoCreate on your OS. – Steffen Jaeschke Dec 13 '20 at 19:08
  • 1
    @kglr In your last edit, you removed the assignment pts1 = p but didn't update all the instances where pts1 occur. – Michael E2 Dec 13 '20 at 20:08
  • thanks @MichaelE2 for catching the edit glitch. Will fix in a moment. – kglr Dec 13 '20 at 20:16
9

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}]
Heike
  • 35,858
  • 3
  • 108
  • 157
  • 1
    This one has the additional benefit of allowing the usage of Dynamic[p] on the second tab – Dr. belisarius May 13 '12 at 19:05
  • 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. – nilo de roock May 13 '12 at 19:09
  • I have edited ( improved ) the question. Your solution did not work ( immediately ) but I am still working with your idea. – nilo de roock May 13 '12 at 19:34
5

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

rm -rf
  • 88,781
  • 21
  • 293
  • 472
-1

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.

Steffen Jaeschke
  • 4,088
  • 7
  • 20