Skip to content

Commit

Permalink
filtering happening in mainwindow only
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit2p committed Aug 18, 2024
1 parent 975fdb1 commit 754053e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
37 changes: 37 additions & 0 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ def __init__(self, parent=None, data_dir=None):
else:
self.data_dir = data_dir
self.create_dir()
# Variable to store filtered operations
self.filtered_operations = []

def view_description(self):
data = {
Expand Down Expand Up @@ -1383,6 +1385,41 @@ def operation_category_handler(self, update_operations=True):
else:
self.add_operations_to_ui()

def apply_regex_filter(self):

"""
Filters the operations list based on a regex pattern provided by the user.
"""
pattern = self.ui.regexFilterLe.text()
if not pattern:
# If no pattern, reset to show all operations
self.filtered_operations = self.operations
else:
try:
regex = re.compile(pattern)
self.filtered_operations = [op for op in self.operations if regex.search(op['path'])]
except re.error:
show_popup(self.ui, "Error", "Invalid regex pattern!", icon=2)
self.filtered_operations = self.operations

# Update the UI with the filtered operations
self.display_operations(self.filtered_operations)

def display_operations(self, operations):
"""
Displays the given list of operations in the UI.
"""
self.ui.listOperationsMSC.clear()
for operation in operations:
operation_desc = f'{operation["path"]} - {operation["access_level"]}'
widgetItem = QtWidgets.QListWidgetItem(operation_desc)
widgetItem.op_id = operation["op_id"]
widgetItem.operation_category = operation["category"]
widgetItem.operation_path = operation["path"]
widgetItem.access_level = operation["access_level"]
widgetItem.active_operation_description = operation["description"]
self.ui.listOperationsMSC.addItem(widgetItem)

def server_options_handler(self, index):
selected_option = self.ui.serverOptionsCb.currentText()
self.ui.serverOptionsCb.blockSignals(True)
Expand Down
7 changes: 7 additions & 0 deletions mslib/msui/msui_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ def __init__(self, mscolab_data_dir=None, tutorial_mode=False, *args):
self.actionSaveActiveFlightTrackAs.triggered.connect(self.save_as_handler)
self.actionCloseSelectedFlightTrack.triggered.connect(self.close_selected_flight_track)

# regex filter
self.regexFilterLe.textChanged.connect(self.apply_filter)

# Views menu.
self.actionTopView.triggered.connect(functools.partial(self.create_view_handler, "topview"))
self.actionSideView.triggered.connect(functools.partial(self.create_view_handler, "sideview"))
Expand Down Expand Up @@ -538,6 +541,10 @@ def __init__(self, mscolab_data_dir=None, tutorial_mode=False, *args):
self.actionUpdater.triggered.connect(self.updater.show)
self.openOperationsGb.hide()

def apply_filter(self):
# Trigger filtering in MSColab
self.mscolab.apply_regex_filter()

def bring_main_window_to_front(self):
self.show()
self.raise_()
Expand Down

0 comments on commit 754053e

Please sign in to comment.