Skip to content

Commit

Permalink
Update splash screen code so that it closes properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
astroDimitrios committed Aug 12, 2024
1 parent 20e6b70 commit e4b7774
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 91 deletions.
21 changes: 6 additions & 15 deletions metomi/rose/config_editor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import tempfile
import warnings

from time import sleep

# Ignore add menu related warnings for now, but remove this later.
warnings.filterwarnings('ignore',
'instance of invalid non-instantiatable type',
Expand Down Expand Up @@ -130,7 +132,7 @@ def __init__(self, config_directory=None, config_objs=None,
self.metadata_off = metadata_off
if opt_meta_paths is None:
opt_meta_paths = []
print(2)

# Set page variable 'verbosity' defaults.
self.page_var_show_modes = {
metomi.rose.config_editor.SHOW_MODE_CUSTOM_DESCRIPTION:
Expand Down Expand Up @@ -195,7 +197,7 @@ def __init__(self, config_directory=None, config_objs=None,
self.reporter,
self.tree_trigger_update
))
print(3)

self.mainwindow = metomi.rose.config_editor.window.MainWindow()

self.section_ops = metomi.rose.config_editor.ops.section.SectionOperations(
Expand Down Expand Up @@ -229,7 +231,7 @@ def __init__(self, config_directory=None, config_objs=None,
self.update_ns_sub_data,
self.reload_namespace_tree
)
print(4)

# Add in the main menu bar and tool bar handler.
self.main_handle = metomi.rose.config_editor.menu.MainMenuHandler(
self.data, self.util, self.reporter,
Expand Down Expand Up @@ -274,27 +276,20 @@ def __init__(self, config_directory=None, config_objs=None,
config_obj_type_dict=config_obj_types,
load_all_apps=load_all_apps,
load_no_apps=load_no_apps)
print(str(threading.get_ident())+"5")
print(metomi.rose.config_editor.EVENT_LOAD_STATUSES.format(
self.data.top_level_name))
self.reporter.report_load_event(
metomi.rose.config_editor.EVENT_LOAD_STATUSES.format(
self.data.top_level_name)
)
print(5.1)
if not self.is_pluggable:
self.generate_toolbar()
self.generate_menubar()
self.generate_nav_panel()
self.generate_status_bar()
# Create notebook (tabbed container) and connect signals.
self.notebook = metomi.rose.gtk.util.Notebook()
print(5.2)
self.updater.nav_panel = getattr(self, "nav_panel", None)
print(6)
# Create the main panel with the menu, toolbar, tree panel, notebook.
if not self.is_pluggable:
print(7)
self.mainwindow.load(name=self.data.top_level_name,
menu=self.top_menu,
accelerators=self.menubar.accelerators,
Expand All @@ -304,7 +299,6 @@ def __init__(self, config_directory=None, config_objs=None,
notebook=self.notebook,
page_change_func=self.handle_page_change,
save_func=self.save_to_file)
print(8)
self.mainwindow.window.connect('destroy', self.main_handle.destroy)
self.mainwindow.window.connect('delete-event',
self.main_handle.destroy)
Expand Down Expand Up @@ -1874,7 +1868,6 @@ def spawn_window(config_directory_path=None, debug_mode=False,
title = config_directory_path.split("/")[-1]
splash_screen = metomi.rose.gtk.splash.SplashScreenProcess(logo, title,
number_of_events)
print("We are now here.")
try:
ctrl = MainController(config_directory_path,
load_updater=splash_screen,
Expand All @@ -1886,7 +1879,7 @@ def spawn_window(config_directory_path=None, debug_mode=False,
except BaseException:
splash_screen.stop()
raise
print("1-------")

# open up any initial_namespaces the user has provided us with
if initial_namespaces:
# if the namespace ends with a / remove it
Expand Down Expand Up @@ -1925,9 +1918,7 @@ def spawn_window(config_directory_path=None, debug_mode=False,
True, "main")
Gtk.Settings.get_default().set_long_property("gtk-menu-images",
True, "main")
print("At the end of spawn window")
splash_screen.stop()
print("After splash stop")
Gtk.main()


Expand Down
1 change: 0 additions & 1 deletion metomi/rose/config_editor/nav_panel_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def ask_is_preview(self, base_ns):
config_data = self.data.config[config_name]
return config_data.is_preview
except KeyError:
print(config_name)
return False

def copy_request(self, base_ns, new_section=None, skip_update=False):
Expand Down
6 changes: 0 additions & 6 deletions metomi/rose/config_editor/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(self, load_updater, status_bar_update_func):
def event_handler(self, message, kind=None, level=None, prefix=None,
clip=None):
"""Handle a message or event."""
print(1000)
message_kwargs = {}
if isinstance(message, metomi.rose.reporter.Event):
if kind is None:
Expand All @@ -66,11 +65,8 @@ def event_handler(self, message, kind=None, level=None, prefix=None,
level = message.level
message_kwargs = message.kwargs
if kind == self.EVENT_KIND_LOAD and not self._no_load:
print(str(threading.get_ident())+" 1001")
ret = self._load_updater.update(str(message), **message_kwargs)
print(str(threading.get_ident())+" 1001---")
return ret
print(1002)
return self._status_bar_update_func(message, kind, level)

def report_load_event(
Expand All @@ -80,9 +76,7 @@ def report_load_event(
kind=self.EVENT_KIND_LOAD,
no_progress=no_progress,
new_total_events=new_total_events)
print("Status 1")
self.report(event)
print("Status 1-1")

def set_no_load(self):
self._no_load = True
Expand Down
2 changes: 2 additions & 0 deletions metomi/rose/config_editor/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import metomi.rose.gtk.util
import metomi.rose.resource

import threading


REC_SPLIT_MACRO_TEXT = re.compile(
'(.{' + str(metomi.rose.config_editor.DIALOG_BODY_MACRO_CHANGES_MAX_LENGTH) +
Expand Down
65 changes: 6 additions & 59 deletions metomi/rose/gtk/splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import metomi.rose.gtk.util
import metomi.rose.popen

GObject.threads_init()
# GObject.threads_init()


class SplashScreen(Gtk.Window):
Expand Down Expand Up @@ -94,7 +94,6 @@ def __init__(self, logo_path, title, total_number_of_events):

def update(self, event, no_progress=False, new_total_events=None):
"""Show text corresponding to an event."""
#print(str(threading.get_ident())+"update")
text = str(event)
if new_total_events is not None:
self.total_number_of_events = new_total_events
Expand All @@ -108,24 +107,18 @@ def update(self, event, no_progress=False, new_total_events=None):
else:
fraction = min(
[1.0, self.event_count / self.total_number_of_events])
#print(str(threading.get_ident())+"update 2")
self._stop_pulse()
#print(str(threading.get_ident())+"update 3")
if not no_progress:
GObject.idle_add(self.progress_bar.set_fraction, fraction)
self._progress_fraction = fraction
#print(str(threading.get_ident())+"update 4")
self.progress_bar.set_text(text)
self._progress_message = text
GObject.timeout_add(self.TIME_IDLE_BEFORE_PULSE,
self._start_pulse, fraction, text)
#print(str(threading.get_ident())+"update 5")
if fraction == 1.0 and not no_progress:
GObject.timeout_add(self.TIME_WAIT_FINISH, self.finish)
#print(str(threading.get_ident())+"update 6")
while Gtk.events_pending():
Gtk.main_iteration()
#print(str(threading.get_ident())+"update 7")

def _start_pulse(self, idle_fraction, idle_message):
"""Start the progress bar pulsing (moving side-to-side)."""
Expand Down Expand Up @@ -198,23 +191,13 @@ def update(self, *args, **kwargs):
return self._update_buffered(*args, **kwargs)
self._flush_buffer()
json_text = json.dumps({"args": args, "kwargs": kwargs})
#print(str(threading.get_ident())+"splash L201")
#print(str(threading.get_ident())+json_text)
self._communicate(json_text)

def _communicate(self, json_text):
# breakpoint()
while True:
#print(str(threading.get_ident())+"COMMUNICATING")
#print(str(threading.get_ident())+json_text)
try:
# what to do with this - got a ValueError not IOError
# because the file end was reached
# self.start()
self.process.stdin.write((json_text + "\n").encode())
#print(str(threading.get_ident())+"COMMUNICATING AHHHHHHHHHH")
except IOError:
#print(str(threading.get_ident())+"aghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")
self.start()
self.process.stdin.write((json_text + "\n").encode())
else:
Expand All @@ -238,21 +221,10 @@ def _update_buffered(self, *args, **kwargs):
__call__ = update

def start(self):
#print(str(threading.get_ident())+"STARTING------------------------------------")
self.process = Popen(["rose", "launch-splash-screen"] + list(self.args), stdin=PIPE)

def stop(self):
print("Inside splash stop")
if self.process is not None and not self.process.stdin.closed:
try:
print("Inside splash stop try")
#print(str(threading.get_ident())+" STOPPING------------------------------------")
print((json.dumps("stop") + "\n"))
self.process.stdin.write((json.dumps("stop") + "\n").encode())
print("Inside splash stop try - completed FINE")
except IOError:
pass
# self.process.kill()
self.process.kill()
self.process = None


Expand All @@ -268,51 +240,29 @@ def __init__(self, window, stop_event, stdin):

def run(self):
"""Loop over time and wait for stdin lines."""
#print(str(threading.get_ident())+"Update 100")
# breakpoint()
GObject.timeout_add(1000, self._check_splash_screen_alive)
while not self.stop_event.is_set():
time.sleep(0.005)
if self.stop_event.is_set():
#print(str(threading.get_ident())+" 123")
return False
try:
print(str(threading.get_ident())+" std_line")
stdin_line = self.stdin.readline()
print(stdin_line)
# if not stdin_line:
# continue
#print(str(threading.get_ident())+"stdin_line")
if not stdin_line:
continue
except IOError:
continue
# if len(stdin_line) == 0:
# #print(str(threading.get_ident())+"HIT HIT HTO")
# # update_input = "stop"
# # self._stop()
# continue
try:
# #print(str(threading.get_ident())+12345)
update_input = json.loads(stdin_line.strip())
print(str(threading.get_ident())+" " +str(update_input))
# #print(str(threading.get_ident())+repr(update_input))
# #print(str(threading.get_ident())+len(update_input))
except ValueError:
continue
# if len(stdin_line) == 0:
# update_input = "stop"
if update_input == "stop":
print(str(threading.get_ident())+" stop message received")
self._stop()
self.stop_event.set()
continue
GObject.idle_add(self._update_splash_screen, update_input)
#print(str(threading.get_ident())+" Update 1001")

def _stop(self):
print(str(threading.get_ident())+" Inside _stop in splash")
self.stop_event.set()
def stop(self):
try:
Gtk.main_quit()
print(str(threading.get_ident())+" Inside _stop in splash - splash was quit")
except RuntimeError:
# This can result from gtk having already quit.
pass
Expand All @@ -326,7 +276,6 @@ def _check_splash_screen_alive(self):

def _update_splash_screen(self, update_input):
"""Update the splash screen with info extracted from stdin."""
#print(str(threading.get_ident())+" _update_splash_screen")
self.window.update(*update_input["args"], **update_input["kwargs"])
return False

Expand All @@ -344,8 +293,6 @@ def main(argv=sys.argv):
except KeyboardInterrupt:
pass
finally:
"FINALLY SPLASH +++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
stop_event.set()
update_thread.join()


Expand Down
10 changes: 0 additions & 10 deletions metomi/rose/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,11 @@ def report(self, message, kind=None, level=None, prefix=None, clip=None):
arguments and return its result instead.
"""
print("reporting 1")
if isinstance(message, bytes):
message = message.decode()
print("reporting 2")
if callable(self.event_handler):
print("reporting 3")
print(message)
print(kind)
print(level)
print(prefix)
print(clip)
ret = self.event_handler(message, kind, level, prefix, clip)
print("Reporter after ret L150")
return ret
print("reporting")
if isinstance(message, Event):
if kind is None:
kind = message.kind
Expand Down

0 comments on commit e4b7774

Please sign in to comment.