Message Boards Message Boards

Non-rotatable Graphics3D occurs in conjunction with drag&drop file import

Dear Community Members,

I'm experiencing a bit of strange behaviour in a dynamically generated plot. I have a piece of code that imports a file and returns a Graphics3D object based on coordinates it reads from the file. Now I'd like to provide an InputField into which users can drag and drop the file, and dynamically get the plot in a separate panel. I want the plot to appear or change only when the cursor is no longer inside the InputField (which is the default behaviour of InputField anyway), so the user has to click someplace else in order to trigger the plot. That's all working nicely, except for one thing: It seems to matter just where that click goes.

I made a minimum dummy code example so that you can try to reproduce the problem; I'm using Mathematica 9.0.1 on Windows 7 and 8, so I don't know if the problem occurs with other operating systems.
 DynamicModule[{file = Null}, Grid[{{
     InputField[Dynamic[file],
      FieldHint ->
       "Drag and drop a file here while holding " <>
        Switch[$OperatingSystem, "Windows", "ctrl+shift", "Unix",
         "shift", "MacOSX", "option", _, "the keyboard shortcut"
         ] <> "."
      ], Button["clear", file = Null]
     }, {
    Dynamic[
     If[MatchQ[file, _String], Graphics3D[{Red, Cuboid[]}],
      "no file selected"], TrackedSymbols :> {file}], SpanFromLeft
    }}]]
Note that the code above doesn't actually do anything with the file, it just  triggers the plot when the file name changes, so you can use any file you happen to have handy. Also, the input field will tell you how to actually drag and drop the file based on your operating system.

When you've dragged your file into the InputField (don't hit enter), click a place outside the output cell: The Graphics3D will appear and it will be rotatable just as it should be. No problems here.

Now press "clear", drag the file over again, but this time, click between the input field and the "clear" button to trigger the dynamic reaction: The Graphics3D appears, but you cannot rotate it. This also happens for some other places inside the output cell, but strangely not for all. Interestingly, this also happens when you don't click anywhere but instead trigger the plot by hitting Return while still inside the InputField.

Most interestingly, the same behaviour does in fact not occur when you manually enter a string into the InputField rather than dragging a file into it, no matter where you click next (or whether you go for Return instead).

I'm rather puzzled by this phenomenon and would appreciate any hints on its origins, and of course on how to prevent it (other than changing the FieldHint to advise clicking outside the output cell, which seems grossly inelegant). It looks a bit like a bug, but maybe I'm just misusing some functionality.

Thank you in advance for any answers... and for reading my lengthy ramblings.

Bianca
POSTED BY: Bianca Eifert
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract