|
|
@@ -25,6 +25,13 @@ STATUS_CONSOLE_TAG = "__status_console"
|
|
|
QUERY_FILTER_TAG = "__query_filter"
|
|
|
ENDPOINT_TEXTINPUT_TAG = "__endpoint_input"
|
|
|
POST_METHOD_CHECKBOX_TAG = "__use_post_method"
|
|
|
+QUERY_RESULT_WINDOW_TAG = "__query_results_window"
|
|
|
+QUERY_RESULT_TAB_TAG = "__query_result_tab"
|
|
|
+RESULT_TABLE_TAG = "__result_table"
|
|
|
+PRIMARY_WINDOW_TAG = "__primary"
|
|
|
+QUERY_EDITOR_VISUAL_TAG = "__query_editor_visual"
|
|
|
+QUERY_EDITOR_TEXTUAL_TAG = "__query_editor_textual"
|
|
|
+EDITOR_SELECTOR_TAG = "__editor_selector"
|
|
|
|
|
|
RADIO_BUTTON_TYPE = "mvAppItemType::mvRadioButton"
|
|
|
|
|
|
@@ -62,6 +69,10 @@ def _config(sender, keyword, user_data):
|
|
|
else:
|
|
|
dpg.configure_item(items, **{keyword: value})
|
|
|
|
|
|
+def __save():
|
|
|
+ """Save current query to a file."""
|
|
|
+ logging.debug("Saving.")
|
|
|
+
|
|
|
def add_main_menu():
|
|
|
with dpg.menu_bar():
|
|
|
with dpg.menu(label="Menu"):
|
|
|
@@ -109,7 +120,7 @@ def create_query_palette(query_palette: List[QueryTemplate]):
|
|
|
|
|
|
def create_query_options(endpoint: str):
|
|
|
with dpg.group(horizontal=True):
|
|
|
- dpg.add_combo(("Visual", "Textual"), default_value="Visual", callback=_mode_select, width=100, tag="__editor_selector")
|
|
|
+ dpg.add_combo(("Visual", "Textual"), default_value="Visual", callback=_mode_select, width=100, tag=EDITOR_SELECTOR_TAG)
|
|
|
dpg.add_input_text(default_value=endpoint, width=300, enabled=False, tag=ENDPOINT_TEXTINPUT_TAG)
|
|
|
dpg.add_checkbox(label="debug", callback=_config)
|
|
|
dpg.add_checkbox(label="annotate", default_value=False, callback=_config) # TODO Actually make this annotate the result data with its type
|
|
|
@@ -117,14 +128,14 @@ def create_query_options(endpoint: str):
|
|
|
# TODO Make the elements color coded etc...
|
|
|
# TODO Fix context menu and keyboard operations
|
|
|
def create_query_editor_visual(example_prefix:str, example_query:str, show: bool = False):
|
|
|
- with dpg.child_window(autosize_x=True, height=500, menubar=True, show=show, tag="__query_editor_visual"):
|
|
|
+ with dpg.child_window(autosize_x=True, height=500, menubar=True, show=show, tag=QUERY_EDITOR_VISUAL_TAG):
|
|
|
with dpg.menu_bar():
|
|
|
dpg.add_menu(label="Visual Query Editor", enabled=False)
|
|
|
with dpg.tab_bar():
|
|
|
with dpg.tab(label="Query", tag="__query_tab"):
|
|
|
- dpg.add_input_text(default_value=example_query, callback=_log, multiline=True, on_enter=True, height=300, width=-1, tag="__query_editor_visual_input")
|
|
|
+ dpg.add_input_text(default_value=example_query, multiline=True, on_enter=True, height=300, width=-1, tag="__query_editor_visual_input")
|
|
|
with dpg.tab(label="Prefix", tag="__prefix_tab"):
|
|
|
- dpg.add_input_text(default_value=example_prefix, callback=_log, multiline=True, on_enter=True, height=300, width=-1, tag="__prefix_editor_visual_input")
|
|
|
+ dpg.add_input_text(default_value=example_prefix, multiline=True, on_enter=True, height=300, width=-1, tag="__prefix_editor_visual_input")
|
|
|
with dpg.tab(label="Advanced", tag="__advanced_tab"):
|
|
|
dpg.add_checkbox(label="Use post method", default_value=False, tag=POST_METHOD_CHECKBOX_TAG)
|
|
|
with dpg.group(tag="__visual_editor_fields"):
|
|
|
@@ -138,14 +149,14 @@ def create_query_editor_visual(example_prefix:str, example_query:str, show: bool
|
|
|
# TODO Maybe remove/change this option, we made all the queries mostly 'visual'
|
|
|
# It's practically a duplicate at this point
|
|
|
def create_query_editor_textual(example_prefix:str, example_query:str, show: bool = False):
|
|
|
- with dpg.child_window(autosize_x=True, height=500, menubar=True, show=show, tag="__query_editor_textual"):
|
|
|
+ with dpg.child_window(autosize_x=True, height=500, menubar=True, show=show, tag=QUERY_EDITOR_TEXTUAL_TAG):
|
|
|
with dpg.menu_bar():
|
|
|
dpg.add_menu(label="Textual Query Editor", enabled=False)
|
|
|
with dpg.tab_bar():
|
|
|
with dpg.tab(label="Query", tag="__query_textual_tab"):
|
|
|
- dpg.add_input_text(default_value=example_query, callback=_log, multiline=True, on_enter=True, height=300, width=-1, tag="__query_editor_textual_input")
|
|
|
+ dpg.add_input_text(default_value=example_query, multiline=True, on_enter=True, height=300, width=-1, tag="__query_editor_textual_input")
|
|
|
with dpg.tab(label="Prefix", tag="__prefix_textual_tab"):
|
|
|
- dpg.add_input_text(default_value=example_prefix, callback=_log, multiline=True, on_enter=True, height=300, width=-1, tag="__prefix_editor_textual_input")
|
|
|
+ dpg.add_input_text(default_value=example_prefix, multiline=True, on_enter=True, height=300, width=-1, tag="__prefix_editor_textual_input")
|
|
|
with dpg.group(horizontal=True):
|
|
|
dpg.add_button(label="Query", callback=_perform_query)
|
|
|
dpg.add_button(label="Save", callback=_select_directory) # TODO
|
|
|
@@ -165,16 +176,16 @@ def set_copy(element: Union[int, str], text_data:str):
|
|
|
dpg.set_value(f"__copy_drag_{i}", shorten(text_data))
|
|
|
|
|
|
def create_query_results():
|
|
|
- with dpg.child_window(autosize_x=True, autosize_y=True, menubar=True, tag="__query_results_window"):
|
|
|
+ with dpg.child_window(autosize_x=True, autosize_y=True, menubar=True, tag=QUERY_RESULT_WINDOW_TAG):
|
|
|
with dpg.menu_bar():
|
|
|
dpg.add_menu(label="Results", enabled=False)
|
|
|
# dpg.add_input_text(label="Filter", tag="__result_filter_input", callback=lambda s, a: dpg.set_value("__result_filter", a))
|
|
|
with dpg.tab_bar():
|
|
|
- with dpg.tab(label="Query Result", tag="__query_result_tab"):
|
|
|
+ with dpg.tab(label="Query Result", tag=QUERY_RESULT_TAB_TAG):
|
|
|
with dpg.table(header_row=True, policy=dpg.mvTable_SizingFixedFit, row_background=True, reorderable=True,
|
|
|
resizable=True, no_host_extendX=False, hideable=True,
|
|
|
borders_innerV=True, delay_search=True, borders_outerV=True, borders_innerH=True,
|
|
|
- borders_outerH=True, tag="__result_table"):
|
|
|
+ borders_outerH=True, tag=RESULT_TABLE_TAG):
|
|
|
pass
|
|
|
with dpg.tab(label="Saved"):
|
|
|
with dpg.group(horizontal=True):
|
|
|
@@ -190,15 +201,12 @@ def create_query_results():
|
|
|
dpg.add_text("This is the debug tab!")
|
|
|
|
|
|
|
|
|
-def _log(sender: int, app_data: str, user_data: Optional[dict]):
|
|
|
- logging.debug(f"sender: {sender}, \t app_data: {app_data}, \t user_data: {user_data}")
|
|
|
-
|
|
|
def _mode_select(sender: int, mode: str, user_data: Optional[dict]):
|
|
|
mode = mode.lower().strip()
|
|
|
visual = mode == "visual"
|
|
|
# TODO When showing visual we need to fix the custom fields
|
|
|
- dpg.configure_item("__query_editor_visual", show=visual)
|
|
|
- dpg.configure_item("__query_editor_textual", show=not visual)
|
|
|
+ dpg.configure_item(QUERY_EDITOR_VISUAL_TAG, show=visual)
|
|
|
+ dpg.configure_item(QUERY_EDITOR_TEXTUAL_TAG, show=not visual)
|
|
|
|
|
|
def shorten(identifier: str) -> str:
|
|
|
for key, value in query.reverse_prefix.items():
|
|
|
@@ -206,7 +214,7 @@ def shorten(identifier: str) -> str:
|
|
|
return identifier
|
|
|
|
|
|
def _query_palette_click(sender: int, mode: str, user_data: Optional[QueryTemplate]):
|
|
|
- mode = dpg.get_value("__editor_selector").lower().strip()
|
|
|
+ mode = dpg.get_value(EDITOR_SELECTOR_TAG).lower().strip()
|
|
|
if mode == "visual" and not user_data.visual_support:
|
|
|
logging.warning(f"Visual mode for template '{user_data.name}' not implemented yet!")
|
|
|
set_status_text(f"Visual mode for template '{user_data.name}' not implemented yet!", StatusMessageType.WARNING)
|
|
|
@@ -222,7 +230,7 @@ def _query_palette_click(sender: int, mode: str, user_data: Optional[QueryTempla
|
|
|
|
|
|
def _perform_query(sender: int, mode: str, user_data: Optional[dict]):
|
|
|
# TODO Fix for new query structure
|
|
|
- mode = dpg.get_value("__editor_selector").lower().strip()
|
|
|
+ mode = dpg.get_value(EDITOR_SELECTOR_TAG).lower().strip()
|
|
|
prefix_text = dpg.get_value(f"__prefix_editor_{mode}_input")
|
|
|
query_text = dpg.get_value(f"__query_editor_{mode}_input")
|
|
|
endpoint = dpg.get_value(ENDPOINT_TEXTINPUT_TAG)
|
|
|
@@ -245,21 +253,21 @@ def _perform_query(sender: int, mode: str, user_data: Optional[dict]):
|
|
|
return
|
|
|
result_items = query_result["results"]["bindings"]
|
|
|
if not result_items:
|
|
|
- dpg.delete_item("__result_table", children_only=True) # TODO Clear table https://github.com/hoffstadt/DearPyGui/issues/1350
|
|
|
+ dpg.delete_item(RESULT_TABLE_TAG, children_only=True)
|
|
|
logging.debug(f"No results returned.")
|
|
|
set_status_text("No results.")
|
|
|
return
|
|
|
- dpg.delete_item("__result_table", children_only=True)
|
|
|
+ dpg.delete_item(RESULT_TABLE_TAG, children_only=True)
|
|
|
set_status_text("Query successful.")
|
|
|
columns = result_items[0].keys()
|
|
|
for column in columns:
|
|
|
- dpg.add_table_column(label=column, width_fixed=True, parent="__result_table")
|
|
|
+ dpg.add_table_column(label=column, width_fixed=True, parent=RESULT_TABLE_TAG)
|
|
|
# dpg.add_table_column(label="CCC", width_stretch=True, init_width_or_weight=0.0)
|
|
|
# TODO This is as brittle as my ego, needs a fix asap
|
|
|
# TODO Fix filter
|
|
|
- # with dpg.filter_set(tag="__result_filter", parent="__query_result_tab"):
|
|
|
+ # with dpg.filter_set(tag="__result_filter", parent=QUERY_RESULT_TAB_TAG):
|
|
|
for result in result_items:
|
|
|
- with dpg.table_row(parent=f"__result_table"):
|
|
|
+ with dpg.table_row(parent=RESULT_TABLE_TAG):
|
|
|
for key, value in result.items():
|
|
|
shortened = shorten(f"{value.get('value')}")
|
|
|
dpg.add_text(shortened, filter_key=shortened)
|
|
|
@@ -287,7 +295,7 @@ def interface(example_prefix: str, example_query: str, palette: List[QueryTempla
|
|
|
"""Show the full user interface."""
|
|
|
dpg.create_context()
|
|
|
dpg.create_viewport(title="Graph Exploring Tool", width=width, height=height)
|
|
|
- with dpg.window(tag="primary", label="Graph Exploring Tool", menubar=True):
|
|
|
+ with dpg.window(tag=PRIMARY_WINDOW_TAG, label="Graph Exploring Tool", menubar=True):
|
|
|
add_main_menu()
|
|
|
with dpg.group(horizontal=True, label="Main"):
|
|
|
create_query_palette(palette)
|
|
|
@@ -300,6 +308,6 @@ def interface(example_prefix: str, example_query: str, palette: List[QueryTempla
|
|
|
# demo.show_demo()
|
|
|
dpg.setup_dearpygui()
|
|
|
dpg.show_viewport()
|
|
|
- dpg.set_primary_window("primary", True)
|
|
|
+ dpg.set_primary_window(PRIMARY_WINDOW_TAG, True)
|
|
|
dpg.start_dearpygui()
|
|
|
dpg.destroy_context()
|