commit/StationPlaylist: josephsl: Encoder support: restructure and braille output improvements.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Sat, 22 Nov 2014 23:11:35 -0000

1 new commit in StationPlaylist:

https://bitbucket.org/nvdaaddonteam/stationplaylist/commits/94939c221579/
Changeset:   94939c221579
Branch:      master
User:        josephsl
Date:        2014-11-22 23:07:05+00:00
Summary:     Encoder support: restructure and braille output improvements.
REstructured encoder support classes to call methods for each class at runtime 
as opposed to the base SAM class handling everything.
Also straem labels will stay on a braille display. This required some small 
hack - trying to find a way to elminate this.

Affected #:  1 file

diff --git a/addon/globalPlugins/SPLStudioUtils.py 
b/addon/globalPlugins/SPLStudioUtils.py
index 325ad4f..39c9e04 100644
--- a/addon/globalPlugins/SPLStudioUtils.py
+++ b/addon/globalPlugins/SPLStudioUtils.py
@@ -268,221 +268,212 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
        def chooseNVDAObjectOverlayClasses(self, obj, clsList):
                if obj.appModule.appName in ["splengine", "splstreamer"]:
                        if obj.windowClassName == "TListView":
-                               clsList.insert(0, self.SAMEncoderWindow)
+                               clsList.insert(0, SAMEncoderWindow)
                        elif obj.windowClassName == "SysListView32":
                                if obj.role == ROLE_LISTITEM:
