From e635549a824f11869f568fe0621b5972dd9db443 Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Mon, 1 Jun 2020 16:03:06 +0200 Subject: [PATCH 1/6] [Editor] Add Refresh Terminologies Cache Functionality --- odmlui/editor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/odmlui/editor.py b/odmlui/editor.py index fe72a33..52f9f64 100644 --- a/odmlui/editor.py +++ b/odmlui/editor.py @@ -8,6 +8,7 @@ import pygtkcompat from odml.property import BaseProperty +import odml.terminology as terminology import odmlui.treemodel.mixin from odmlui.info import AUTHOR, CONTACT, COPYRIGHT, HOMEPAGE, VERSION, ODMLTABLES_VERSION @@ -64,6 +65,7 @@ + @@ -185,7 +187,7 @@ class EditorWindow(gtk.Window): welcome_disabled_actions = ["Save", "SaveAs", "Undo", "Redo", "NewSection", "NewProperty", "NewValue", "Delete", "CloneTab", "Validate", "odMLTablesCompare", "odMLTablesConvert", - "odMLTablesFilter", "odMLTablesMerge"] + "odMLTablesFilter", "odMLTablesMerge", "RefreshCache"] def __init__(self, parent=None): gtk.Window.__init__(self) @@ -944,6 +946,12 @@ def quit(self, action, extra=None): return True gtk.main_quit() + @gui_action("RefreshCache", tooltip="Refresh Document Terminologies Cache", label="Refresh Cache") + def on_refresh_cache(self, action): + url = self.current_tab.document.repository + if url: + terminology.refresh(url) + @gui_action("NewSection", label="Add Section", tooltip="Add a section to the current selected one", stock_id="odml_addSection") From 538f259aa507eae06f628d4b98161e9b95995a0c Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Tue, 2 Jun 2020 22:49:09 +0200 Subject: [PATCH 2/6] [Editor] Add Threading for Cache Refresh --- odmlui/editor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odmlui/editor.py b/odmlui/editor.py index 52f9f64..0dfb4aa 100644 --- a/odmlui/editor.py +++ b/odmlui/editor.py @@ -14,6 +14,8 @@ from odmlui.info import AUTHOR, CONTACT, COPYRIGHT, HOMEPAGE, VERSION, ODMLTABLES_VERSION from odmlui.treemodel import section_model, value_model +import threading + import gtk import gobject @@ -950,7 +952,8 @@ def quit(self, action, extra=None): def on_refresh_cache(self, action): url = self.current_tab.document.repository if url: - terminology.refresh(url) + thread = threading.Thread(target=lambda rep_url: terminology.refresh, args=(url,)) + thread.start() @gui_action("NewSection", label="Add Section", tooltip="Add a section to the current selected one", From 590d8d518b24cfc8906026412762487a5344a5e3 Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Thu, 18 Jun 2020 10:57:25 +0200 Subject: [PATCH 3/6] [message_dialog] Add WaitDialog For longer processes blocking the application. --- odmlui/message_dialog.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/odmlui/message_dialog.py b/odmlui/message_dialog.py index 2f23e93..061dc4e 100644 --- a/odmlui/message_dialog.py +++ b/odmlui/message_dialog.py @@ -68,3 +68,15 @@ def display(self): if response == gtk.ResponseType.OK: return True return False + + +class WaitDialog(gtk.MessageDialog): + + def __init__(self, parent, primary_msg, secondary_msg): + super(WaitDialog, self).__init__() + self.set_property('text', primary_msg) + self.set_property('secondary-text', secondary_msg) + self.set_transient_for(parent) + + def change(self, msg): + self.set_property('secondary-text', msg) From ead519bffe115088e4cfba42d35f78cc29a0d11c Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Thu, 18 Jun 2020 11:04:56 +0200 Subject: [PATCH 4/6] [editor] Imports for Updating Terminologies Cache --- odmlui/editor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/odmlui/editor.py b/odmlui/editor.py index 0dfb4aa..f386d21 100644 --- a/odmlui/editor.py +++ b/odmlui/editor.py @@ -5,6 +5,10 @@ from distutils.version import LooseVersion as CheckVer +import time +import threading +from gi.repository import GLib, GObject + import pygtkcompat from odml.property import BaseProperty @@ -14,8 +18,6 @@ from odmlui.info import AUTHOR, CONTACT, COPYRIGHT, HOMEPAGE, VERSION, ODMLTABLES_VERSION from odmlui.treemodel import section_model, value_model -import threading - import gtk import gobject @@ -26,7 +28,7 @@ from .helpers import uri_to_path, get_extension, get_parser_for_file_type, \ get_parser_for_uri, get_conda_root, run_odmltables from .info_bar import EditorInfoBar -from .message_dialog import DecisionDialog +from .message_dialog import DecisionDialog, WaitDialog from .navigation_bar import NavigationBar from .property_view import PropertyView from .scrolled_window import ScrolledWindow From 999373701e7da6aea54077b3d2616902d2d50c63 Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Thu, 18 Jun 2020 11:05:57 +0200 Subject: [PATCH 5/6] [editor] Change to GObject.threads_init() --- odmlui/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odmlui/editor.py b/odmlui/editor.py index f386d21..15fdcbe 100644 --- a/odmlui/editor.py +++ b/odmlui/editor.py @@ -38,7 +38,7 @@ pygtkcompat.enable() pygtkcompat.enable_gtk(version='3.0') -gtk.gdk.threads_init() +GObject.threads_init() UI_INFO = \ ''' From fd9620d549e3c32858f4810ad1d7ef7cdcf8a2fc Mon Sep 17 00:00:00 2001 From: fschrader1992 Date: Thu, 18 Jun 2020 11:33:00 +0200 Subject: [PATCH 6/6] [editor] Fix Terminologies Update Cache and Add Waiting Message --- odmlui/editor.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/odmlui/editor.py b/odmlui/editor.py index 15fdcbe..693e892 100644 --- a/odmlui/editor.py +++ b/odmlui/editor.py @@ -13,6 +13,7 @@ from odml.property import BaseProperty import odml.terminology as terminology +from odml.terminology import cache_load import odmlui.treemodel.mixin from odmlui.info import AUTHOR, CONTACT, COPYRIGHT, HOMEPAGE, VERSION, ODMLTABLES_VERSION @@ -953,8 +954,40 @@ def quit(self, action, extra=None): @gui_action("RefreshCache", tooltip="Refresh Document Terminologies Cache", label="Refresh Cache") def on_refresh_cache(self, action): url = self.current_tab.document.repository + + def update_progress_dialog(wait_dial, msg): + wait_dial.change(msg) + return False + + def terminologies_refresh(url, wait_dial): + try: + cache_load(url, True) + term = terminology.Terminologies({}) + term_doc = terminology.Terminologies._load(term, url) + file_num = str(len(term_doc.sections) + 1) + GLib.idle_add(update_progress_dialog, wait_dial, "Please wait, while updating " + + file_num + " Documents...") + + # added to ensure message is shown + time.sleep(0.2) + + for s_ti, s_term in enumerate(term_doc.sections, 1): + s_term_url = s_term.include + GLib.idle_add(update_progress_dialog, wait_dial, + "Updating File " + str(s_ti) + " of " + file_num + "...") + # added to ensure message is shown + time.sleep(0.1) + terminology.refresh(s_term_url) + + except RuntimeError: + pass + finally: + GLib.idle_add(wait_dial.destroy) + if url: - thread = threading.Thread(target=lambda rep_url: terminology.refresh, args=(url,)) + wait_dial = WaitDialog(self, "Refreshing Terminology Cache", "") + wait_dial.show_all() + thread = threading.Thread(target=terminologies_refresh, daemon=True, args=(url, wait_dial)) thread.start() @gui_action("NewSection", label="Add Section",