Skip to content

Commit

Permalink
For #14: Don't render results table if user requested more than 64 co…
Browse files Browse the repository at this point in the history
…lumns
  • Loading branch information
retifrav committed Jan 21, 2022
1 parent 83e066d commit f85eb0f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/tap_adql_sandbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@

tabulateFloatfmtPrecision = "g"

# Dear PyGui (and Dear ImGui) has a limitation of 64 columns in a table
# https://dearpygui.readthedocs.io/en/latest/documentation/tables.html
# https://github.com/ocornut/imgui/issues/2957#issuecomment-758136035
# https://github.com/ocornut/imgui/pull/4876
dpgColumnsMax = 64

windowMinWidth = 900

lastQueryResults = {}
executingQuery = False

Expand Down Expand Up @@ -125,6 +133,23 @@ def executeQuery():
print(f"[WARNING] Couldn't print results. {ex}")

lastQueryResults = results.to_table().to_pandas()
rowsCount, columnsCount = lastQueryResults.shape
if debugMode:
print(f"[DEBUG] Columns: {columnsCount}, rows: {rowsCount}")
if columnsCount > dpgColumnsMax:
dpg.set_value(
"errorMessage",
" ".join((
"You have requested too many columns in your query.",
f"Dear PyGui only supports maximum {dpgColumnsMax} columns",
"in a table, and so trying to display results for your query",
"will crash the application. Remove some columns from your",
"SELECT statement and try again."
))
)
dpg.show_item("errorMessage")
showLoading(False)
return
# try:
with dpg.table(
parent="resultsGroup",
Expand Down Expand Up @@ -395,6 +420,8 @@ def main():
dpg.add_text(
tag="errorMessage",
default_value="Error",
# https://github.com/hoffstadt/DearPyGui/issues/1275
wrap=windowMinWidth-50,
show=False
)

Expand Down Expand Up @@ -505,7 +532,7 @@ def main():
title="TAP ADQL sandbox",
width=1200,
height=800,
min_width=900,
min_width=windowMinWidth,
min_height=600,
small_icon=str(applicationPath/"icons/planet-128.ico"),
large_icon=str(applicationPath/"icons/planet-256.ico")
Expand Down

0 comments on commit f85eb0f

Please sign in to comment.