@@ -60,6 +60,7 @@ def __init__(self, parent):
6060 self .__filterByHostNameSetup (hlayout )
6161 self .__filterAllocationSetup (hlayout )
6262 self .__filterHardwareStateSetup (hlayout )
63+ self .__filterLockStateSetup (hlayout )
6364 hlayout .addStretch ()
6465 self .__refreshToggleCheckBoxSetup (hlayout )
6566 self .__refreshButtonSetup (hlayout )
@@ -265,6 +266,96 @@ def __filterHardwareStateHandle(self, action):
265266
266267 self .hostMonitorTree .updateRequest ()
267268
269+ # ==============================================================================
270+ # Menu to filter by lock state
271+ # ==============================================================================
272+ def __filterLockStateSetup (self , layout ):
273+ self .__filterLockStateList = sorted (opencue .api .host_pb2 .LockState .keys ())
274+
275+ btn = QtWidgets .QPushButton ("Filter LockState" )
276+ btn .setMaximumHeight (FILTER_HEIGHT )
277+ btn .setFocusPolicy (QtCore .Qt .NoFocus )
278+ btn .setContentsMargins (0 , 0 , 0 , 0 )
279+ btn .setFlat (True )
280+
281+ menu = QtWidgets .QMenu (self )
282+ btn .setMenu (menu )
283+ QtCore .QObject .connect (menu ,
284+ QtCore .SIGNAL ("triggered(QAction*)" ),
285+ self .__filterLockStateHandle )
286+
287+ for item in ["Clear" , None ] + self .__filterLockStateList :
288+ if item :
289+ a = QtWidgets .QAction (menu )
290+ a .setText (str (item ))
291+ if item != "Clear" :
292+ a .setCheckable (True )
293+ menu .addAction (a )
294+ else :
295+ menu .addSeparator ()
296+
297+ layout .addWidget (btn )
298+ self .__filterLockStateButton = btn
299+
300+ def __filterLockStateClear (self ):
301+ """Clears the currently selected lock state menu items"""
302+ btn = self .__filterLockStateButton
303+ menu = btn .menu ()
304+ for action in menu .actions ():
305+ action .setChecked (False )
306+ self .hostMonitorTree .hostSearch .options ['lock_state' ] = []
307+
308+ def __filterLockStateHandle (self , action ):
309+ """Called when an option in the filter lock state menu is triggered.
310+ Tells the HostMonitorTree widget what lock state to filter by.
311+ @param action: Defines the menu item selected
312+ @type action: QAction"""
313+ __hostSearch = self .hostMonitorTree .hostSearch
314+ if action .text () == "Clear" :
315+ self .__clearLockStateFilter (__hostSearch )
316+ return
317+
318+ self .__updateLockStateFilter (__hostSearch , action )
319+
320+ self .hostMonitorTree .updateRequest ()
321+
322+ def __clearLockStateFilter (self , __hostSearch ):
323+ """
324+ Clears the currently selected lock state menu items and updates the search options.
325+ @param __hostSearch: The host search criteria object to update.
326+ @type __hostSearch: HostSearchCriteria
327+ """
328+ for item in self .__filterLockStateButton .menu ().actions ():
329+ if item .isChecked () and item .text () != "Clear" :
330+ # Remove the lock state from the search options
331+ __hostSearch .options ['lock_state' ].remove (
332+ getattr (opencue .api .host_pb2 , str (item .text ())))
333+ # Uncheck the menu item
334+ item .setChecked (False )
335+
336+ def __updateLockStateFilter (self , __hostSearch , action ):
337+ """
338+ Updates the lock state filter based on the selected action.
339+ @param __hostSearch: The host search criteria object to update.
340+ @type __hostSearch: HostSearchCriteria
341+ @param action: The action that was triggered.
342+ @type action: QAction
343+ """
344+ # Get the current lock states from the search options
345+ lock_states = __hostSearch .options .get ('lock_state' , [])
346+ # Get the lock state corresponding to the action text
347+ lock_state = getattr (opencue .api .host_pb2 , str (action .text ()))
348+
349+ if action .isChecked ():
350+ # Add the lock state if the action is checked
351+ lock_states .append (lock_state )
352+ else :
353+ # Remove the lock state if the action is unchecked
354+ lock_states .remove (lock_state )
355+
356+ # Update the search options with the new lock states
357+ __hostSearch .options ['lock_state' ] = lock_states
358+
268359 # ==============================================================================
269360 # Checkbox to toggle auto-refresh
270361 # ==============================================================================
@@ -326,6 +417,7 @@ def __clearButtonHandle(self):
326417 self .hostMonitorTree .ticksWithoutUpdate = - 1
327418 self .__filterAllocationClear ()
328419 self .__filterHardwareStateClear ()
420+ self .__filterLockStateClear ()
329421 self .__filterByHostNameClear ()
330422 self .hostMonitorTree .clearFilters ()
331423
0 commit comments