-                                       clsList.insert(0, self.SPLEncoderWindow)
-
-       class SAMEncoderWindow(IAccessible):
-               # Support for Sam Encoder window.
-
-               # Few useful variables for encoder list:
-               focusToStudio = False # If true, Studio will gain focus after 
encoder connects.
-               playAfterConnecting = False # When connected, the first track 
will be played.
-               encoderType = "SAM"
-
-
-               def reportConnectionStatus(self):
-                       # Keep an eye on the stream's description field until 
connected or error occurs.
-                       # In order to not block NVDA commands, this will be 
done using a different thread.
-                       SPLWin = user32.FindWindowA("SPLStudio", None)
-                       toneCounter = 0
-                       while True:
-                               time.sleep(0.001)
-                               toneCounter+=1
-                               if toneCounter%250 == 0:
-                                       tones.beep(500, 50)
-                                       if toneCounter >= 750 and "Idle" in 
self.description:
-                                               tones.beep(250, 250)
-                                               return
-                               if "Error" in self.description:
-                                       # Announce the description of the error.
-                                       
ui.message(self.description[self.description.find("Status")+8:])
-                                       break
-                               elif "Encoding" in self.description or 
"Encoded" in self.description:
-                                       # We're on air, so exit.
-                                       if self.focusToStudio:
-                                               
fetchSPLForegroundWindow().setFocus()
-                                       tones.beep(1000, 150)
-                                       if self.playAfterConnecting:
-                                               winUser.sendMessage(SPLWin, 
SPLMSG, 0, SPLPlay)
-                                       break
-
-               def script_connect(self, gesture):
-                       gesture.send()
-                       # Translators: Presented when SAM Encoder is trying to 
connect to a streaming server.
-                       ui.message(_("Connecting..."))
-                       # Oi, status thread, can you keep an eye on the 
connection status for me?
-                       statusThread = 
threading.Thread(target=self.reportConnectionStatus)
-                       statusThread.name = "Connection Status Reporter"
-                       statusThread.start()
-
-               def script_disconnect(self, gesture):
-                       gesture.send()
-                       # Translators: Presented when SAM Encoder is 
disconnecting from a streaming server.
-                       ui.message(_("Disconnecting..."))
-
-               def script_toggleFocusToStudio(self, gesture):
-                       if not self.focusToStudio:
-                               self.focusToStudio = True
-                               # Translators: Presented when toggling the 
setting to switch to Studio when connected to a streaming server.
-                               ui.message(_("Switch to Studio after 
connecting"))
-                       else:
-                               self.focusToStudio = False
-                               # Translators: Presented when toggling the 
setting to switch to Studio when connected to a streaming server.
-                               ui.message(_("Do not switch to Studio after 
connecting"))
-                       if self.encoderType == "SAM":
-                               SAMFocusToStudio[self.name] = self.focusToStudio
-                       elif self.encoderType == "SPL":
-                               SPLFocusToStudio[str(self.IAccessibleChildID)] 
= self.focusToStudio
-               # Translators: Input help mode message in SAM Encoder window.
-               script_toggleFocusToStudio.__doc__=_("Toggles whether NVDA will 
switch to Studio when connected to a streaming server.")
-
-               def script_togglePlay(self, gesture):
-                       if not self.playAfterConnecting:
-                               self.playAfterConnecting = True
-                               # Translators: Presented when toggling the 
setting to play selected song when connected to a streaming server.
-                               ui.message(_("Play first track after 
connecting"))
-                       else:
-                               self.playAfterConnecting = False
-                               # Translators: Presented when toggling the 
setting to switch to Studio when connected to a streaming server.
-                               ui.message(_("Do not play first track after 
connecting"))
-                       if self.encoderType == "SAM":
-                               SAMPlayAfterConnecting[self.name] = 
self.playAfterConnecting
-                       elif self.encoderType == "SPL":
-                               
SPLPlayAfterConnecting[str(self.IAccessibleChildID)] = self.playAfterConnecting
-               # Translators: Input help mode message in SAM Encoder window.
-               script_togglePlay.__doc__=_("Toggles whether Studio will play 
the first song when connected to a streaming server.")
-
-               def script_streamLabeler(self, gesture):
-                       curStreamLabel = ""
-                       if self.encoderType == "SAM" and self.name in 
SAMStreamLabels:
-                               curStreamLabel = SAMStreamLabels[self.name]
-                       elif self.encoderType == "SPL" and 
str(self.IAccessibleChildID) in SPLStreamLabels:
-                               curStreamLabel = 
SPLStreamLabels[str(self.IAccessibleChildID)]
-                       # Translators: The title of the stream labeler dialog 
(example: stream labeler for 1).
-                       streamTitle = _("Stream labeler for 
{streamEntry}").format(streamEntry = self.name)
-                       # Translators: The text of the stream labeler dialog.
-                       streamText = _("Enter the label for this stream")
-                       dlg = wx.TextEntryDialog(gui.mainFrame,
-                       streamText, streamTitle, defaultValue=curStreamLabel)
-                       def callback(result):
-                               if result == wx.ID_OK:
-                                       if dlg.GetValue() != "":
-                                               if self.encoderType == "SAM": 
SAMStreamLabels[self.name] = dlg.GetValue()
-                                               elif self.encoderType == "SPL": 
SPLStreamLabels[str(self.IAccessibleChildID)] = dlg.GetValue()
-                                       else:
-                                               if self.encoderType == "SAM": 
del SAMStreamLabels[self.name]
-                                               elif self.encoderType == "SPL": 
del SPLStreamLabels[(self.IAccessibleChildID)]
-                       gui.runScriptModalDialog(dlg, callback)
-               # Translators: Input help mode message in SAM Encoder window.
-               script_streamLabeler.__doc__=_("Opens a dialog to label the 
selected encoder.")
-
-
-               def initOverlayClass(self):
-                       # Can I switch to Studio when connected to a streaming 
server?
-                       try:
-                               self.focusToStudio = SAMFocusToStudio[self.name]
-                       except KeyError:
-                               pass
+                                       clsList.insert(0, SPLEncoderWindow)
 
-               def event_gainFocus(self):
-                       try:
-                               streamLabel = SAMStreamLabels[self.name]
-                       except KeyError:
-                               streamLabel = None
-                       # Speak the stream label if it exists.
-                       if streamLabel is not None: 
speech.speakMessage(streamLabel)
-                       super(type(self), self).reportFocus()
-                       # Braille the stream label if present.
-                       if streamLabel is not None:
-                               brailleStreamLabel = self.name + ": " + 
streamLabel
-                               braille.handler.message(brailleStreamLabel)
-
-
-               __gestures={
-                       "kb:f9":"connect",
-                       "kb:f10":"disconnect",
-                       "kb:f11":"toggleFocusToStudio",
-                       "kb:shift+f11":"togglePlay",
-                       "kb:f12":"streamLabeler"
-               }
-
-       class SPLEncoderWindow(SAMEncoderWindow):
-               # Support for SPL Encoder window.
-
-               # A few more subclass flags.
-               encoderType = "SPL"
-
-               def reportConnectionStatus(self):
-                       # Same routine as SAM encoder: use a thread to prevent 
blocking NVDA commands.
-                       SPLWin = user32.FindWindowA("SPLStudio", None)
-                       attempt = 0
-                       while True:
-                               time.sleep(0.001)
-                               try:
-                                       statChild = self.children[1]
-                               except IndexError:
-                                       return # Don't leave zombie objects 
around.
-                               attempt += 1
-                               if attempt%250 == 0:
-                                       tones.beep(500, 50)
-                                       if attempt>= 500 and statChild.name == 
"Disconnected":
-                                               tones.beep(250, 250)
-                                               return
-                               if "Unable to connect" in statChild.name or 
"Failed" in statChild.name:
-                                       ui.message(statChild.name)
-                                       break
-                               if statChild.name == "Connected":
-                                       # We're on air, so exit.
-                                       if self.focusToStudio:
-                                               
fetchSPLForegroundWindow().setFocus()
-                                       tones.beep(1000, 150)
-                                       if self.playAfterConnecting:
-                                               winUser.sendMessage(SPLWin, 
SPLMSG, 0, SPLPlay)
-                                       break
-                       #if not self.name.endswith("Connected"): 
ui.message(self.name[self.name.find("Transfer")+15:])
-
-               def script_connect(self, gesture):
-                       # Same as SAM's connection routine, but this time, keep 
an eye on self.name and a different connection flag.
-                       connectButton = api.getForegroundObject().children[2]
-                       if connectButton.name == "Disconnect": return
-                       ui.message(_("Connecting..."))
-                       # Juggle the focus around.
-                       connectButton.doAction()
-                       self.setFocus()
-                       # Same as SAM encoders.
-                       statusThread = 
threading.Thread(target=self.reportConnectionStatus)
-                       statusThread.name = "Connection Status Reporter"
-                       statusThread.start()
-               script_connect.__doc__=_("Connects to a streaming server.")
-
-
-               def initOverlayClass(self):
-                       # Can I switch to Studio when connected to a streaming 
server?
-                       try:
-                               self.focusToStudio = 
SPLFocusToStudio[str(self.IAccessibleChildID)]
-                       except KeyError:
-                               pass
+class SAMEncoderWindow(IAccessible):
+       # Support for Sam Encoder window.
+
+       # Few useful variables for encoder list:
+       focusToStudio = False # If true, Studio will gain focus after encoder 
connects.
+       playAfterConnecting = False # When connected, the first track will be 
played.
+       encoderType = "SAM"
+
+
+       def reportConnectionStatus(self):
+               # Keep an eye on the stream's description field until connected 
or error occurs.
+               # In order to not block NVDA commands, this will be done using 
a different thread.
+               SPLWin = user32.FindWindowA("SPLStudio", None)
+               toneCounter = 0
+               while True:
+                       time.sleep(0.001)
+                       toneCounter+=1
+                       if toneCounter%250 == 0:
+                               tones.beep(500, 50)
+                               if toneCounter >= 750 and "Idle" in 
self.description:
+                                       tones.beep(250, 250)
+                                       return
+                       if "Error" in self.description:
+                               # Announce the description of the error.
+                               
ui.message(self.description[self.description.find("Status")+8:])
+                               break
+                       elif "Encoding" in self.description or "Encoded" in 
self.description:
+                               # We're on air, so exit.
+                               if self.focusToStudio:
+                                       fetchSPLForegroundWindow().setFocus()
+                               tones.beep(1000, 150)
+                               if self.playAfterConnecting:
+                                       winUser.sendMessage(SPLWin, SPLMSG, 0, 
SPLPlay)
+                               break
+
+       def script_connect(self, gesture):
+               gesture.send()
+               # Translators: Presented when SAM Encoder is trying to connect 
to a streaming server.
+               ui.message(_("Connecting..."))
+               # Oi, status thread, can you keep an eye on the connection 
status for me?
+               statusThread = 
threading.Thread(target=self.reportConnectionStatus)
+               statusThread.name = "Connection Status Reporter"
+               statusThread.start()
+
+       def script_disconnect(self, gesture):
+               gesture.send()
+               # Translators: Presented when SAM Encoder is disconnecting from 
a streaming server.
+               ui.message(_("Disconnecting..."))
+
+       def script_toggleFocusToStudio(self, gesture):
+               if not self.focusToStudio:
+                       self.focusToStudio = True
+                       # Translators: Presented when toggling the setting to 
switch to Studio when connected to a streaming server.
+                       ui.message(_("Switch to Studio after connecting"))
+               else:
+                       self.focusToStudio = False
+                       # Translators: Presented when toggling the setting to 
switch to Studio when connected to a streaming server.
+                       ui.message(_("Do not switch to Studio after 
connecting"))
+               if self.encoderType == "SAM":
+                       SAMFocusToStudio[self.IAccessibleChildID] = 
self.focusToStudio
+               elif self.encoderType == "SPL":
+                       SPLFocusToStudio[self.IAccessibleChildID] = 
self.focusToStudio
+       # Translators: Input help mode message in SAM Encoder window.
+       script_toggleFocusToStudio.__doc__=_("Toggles whether NVDA will switch 
to Studio when connected to a streaming server.")
+
+       def script_togglePlay(self, gesture):
+               if not self.playAfterConnecting:
+                       self.playAfterConnecting = True
+                       # Translators: Presented when toggling the setting to 
play selected song when connected to a streaming server.
+                       ui.message(_("Play first track after connecting"))
+               else:
+                       self.playAfterConnecting = False
+                       # Translators: Presented when toggling the setting to 
switch to Studio when connected to a streaming server.
+                       ui.message(_("Do not play first track after 
connecting"))
+               if self.encoderType == "SAM":
+                       SAMPlayAfterConnecting[self.IAccessibleChildID] = 
self.playAfterConnecting
+               elif self.encoderType == "SPL":
+                       SPLPlayAfterConnecting[self.IAccessibleChildID] = 
self.playAfterConnecting
+       # Translators: Input help mode message in SAM Encoder window.
+       script_togglePlay.__doc__=_("Toggles whether Studio will play the first 
song when connected to a streaming server.")
+
+       def script_streamLabeler(self, gesture):
+               curStreamLabel, title = self.getStreamLabel(), ""
+               if not curStreamLabel: curStreamLabel = ""
+               if self.encoderType == "SAM":
+                       title = self.IAccessibleChildID
+               elif self.encoderType == "SPL":
+                       title = self.firstChild.name
+               # Translators: The title of the stream labeler dialog (example: 
stream labeler for 1).
+               streamTitle = _("Stream labeler for 
{streamEntry}").format(streamEntry = title)
+               # Translators: The text of the stream labeler dialog.
+               streamText = _("Enter the label for this stream")
+               dlg = wx.TextEntryDialog(gui.mainFrame,
+               streamText, streamTitle, defaultValue=curStreamLabel)
+               def callback(result):
+                       if result == wx.ID_OK:
+                               if dlg.GetValue() != "":
+                                       if self.encoderType == "SAM": 
SAMStreamLabels[self.name] = dlg.GetValue()
+                                       elif self.encoderType == "SPL": 
SPLStreamLabels[str(self.IAccessibleChildID)] = dlg.GetValue()
+                               else:
+                                       if self.encoderType == "SAM": del 
SAMStreamLabels[self.name]
+                                       elif self.encoderType == "SPL": del 
SPLStreamLabels[(self.IAccessibleChildID)]
+               gui.runScriptModalDialog(dlg, callback)
+       # Translators: Input help mode message in SAM Encoder window.
+       script_streamLabeler.__doc__=_("Opens a dialog to label the selected 
encoder.")
+
+
+       def initOverlayClass(self):
+               # Can I switch to Studio when connected to a streaming server?
+               try:
+                       self.focusToStudio = 
SAMFocusToStudio[self.IAccessibleChildID]
+               except KeyError:
+                       pass
+
+       def getStreamLabel(self):
+               if str(self.IAccessibleChildID) in SAMStreamLabels:
+                       return SAMStreamLabels[str(self.IAccessibleChildID)]
+               return None
+
+       def reportFocus(self):
+               import globalPlugins
+               streamLabel = self.getStreamLabel()
+               # Speak the stream label if it exists.
+               if streamLabel is not None:
+                       self.name = "(" + streamLabel + ") " + self.name
+               super(globalPlugins.SPLStudioUtils.SAMEncoderWindow, 
self).reportFocus()
 
-               def event_gainFocus(self):
+
+       __gestures={
+               "kb:f9":"connect",
+               "kb:f10":"disconnect",
+               "kb:f11":"toggleFocusToStudio",
+               "kb:shift+f11":"togglePlay",
+               "kb:f12":"streamLabeler"
+       }
+
+class SPLEncoderWindow(SAMEncoderWindow):
+       # Support for SPL Encoder window.
+
+       # A few more subclass flags.
+       encoderType = "SPL"
+
+       def reportConnectionStatus(self):
+               # Same routine as SAM encoder: use a thread to prevent blocking 
NVDA commands.
+               SPLWin = user32.FindWindowA("SPLStudio", None)
+               attempt = 0
+               while True:
+                       time.sleep(0.001)
                        try:
-                               streamLabel = 
SPLStreamLabels[str(self.IAccessibleChildID)]
-                       except KeyError:
-                               streamLabel = None
-                       # Speak the stream label if it exists.
-                       if streamLabel is not None: 
speech.speakMessage(streamLabel)
-                       super(type(self), self).reportFocus()
-                       # Braille the stream label if present.
-                       if streamLabel is not None:
-                               brailleStreamLabel = 
str(self.IAccessibleChildID) + ": " + streamLabel
-                               braille.handler.message(brailleStreamLabel)
-
-
-
-               __gestures={
-                       "kb:f9":"connect",
-                       "kb:f10":None
-               }
+                               statChild = self.children[1]
+                       except IndexError:
+                               return # Don't leave zombie objects around.
+                       attempt += 1
+                       if attempt%250 == 0:
+                               tones.beep(500, 50)
+                               if attempt>= 500 and statChild.name == 
"Disconnected":
+                                       tones.beep(250, 250)
+                                       return
+                       if "Unable to connect" in statChild.name or "Failed" in 
statChild.name:
+                               ui.message(statChild.name)
+                               break
+                       if statChild.name == "Connected":
+                               # We're on air, so exit.
+                               if self.focusToStudio:
+                                       fetchSPLForegroundWindow().setFocus()
+                               tones.beep(1000, 150)
+                               if self.playAfterConnecting:
+                                       winUser.sendMessage(SPLWin, SPLMSG, 0, 
SPLPlay)
+                               break
+
+       def script_connect(self, gesture):
+               # Same as SAM's connection routine, but this time, keep an eye 
on self.name and a different connection flag.
+               connectButton = api.getForegroundObject().children[2]
+               if connectButton.name == "Disconnect": return
+               ui.message(_("Connecting..."))
+               # Juggle the focus around.
+               connectButton.doAction()
+               self.setFocus()
+               # Same as SAM encoders.
+               statusThread = 
threading.Thread(target=self.reportConnectionStatus)
+               statusThread.name = "Connection Status Reporter"
+               statusThread.start()
+       script_connect.__doc__=_("Connects to a streaming server.")
+
+
+       def initOverlayClass(self):
+               # Can I switch to Studio when connected to a streaming server?
+               try:
+                       self.focusToStudio = 
SPLFocusToStudio[self.IAccessibleChildID]
+               except KeyError:
+                       pass
+
+       def getStreamLabel(self):
+               if str(self.IAccessibleChildID) in SPLStreamLabels:
+                       return SPLStreamLabels[str(self.IAccessibleChildID)]
+               return None
+
+
+       __gestures={
+               "kb:f9":"connect",
+               "kb:f10":None
+       }

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: Encoder support: restructure and braille output improvements. - commits-noreply