Skip to content

Experiments with embedding a text editor in Slicer

License

Notifications You must be signed in to change notification settings

pieper/SlicerEditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This was an experiment that has been migrated to its official home in SlicerMorph: https://github.com/SlicerMorph/SlicerEditor/tree/main

SlicerEditor

Experiments to embed an editor in Slicer.

Currently uses ths monaco editor (the one used in VSCode) in a qSlicerWebWidget.

To try this in Slicer, use a Slicer preview newer than March 5, 2024 (where this feature is available).

Hosted online from CDN example

Then paste the following in the python console:

editor = slicer.qSlicerWebWidget()
editor.size = qt.QSize(900, 750)
editor.url = "https://pieper.github.io/SlicerEditor"
editor.show()

image

You will get autocomplete suggestions based on the current Slicer session.

Press the slicer icon to run the code.

Notes

  • Running code from web pages in Slicer is a possible security issue, so you must approve with the dialog. Use care when accessing untrusted pages using the qSlicerWebWidget infrastructure.

image

Offline examples

These examples do not need an internet connection.

For these, download https://github.com/pieper/SlicerEditor/releases/download/prototype/offline.tar.gz

Open the archive and update the URL parameters below to point to your extracted file.

Note: the archive is monaco build tree and has not been optimized for size.

Hosted from Slicer WebServer example


DOCROOT = "/Users/pieper/slicer/latest/SlicerEditor/offline".encode()
PORT = 9916
import WebServer
try:
    logic.stop()
except NameError:
    pass
logMessage = WebServer.WebServerLogic.defaultLogMessage
logic = WebServer.WebServerLogic(port=PORT, logMessage=logMessage)
logic.docroot = DOCROOT
logic.requestHandlers = []
logic.addDefaultRequestHandlers(enableSlicer=False, enableStaticPages=True)
logic.start()

editor = slicer.qSlicerWebWidget()
editor.size = qt.QSize(900, 750)
#editor.url = f"http://localhost:{PORT}".encode()
editor.show()

Read directly from file example

URL = "file:///Users/pieper/slicer/latest/SlicerEditor/offline/index.html"

editor = slicer.qSlicerWebWidget()
editor.size = qt.QSize(900, 750)
editor.url = URL
editor.show()
  • This is just a skeleton prototype as a proof of concept. See this dicussion for more ideas about how this can be improved to be useful.

About

Experiments with embedding a text editor in Slicer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages