Exemple #1
0
    def showWindow(self, settingName=None, position=True):
        """ Creates a new window, adjusts aesthetics, then shows.
        """

        self.setTab(settingName)
        self.MODULE.SettingsFile.backupCurrentSettings()
        #--------------------
        # Reposition window if argument is true.
        #--------------------
        if position:
            mainWindow = slicer.util.mainWindow()
            screenMainPos = mainWindow.pos
            x = screenMainPos.x() + mainWindow.width / 2 - self.width / 2
            y = screenMainPos.y() + mainWindow.height / 2 - self.height / 2
            self.move(qt.QPoint(x, y))

        #--------------------
        # Show the window.
        #--------------------
        self.show()
        self.raise_()

        #--------------------
        # Sync the Metadata settings dropdown with the login menu
        #--------------------
        self.MODULE.Settings['METADATA'].update()
        self.updateSettingWidgets()
Exemple #2
0
    def repositionToMainSlicerWindow(self, positionable, location = "center"):
        """ As stated.  User can provide location of window
            within the arguments.
        """

        #---------------------------
        # Make sure positionable is open.
        #---------------------------
        positionable.show()



        #---------------------------
        # Get main window and its position.
        #---------------------------
        mainWindow = slicer.util.mainWindow()
        screenMainPos = mainWindow.pos


        
        #---------------------------
        # Derive coordinates
        #---------------------------
        location = location.lower().strip()
        if location == 'upperleftcorner':
            x = screenMainPos.x()
            y = screenMainPos.y()  
        #
        # If location = 'center'
        #
        else :
            x = screenMainPos.x() + mainWindow.width/2 - positionable.width/2
            y = screenMainPos.y() + mainWindow.height/2 - positionable.height/2
            
        positionable.move(qt.QPoint(x,y))
Exemple #3
0
 def cursorForEffect(self, effectName):
     """Return an instance of QCursor customized for the given effectName.
 TODO: this could be moved to the EffectTool class so that effects can manage
 per-widget cursors, possibly turning them off or making them dynamic
 """
     if not effectName in self.effectCursors:
         baseImage = qt.QImage(":/Icons/AnnotationPointWithArrow.png")
         effectImage = qt.QImage(self.effectIconFiles[effectName])
         width = max(baseImage.width(), effectImage.width())
         pad = -9
         height = pad + baseImage.height() + effectImage.height()
         width = height = max(width, height)
         center = int(width / 2)
         cursorImage = qt.QImage(width, height, qt.QImage().Format_ARGB32)
         painter = qt.QPainter()
         cursorImage.fill(0)
         painter.begin(cursorImage)
         point = qt.QPoint(center - (baseImage.width() / 2), 0)
         painter.drawImage(point, baseImage)
         point.setX(center - (effectImage.width() / 2))
         point.setY(cursorImage.height() - effectImage.height())
         painter.drawImage(point, effectImage)
         painter.end()
         cursorPixmap = qt.QPixmap()
         cursorPixmap = cursorPixmap.fromImage(cursorImage)
         self.effectCursors[effectName] = qt.QCursor(
             cursorPixmap, center, 0)
     return self.effectCursors[effectName]
    def test_DICOMwebInterface1(self):
        """ Ideally you should have several levels of tests.  At the lowest level
    tests should exercise the functionality of the logic with different inputs
    (both valid and invalid).  At higher levels your tests should emulate the
    way the user would interact with your code and confirm that it still works
    the way you intended.
    One of the most important features of the tests is that it should alert other
    developers when their changes will have an impact on the behavior of your
    module.  For example, if a developer removes a feature that you depend on,
    your test should break so they know that the feature is needed.
    """

        self.delayDisplay("Starting the test", 50)

        webPath = os.path.dirname(
            os.path.dirname(slicer.modules.dicomwebinterface.path))
        url = 'file://' + os.path.join(webPath, 'StudyBrowser/index.html')

        webWidget = slicer.qSlicerWebWidget()
        slicerGeometry = slicer.util.mainWindow().geometry
        webWidget.size = qt.QSize(900, 600)
        webWidget.pos = qt.QPoint(slicerGeometry.x() + 256,
                                  slicerGeometry.y() + 128)

        self.dicomWebServer = 'https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs'

        webWidget.url = url + "?server=" + self.dicomWebServer
        print(url)
        webWidget.show()

        slicer.modules.DICOMwebInterfaceWidget.webWidget = webWidget
Exemple #5
0
 def enterFloatingMode(self):
   self.mainFrame.setParent(None)
   cursorPosition = qt.QCursor().pos()
   w = self.mainFrame.width
   h = self.mainFrame.height
   self.mainFrame.pos = qt.QPoint(cursorPosition.x() - w/2, cursorPosition.y() - h/2)
   self.mainFrame.show()
   self.mainFrame.raise_()
   Key_Space = 0x20 # not in PythonQt
   self.toggleShortcut = qt.QShortcut(self.mainFrame)
   self.toggleShortcut.setKey( qt.QKeySequence(Key_Space) )
   self.toggleShortcut.connect( 'activated()', self.toggleFloatingMode )
