Commit e7c817c0 authored by pieper's avatar pieper
Browse files

BUG: make sure precache tags are set for database instances

Since the precache tags are specific to the ctkDICOMDatabase,
be sure to set the correct values to both slicer.app.dicomDatabase
and the database that is internal to the ctkDICOMAppWidget.

Need to use a timer here, because we want to ensure that all plugins
(which are modules) have been discovered before we set the precache
tags.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21526 3bd1e089-480b-0410-8dfb-8563597acbee
parent 6e34166d
......@@ -16,6 +16,23 @@ import DICOMLib
#
class DICOM:
@staticmethod
def setDatabasePrecacheTags(dicomApp=None):
"""query each plugin for tags that should be cached on import
and set them for the dicom app widget and slicer"""
if not slicer.dicomDatabase:
return
tagsToPrecache = list(slicer.dicomDatabase.tagsToPrecache)
for pluginClass in slicer.modules.dicomPlugins:
plugin = slicer.modules.dicomPlugins[pluginClass]()
tagsToPrecache += plugin.tags.values()
tagsToPrecache = list(set(tagsToPrecache)) # remove duplicates
tagsToPrecache.sort()
slicer.dicomDatabase.tagsToPrecache = tagsToPrecache
if dicomApp:
dicomApp.tagsToPrecache = tagsToPrecache
def __init__(self, parent):
import string
parent.title = "DICOM"
......@@ -62,7 +79,9 @@ This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community. Se
# Trigger the menu to be added when application has started up
if not slicer.app.commandOptions().noMainWindow :
qt.QTimer.singleShot(0, self.addMenu);
qt.QTimer.singleShot(0, self.addMenu)
# set the dicom pre-cache tags once all plugin classes have been initialized
qt.QTimer.singleShot(0, DICOM.setDatabasePrecacheTags)
def addMenu(self):
#actionIcon = self.parent.icon
......@@ -200,6 +219,7 @@ class DICOMWidget:
# in the CTK code to avoid the findChildren calls
#
self.dicomApp = ctk.ctkDICOMAppWidget()
DICOM.setDatabasePrecacheTags(self.dicomApp)
if self.hideSearch:
# hide the search options - doesn't work yet and doesn't fit
# well into the frame
......@@ -299,7 +319,7 @@ class DICOMWidget:
def onDatabaseDirectoryChanged(self,databaseDirectory):
if not hasattr(slicer, 'dicomDatabase') or not slicer.dicomDatabase:
slicer.dicomDatabase = ctk.ctkDICOMDatabase()
self.setDatabasePrecacheTags()
DICOM.setDatabasePrecacheTags(self.dicomApp)
databaseFilepath = databaseDirectory + "/ctkDICOM.sql"
messages = ""
if not os.path.exists(databaseDirectory):
......@@ -330,20 +350,6 @@ class DICOMWidget:
if slicer.dicomDatabase:
slicer.app.setDICOMDatabase(slicer.dicomDatabase)
def setDatabasePrecacheTags(self):
"""query each plugin for tags that should be cached on import
and set them for the dicom app widget and slicer"""
tagsToPrecache = list(slicer.dicomDatabase.tagsToPrecache)
for pluginClass in slicer.modules.dicomPlugins:
plugin = slicer.modules.dicomPlugins[pluginClass]()
tagsToPrecache += plugin.tags.values()
tagsToPrecache = list(set(tagsToPrecache)) # remove duplicates
tagsToPrecache.sort()
if hasattr(slicer, 'dicomDatabase'):
slicer.dicomDatabase.tagsToPrecache = tagsToPrecache
if self.dicomApp:
self.dicomApp.tagsToPrecache = tagsToPrecache
def promptForDatabaseDirectory(self):
"""Ask the user to pick a database directory.
But, if the application is in testing mode, just pick
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment