<gh_stars>0
import os, sys
import unittest
from __main__ import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
import logging

# # Add the CIP common library to the path if it has not been loaded yet
# try:
#     from CIP.logic.SlicerUtil import SlicerUtil
# except Exception as ex:
#     import inspect
#     path = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     if os.path.exists(os.path.normpath(path + '/../CIP_Common')):
#         path = os.path.normpath(path + '/../CIP_Common')        # We assume that CIP_Common is a sibling folder of the one that contains this module
#     elif os.path.exists(os.path.normpath(path + '/CIP')):
#         path = os.path.normpath(path + '/CIP')        # We assume that CIP is a subfolder (Slicer behaviour)
#     sys.path.append(path)
#     from CIP.logic.SlicerUtil import SlicerUtil
#     print("CIP was added to the python path manually in CIP_Blank")
#
# from CIP.logic import Util
#
#

#
# CIP_Blank
#
class CIP_Blank(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 = "CIP_Blank"
        self.parent.categories = SlicerUtil.CIP_ModulesCategory
        self.parent.dependencies = [SlicerUtil.CIP_ModuleName]
        self.parent.contributors = ["<NAME> (<EMAIL>)", "Applied Chest Imaging Laboratory", "Brigham and Women's Hospital"]
        self.parent.helpText = """Write here the description of your module"""
        self.parent.acknowledgementText = SlicerUtil.ACIL_AcknowledgementText

#
# CIP_BlankWidget
#

class CIP_BlankWidget(ScriptedLoadableModuleWidget):
    """Uses ScriptedLoadableModuleWidget base class, available at:
    https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
    """
    def __init__(self, parent):
        ScriptedLoadableModuleWidget.__init__(self, parent)

    def setup(self):
        """This is called one time when the module GUI is initialized
        """
        ScriptedLoadableModuleWidget.setup(self)

        # Create objects that can be used anywhere in the module. Example: in most cases there should be just one
        # object of the logic class
        self.logic = CIP_BlankLogic()


        # Create all the widgets. Main Area
        mainAreaCollapsibleButton = ctk.ctkCollapsibleButton()
        mainAreaCollapsibleButton.text = "Main parameters"
        self.layout.addWidget(mainAreaCollapsibleButton)
        # Layout within the dummy collapsible button. See http://doc.qt.io/qt-4.8/layout.html for more info about layouts
        self.mainAreaLayout = qt.QFormLayout(mainAreaCollapsibleButton)

        # Example button with some common properties
        self.exampleButton = ctk.ctkPushButton()
        self.exampleButton.text = "Push me!"
        self.exampleButton.toolTip = "This is the button tooltip"
        self.exampleButton.setIcon(qt.QIcon("{0}/Reload.png".format(SlicerUtil.CIP_ICON_DIR)))
        self.exampleButton.setIconSize(qt.QSize(20,20))
        self.exampleButton.setStyleSheet("font-weight:bold; font-size:12px" )
        self.exampleButton.setFixedWidth(200)
        self.mainAreaLayout.addWidget(self.exampleButton)

        # Connections
        self.exampleButton.connect('clicked()', self.onApplyButton)

    def enter(self):
        """This is invoked every time that we select this module as the active module in Slicer (not only the first time)"""
        pass

    def exit(self):
        """This is invoked every time that we switch to another module (not only when Slicer is closed)."""
        pass

    def cleanup(self):
        """This is invoked as a destructor of the GUI when the module is no longer going to be used"""
        pass

    def onApplyButton(self):
        message = self.logic.printMessage("This is the message that I want to print")
        qt.QMessageBox.information(slicer.util.mainWindow(), 'OK!', 'The test was ok. Review the console for details')


#
# CIP_BlankLogic
#
class CIP_BlankLogic(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):
        """Constructor. """
        ScriptedLoadableModuleLogic.__init__(self)

    def printMessage(self, message):
        print("This is your message: ", message)
        return "I have printed this message: " + message



class CIP_BlankTest(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):
        """Run as few or as many tests as needed here.
        """
        self.setUp()
        self.test_CIP_Blank_PrintMessage()

    def test_CIP_Blank_PrintMessage(self):
        self.delayDisplay("Starting the test")
        logic = CIP_BlankLogic()

        myMessage = "Print this test message in console"
        logging.info("Starting the test with this message: " + myMessage)
        expectedMessage = "I have printed this message: " + myMessage
        logging.info("The expected message would be: " + expectedMessage)
        responseMessage = logic.printMessage(myMessage)
        logging.info("The response message was: " + responseMessage)
        self.assertTrue(responseMessage == expectedMessage)
        self.delayDisplay('Test passed!')

import os, sys
import unittest
from __main__ import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
import logging

# # Add the CIP common library to the path if it has not been loaded yet
# try:
#     from CIP.logic.SlicerUtil import SlicerUtil
# except Exception as ex:
#     import inspect
#     path = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     if os.path.exists(os.path.normpath(path + '/../CIP_Common')):
#         path = os.path.normpath(path + '/../CIP_Common')        # We assume that CIP_Common is a sibling folder of the one that contains this module
#     elif os.path.exists(os.path.normpath(path + '/CIP')):
#         path = os.path.normpath(path + '/CIP')        # We assume that CIP is a subfolder (Slicer behaviour)
#     sys.path.append(path)
#     from CIP.logic.SlicerUtil import SlicerUtil
#     print("CIP was added to the python path manually in CIP_Blank")
#
# from CIP.logic import Util
#
#

#
# CIP_Blank
#
class CIP_Blank(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 = "CIP_Blank"
        self.parent.categories = SlicerUtil.CIP_ModulesCategory
        self.parent.dependencies = [SlicerUtil.CIP_ModuleName]
        self.parent.contributors = ["<NAME> (<EMAIL>)", "Applied Chest Imaging Laboratory", "Brigham and Women's Hospital"]
        self.parent.helpText = """Write here the description of your module"""
        self.parent.acknowledgementText = SlicerUtil.ACIL_AcknowledgementText

#
# CIP_BlankWidget
#

class CIP_BlankWidget(ScriptedLoadableModuleWidget):
    """Uses ScriptedLoadableModuleWidget base class, available at:
    https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
    """
    def __init__(self, parent):
        ScriptedLoadableModuleWidget.__init__(self, parent)

    def setup(self):
        """This is called one time when the module GUI is initialized
        """
        ScriptedLoadableModuleWidget.setup(self)

        # Create objects that can be used anywhere in the module. Example: in most cases there should be just one
        # object of the logic class
        self.logic = CIP_BlankLogic()


        # Create all the widgets. Main Area
        mainAreaCollapsibleButton = ctk.ctkCollapsibleButton()
        mainAreaCollapsibleButton.text = "Main parameters"
        self.layout.addWidget(mainAreaCollapsibleButton)
        # Layout within the dummy collapsible button. See http://doc.qt.io/qt-4.8/layout.html for more info about layouts
        self.mainAreaLayout = qt.QFormLayout(mainAreaCollapsibleButton)

        # Example button with some common properties
        self.exampleButton = ctk.ctkPushButton()
        self.exampleButton.text = "Push me!"
        self.exampleButton.toolTip = "This is the button tooltip"
        self.exampleButton.setIcon(qt.QIcon("{0}/Reload.png".format(SlicerUtil.CIP_ICON_DIR)))
        self.exampleButton.setIconSize(qt.QSize(20,20))
        self.exampleButton.setStyleSheet("font-weight:bold; font-size:12px" )
        self.exampleButton.setFixedWidth(200)
        self.mainAreaLayout.addWidget(self.exampleButton)

        # Connections
        self.exampleButton.connect('clicked()', self.onApplyButton)

    def enter(self):
        """This is invoked every time that we select this module as the active module in Slicer (not only the first time)"""
        pass

    def exit(self):
        """This is invoked every time that we switch to another module (not only when Slicer is closed)."""
        pass

    def cleanup(self):
        """This is invoked as a destructor of the GUI when the module is no longer going to be used"""
        pass

    def onApplyButton(self):
        message = self.logic.printMessage("This is the message that I want to print")
        qt.QMessageBox.information(slicer.util.mainWindow(), 'OK!', 'The test was ok. Review the console for details')


#
# CIP_BlankLogic
#
class CIP_BlankLogic(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):
        """Constructor. """
        ScriptedLoadableModuleLogic.__init__(self)

    def printMessage(self, message):
        print("This is your message: ", message)
        return "I have printed this message: " + message



class CIP_BlankTest(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):
        """Run as few or as many tests as needed here.
        """
        self.setUp()
        self.test_CIP_Blank_PrintMessage()

    def test_CIP_Blank_PrintMessage(self):
        self.delayDisplay("Starting the test")
        logic = CIP_BlankLogic()

        myMessage = "Print this test message in console"
        logging.info("Starting the test with this message: " + myMessage)
        expectedMessage = "I have printed this message: " + myMessage
        logging.info("The expected message would be: " + expectedMessage)
        responseMessage = logic.printMessage(myMessage)
        logging.info("The response message was: " + responseMessage)
        self.assertTrue(responseMessage == expectedMessage)
        self.delayDisplay('Test passed!')
# # Add the CIP common library to the path if it has not been loaded yet # try: #     from CIP.logic.SlicerUtil import SlicerUtil # except Exception as ex: #     import inspect #     path = os.path.dirname(inspect.getfile(inspect.currentframe())) #     if os.path.exists(os.path.normpath(path + '/../CIP_Common')): #         path = os.path.normpath(path + '/../CIP_Common')        # We assume that CIP_Common is a sibling folder of the one that contains this module #     elif os.path.exists(os.path.normpath(path + '/CIP')): #         path = os.path.normpath(path + '/CIP')        # We assume that CIP is a subfolder (Slicer behaviour) #     sys.path.append(path) #     from CIP.logic.SlicerUtil import SlicerUtil #     print("CIP was added to the python path manually in CIP_Blank") # # from CIP.logic import Util # # # # CIP_Blank # Uses ScriptedLoadableModule base class, available at:     https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py Write here the description of your module # # CIP_BlankWidget # Uses ScriptedLoadableModuleWidget base class, available at:     https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py This is called one time when the module GUI is initialized # Create objects that can be used anywhere in the module. Example: in most cases there should be just one # object of the logic class # Create all the widgets. Main Area # Layout within the dummy collapsible button. See http://doc.qt.io/qt-4.8/layout.html for more info about layouts # Example button with some common properties # Connections This is invoked every time that we select this module as the active module in Slicer (not only the first time) This is invoked every time that we switch to another module (not only when Slicer is closed). This is invoked as a destructor of the GUI when the module is no longer going to be used # # CIP_BlankLogic # 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 Constructor. 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 Do whatever is needed to reset the state - typically a scene clear will be enough. Run as few or as many tests as needed here.