Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.1k stars 106 forks source link

Support Compose for Desktop #269

Open ebraminio opened 3 years ago

ebraminio commented 3 years ago

Supporting a GUI kit with jupyter notebook isn't a too crazy idea (see all the different toolkits it supposed to work) so as I like to have access to Compose for Desktop but that in addition to library additions needs some plugins for code generation tasks also so I was wondering about the idea of supporting with kotlin-jupyter can be progressed somehow maybe just like other Java toolkits that can be issued even from jshell/kotlin shell as given in this link or probably not. Thanks!

altavir commented 3 years ago

You do not need to have any special support to launch Swing applications from Jupyter. Just create a frame like you do from a regular Java application and it will work. I think I showed that in one of the videos, but I do not remember where.

ebraminio commented 3 years ago

Oh feel free to review the file again as I didn't ask about Swing and even have given a link to a swing example which I've written myself which works already but have asked for Compose for Desktop, the brand new Jetbrains UI framework which understandably is hard one and needs code generation and other magics I think but is worthy both for to learn the new library (think of jupyter tutorials for Compose for Desktop) and all the modern things it brings on the table.

Swing example hopefully useful for others,

import javax.swing.*
import java.awt.GridLayout

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
JFrame().also { frame ->
    frame.title = "Swing Hello World"
    frame.setSize(400, 400)
    frame.layout = GridLayout(0, 2)
    frame.setLocationRelativeTo(null)
    (1..4).map {
        JButton("Button $it").also { button ->
            button.addActionListener {
                println("Button $it is clicked")
            }
        }
    }.forEach(frame::add)
}.setVisible(true)
image
altavir commented 3 years ago

Compose desktop currently works on top of Swing. So you can launch it in Swing pane. If you want to write composable functions themselves in the jupyter, it probably won't be possible, because it indeed requires an external compiler plugin to be loaded in the host.

ebraminio commented 3 years ago

Yes, to say for example write step by step tutorials of learning compose desktop in jupyter, something common for libraries and so, but understandably is hard to do, feel free to close the file if you feel keeping this around won't be productive, I wouldn't mind at least just was believing would be nice to have.