Exemple #6
0
 def open(self):
     if not self.window.isVisible():
         self.window.show()
         if self.popupGeometry.isValid():
             self.window.setGeometry(self.popupGeometry)
             self.popupPositioned = True
     if not self.popupPositioned:
         mainWindow = slicer.util.mainWindow()
         screenMainPos = mainWindow.pos
         x = screenMainPos.x() + 100
         y = screenMainPos.y() + 100
         self.window.move(qt.QPoint(x, y))
         self.popupPositioned = True
     self.window.raise_()
Exemple #7
0
    def show(self, position=True):
        """ Generic show function.  Repositions the
            popup to be cenetered within the slicer app.
        """
        self.window.show()

        if position:
            self.window.show()
            mainWindow = slicer.util.mainWindow()
            screenMainPos = mainWindow.pos
            x = screenMainPos.x(
            ) + mainWindow.width / 2 - self.window.width / 2
            y = screenMainPos.y(
            ) + mainWindow.height / 2 - self.window.height / 2
            self.window.move(qt.QPoint(x, y))

        self.window.raise_()
Exemple #8
0
 def open(self):
   self.window.show()
   if not self.popupPositioned:
     if False:
       appWidth = self.dicomApp.geometry.width()
       screenAppPos = self.dicomApp.mapToGlobal(self.dicomApp.pos)
       x = screenAppPos.x() + appWidth
       y = screenAppPos.y()
     else:
       mainWindow = slicer.util.mainWindow()
       #screenMainPos = mainWindow.mapToGlobal(mainWindow.pos)
       screenMainPos = mainWindow.pos
       x = screenMainPos.x() + 100
       y = screenMainPos.y() + 100
     self.window.move(qt.QPoint(x,y))
     self.popupPositioned = True
   self.window.raise_()
Exemple #9
0
    def show(self):
        """ Shows the first dialog in a dialog sequence,
            and adjusts its position.
        """

        #--------------------
        # Show first window in the dialog sequence.
        #--------------------
        self.dialogs[0].show()

        #--------------------
        # Adjust position of first window.
        #--------------------
        mainWindow = slicer.util.mainWindow()
        screenMainPos = mainWindow.pos
        x = screenMainPos.x() + 400
        y = screenMainPos.y() + 400
        self.dialogs[0].move(qt.QPoint(x, y))
Exemple #10
0
    def repositionToMainSlicerWindow(positionable, location="center"):
        """ 
        Repositions a widget window to the main slicer window relative
        to the "location" argument.

        @param positionable: The widget to reposition.
        @type positionable: qt.QWidget


        @param location: The location of the widget.
        @type location: string
        """

        #---------------------------
        # Get main window and its position.
        #---------------------------
        mainWindow = slicer.util.mainWindow()
        screenMainPos = mainWindow.pos

        #---------------------------
        # Derive coordinates
        #---------------------------
        location = location.lower().strip()
        if location == 'upperleftcorner':
            x = screenMainPos.x()
            y = screenMainPos.y()
        #
        # If location = 'center'
        #
        else:
            x = screenMainPos.x(
            ) + mainWindow.width / 2 - positionable.width / 2
            y = screenMainPos.y(
            ) + mainWindow.height / 2 - positionable.height / 2

        positionable.move(qt.QPoint(x, y))
