commit/StationPlaylist: josephsl: Bug hunters 3: NVDA will now pop up an error dialog if attempting to open more than one instance of an alarm dialog.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Sun, 01 Mar 2015 21:05:32 -0000

1 new commit in StationPlaylist:

https://bitbucket.org/nvdaaddonteam/stationplaylist/commits/14bbe593066d/
Changeset:   14bbe593066d
Branch:      bugHunters/multiInstance
User:        josephsl
Date:        2015-03-01 20:39:33+00:00
Summary:     Bug hunters 3: NVDA will now pop up an error dialog if attempting 
to open more than one instance of an alarm dialog.
For now, borrowed features from exit dialog code from GUI package. This allows 
only one instance of the alarm dialog to be active. At this point, end of track 
dialog has been modified to take advantage of this.
Refinements to come in later commits.

Affected #:  2 files

diff --git a/addon/appModules/splstudio/__init__.py 
b/addon/appModules/splstudio/__init__.py
index 45dcbeb..bf2255e 100755
--- a/addon/appModules/splstudio/__init__.py
+++ b/addon/appModules/splstudio/__init__.py
@@ -516,16 +516,21 @@ class AppModule(appModuleHandler.AppModule):
        # Set the end of track alarm time between 1 and 59 seconds.
 
        def script_setEndOfTrackTime(self, gesture):
-               timeVal = splconfig.SPLConfig["EndOfTrackTime"]
-               d = splconfig.SPLAlarmDialog(gui.mainFrame, "EndOfTrackTime", 
"SayEndOfTrack",
-               # Translators: The title of end of track alarm dialog.
-               _("End of track alarm"),
-               # Translators: A dialog message to set end of track alarm 
(curAlarmSec is the current end of track alarm in seconds).
-               _("Enter &end of track alarm time in seconds (currently 
{curAlarmSec})").format(curAlarmSec = timeVal),
-               "&Notify when end of track is approaching", 1, 59)
-               gui.mainFrame.prePopup()
-               d.Show()
-               gui.mainFrame.postPopup()
+               try:
+                       timeVal = splconfig.SPLConfig["EndOfTrackTime"]
+                       d = splconfig.SPLAlarmDialog(gui.mainFrame, 
"EndOfTrackTime", "SayEndOfTrack",
+                       # Translators: The title of end of track alarm dialog.
+                       _("End of track alarm"),
+                       # Translators: A dialog message to set end of track 
alarm (curAlarmSec is the current end of track alarm in seconds).
+                       _("Enter &end of track alarm time in seconds (currently 
{curAlarmSec})").format(curAlarmSec = timeVal),
+                       "&Notify when end of track is approaching", 1, 59)
+                       gui.mainFrame.prePopup()
+                       d.Raise()
+                       d.Show()
+                       gui.mainFrame.postPopup()
+                       splconfig._alarmDialogOpened = True
+               except RuntimeError:
+                       wx.CallAfter(splconfig._alarmError)
        # Translators: Input help mode message for a command in Station 
Playlist Studio.
        script_setEndOfTrackTime.__doc__=_("sets end of track alarm (default is 
5 seconds).")
 
@@ -533,19 +538,16 @@ class AppModule(appModuleHandler.AppModule):
 
        def script_setSongRampTime(self, gesture):
                rampVal = long(splconfig.SPLConfig["SongRampTime"])
-               # Translators: A dialog message to set song ramp alarm 
(curRampSec is the current intro monitoring alarm in seconds).
-               timeMSG = _("Enter song intro alarm time in seconds (currently 
{curRampSec})").format(curRampSec = rampVal)
-               dlg = wx.NumberEntryDialog(gui.mainFrame,
-               timeMSG, "",
+               d = splconfig.SPLAlarmDialog(gui.mainFrame, "SongRampTime", 
"SaySongRamp",
                # Translators: The title of song intro alarm dialog.
                _("Song intro alarm"),
-               rampVal, 1, 9)
-               def callback(result):
-                       if result == wx.ID_OK:
-                               newVal = dlg.GetValue()
-                               if user32.FindWindowA("SPLStudio", None) and 
newVal != rampVal:
-                                       splconfig.SPLConfig["SongRampTime"] = 
newVal
-               gui.runScriptModalDialog(dlg, callback)
+               # Translators: A dialog message to set song ramp alarm 
(curRampSec is the current intro monitoring alarm in seconds).
+               _("Enter song &intro alarm time in seconds (currently 
{curRampSec})").format(curRampSec = rampVal),
+               _("&Notify when end of introduction is approaching"), 1, 9)
+               gui.mainFrame.prePopup()
+               d.Raise()
+               d.Show()
+               gui.mainFrame.postPopup()
        # Translators: Input help mode message for a command in Station 
