Skip to content

Commit

Permalink
WIP: msg box not working
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Jun 30, 2023
1 parent 65a3abd commit 7dc9e4b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
22 changes: 18 additions & 4 deletions dwi_ml/gui/main_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
prepare_and_show_train_l2t_window
from dwi_ml.gui.transformers_menus import open_tto_from_checkpoint_window, \
open_ttst_from_checkpoint_window, open_tto_window, open_ttst_window
from dwi_ml.gui.utils.gui_popup_message import show_info, \
on_selection
from dwi_ml.gui.utils.inputs import assert_single_choice_file_dialog
from dwi_ml.gui.utils.my_styles import get_my_fonts_dictionary
from dwi_ml.gui.utils.window import start_dpg, show_and_end_dpg
Expand All @@ -18,7 +20,6 @@ def file_dialog_ok_callback(sender, app_data):
chosen_path = app_data['current_path']
if sender == "file_dialog_resume_from_checkpoint":
open_checkpoint_subwindow(chosen_path)
# else, nothing. We can access the value of the sender later.


def file_dialog_cancel_callback(_, __):
Expand Down Expand Up @@ -60,8 +61,8 @@ def prepare_main_menu():
# ---------
titles = []
with dpg.window(tag="Primary Window"):
main_title = dpg.add_text(" "
" WELCOME TO DWI_ML")
main_title = dpg.add_text(" "
" WELCOME TO DWI_ML")

##########
# 1. Preparing the HDF5
Expand All @@ -83,6 +84,11 @@ def prepare_main_menu():
##########
# 3. Resume from checkpoint.
##########
dpg.add_button(label="Open Messagebox",
callback=lambda: show_info("Message Box",
"Do you wish to proceed?",
on_selection))

titles.append(dpg.add_text(
"\n\nContinue training model from an existing experiment "
"(resume from checkpoint):"))
Expand Down Expand Up @@ -114,7 +120,15 @@ def prepare_main_menu():
def open_checkpoint_subwindow(chosen_path):
# toDo: if raises a FileNotFoundError, show a pop-up warning?
# Currently, prints the warning in terminal.
checkpoint_path = verify_checkpoint_exists(chosen_path)
try:
checkpoint_path = verify_checkpoint_exists(chosen_path)
except FileNotFoundError:
print("SHOULD SHOW A WARNING")
show_info("Message Box",
"No checkpoint folder found in this directory! Please "
"select another one",
on_selection)
return

model_dir = os.path.join(checkpoint_path, 'model')
model_type = verify_which_model_in_path(model_dir)
Expand Down
38 changes: 38 additions & 0 deletions dwi_ml/gui/utils/gui_popup_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

import dearpygui.dearpygui as dpg


def show_info(title, message, selection_callback):
# guarantee these commands happen in the same frame
with dpg.mutex():
viewport_width = dpg.get_viewport_client_width()
viewport_height = dpg.get_viewport_client_height()
print("HEIGHT, WIDTH: ", viewport_height, viewport_width)

with dpg.window(label=title, modal=True, no_close=True) as modal_id:
dpg.add_text(message)
with dpg.group(horizontal=True):
dpg.add_button(label="Ok", width=75,
user_data=(modal_id, True),
callback=selection_callback)
dpg.add_button(label="Cancel", width=75,
user_data=(modal_id, False),
callback=selection_callback)

# guarantee these commands happen in another frame
dpg.split_frame()
width = dpg.get_item_width(modal_id)
height = dpg.get_item_height(modal_id)
dpg.set_item_pos(modal_id, [viewport_width // 2 - width // 2,
viewport_height // 2 - height // 2])


def on_selection(sender, unused, user_data):
if user_data[1]:
print("User selected 'Ok'")
else:
print("User selected 'Cancel'")

# delete window
dpg.delete_item(user_data[0])

0 comments on commit 7dc9e4b

Please sign in to comment.