Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Locator

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88426] Re: [mg88393] Re: Locator
  • From: Ekta Obheroi <ektaobheroi at yahoo.ca>
  • Date: Mon, 5 May 2008 06:12:38 -0400 (EDT)

Hi Albert,
Thanks very much for the response. This will help me tremendously. I was also wondering if you can recommend some tutorials for the interactive component of 6.0. I have been going through the documentation slowly as well. Is there anything else?

Thanks


----- Original Message ----
From: Albert Retey <awnl at arcor.net>
To: mathgroup at smc.vnet.net
Sent: Saturday, May 3, 2008 4:20:28 AM
Subject: [mg88426] [mg88393] Re: Locator

Hi,

> Very recently I started using Mathematica with the hopes of accomplishing the following. I have had some progress by using extensively the documentation center, however, any help will be really appreciated. I have 2 questions in particular and have described them below:

Unusual things to try when starting to use Mathematica :-)

> I have created 3 notebooks with the following command:
> lst = Table[
>    NotebookCreate[WindowSize -> {240, 240}, WindowTitle -> "new", 
>     WindowMargins -> {{RandomInteger[{0, 100}], Automatic}, { Automatic, 
>        RandomInteger[{0, 50}]}}], {3}];
> 
>>From all the open notebooks I get the 3 newly generated notebooks and get their locations. The following command does work however, it gives me a red symbol in Mathematica which I assume means that something is missing. Any ideas as to what is missing?:
> newlst=Map[WindowMargins /. Options@# &, 
>  Select[Notebooks[], 
>   StringMatchQ[("WindowTitle" /. NotebookInformation[#]), "new"] &]]
> 
> I then retrieve the notebook locations for the 3 notebooks. 
> coord =  Map[({#[[1, 1]], #[[2, 2]] }) &, newlst]
> 
> Finally, I want to create locators for each of the above notebooks, such that when I move the locators the notebooks are moved. In other words, the {x,y} position of the locators is mapped to the WindowMargins of that particular notebook. I have successfully created the locators but I have no clue how to map the locators such that the notebooks are moved. Below is the code for it: 
> 
> DynamicModule[{pt = new1}, 
>  LocatorPane[Dynamic[pt], 
>   Dynamic@
>    ListPlot[pt, AxesOrigin -> {0, 0}, PlotRange -> {{0, 100}, {0, 50}}]]]
> 
> I can move the locators, but with the moving of locators I need to the move corresponding notebook. Any help would be of great help

when experimenting it is usually easier to get things working for a
simple case. Here I'll start of with one notebook. Note that
NotebookCreate returns a notebookobject which you can refer to later, so
there is no need to search Notebooks[] for it:

nb = NotebookCreate[
  WindowSize -> {240, 240},
  WindowMargins -> {
    {RandomInteger[{0, 100}], Automatic},
    {Automatic, RandomInteger[{0, 50}]}
    }
  ]

these define the screensizes and are handy lateron:

screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2, 2]]

screenwidth = (ScreenRectangle /. Options[$FrontEnd])[[1, 2]]

this is a function that moves the window for a given notebook to new
values of WindowMargins:

movenb[nb_, {x_, y_}] :=
SetOptions[nb,
  WindowMargins -> {{x, Automatic}, {Automatic, screenheight - y}}]

This shows a LocatorPane which will move the window. The trick is to use
the two argument version of Dynamic:

DynamicModule[{pt = {#1, screenheight - #2} & @@
    Flatten[WindowMargins /. Options[nb]][[{1, -1}]]},
LocatorPane[
  Dynamic[pt,
   Function[pt = #; movenb[nb, pt]; pt]
   ],
  Graphics[{},
   Frame -> True,
   PlotRange -> (ScreenRectangle /. Options[$FrontEnd])
   ]
  ]]

It turns out that handling lists is easier with this, which uses Locator
instead of LocatorPane and happens to be more compact in this case as well:

DynamicModule[{pt = {#1, screenheight - #2} & @@
    Flatten[WindowMargins /. Options[nb]][[{1, -1}]]},
Graphics[{Locator[Dynamic[pt,
     Function[pt = #; movenb[nb, pt]; pt]
     ]]},
  Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd])
  ]
]

now we are ready to work with a list of notebooks:

nblst = Table[NotebookCreate[
   WindowSize -> {240, 240},
   WindowMargins -> {
     {RandomInteger[{0, screenwidth}], Automatic},
     {Automatic, RandomInteger[{0, screenheight}]}
     }
   ], {3}]

This defines a graphics with one locator for each window:

nbcoords =
Map[Flatten[WindowMargins /. Options[#]][[{1, -1}]] &, nblst]

With[{screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2,
    2]]},
DynamicModule[{
   ptlst = {#1, screenheight - #2} & @@@ nbcoords
   },
  Graphics[{
    Table[
     With[{nn = n},
      Locator[
       Dynamic[ptlst[[nn]],
        Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]]
       ]
      ],
     {n, Length[nblst]}]
    },
   Frame -> True,
   PlotRange -> (ScreenRectangle /. Options[$FrontEnd])
   ]
  ]
]

to make it look nicer you might want to use rectangles as
representations for your windows. You might want them to be of the
correct relative size and use the top left corner for their positions to
reflect more closely the actual window on screen, which I did not
implement here:

Deploy@DynamicModule[{
   ptlst = {#1, screenheight - #2} & @@@ nbcoords
   },
  Graphics[{
    Table[
     With[{nn = n},
      Locator[
       Dynamic[ptlst[[nn]],
        Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]],
       Graphics[{Opacity[0.5], Rectangle[]}, ImageSize -> 48]
       ]
      ],
     {n, Length[nblst]}]
    },
   Frame -> True,
   PlotRange -> (ScreenRectangle /. Options[$FrontEnd]),
   FrameTicks -> None
   ]
  ]

hth,

albert



  • Prev by Date: Re: Re: function to check if array is empty
  • Next by Date: Re: Identical elements
  • Previous by thread: Re: Locator
  • Next by thread: Re: Locator