Skip to content

Commit

Permalink
Make so File->Open->Browse also works with image files that have QR c…
Browse files Browse the repository at this point in the history
…odes.

Removed some dialog jank that happened when you opened a URl picture, because the SimpleDialog brings itself to the front after some delays.
Some smaller improvements like internationalizing the text of file upload dialog, not leaving dangling promt-dialogs.
  • Loading branch information
wcjohns committed Feb 26, 2025
1 parent 0ce3a2f commit 2997174
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 46 deletions.
17 changes: 17 additions & 0 deletions InterSpec/SimpleDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class SimpleDialog : public Wt::WDialog
SimpleDialog( const Wt::WString &title, const Wt::WString &content );
~SimpleDialog();

/** See notes for \c m_multipleBringToFront, but basically this is an over-ride to avoid
jank when creating multiple SimpleDialogs at the same time (or close together anyway).
You must call this function before initial render of the dialog for it to have any effect.
*/
void doNotUseMultpleBringstoFront();

/** Add a button to the footer.
Buttons are added left-to-right, and clicking on them will cause the dialog to hide and become deleted, so you dont need to worry
Expand Down Expand Up @@ -100,6 +107,16 @@ class SimpleDialog : public Wt::WDialog
This pointer is never accessed from this class, but may be updated by derived classes.
*/
Wt::WText *m_msgContents;

/** When this dialog is initially rendered, some javascript will run on a delay, and a few times
to make sure it is the front-most window (specifically for on mobile when you create a QR
code by tapping on a AuxWindows title button, which then calls that windows bring to front
on a delay).
However, this can create some jank, specifically when you upload a picture that finds a QR
code. So this variable allows us to override the default behavior.
*/
bool m_multipleBringToFront;
};//class SimpleDialog


Expand Down
2 changes: 1 addition & 1 deletion InterSpec/SpecMeasManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SpecMeasManager : public Wt::WObject
static void fileTooLarge( const ::int64_t size_tried );

//The dataUploaded(..) with two arguments is to help keep from having to
// parse file twice to display when SpectraHeader is not cahcing the
// parse file twice to display when SpectraHeader is not caching the
// SpecMeas obj.
//XXX - The dataUploaded() with one argument is called whe a user uploads from
// the 'File Manager' screen - when they will probably want to load the
Expand Down
4 changes: 4 additions & 0 deletions InterSpec_resources/app_text/InterSpec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<message id="Distance">Distance</message>
<message id="Activity">Activity</message>
<message id="Remark">Remark</message>
<message id="Tap">Tap</message>
<message id="Click">Click</message>
<message id="tap">tap</message>
<message id="click">click</message>


<!-- Words not used in InterSpec.cpp, but at least a few places throughout the app -->
Expand Down
19 changes: 18 additions & 1 deletion InterSpec_resources/app_text/SpecMeasManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
smm- is short for Spectrum Measurement Manager
musd- is short for MultiUrlSpectrumDialog
uid- is short for UploadedImgDisplay.
fud- is short for FileUploadDialog
-->
<message id="smm-window-title">Spectrum Manager</message>
<message id="smm-load-spec-from">Load spectrum from: </message>
Expand All @@ -29,6 +30,7 @@
<message id="smm-empty-file">File was probably an empty file - not a spectrum file.</message>
<message id="smm-failed-reading-nonspec-file">Failed to read non-spectrum file.</message>
<message id="smm-not-spec-file">Not a spectrum file</message>
<message id="smm-image-file">Image File Selected</message>
<message id="smm-icd2">This looks to be an N42 ICD2 file that contains analysis results
rather than raw spectra.
<br />
Expand Down Expand Up @@ -278,7 +280,22 @@
- but the displayed background <b>HAS NOT</b> been updated.
</message>


<message id="fud-dialog-title">Select File To Open</message>
<message id="fud-open-foreground-only-msg">{1} below to choose a foreground spectrum file to open.</message>
<message id="fud-open-any-type-msg">Select how you would like to open the spectrum file, and then {1} below to browse for the file.</message>
<message id="fud-btn-grp-title">Open file as:</message>
<message id="fud-drg-n-drop-msg">
You can also drag and drop the file directly into the <br />
application window as a quicker alternative.<br />
<br />For more advanced file opening and<br />
manipulation use the <b>File Manager</b>
</message>
<message id="fud-drg-n-drop-msg-mbl">
<span style="font-size: 10px;">
You can also open spectrum files from email or file apps.
</span>
</message>