Playlist Studio.
        script_setSongRampTime.__doc__=_("sets song intro alarm (default is 5 
seconds).")
 

diff --git a/addon/appModules/splstudio/splconfig.py 
b/addon/appModules/splstudio/splconfig.py
index bd43d1c..bb09ddd 100755
--- a/addon/appModules/splstudio/splconfig.py
+++ b/addon/appModules/splstudio/splconfig.py
@@ -7,6 +7,7 @@ import os
 from cStringIO import StringIO
 from configobj import ConfigObj
 from validate import Validator
+import weakref
 import globalVars
 import ui
 import gui
@@ -228,16 +229,43 @@ class SPLConfigDialog(gui.SettingsDialog):
                        self.introSizer.Show(self.songRampAlarm)
                self.Fit()
 
-# Additional configuration dialogs
+
+               # Additional configuration dialogs
 
 # Common alarm dialogs.
 # Based on NVDA core's find dialog code (implemented by the author of this 
add-on).
+# Only one instance can be active at a given moment (code borrowed from GUI's 
exit dialog routine).
+_alarmDialogOpened = False
+
+# A common alarm error dialog.
+def _alarmError():
+       gui.messageBox(_("An alarm dialog is already 
opened."),_("Error"),style=wx.OK | wx.ICON_ERROR)
+
 class SPLAlarmDialog(wx.Dialog):
        """A dialog providing common alarm settings.
        This dialog contains a number entry field for alarm duration and a 
check box to enable or disable the alarm.
        """
 
+       # The following comes from exit dialog class from GUI package (credit: 
NV Access and Zahari from Bulgaria).
+       _instance = None
+
+       def __new__(cls, parent, *args, **kwargs):
+               # Make this a singleton and prompt an error dialog if it isn't.
+               if _alarmDialogOpened:
+                       raise RuntimeError("An instance of alarm dialog is 
opened")
+               inst = cls._instance() if cls._instance else None
+               if not inst:
+                       return super(cls, cls).__new__(cls, parent, *args, 
**kwargs)
+               return inst
+
        def __init__(self, parent, setting, toggleSetting, title, alarmPrompt, 
alarmToggleLabel, min, max):
+               inst = SPLAlarmDialog._instance() if SPLAlarmDialog._instance 
else None
+               if inst:
+                       return
+               # Use a weakref so the instance can die.
+               SPLAlarmDialog._instance = weakref.ref(self)
+
+               # Now the actual alarm dialog code.
                super(SPLAlarmDialog, self).__init__(parent, wx.ID_ANY, title)
                self.setting = setting
                self.toggleSetting = toggleSetting
@@ -264,6 +292,7 @@ class SPLAlarmDialog(wx.Dialog):
                self.alarmEntry.SetFocus()
 
        def onOk(self, evt):
+               global _alarmDialogOpened
                # Optimization: don't bother if Studio is dead and if the same 
value has been entered.
                if user32.FindWindowA("SPLStudio", None):
                        newVal = self.alarmEntry.GetValue()
@@ -271,6 +300,9 @@ class SPLAlarmDialog(wx.Dialog):
                        if SPLConfig[self.setting] != newVal: 
SPLConfig[self.setting] = newVal
                        elif SPLConfig[self.toggleSetting] != newToggle: 
SPLConfig[self.toggleSetting] = newToggle
                self.Destroy()
+               _alarmDialogOpened = False
 
        def onCancel(self, evt):
                self.Destroy()
+               global _alarmDialogOpened
+               _alarmDialogOpened = False

Repository URL: https://bitbucket.org/nvdaaddonteam/stationplaylist/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Other related posts:

  • » commit/StationPlaylist: josephsl: Bug hunters 3: NVDA will now pop up an error dialog if attempting to open more than one instance of an alarm dialog. - commits-noreply