Exemple #11
0
    def test_Part1DICOM(self):
        """ Test the DICOM part of the test using the head atlas
    """

        import os
        self.delayDisplay("Starting the DICOM test")
        #
        # first, get the data - a zip file of dicom data
        #
        import urllib
        downloads = (('http://slicer.kitware.com/midas3/download?items=18822',
                      'Dcmtk-db.zip'), )

        self.delayDisplay("Downloading")
        for url, name in downloads:
            filePath = slicer.app.temporaryPath + '/' + name
            if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
                self.delayDisplay('Requesting download %s from %s...\n' %
                                  (name, url))
                urllib.urlretrieve(url, filePath)
        self.delayDisplay('Finished with download\n')

        self.delayDisplay("Unzipping")
        dicomFilesDirectory = slicer.app.temporaryPath + '/dicomFiles'
        qt.QDir().mkpath(dicomFilesDirectory)
        slicer.app.applicationLogic().Unzip(filePath, dicomFilesDirectory)

        try:
            self.delayDisplay("Switching to temp database directory")
            tempDatabaseDirectory = slicer.app.temporaryPath + '/tempDICOMDatbase'
            qt.QDir().mkpath(tempDatabaseDirectory)
            if slicer.dicomDatabase:
                originalDatabaseDirectory = os.path.split(
                    slicer.dicomDatabase.databaseFilename)[0]
            else:
                originalDatabaseDirectory = None
                settings = qt.QSettings()
                settings.setValue('DatabaseDirectory', tempDatabaseDirectory)
            dicomWidget = slicer.modules.dicom.widgetRepresentation().self()
            dicomWidget.onDatabaseDirectoryChanged(tempDatabaseDirectory)

            self.delayDisplay('Start Local DICOM Q/R SCP')
            import subprocess
            import os
            configFilePath = dicomFilesDirectory + '/Dcmtk-db/dcmqrscp.cfg'
            processCurrentPath = dicomFilesDirectory + '/Dcmtk-db/'

            dcmqrscpExeOptions = (
                '/bin',
                '/../CTK-build/CMakeExternals/Install/bin',
                '/../DCMTK-install/bin',
                '/../DCMTK-build/bin',
            )

            dcmqrscpExePath = None
            dcmqrscpExeName = '/dcmqrscp'
            if slicer.app.os == 'win':
                dcmqrscpExeName = dcmqrscpExeName + '.exe'
            for path in dcmqrscpExeOptions:
                testPath = slicer.app.slicerHome + path + dcmqrscpExeName
                if os.path.exists(testPath):
                    dcmqrscpExePath = testPath
                    break
            if not dcmqrscpExePath:
                raise (UserWarning("Could not find dcmqrscp executable"))

            args = (dcmqrscpExePath, '-c', configFilePath)
            popen = subprocess.Popen(args,
                                     stdout=subprocess.PIPE,
                                     cwd=processCurrentPath)

            self.delayDisplay('Retrieve DICOM')
            mainWindow = slicer.util.mainWindow()
            mainWindow.moduleSelector().selectModule('DICOM')
            dicomWidget.dicomApp.suspendModel()
            dicomRetrieve = ctk.ctkDICOMRetrieve()
            dicomRetrieve.setKeepAssociationOpen(True)
            dicomRetrieve.setDatabase(slicer.dicomDatabase)
            dicomRetrieve.setCallingAETitle('SlicerAE')
            dicomRetrieve.setCalledAETitle('DCMTK')
            dicomRetrieve.setPort(12345)
            dicomRetrieve.setHost('localhost')
            dicomRetrieve.getStudy(
                '1.2.124.113932.1.170.223.162.178.20050502.160340.12640015')
            dicomWidget.dicomApp.resumeModel()
            popen.kill()
            dicomWidget.detailsPopup.open()
            # click on the first row of the tree
            index = dicomWidget.tree.indexAt(qt.QPoint(0, 0))
            dicomWidget.onTreeClicked(index)

            self.delayDisplay('Loading Selection')
            dicomWidget.detailsPopup.loadCheckedLoadables()

            self.delayDisplay('Change Level')
            layoutManager = slicer.app.layoutManager()
            redWidget = layoutManager.sliceWidget('Red')
            self.clickAndDrag(redWidget, start=(10, 10), end=(10, 40))

            self.delayDisplay('Change Window')
            self.clickAndDrag(redWidget, start=(10, 10), end=(40, 10))

            self.delayDisplay('Change Layout')
            layoutManager = slicer.app.layoutManager()
            layoutManager.setLayout(
                slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpRedSliceView)

            self.delayDisplay('Zoom')
            self.clickAndDrag(redWidget,
                              button='Right',
                              start=(10, 10),
                              end=(10, 40))

            self.delayDisplay('Pan')
            self.clickAndDrag(redWidget,
                              button='Middle',
                              start=(10, 10),
                              end=(40, 40))

            self.delayDisplay('Center')
            redWidget.sliceController().fitSliceToBackground()

            self.delayDisplay('Lightbox')
            redWidget.sliceController().setLightboxTo6x6()

            self.delayDisplay('Conventional Layout')
            layoutManager.setLayout(
                slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView)

            self.delayDisplay('No Lightbox')
            redWidget.sliceController().setLightboxTo1x1()

            self.delayDisplay('Four Up Layout')
            layoutManager.setLayout(
                slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)

            self.delayDisplay('Shift Mouse')
            self.clickAndDrag(redWidget,
                              button='None',
                              start=(100, 100),
                              end=(140, 140),
                              modifiers=['Shift'])

            self.delayDisplay('Conventional, Link, Slice Model')
            layoutManager.setLayout(
                slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView)
            redWidget.sliceController().setSliceLink(True)
            redWidget.sliceController().setSliceVisible(True)

            self.delayDisplay('Rotate')
            threeDView = layoutManager.threeDWidget(0).threeDView()
            self.clickAndDrag(threeDView)

            self.delayDisplay('Zoom')
            threeDView = layoutManager.threeDWidget(0).threeDView()
            self.clickAndDrag(threeDView, button='Right')

            self.delayDisplay('Test passed!')
        except Exception, e:
            import traceback
            traceback.print_exc()
            self.delayDisplay('Test caused exception!\n' + str(e))
