commit/StationPlaylist: josephsl: Categorical find (6.0-dev): Foundation for column/categorical search

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Fri, 26 Jun 2015 18:09:57 -0000

1 new commit in StationPlaylist:

https://bitbucket.org/nvdaaddonteam/stationplaylist/commits/3283badb31b6/
Changeset: 3283badb31b6
Branch: 6.0/categoricalSearch
User: josephsl
Date: 2015-06-19 21:16:08+00:00
Summary: Categorical find (6.0-dev): Foundation for column/categorical
search

Added a new track finder dialog class, which replaces previously used text
entry dialog. This new dialog handles regular track finder case and the column
search option. Once the text has been entered, the dialog uses find function
found in appmodule to find text, using the column keyword argument if necessary.
Eventually, track finder will be split into two scripts: the regular script,
and the column search script that instantiates the same dialog with different
arguments. The former will still use track find command, while the other will
be unassigned. Another possible solution is to provide a check box that
specifies which finder dialog to instantiate.
Because of extensive API changes, this will be available in 6.0.

Affected #: 2 files

diff --git a/addon/appModules/splstudio/__init__.py
b/addon/appModules/splstudio/__init__.py
index af5b771..8731e30 100755
--- a/addon/appModules/splstudio/__init__.py
+++ b/addon/appModules/splstudio/__init__.py
@@ -707,14 +707,18 @@ class AppModule(appModuleHandler.AppModule):
_trackFinderDlgOpen = False

