Exemplo n.º 1
0
  def qiicrChartMessage(self,message):
    if message == "":
      return
    import json
    doc = json.loads(message)
    instanceUID = doc['instanceUID']

    print('want to load', instanceUID)
    # instanceUID = '1.2.276.0.7230010.3.1.4.8323329.10006.1436811198.81030'
    print('instead loading', instanceUID)

    seriesUID = slicer.dicomDatabase.instanceValue(instanceUID,'0020,000E')
    print('actually offering', seriesUID)


    from DICOMLib import DICOMDetailsPopup
    self.detailsPopup = DICOMDetailsPopup()
    self.detailsPopup.offerLoadables(seriesUID, 'Series')
    self.detailsPopup.examineForLoading()
    self.detailsPopup.loadCheckedLoadables()
Exemplo n.º 2
0
class WebServerWidget(ScriptedLoadableModuleWidget):
  """Uses ScriptedLoadableModuleWidget base class, available at:
  https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
  """


  def __init__(self, parent=None):
    ScriptedLoadableModuleWidget.__init__(self, parent)
    self.observerTags = []
    self.guiMessages = True
    self.consoleMessages = True

  def enter(self):
    pass

  def exit(self):
    pass

  def setLogging(self):
    self.consoleMessages = self.logToConsole.checked
    self.guiMessages = self.logToGUI.checked

  def setup(self):
    ScriptedLoadableModuleWidget.setup(self)

    # reload button
    self.reloadButton = qt.QPushButton("Reload")
    self.reloadButton.name = "WebServer Reload"
    self.reloadButton.toolTip = "Reload this module."
    self.layout.addWidget(self.reloadButton)
    self.reloadButton.connect('clicked(bool)', self.onReload)

    self.log = qt.QTextEdit()
    self.log.readOnly = True
    self.layout.addWidget(self.log)
    self.logMessage('<p>Status: <i>Idle</i>\n')

    # log to console
    self.logToConsole = qt.QCheckBox('Log to Console')
    self.logToConsole.setChecked(self.consoleMessages)
    self.logToConsole.toolTip = "Copy log messages to the python console and parent terminal"
    self.layout.addWidget(self.logToConsole)
    self.logToConsole.connect('clicked()', self.setLogging)

    # log to GUI
    self.logToGUI = qt.QCheckBox('Log to GUI')
    self.logToGUI.setChecked(self.guiMessages)
    self.logToGUI.toolTip = "Copy log messages to the log widget"
    self.layout.addWidget(self.logToGUI)
    self.logToGUI.connect('clicked()', self.setLogging)

    # clear log button
    self.clearLogButton = qt.QPushButton("Clear Log")
    self.clearLogButton.toolTip = "Clear the log window."
    self.layout.addWidget(self.clearLogButton)
    self.clearLogButton.connect('clicked()', self.log.clear)

    # TODO: button to start/stop server
    # TODO: warning dialog on first connect
    # TODO: config option for port

    # open local connection button
    self.localConnectionButton = qt.QPushButton("Open Browser Page")
    self.localConnectionButton.toolTip = "Open a connection to the server on the local machine with your system browser."
    self.layout.addWidget(self.localConnectionButton)
    self.localConnectionButton.connect('clicked()', self.openLocalConnection)

    # open local connection button
    self.localQtConnectionButton = qt.QPushButton("Open QtWebKit Page")
    self.localQtConnectionButton.toolTip = "Open a connection with Qt to the server on the local machine."
    self.layout.addWidget(self.localQtConnectionButton)
    self.localQtConnectionButton.connect('clicked()', self.openQtLocalConnection)

    # open local connection button
    self.qiicrChartButton = qt.QPushButton("Open QIICR Chart Demo")
    self.qiicrChartButton.toolTip = "Open the QIICR chart demo.  You need to be on the internet to access the page and you need to have the QIICR Iowa data loaded in your DICOM database in order to drill down to the image level."
    self.layout.addWidget(self.qiicrChartButton)
    self.qiicrChartButton.connect('clicked()', self.openQIICRChartDemo)

    self.logic = WebServerLogic(logMessage=self.logMessage)
    self.logic.start()

    # Add spacer to layout
    self.layout.addStretch(1)

  def openLocalConnection(self):
    qt.QDesktopServices.openUrl(qt.QUrl('http://localhost:2016'))

  def openQtLocalConnection(self):
    self.webView = qt.QWebView()
    html = """
    <h1>Loading from <a href="http://localhost:2016">Localhost 2016</a></h1>
    """
    self.webView.setHtml(html)
    self.webView.settings().setAttribute(qt.QWebSettings.DeveloperExtrasEnabled, True)
    self.webView.setUrl(qt.QUrl('http://localhost:2016/work'))
    self.webView.show()

  def openQIICRChartDemo(self):
    self.qiicrWebView = qt.QWebView()
    self.qiicrWebView.setGeometry(50, 50, 1750, 1200)
    url = "http://localhost:12345/dcsr/qiicr-chart/index.html"
    url = "http://pieper.github.io/qiicr-chart/dcsr/qiicr-chart"
    html = """
    <h1>Loading from <a href="%(url)s">%(url)s/a></h1>
    """ % {'url' : url}
    self.qiicrWebView.setHtml(html)
    self.qiicrWebView.settings().setAttribute(qt.QWebSettings.DeveloperExtrasEnabled, True)
    self.qiicrWebView.setUrl(qt.QUrl(url))
    self.qiicrWebView.show()

    page = self.qiicrWebView.page()
    if not page.connect('statusBarMessage(QString)', self.qiicrChartMessage):
      logging.error('statusBarMessage connect failed')

  def qiicrChartMessage(self,message):
    if message == "":
      return
    import json
    doc = json.loads(message)
    instanceUID = doc['instanceUID']

    print('want to load', instanceUID)
    # instanceUID = '1.2.276.0.7230010.3.1.4.8323329.10006.1436811198.81030'
    print('instead loading', instanceUID)

    seriesUID = slicer.dicomDatabase.instanceValue(instanceUID,'0020,000E')
    print('actually offering', seriesUID)


    from DICOMLib import DICOMDetailsPopup
    self.detailsPopup = DICOMDetailsPopup()
    self.detailsPopup.offerLoadables(seriesUID, 'Series')
    self.detailsPopup.examineForLoading()
    self.detailsPopup.loadCheckedLoadables()

  def onReload(self):
    self.logic.stop()
    ScriptedLoadableModuleWidget.onReload(self)
    slicer.modules.WebServerWidget.logic.start()


  def logMessage(self,*args):
    if self.consoleMessages:
      for arg in args:
        print(arg)
    if self.guiMessages:
      for arg in args:
        self.log.insertHtml(arg)
      self.log.insertPlainText('\n')
      self.log.ensureCursorVisible()
      self.log.repaint()