Skip to content

Commit

Permalink
Merge pull request #178 from fschrader1992/dev
Browse files Browse the repository at this point in the history
Add Refresh Terminologies Cache Functionality
  • Loading branch information
mpsonntag authored Jun 19, 2020
2 parents 80230a3 + fd9620d commit 771988e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
52 changes: 49 additions & 3 deletions odmlui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

from distutils.version import LooseVersion as CheckVer

import time
import threading
from gi.repository import GLib, GObject

import pygtkcompat

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
Expand All @@ -23,7 +29,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
Expand All @@ -33,7 +39,7 @@
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

gtk.gdk.threads_init()
GObject.threads_init()

UI_INFO = \
'''
Expand Down Expand Up @@ -64,6 +70,7 @@
<separator/>
<menuitem action='CloneTab'/>
<menuitem action='Validate'/>
<menuitem action='RefreshCache'/>
</menu>
<menu action='HelpMenu'>
<menuitem action='VisitHP'/>
Expand Down Expand Up @@ -185,7 +192,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)
Expand Down Expand Up @@ -944,6 +951,45 @@ 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

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:
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",
tooltip="Add a section to the current selected one",
stock_id="odml_addSection")
Expand Down
12 changes: 12 additions & 0 deletions odmlui/message_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 771988e

Please # to comment.