def trackFinder(self, text, obj, directionForward=True, column=None):
+ speech.cancelSpeech()
while obj is not None:
- if text in obj.description or (obj.name and text in
obj.name and self.productVersion < "5.10"):
- self.findText = text
- # We need to fire set focus event twice and
exit this routine.
- obj.setFocus(), obj.setFocus()
- return
- else:
- obj = obj.next if directionForward else
obj.previous
+ try:
+ if (not column and (text in obj.description or
(obj.name and text in obj.name and self.productVersion < "5.10"))
+ or (column and text in
obj._getColumnContent(column))):
+ self.findText = text
+ # We need to fire set focus event twice
and exit this routine.
+ obj.setFocus(), obj.setFocus()
+ return
+ except TypeError:
+ pass
+ obj = obj.next if directionForward else obj.previous
wx.CallAfter(gui.messageBox,
# Translators: Standard dialog message when an item one wishes
to search is not found (copy this from main nvda.po).
_("Search string not found."),
@@ -733,30 +737,15 @@ class AppModule(appModuleHandler.AppModule):
# Translators: Presented when a user wishes to find a
track but didn't add any tracks.
ui.message(_("You need to add at least one track to
find tracks."))
else:
- if self._trackFinderOpen:
- if not self._trackFinderDlgOpen:
- # Translators: Standard dialog message
when find dialog is already open.
- wx.CallAfter(gui.messageBox, _("Find
track dialog is already open."), _("Error"),wx.OK|wx.ICON_ERROR)
- self._trackFinderDlgOpen = True
- else:
- ui.message(_("Find track dialog is
already open."))
- else:
- startObj = api.getFocusObject()
- # Translators: The text of the dialog for
finding tracks.
- searchMSG = _("Enter the name of the track you
wish to search.")
- dlg = wx.TextEntryDialog(gui.mainFrame,
- searchMSG,
- # Translators: The title of the find tracks
dialog.
- _("Find track"), defaultValue=self.findText)
- self._trackFinderOpen = True
- def callback(result):
- self._trackFinderOpen = False
- self._trackFinderDlgOpen = False
- if result == wx.ID_OK:
- if dlg.GetValue() is None:
return
- elif dlg.GetValue() ==
self.findText: self.trackFinder(dlg.GetValue(), startObj.next)
- else:
self.trackFinder(dlg.GetValue(), startObj)
- gui.runScriptModalDialog(dlg, callback)
+ try:
+ d = splconfig.SPLFindDialog(gui.mainFrame,
api.getFocusObject(), self.findText, "Find track", columnSearch = True)
+ gui.mainFrame.prePopup()
+ d.Raise()
+ d.Show()
+ gui.mainFrame.postPopup()
+ splconfig._findDialogOpened = True
+ except RuntimeError:
+ wx.CallAfter(splconfig._finderError)
# Translators: Input help mode message for a command in Station
Playlist Studio.
script_findTrack.__doc__=_("Finds a track in the track list.")


diff --git a/addon/appModules/splstudio/splconfig.py
b/addon/appModules/splstudio/splconfig.py
index 01e3869..7c9dbb2 100755
--- a/addon/appModules/splstudio/splconfig.py
+++ b/addon/appModules/splstudio/splconfig.py
@@ -386,3 +386,95 @@ class SPLAlarmDialog(wx.Dialog):
self.Destroy()
global _alarmDialogOpened
_alarmDialogOpened = False
+
+
+# A common dialog for Track Finder
+# To be split into a new module later.
+_findDialogOpened = False
+
+# Track Finder error dialog.
+# This will be refactored into something else.
+def _finderError():
+ # Translators: Text of the dialog when another find dialog is open.
+ gui.messageBox(_("Another find dialog is open."),_("Error"),style=wx.OK
| wx.ICON_ERROR)
+
+class SPLFindDialog(wx.Dialog):
+
+ _instance = None
+
+ def __new__(cls, parent, *args, **kwargs):
+ # Make this a singleton and prompt an error dialog if it isn't.
+ if _findDialogOpened:
+ raise RuntimeError("An instance of find 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, obj, text, title, columnSearch=False):
+ inst = SPLFindDialog._instance() if SPLFindDialog._instance
else None
+ if inst:
+ return
+ # Use a weakref so the instance can die.
+ SPLFindDialog._instance = weakref.ref(self)
+
+ super(SPLFindDialog, self).__init__(parent, wx.ID_ANY, title)
+ self.obj = obj
+ self.columnSearch = columnSearch
+ if not columnSearch:
+ findPrompt = _("Enter the name or the artist of the
track you wish to &search")
+ else:
+ findPrompt = _("Enter text to be &searched in a column")
+
+ mainSizer = wx.BoxSizer(wx.VERTICAL)
+
+ findSizer = wx.BoxSizer(wx.HORIZONTAL)
+ findMessage = wx.StaticText(self, wx.ID_ANY, label=findPrompt)
+ findSizer.Add(findMessage)
+ self.findEntry = wx.TextCtrl(self, wx.ID_ANY)
+ self.findEntry.SetValue(text)
+ findSizer.Add(self.findEntry)
+ mainSizer.Add(findSizer,border=20,flag=wx.LEFT|wx.RIGHT|wx.TOP)
+
+ if columnSearch:
+ columnSizer = wx.BoxSizer(wx.HORIZONTAL)
+ # Translators: The label in track finder to search
columns.
+ label = wx.StaticText(self, wx.ID_ANY, label=_("C&olumn
to search:"))
+ left = 1 if obj.appModule.productVersion >= "5.10" else 0
+ headers = [header.name for header in
obj.parent.children[-1].children[left:]]
+ self.columnHeaders = wx.Choice(self, wx.ID_ANY,
choices=headers)
+ try:
+ self.columnHeaders.SetSelection(0)
+ except:
+ pass
+ columnSizer.Add(label)
+ columnSizer.Add(self.columnHeaders)
+ mainSizer.Add(columnSizer, border=10, flag=wx.BOTTOM)
+
+ mainSizer.AddSizer(self.CreateButtonSizer(wx.OK|wx.CANCEL))
+ self.Bind(wx.EVT_BUTTON,self.onOk,id=wx.ID_OK)
+ self.Bind(wx.EVT_BUTTON,self.onCancel,id=wx.ID_CANCEL)
+ mainSizer.Fit(self)
+ self.SetSizer(mainSizer)
+ self.Center(wx.BOTH | wx.CENTER_ON_SCREEN)
+ self.findEntry.SetFocus()
+
+ def onOk(self, evt):
+ global _findDialogOpened
+ text = self.findEntry.GetValue()
+ # Studio, are you alive?
+ if user32.FindWindowA("SPLStudio", None) and text:
+ appMod = self.obj.appModule
+ column = self.columnHeaders.Selection if
self.columnSearch else None
+ if appMod.productVersion >= "5.10": column+=1
+ startObj = self.obj
+ if text == appMod.findText: startObj = startObj.next
+ # If this is called right away, we land on an invisible
window.
+ wx.CallLater(100, appMod.trackFinder, text, startObj,
column=column)
+ self.Destroy()
+ _findDialogOpened = False
+
+ def onCancel(self, evt):
+ self.Destroy()
+ global _findDialogOpened
+ _findDialogOpened = 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: Categorical find (6.0-dev): Foundation for column/categorical search - commits-noreply