Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Re: suggestion for frontend

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51954] Re: [mg51879] Re: suggestion for frontend
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Fri, 5 Nov 2004 02:19:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

My reply is interwoven below:

>-----Original Message-----
>From: David Bailey [mailto:dave at Remove_Thisdbailey.co.uk]
To: mathgroup at smc.vnet.net
>Sent: Thursday, November 04, 2004 07:50
>To: mathgroup at smc.vnet.net
>Subject: [mg51954] [mg51879] Re: suggestion for frontend
>
>
>Hi,
>
>I wish someone would make the frontend API a bit more rounded. For
>example, although you can set the selection in a notebook, there is no
>way of determining EXACTLY where the selection is before you start - so
>you can't perform a task and leave the user with his selection
>unchanged. This seems to be typical of a lot of frontend functionality.

You might use the undocumented function CellInformation, mentioned by John
Fultz in [mg51798] and [mg51847] recently. You might use it wrapped into the
following functions:

ReadCellInformation[
    notebook_NotebookObject] := (LinkWrite[$ParentLink,
      CellInformation[notebook]];
LinkRead[$ParentLink]);

ReadCursorPosition[
    notebook_NotebookObject] := ("CursorPosition" /.
      Flatten[ReadCellInformation[notebook]]);

ReadCellSerialNumbers[notebook_NotebookObject] :=
  Cases[ReadCellInformation[notebook], (Rule["CellSerialNumber", x_]) -> x,
2];

I would like the ability to get back to a given selection after I have moved
away from it.

>A few general priciples come to mind:
>
>1) If you can set the state of something you should also be able to read
>it back.

One example related to this is that NotebookWrite[nb, NotebookRead[nb]] does
not always leave the notebook unaltered. If the selection is within a
textcell, and the selection contains a inline cell, text content after the
inline cell in turned into Box form, which is not always wanted. That is
connected to the bad design choice (bug?) that the TextData wrapper is
stripped off the item read by NotebookRead from a text cell. It then is
impossible (without using CellInformation or reading the notebook in another
way) to know if the read item is e.g. a set of ordinary cells or a set of
inline cells. My way to handle this is to use the following replacement for
NotebookRead:

MyNotebookRead[nb_] :=
  Module[{clipboardcontent, readitem, evalnb}, readitem = NotebookRead[nb];
    Which[readitem == {}, Null,
      ListQ[readitem], evalnb = EvaluationNotebook[];
      SelectionMove[ClipboardNotebook[], All, Notebook];
      clipboardcontent = NotebookRead[ClipboardNotebook[]];
      SetSelectedNotebook[nb]; FrontEndExecute[FrontEndToken["Copy"] ];
      SetSelectedNotebook[evalnb];
      SelectionMove[ClipboardNotebook[], All, Notebook];
      readitem = NotebookRead[ClipboardNotebook[]];
      SelectionMove[ClipboardNotebook[], All, Notebook];
      NotebookWrite[ClipboardNotebook[], clipboardcontent];
      If[MatchQ[readitem, Cell[TextData[__], "Text"]],
        readitem = readitem[[1]]]]; readitem]

It should be possible to rewrite this routine, using CellInformation instead
of ClipboardNotebook[], but that maybe should wait until CellInformation
becomes an official documented function.


>2) If there is a difficult way of achieving something - say augmenting
>the Mathematica menus - and support has described this to customers, why
>not add an easy-to-use API at the next version?
>
>3) Programmed notebook manipulations can go wrong if the user is
>manipulating the notebook at the same time. It would be very valuable to
>be able to lock the user out (unless perhaps they abort) while a
>sequence of operations is performed.

You might lock out the user from an individual notebook temporarily. Say
that the notebook object is nb.

Lock by

SetOptions[nb, WindowClickSelect -> False,
    Editable -> False, Selectable -> False, Background -> GrayLevel[0.8]];
If[SelectedNotebook[] == nb, invisible=NotebookCreate[Visible -> False];
    SetSelectedNotebook[invisible]];

Unlock by

SetOptions[nb, WindowClickSelect -> True, Editable -> True,
    Selectable -> True, Background -> GrayLevel[1]];
If[SelectedNotebook[] == invisible, NotebookClose[invisible];
  SetSelectedNotebook[nb]];

Maybe I am changing too many options, but this seems to work. You might of
course remove the graying feature if you do not like it.

>If there are already ways to do any of the above, I am sure someone here
>will supply them!

At least partially

>David Bailey

Regards

Ingolf Dahl
ingolf.dahl at telia.com
Sweden


  • Prev by Date: Re: Re: Zero divided by a number...
  • Next by Date: Re: Publicon LaTeX conversion problems
  • Previous by thread: Re: suggestion for frontend
  • Next by thread: Re: suggestion for frontend