Message Boards Message Boards

1
|
5694 Views
|
1 Reply
|
3 Total Likes
View groups...
Share
Share this post:

How would I find the notebook object associated with InputString?

Posted 11 years ago
InputString[""]
Creates a notebook object.
By doing this:
Dynamic@Column[Notebooks[]]
I was able to determine that the notebook which is created by InputString[] is displayed like this:


So that I can ensure that this NotebookOject is the selected one (thus ensuring that all typed text goes there), I need to
SetSelectedNotebook on this NotebookObject.

However, I can't see any way of getting at the NotebookObject associated with an instance of InputString[].

The Question: Does anyone know how I would find this NotebookObject?


You may wonder why one might need to do this. Note that
Module[{anumber},
anumber = InputString["enter a number", WindowFloating -> True];
anumber^2
]
does not set the InputString's NotebookObject to the SelectedNotebook

Postscript to Post: I've solved the problem by replacing InputString with a simple Input[]. The question remains, but is not urgent for my purposes.
POSTED BY: W. Craig Carter
Hello:

The dialog created by InputString[] is from before the days that Dynamic[] was implemented in Mathematica.  It probably does not play particularly well with the new kids.

However, there should be a way to do what you want using InputField[] instead.  Many of the dialogs within Mathematica are just Mathematica notebooks implemented in this way.  Examples include the dialogs from File->'Install...' and Edit->'Preferences...'.  The following is a bit crude but it is essentially an approximation of what InputString[] would look like if implemented using InputField[], with the yellowing showing that you can still access the notebook after the value has been entered:

 Block[{anumber},
  DynamicModule[{holder = "", running = True},
   notebook =
    CreateDocument[
     ExpressionCell[
      EventHandler[
       InputField[Dynamic[holder],
        String], {"ReturnKeyDown" :> (running = False)}]],
     WindowSize -> {400, 100}];
  SelectionMove[notebook, Before, Notebook];
  SelectionMove[notebook, Next, Cell];
  SelectionMove[notebook, After, CellContents];
  SelectionMove[notebook, Previous, Character];
  SelectionMove[notebook, Previous, Character];
  While[And[running, "" === holder], Pause[.1]];
  anumber = holder;
  SetOptions[notebook, Background -> Yellow];
  Pause[1];
  NotebookClose[notebook];
  ];
anumber^2
]

Also, there is the possibility of using 
InputField[Dynamic[holder], Number]
instead of 
InputField[Dynamic[holder], String]
which would guarantee that you were making the square of a number instead of a string.

I am sure that this does not answer all of your questions, but hopefully it will allow you to create a novel new set of them.
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