<message id="musd-dialog-title">Multi-part QR/URL Spectrum</message>
<message id="musd-err-diff-spec">URL/QR-code received was from a different spectrum than previous URL/QR-code</message>
<message id="musd-err-duplicate-url">Have already received this URL/QR-code</message>
Expand Down
2 changes: 1 addition & 1 deletion src/DoseCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace DoseCalc
{
const float energy = energies[energyInd];
const float I_0 = intensity[energyInd];
// const double mu = MassAttenuation::massAttenuationCoeficientFracAN( an, energy );
// const double mu = MassAttenuation::massAttenuationCoefficientFracAN( an, energy );
// const double transmittion = exp( -mu * areal_density );

const float hydrogen_frac_ad = 0.0f;
Expand Down
37 changes: 24 additions & 13 deletions src/SimpleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ WT_DECLARE_WT_MEMBER
SimpleDialog::SimpleDialog()
: Wt::WDialog( InterSpec::instance() ), //for lifetime purposes
m_title( nullptr ),
m_msgContents( nullptr )
m_msgContents( nullptr ),
m_multipleBringToFront( true )
{
init( "", "" );
}
Expand All @@ -75,7 +76,8 @@ SimpleDialog::SimpleDialog()
SimpleDialog::SimpleDialog( const Wt::WString &title )
: Wt::WDialog( InterSpec::instance() ), //for lifetime purposes
m_title( nullptr ),
m_msgContents( nullptr )
m_msgContents( nullptr ),
m_multipleBringToFront( true )
{
init( title, "" );
}
Expand All @@ -84,7 +86,8 @@ SimpleDialog::SimpleDialog( const Wt::WString &title )
SimpleDialog::SimpleDialog( const Wt::WString &title, const Wt::WString &content )
: Wt::WDialog( InterSpec::instance() ), //for lifetime purposes
m_title( nullptr ),
m_msgContents( nullptr )
m_msgContents( nullptr ),
m_multipleBringToFront( true )
{
init( title, content );
}
Expand Down Expand Up @@ -118,6 +121,19 @@ void SimpleDialog::render( Wt::WFlags<Wt::RenderFlag> flags )
wApp->doJavaScript(wApp->javaScriptClass() + ".RaiseWinCntrlsAboveCover();");
}
#endif

// On mobile, it seems Wt.WT.AuxWindowBringToFront(...) may get called after this window is
// created (happens on the "QR code" link on Nuclide Decay Tool - since the user clicks
// a button in the titlebar), which will bring that dialog above this one - which isnt wanted,
// so we'll manually bring this dialog to the top on a delay.
// We'll add this JS, even on non-mobile, JIC
LOAD_JAVASCRIPT(wApp, "SimpleDialog.cpp", "SimpleDialog", wtjsSimpleDialogBringToFront);

const string time_delays_array = m_multipleBringToFront ? "[5,100,500]" : "[5]";

doJavaScript( "for( const d of " + time_delays_array + "){"
"setTimeout( function(){ Wt.WT.SimpleDialogBringToFront('" + id() + "');}, d);"
"}");
}//if( flags & RenderFull )
}//render( flags )

Expand Down Expand Up @@ -163,16 +179,6 @@ void SimpleDialog::init( const Wt::WString &title, const Wt::WString &content )
// I havent checked version of Wt that does include `raiseToFront()`, but 3.3.4 doesnt.
raiseToFront();
#endif

// On mobile, it seems Wt.WT.AuxWindowBringToFront(...) may get called after this window is
// created (happens on the "QR code" link on Nuclide Decay Tool - since the user clicks
// a button in the titlebar), which will bring that dialog above this one - which isnt wanted,
// so we'll manually bring this dialog to the top on a delay.
// We'll add this JS, even on non-mobile, JIC
LOAD_JAVASCRIPT(wApp, "SimpleDialog.cpp", "SimpleDialog", wtjsSimpleDialogBringToFront);
doJavaScript( "for( const d of [5,100,500]){"
"setTimeout( function(){ Wt.WT.SimpleDialogBringToFront('" + id() + "');}, d);"
"}");
}//init(...)


Expand All @@ -181,6 +187,11 @@ SimpleDialog::~SimpleDialog()
}


void SimpleDialog::doNotUseMultpleBringstoFront()
{
m_multipleBringToFront = false;
}

Wt::WPushButton *SimpleDialog::addButton( const Wt::WString &txt )
{
Wt::WPushButton *b = new WPushButton( txt, footer() );
Expand Down
Loading

0 comments on commit 2997174

Please sign in to comment.