Message Boards Message Boards

1
|
8563 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Avoid enter-shift on CDF user interface?

Posted 9 years ago

Hello, I am developing apps and deploying as CDF file. I would like to prevent user shift-enter and run the GUI to create second one. An example code is :

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "DummyPackage.wl"}]];
Panel[DynamicModule[{np = 100, nd = 30, Res = 1.0}, 
  Column[{Style["Random", "Function"] , 
    Row[{"Digits ", InputField[Dynamic[nd]]}, Spacer[5]], 
    Row[{"Precision ", InputField[Dynamic[np]]}, Spacer[5]], 
    Button[Style["Calculate", Green, Bold], 
     Res = DummyPackage`myDummyF[nd, np], Method -> "Queued"], 
    Row[{Style["Result ", 12, Red], 
      InputField[Dynamic[Res], FieldSize -> 30, Enabled -> False]}, 
     Spacer[15]]

    }],
  Initialization :> (
    Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
        "DummyPackage.wl"}]];)]]

It is just random multiplication. And the package file is

BeginPackage["DummyPackage`"]
myDummyF[nd_,np_]:=Module[{mat,mat2,aI},

ns=200;
mat=SetAccuracy[RandomReal[{-100,100},ns],nd];
mat2=SetAccuracy[RandomReal[{-200,200},ns],nd];

d=0;
aI=ConstantArray[0,np];
SetSharedVariable[aI,d];

Time=AbsoluteTiming[
If[nd<=16,
Monitor[Do[
If[iC==2,Print["Do Loop"]];
aI[[iC]]=SetAccuracy[mat.(mat2/iC^0.5),nd],{iC,np}],ProgressIndicator[Dynamic[iC/np]]],
Monitor[ParallelDo[d++;
If[iC==2,Print[" ParallelDo Loop"]];
aI[[iC]]=SetAccuracy[mat.(mat2/iC^0.5),nd];
,{iC,np}],
ProgressIndicator[Dynamic[d/np]]]]];

Print["Do loop time = ",Time[[1]],", np = ",np,", nd = ",nd];
aInum=Apply[Plus,(aI/np)];
Print["Total = ",aInum];
Return[aInum]];
SetAttributes[{myDummyF},{ReadProtected,Protected,Locked}];
EndPackage[];

I create a cdf file using these two files and I get the cdf file in the attachment. In the CDF file I can shift-enter and create a second user interface. In the following CDF book example I can't do that and I wonder how that is done.

https://www.wolfram.com/cdf/uses-examples/textbooks.html

enter image description here

POSTED BY: Erdem Uguz
5 Replies

This problem is on my list of things to do for notebooks in general, not just CDF. You can't expect a user to just hit return or tab.

There is a command called EventHandler that deals with low lever events. I am hoping that this will enable me to 'swallow' shift-enter events, or at least turn them into return, when an input field is active.

suppressReturn = EventHandler[#, {
        {"MenuCommand", "HandleShiftReturn"}  :> {}, 
        {"MenuCommand", "EvaluateCells"}      :> {}
}] &;

In InputField, how to prevent Shift-Return from generating a new cell? (comments are relevant too)

POSTED BY: Kuba Podkalicki
Posted 9 years ago

I am not sure if I am following the use of EvenHandler, from the link that you gave , I tried to put something together but still the same behavior.

DynamicModule[{x = ""}, 
 Column[{EventHandler[
    InputField[Dynamic[x], 
     String], {{"MenuCommand", 
       "HandleShiftReturn"} :> {} {"MenuCommand", 
         "EvaluateCells"} :> {}}], Dynamic[x]}]]
POSTED BY: Erdem Uguz

Except of missing coma after the first {} it is what I meant. It works ok in Mathematica and Player. No additional cell is created after Shift+Enter or num pad Enter.

POSTED BY: Kuba Podkalicki
Posted 9 years ago

That prevents even the creation of the inputfield. I would like to create the inputfield but I would like to prevent to create a second inputfield by simply shift+enter to the 1st inputfield.

POSTED BY: Erdem Uguz
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