Exemple #12
0
  def test_Part1DICOM(self):
    """ Test the DICOM part of the test using the head atlas
    """

    import os
    self.delayDisplay("Starting the DICOM test")
    #
    # first, get the data - a zip file of dicom data
    #
    import urllib
    downloads = (
        ('http://slicer.kitware.com/midas3/download?items=8610', 'dicom.zip'),
        )

    self.delayDisplay("Downloading")
    for url,name in downloads:
      filePath = slicer.app.temporaryPath + '/' + name
      if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
        self.delayDisplay('Requesting download %s from %s...\n' % (name, url))
        urllib.urlretrieve(url, filePath)
    self.delayDisplay('Finished with download\n')

    self.delayDisplay("Unzipping")
    dicomFilesDirectory = slicer.app.temporaryPath + '/dicomFiles'
    qt.QDir().mkpath(dicomFilesDirectory)
    slicer.app.applicationLogic().Unzip(filePath, dicomFilesDirectory)

    try:
      self.delayDisplay("Switching to temp database directory")
      tempDatabaseDirectory = slicer.app.temporaryPath + '/tempDICOMDatbase'
      qt.QDir().mkpath(tempDatabaseDirectory)
      if slicer.dicomDatabase:
        originalDatabaseDirectory = os.path.split(slicer.dicomDatabase.databaseFilename)[0]
      else:
        originalDatabaseDirectory = None
        settings = qt.QSettings()
        settings.setValue('DatabaseDirectory', tempDatabaseDirectory)
      dicomWidget = slicer.modules.dicom.widgetRepresentation().self()
      dicomWidget.onDatabaseDirectoryChanged(tempDatabaseDirectory)

      self.delayDisplay('Importing DICOM')
      mainWindow = slicer.util.mainWindow()
      mainWindow.moduleSelector().selectModule('DICOM')
      dicomWidget.dicomApp.suspendModel()
      indexer = ctk.ctkDICOMIndexer()
      indexer.addDirectory(slicer.dicomDatabase, dicomFilesDirectory, None)
      indexer.waitForImportFinished()
      dicomWidget.dicomApp.resumeModel()
      dicomWidget.detailsPopup.open()
      # click on the first row of the tree
      index = dicomWidget.tree.indexAt(qt.QPoint(0,0))
      dicomWidget.onTreeClicked(index)

      self.delayDisplay('Loading Selection')
      dicomWidget.detailsPopup.loadCheckedLoadables()

      self.delayDisplay('Change Level')
      layoutManager = slicer.app.layoutManager()
      redWidget = layoutManager.sliceWidget('Red')
      self.clickAndDrag(redWidget,start=(10,10),end=(10,40))

      self.delayDisplay('Change Window')
      self.clickAndDrag(redWidget,start=(10,10),end=(40,10))

      self.delayDisplay('Change Layout')
      layoutManager = slicer.app.layoutManager()
      layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpRedSliceView)

      self.delayDisplay('Zoom')
      self.clickAndDrag(redWidget,button='Right',start=(10,10),end=(10,40))

      self.delayDisplay('Pan')
      self.clickAndDrag(redWidget,button='Middle',start=(10,10),end=(40,40))

      self.delayDisplay('Center')
      redWidget.sliceController().fitSliceToBackground()

      self.delayDisplay('Lightbox')
      redWidget.sliceController().setLightboxTo6x6()

      self.delayDisplay('Conventional Layout')
      layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView)

      self.delayDisplay('No Lightbox')
      redWidget.sliceController().setLightboxTo1x1()

      self.delayDisplay('Four Up Layout')
      layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)

      self.delayDisplay('Shift Mouse')
      self.clickAndDrag(redWidget,button='None',start=(100,100),end=(140,140),modifiers=['Shift'])

      self.delayDisplay('Conventional, Link, Slice Model')
      layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutConventionalView)
      redWidget.sliceController().setSliceLink(True)
      redWidget.sliceController().setSliceVisible(True);

      self.delayDisplay('Rotate')
      threeDView = layoutManager.threeDWidget(0).threeDView()
      self.clickAndDrag(threeDView)

      self.delayDisplay('Zoom')
      threeDView = layoutManager.threeDWidget(0).threeDView()
      self.clickAndDrag(threeDView,button='Right')

      self.delayDisplay('Test passed!')
    except Exception, e:
      import traceback
      traceback.print_exc()
      self.delayDisplay('Test caused exception!\n' + str(e))