8000 refactor/viewdock/show-hide-models by pRottinghuis · Pull Request #192 · RBVI/ChimeraX · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor/viewdock/show-hide-models #19 8000 2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 33 additions & 25 deletions src/bundles/viewdock/src/tool.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ def top_buttons_setup(self):
"""
Create the top buttons for the tool (HBonds and Clashes).
"""
# Add "Show All" button
self.show_all_button = QPushButton("Show All")
self.show_all_button.clicked.connect(
lambda: self.set_visibility(self.structures, True)
)
self.top_buttons_layout.addWidget(self.show_all_button)

# Add "Hide All" button
self.hide_all_button = QPushButton("Hide All")
self.hide_all_button.clicked.connect(
lambda: self.set_visibility(self.structures, False)
)
self.top_buttons_layout.addWidget(self.hide_all_button)

self.hbonds_button = QPushButton("HBonds")
self.hbonds_button.clicked.connect(
lambda: self.popup_callback(
Expand Down Expand Up @@ -159,7 +145,7 @@ def ok_cb():

def table_setup(self):
"""
Create the ItemTable for the structures. Add a column for the display with check boxes, a column for the
Create the ItemTable for the structures. Add a for the
structure ID, a column for the Rating with a custom delegate, and columns for each key in the viewdock_data
attribute of each structure (e.g., Name, Description, Energy Score...). If a structure does not have a key from
the set, the cell will be empty.
Expand All @@ -172,8 +158,7 @@ def table_setup(self):
table_group_layout.addWidget(self.col_display_widget)
table_group.setLayout(table_group_layout)

# Fixed columns. Generic based on ChimeraX model attributes.
self.display_col = self.struct_table.add_column('Show', lambda s: s.display, data_set=self.set_visibility, format=ItemTable.COL_FORMAT_BOOLEAN)
# Fixed columns. Generic based on ChimeraX model attribute(s).
self.struct_table.add_column('ID', lambda s: s.id_string)

# Custom Rating delegate
Expand Down Expand Up @@ -223,14 +208,42 @@ def description_box_setup(self):
self.description_group.setFont(title_font)

self.struct_table.selection_changed.connect(
lambda newly_selected, newly_deselected: self.update_model_description(newly_selected)
lambda newly_selected, newly_deselected: self.table_selection_changed(newly_selected, newly_deselected)
)

# Add the group box to the main layout
self.main_v_layout.addWidget(self.description_group)
# Select the first structure in the table to display its data in the description box
self.struct_table.selected = [self.structures[0]]

def table_selection_changed(self, newly_selected, newly_deselected):
"""
Callback for when the selection in the ItemTable changes. Updates what docking structure is visible and the
description box with the newly selected structure's data.

Args:
newly_selected (list): The newly selected structure(s) in the ItemTable.
newly_deselected (list): The previously selected structure(s) in the ItemTable.
"""
self.update_structure_displays(newly_selected)
self.update_model_description(newly_selected)

def update_structure_displays(self, newly_selected):
"""
Update the display of the docking structures. The newly selected structures will be shown, and all other docking
structures will be hidden.

Args:
newly_selected (list): The newly selected structure(s) in the ItemTable.
"""
# Generate arrays for newly selected and the difference
newly_selected_array = newly_selected
others_array = [s for s in self.structures if s not in newly_selected_array]

# Call set_visibility to show newly selected and hide others
self.set_visibility(newly_selected_array, True)
self.set_visibility(others_array, False)

def update_model_description(self, newly_selected):
"""
Update the description box with the most recently selected structure's data. If more than one structure is
Expand Down Expand Up @@ -302,11 +315,6 @@ def add_handlers(self):
REMOVE_MODELS,
lambda trigger_name, trigger_data: self.remove_models_cb(trigger_name, trigger_data)
))
self.handlers.append(self.session.triggers.add_handler(
MODEL_DISPLAY_CHANGED,
lambda trigger_name, trigger_data: self.struct_table.update_cell(self.display_col, trigger_data)
if trigger_data in self.structures else None
))

def remove_models_cb(self, trigger_name, trigger_data):
""& 7351 quot;
Expand Down Expand Up @@ -339,9 +347,9 @@ def set_visibility(self, structs, value):

model_spec = concise_model_spec(self.session, structs)
if value:
run(self.session, f'show {model_spec} models')
run(self.session, f'show {model_spec} models', log=False)
else:
run(self.session, f'hide {model_spec} models')
run(self.session, f'hide {model_spec} models', log=False)

def delete(self):
"""
Expand Down
Loading
0