Skip to content

Commit

Permalink
New approach to tests, plus nice interface, plus a load of debugging …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
robintw committed Oct 9, 2021
1 parent 7800dae commit bd23c86
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 117 deletions.
1 change: 1 addition & 0 deletions pepys_admin/maintenance/dialogs/progress_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def coroutine():
is_cancelled=self.is_cancelled,
),
)
get_app().progress_bar_finished.fire()
self.future.set_result(result)
except Exception as e:
try:
Expand Down
10 changes: 10 additions & 0 deletions pepys_admin/maintenance/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from prompt_toolkit.layout.menus import CompletionsMenu
from prompt_toolkit.lexers.pygments import PygmentsLexer
from prompt_toolkit.styles import Style
from prompt_toolkit.utils import Event
from prompt_toolkit.widgets.base import Border, Label
from pygments.lexers.sql import SqlLexer
from sqlalchemy.orm import joinedload, undefer
Expand Down Expand Up @@ -141,6 +142,8 @@ def __init__(self, data_store=None):
)

self.app.dropdown_opened = False
self.app.progress_bar_finished = Event(self.app)
self.app.preview_table_updated = Event(self.app)

def init_ui_components(self):
"""Initialise all of the UI components, controls, containers and widgets"""
Expand Down Expand Up @@ -381,6 +384,7 @@ def filter_column_data(self, column_data):
def run_query(self):
"""Runs the query as defined by the FilterWidget,
and displays the result in the preview table."""
logger.debug("Running query")
if self.current_table_object is None:
return

Expand Down Expand Up @@ -460,6 +464,11 @@ def run_query(self):
# the selected items label
self.preview_table.current_values = []
self.update_selected_items_label()
app.invalidate()

logger.debug("Firing preview updated")
logger.debug(f"{len(self.table_objects)=}")
self.app.preview_table_updated.fire()

def get_table_data(self):
return self.table_data
Expand Down Expand Up @@ -582,6 +591,7 @@ def on_filter_widget_change(self, value):
widget is sensible about this and only raises this event if there has actually been
a change in the output of the filters property. That means we can run a query
each time this is called, and the query shouldn't get run more often than is needed."""
logger.debug("on filter widget change")
# Convert the filter object to a SQL string to display in the Complete Query tab
if value != []:
filter_query = filter_widget_output_to_query(
Expand Down
4 changes: 4 additions & 0 deletions pepys_admin/maintenance/widgets/filter_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)

CONTEXTUAL_HELP_STRING = "# Second panel: Build filters (F3)"
from loguru import logger


class FilterWidget:
Expand Down Expand Up @@ -104,6 +105,8 @@ def set_contextual_help(self, widget, text):

def trigger_on_change(self, event=None):
"""Triggers the on_change_handler, if it is defined"""
logger.debug("trigger on change")
logger.debug(f"{self.filters=}")
if self.on_change_handler is not None:
if not list_deep_equals(self.filters, self.last_filters_output):
# Only call event there is a difference from last time we called
Expand Down Expand Up @@ -202,6 +205,7 @@ def filters(self):

for entry_or_boolean in entries_and_booleans:
strings = entry_or_boolean.get_string_values()
logger.debug(f"{strings=}")
if strings[0] == self.column_prompt:
# The column dropdown is still at the default value
continue
Expand Down
Loading

0 comments on commit bd23c86

Please sign in to comment.