new: test new gui (dpg)
This commit is contained in:
parent
e0c6686d2b
commit
f06eb9aaad
Binary file not shown.
137
anisotropy/newgui/geometry.py
Normal file
137
anisotropy/newgui/geometry.py
Normal file
@ -0,0 +1,137 @@
|
||||
import dearpygui.dearpygui as dpg
|
||||
|
||||
def create_geometry(parent):
|
||||
with dpg.child_window(
|
||||
tag = "geometry_container",
|
||||
parent = parent
|
||||
) as container:
|
||||
dpg.add_button(label = "Add case", callback = Case.create(container))
|
||||
with dpg.group(horizontal = True):
|
||||
dpg.add_text("Cases")
|
||||
dpg.add_separator()
|
||||
|
||||
return container
|
||||
|
||||
class Case:
|
||||
case_list = []
|
||||
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.uuid = dpg.generate_uuid()
|
||||
self.values = {}
|
||||
Case.case_list.append(self)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"<Case: { self.uuid }, type: geometry>"
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
@staticmethod
|
||||
def create(parent):
|
||||
def create_callback():
|
||||
case = Case(parent)
|
||||
|
||||
with dpg.collapsing_header(label = f"g-case-{ case.uuid }", parent = case.parent) as case._case:
|
||||
with dpg.child_window(height = 300) as case.child_window:
|
||||
with dpg.group(horizontal = True):
|
||||
case._source = dpg.add_combo(["", "from file", "periodic"], label = "Source")
|
||||
|
||||
dpg.add_button(label = "Remove", callback = case.remove_case)
|
||||
dpg.add_button(label = "Edit", callback = case.edit_case)
|
||||
|
||||
case.create_stats()
|
||||
|
||||
case.create_params_file()
|
||||
case.create_params_periodic()
|
||||
|
||||
return create_callback
|
||||
|
||||
def remove_case(self):
|
||||
dpg.delete_item(self._case)
|
||||
Case.case_list.remove(self)
|
||||
|
||||
def edit_case(self):
|
||||
source_val = dpg.get_value(self._source)
|
||||
|
||||
if source_val == "from file":
|
||||
dpg.show_item(self._file_params)
|
||||
|
||||
elif source_val == "periodic":
|
||||
dpg.show_item(self._periodic_params)
|
||||
|
||||
def create_stats(self):
|
||||
with dpg.table(header_row = True, parent = self.child_window) as self._case_stats:
|
||||
dpg.add_table_column(label = "Parameters")
|
||||
dpg.add_table_column(label = "")
|
||||
|
||||
for k, v in self.values.items():
|
||||
with dpg.table_row():
|
||||
dpg.add_text(k)
|
||||
dpg.add_text(v)
|
||||
|
||||
def update_stats(self):
|
||||
dpg.delete_item(self._case_stats)
|
||||
self.create_stats()
|
||||
|
||||
def create_params_file(self):
|
||||
with dpg.window(show = False, modal = True, height = 600, width = 400) as self._file_params:
|
||||
with dpg.group(horizontal = True):
|
||||
self._file_input = dpg.add_input_text(label = "File")
|
||||
dpg.add_button(label = "..", callback = lambda: dpg.show_item(self._file_dialog))
|
||||
|
||||
with dpg.file_dialog(
|
||||
directory_selector = False,
|
||||
show = False,
|
||||
modal = True,
|
||||
callback = lambda s, d: dpg.set_value(self._file_input, d['file_path_name']),
|
||||
height = 400,
|
||||
width = 600
|
||||
) as self._file_dialog:
|
||||
dpg.add_file_extension(".geo")
|
||||
|
||||
dpg.add_button(label = "Save", width = -1)
|
||||
|
||||
def create_params_periodic(self):
|
||||
def alpha_type_cb(s, d):
|
||||
type_val = dpg.get_value(self._alpha_type)
|
||||
|
||||
if type_val == "float":
|
||||
dpg.show_item(self._alpha_float)
|
||||
dpg.hide_item(self._alpha_range)
|
||||
|
||||
elif type_val == "range":
|
||||
dpg.hide_item(self._alpha_float)
|
||||
dpg.show_item(self._alpha_range)
|
||||
|
||||
with dpg.window(show = False, modal = True, height = 600, width = 400) as self._periodic_params:
|
||||
self._label_str = dpg.add_input_text(label = "label")
|
||||
|
||||
with dpg.group(horizontal = True):
|
||||
self._alpha_type = dpg.add_combo(["float", "range"], default_value = "float", width = 100, callback = alpha_type_cb)
|
||||
self._alpha_float = dpg.add_input_float(label = "alpha")
|
||||
self._alpha_range = dpg.add_input_floatx(label = "alpha", size = 3, show = False)
|
||||
|
||||
self._r0_float = dpg.add_input_float(label = "r_0")
|
||||
|
||||
dpg.add_separator()
|
||||
dpg.add_button(label = "Save", width = -1, callback = self.save_params)
|
||||
|
||||
def save_params(self):
|
||||
source_val = dpg.get_value(self._source)
|
||||
|
||||
if source_val == "from file":
|
||||
self.values.update(
|
||||
filepath = dpg.get_value(self._file_input)
|
||||
)
|
||||
|
||||
elif source_val == "periodic":
|
||||
self.values.update(
|
||||
label = dpg.get_value(self._label_str),
|
||||
alpha = dpg.get_value(self._alpha_range) if dpg.get_value(self._alpha_type) == "range" else dpg.get_value(self._alpha_float),
|
||||
r0 = dpg.get_value(self._r0_float),
|
||||
)
|
||||
|
||||
self.update_stats()
|
||||
dpg.hide_item(self._periodic_params)
|
88
anisotropy/newgui/newgui.py
Normal file
88
anisotropy/newgui/newgui.py
Normal file
@ -0,0 +1,88 @@
|
||||
import dearpygui.dearpygui as dpg
|
||||
import pathlib
|
||||
|
||||
import geometry
|
||||
|
||||
|
||||
gui_path = pathlib.Path(__file__).resolve().parent
|
||||
dpg.create_context()
|
||||
|
||||
|
||||
with dpg.font_registry():
|
||||
print(gui_path)
|
||||
default_font = dpg.add_font(gui_path / "fonts/NotoSansMono-Regular-Nerd-Font-Complete.ttf", 20)
|
||||
|
||||
|
||||
|
||||
with dpg.window(tag = "Primary") as primary:
|
||||
dpg.bind_font(default_font)
|
||||
|
||||
with dpg.menu_bar(tag = "m1"):
|
||||
with dpg.menu(label = "File"):
|
||||
dpg.add_menu_item(label = "Preferences", callback = lambda: dpg.configure_item("preferences", show = True))
|
||||
dpg.add_menu_item(label = "Exit", callback = lambda: dpg.destroy_context())
|
||||
|
||||
with dpg.menu(label = "Tools"):
|
||||
dpg.add_menu_item(label = "Geometry", callback = lambda: dpg.show_item("geometry"))
|
||||
dpg.add_menu_item(label = "Mesh", callback = lambda: dpg.show_item("mesh"))
|
||||
dpg.add_menu_item(label = "Solver", callback = lambda: dpg.show_item("solver"))
|
||||
dpg.add_menu_item(label = "Runner", callback = lambda: dpg.show_item("runner"))
|
||||
dpg.add_separator()
|
||||
dpg.add_menu_item(label = "Database", callback = lambda: dpg.show_item("database"))
|
||||
dpg.add_menu_item(label = "Post-processing", callback = lambda: dpg.show_item("post-processing"))
|
||||
|
||||
with dpg.child_window(tag = "Test22", border = False, height = -40):
|
||||
|
||||
with dpg.child_window(tag = "Test", border = False):
|
||||
with dpg.tab_bar(label = "tabbar"):
|
||||
with dpg.tab(label = "Geometry", tag = "geometry", closable = True, show = False):
|
||||
geometry.create_geometry("geometry")
|
||||
|
||||
with dpg.item_handler_registry(tag="widget handler"):
|
||||
dpg.add_item_edited_handler(callback = lambda: dpg.delete_item("mesh") if not dpg.is_item_shown("mesh") else None)
|
||||
|
||||
with dpg.tab(label = "Mesh", tag = "mesh", closable = True, show = False):
|
||||
with dpg.child_window(tag = "mesh_container", border = True):
|
||||
dpg.add_text("")
|
||||
|
||||
# bind item handler registry to item
|
||||
dpg.bind_item_handler_registry("mesh", "widget handler")
|
||||
|
||||
with dpg.tab(label = "Solver", tag = "solver", closable = True, show = False):
|
||||
with dpg.child_window(tag = "solver_container", border = True):
|
||||
dpg.add_text("")
|
||||
|
||||
with dpg.tab(label = "Runner", tag = "runner", closable = True, show = False):
|
||||
with dpg.child_window(tag = "runner_container", border = True):
|
||||
dpg.add_text("")
|
||||
|
||||
with dpg.tab(label = "Database", tag = "database", closable = True, show = False):
|
||||
with dpg.child_window(tag = "database_container", border = True):
|
||||
dpg.add_text("")
|
||||
|
||||
with dpg.tab(label = "Post-processing", tag = "post-processing", closable = True, show = False):
|
||||
with dpg.child_window(tag = "post-processing_container", border = True):
|
||||
dpg.add_text("")
|
||||
|
||||
dpg.add_separator()
|
||||
with dpg.table(tag = "statusbar", header_row = False):
|
||||
dpg.add_table_column(label = "")
|
||||
dpg.add_table_column(label = "")
|
||||
|
||||
with dpg.table_row():
|
||||
dpg.add_button(label = "Debug", callback = lambda: print(dpg.get_value("mesh")))
|
||||
dpg.add_text("status")
|
||||
|
||||
with dpg.window(label = "Preferences", tag = "preferences", modal = True, show = False, width = 400, height = 600):
|
||||
with dpg.collapsing_header(label = "General"):
|
||||
with dpg.group(horizontal = True):
|
||||
dpg.add_text("Font")
|
||||
dpg.add_text(dpg.get_item_font("Primary"))
|
||||
|
||||
dpg.create_viewport(title = "New GUI", width = 1000, height = 800)
|
||||
dpg.setup_dearpygui()
|
||||
dpg.show_viewport()
|
||||
dpg.set_primary_window("Primary", True)
|
||||
dpg.start_dearpygui()
|
||||
|
||||
dpg.destroy_context()
|
Loading…
Reference in New Issue
Block a user