123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import os
- import unittest
- from __main__ import vtk, qt, ctk, slicer
- from slicer.ScriptedLoadableModule import *
- #import slicerNetwork
- import json
- import zipfile
- import pathlib
- import sys
- import urllib3
- import string
- import chardet
- import base64
- try:
- import nixWrapper
- except ModuleNotFoundError:
- import subprocess
- py='{}PythonSlicer'.format(slicer.app.slicerHome[:-2])
- print(f'Executable: {py}')
- subprocess.check_call([py, '-m', 'pip', 'install', 'nixWrapper'])
- import nixWrapper
- #
- # labkeySlicerPythonExtension
- #
- class nixModule(ScriptedLoadableModule):
- """Uses ScriptedLoadableModule base class, available at:
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
- """
- def __init__(self, parent):
- ScriptedLoadableModule.__init__(self, parent)
- self.parent.title = "nixModule" # TODO make this more human readable by adding spaces
- self.parent.categories = ["NIX"]
- self.parent.dependencies = []
- self.parent.contributors = ["Andrej Studen (UL/FMF)"] # replace with "Firstname Lastname (Organization)"
- self.parent.helpText = """
- Interface to NIX software
- """
- self.parent.acknowledgementText = """
- Developed within the medical physics research programme of the Slovenian research agency.
- """ # replace with organization, grant and thanks.
- #
- # labkeySlicerPythonExtensionWidget
- #
- class nixModuleWidget(ScriptedLoadableModuleWidget):
- """Uses ScriptedLoadableModuleWidget base class, available at:
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
- """
- def setup(self):
- ScriptedLoadableModuleWidget.setup(self)
- # Instantiate and connect widgets ...
- self.logic=nixModuleLogic(self)
- fhome=os.path.expanduser('~')
- #fwrapper=getWrapper('nixWrapper.py')
- #p=pathlib.Path(fwrapper)
- #sys.path.append(str(p.parent))
- self.remoteResources=nixWrapper.getResources()
-
- #self.network=slicerNetwork.labkeyURIHandler()
- #
- # Parameters Area
- #
- loadCollapsibleButton = ctk.ctkCollapsibleButton()
- loadCollapsibleButton.text = "Add module"
- self.layout.addWidget(loadCollapsibleButton)
- loadFormLayout = qt.QFormLayout(loadCollapsibleButton)
- self.libraryName=qt.QComboBox()
- self.libraryName.insertItems(0,[m for m in self.remoteResources])
- self.libraryName.currentIndexChanged.connect(self.onLibraryNameChanged)
- loadFormLayout.addRow("Library: ", self.libraryName)
- self.moduleName=qt.QComboBox()
- try:
- print('Library: '.format(self.libraryName.currentText))
- self.moduleName.insertItems(0,[m for m in self.remoteResources[self.libraryName.currentText]['modules']])
- except KeyError:
- pass
- self.moduleName.currentIndexChanged.connect(self.onModuleNameChanged)
- loadFormLayout.addRow("Module: ", self.moduleName)
-
- self.loadLibraryButton=qt.QPushButton("Load")
- self.loadLibraryButton.toolTip="Load library"
- self.loadLibraryButton.clicked.connect(self.onLoadLibraryButtonClicked)
- loadFormLayout.addRow("Load library:",self.loadLibraryButton)
- self.loadModuleButton=qt.QPushButton("Load")
- self.loadModuleButton.toolTip="Load library"
- self.loadModuleButton.clicked.connect(self.onLoadModuleButtonClicked)
- loadFormLayout.addRow("Load module:",self.loadModuleButton)
- def onLoadModuleButtonClicked(self):
- self.logic.loadModule(self.libraryName.currentText,self.moduleName.currentText)
- print('onLoadModuleButtonClicked')
- def onLoadLibraryButtonClicked(self):
- self.logic.loadLibrary(self.libraryName.currentText)
- print('onLoadLibraryButtonClicked')
- def onModuleNameChanged(self):
- pass
- def onLibraryNameChanged(self):
- self.moduleName.clear()
- self.moduleName.insertItem(0,'Select')
- self.moduleName.insertItems(1,self.remoteResources[self.libraryName.currentText]['modules'])
-
- # labkeySlicerPythonExtensionLogic
- #
- class nixModuleLogic(ScriptedLoadableModuleLogic):
- """This class should implement all the actual
- computation done by your module. The interface
- should be such that other python code can import
- this class and make use of the functionality without
- requiring an instance of the Widget.
- Uses ScriptedLoadableModuleLogic base class, available at:
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
- """
- def __init__(self,parent):
- ScriptedLoadableModuleLogic.__init__(self, parent)
- def loadModule(self,libName,modName):
- # import nixWrapper
- nixWrapper.loadModule(slicer,qt,libName,modName)
- def loadLibrary(self,libName):
- # import nixWrapper
- nixWrapper.loadLibrary(libName)
- class nixModuleTest(ScriptedLoadableModuleTest):
- """
- This is the test case for your scripted module.
- Uses ScriptedLoadableModuleTest base class, available at:
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
- """
- def setUp(self):
- """ Do whatever is needed to reset the state - typically a scene clear will be enough.
- """
- slicer.mrmlScene.Clear(0)
- def runTest(self):
- pass
|