Skip to content

Commit

Permalink
Merge pull request #2100 from AllenInstitute/bugfix/2100-databrowser-…
Browse files Browse the repository at this point in the history
…title-automation-mode

Use desired titles for sweepbrowser/databrowser
  • Loading branch information
t-b authored Jun 17, 2024
2 parents 7477cee + 72fb9ea commit 282b0a3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
45 changes: 16 additions & 29 deletions Packages/MIES/MIES_BrowserSettingsPanel.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -476,26 +476,7 @@ static Function/S BSP_SetBrowserType(string win, string type, variable mode)
ASSERT(WindowExists(mainPanel), "specified panel does not exist.")

SetWindow $mainPanel, userdata($MIES_BSP_BROWSER)=type

if(mode == BROWSER_MODE_USER)
suffix = ""
elseif(mode == BROWSER_MODE_AUTOMATION)
suffix = " (A*U*T*O*M*A*T*I*O*N)"
endif

SetWindow $mainPanel, userdata($MIES_BSP_BROWSER_MODE)=BSP_SerializeBrowserMode(mode)

if(!CmpStr(type, BROWSERTYPE_SWEEPBROWSER))
title = SWEEPBROWSER_WINDOW_NAME
elseif(!CmpStr(type, BROWSERTYPE_DATABROWSER))
title = DATABROWSER_WINDOW_NAME
else
ASSERT(0, "Invalid type")
endif

title += suffix

DoWindow/T $mainPanel, title
End

static Function BSP_ParseBrowserMode(string mode)
Expand Down Expand Up @@ -524,15 +505,14 @@ static Function/S BSP_SerializeBrowserMode(variable mode)
endswitch
End

Function BSP_HasMode(string win, variable mode)
Function BSP_GetBrowserMode(string win)

string mainPanel
variable foundMode
string mainPanel, browserModeStr

mainPanel = GetMainWindow(win)
foundMode = BSP_ParseBrowserMode(GetUserData(mainPanel, "", MIES_BSP_BROWSER_MODE))
mainPanel = GetMainWindow(win)
browserModeStr = GetUserData(mainPanel, "", MIES_BSP_BROWSER_MODE)

return foundMode & mode
return BSP_ParseBrowserMode(browserModeStr)
End

/// @brief wrapper function for external calls
Expand Down Expand Up @@ -1978,11 +1958,13 @@ End
Function/S BSP_RenameAndSetTitle(string win, string newName)

variable numOtherBrowser
string newTitle
string suffix = ""
string newTitle, suffix
string modeSuffix = ""

if(BSP_IsDataBrowser(win) && BSP_HasBoundDevice(win))
suffix = " with \"" + BSP_GetDevice(win) + "\""
else
suffix = " "
endif

if(WindowExists(newName) && cmpstr(win, newName))
Expand All @@ -1992,13 +1974,18 @@ Function/S BSP_RenameAndSetTitle(string win, string newName)
DoWindow/W=$win/C $newName
win = newName

switch(BSP_GetBrowserMode(win))
case BROWSER_MODE_AUTOMATION:
modeSuffix = " (A*U*T*O*M*A*T*I*O*N)"
break
endswitch

numOtherBrowser += ItemsInList(WinList(SWEEPBROWSER_WINDOW_NAME + "*", ";", "WIN:1"))
numOtherBrowser += ItemsInList(WinList(DATABROWSER_WINDOW_NAME + "*", ";", "WIN:1"))
numOtherBrowser += ItemsInList(WinList("DB_*", ";", "WIN:1"))
numOtherBrowser = max(0, numOtherBrowser - 1)

sprintf newTitle, "Browser %s%s", SelectString(numOtherBrowser, "", " [" + num2str(numOtherBrowser) + "]"), suffix
newTitle = RemoveEnding(newTitle, " ")
sprintf newTitle, "Browser%s%s%s", SelectString(numOtherBrowser, "", " [" + num2str(numOtherBrowser) + "]"), suffix, modeSuffix
DoWindow/T $win, newTitle

return win
Expand Down
4 changes: 2 additions & 2 deletions Packages/MIES/MIES_DataBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ static Function/S DB_LockToDevice(win, device)
newWindow = "DB_" + device
endif

DB_SetUserData(win, device)
win = BSP_RenameAndSetTitle(win, newWindow)

DB_SetUserData(win, device)
if(windowExists(BSP_GetPanel(win)) && BSP_HasBoundDevice(win))
BSP_DynamicStartupSettings(win)
[first, last] = BSP_FirstAndLastSweepAcquired(win)
Expand Down Expand Up @@ -710,7 +710,7 @@ Function/WAVE DB_FindAllDataBrowser(string device, [variable mode])
continue
endif

if(!BSP_HasMode(panel, mode))
if(!(BSP_GetBrowserMode(panel) & mode))
continue
endif

Expand Down
34 changes: 34 additions & 0 deletions Packages/tests/HardwareBasic/UTF_Databrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@ Function CanFindAllDataBrowsers([string str])
CHECK_WAVE(matches, TEXT_WAVE)

CHECK_EQUAL_VAR(DimSize(matches, ROWS), 2)

WAVE/T/Z matchesAll = DB_FindAllDataBrowser(str, mode = BROWSER_MODE_ALL)
CHECK_EQUAL_WAVES(matches, matchesAll)

WAVE/T/Z matchesUser = DB_FindAllDataBrowser(str, mode = BROWSER_MODE_USER)
CHECK_EQUAL_WAVES(matches, matchesUser)

WAVE/T/Z matchesAuto = DB_FindAllDataBrowser(str, mode = BROWSER_MODE_AUTOMATION)
CHECK_WAVE(matchesAuto, NULL_WAVE)

DB_GetBoundDataBrowser(str, mode = BROWSER_MODE_AUTOMATION)

WAVE/T/Z matchesAuto = DB_FindAllDataBrowser(str, mode = BROWSER_MODE_AUTOMATION)
CHECK_WAVE(matchesAuto, TEXT_WAVE)

CHECK_EQUAL_VAR(DimSize(matchesAuto, ROWS), 1)
End

// UTF_TD_GENERATOR DeviceNameGeneratorMD1
Function CheckWindowTitles([string str])

string win

CreateLockedDAEphys(str)

// check window titles

win = DB_GetBoundDataBrowser(str, mode = BROWSER_MODE_USER)
GetWindow $win, wtitle
CHECK_EQUAL_STR(S_Value, "Browser with \"" + str + "\"")

win = DB_GetBoundDataBrowser(str, mode = BROWSER_MODE_AUTOMATION)
GetWindow $win, wtitle
CHECK_EQUAL_STR(S_Value, "Browser [1] with \"" + str + "\" (A*U*T*O*M*A*T*I*O*N)")
End

static Function/WAVE AllDatabrowserSubWindows()
Expand Down

0 comments on commit 282b0a3

Please sign in to comment.