wxMaxima-developers / wxmaxima

A gui for the computer algebra system Maxima built with wxWidgets
https://wxMaxima-developers.github.io/wxmaxima/
Other
471 stars 98 forks source link

wxmaxima as a language agnostic notebook environment #824

Open Foadsf opened 7 years ago

Foadsf commented 7 years ago

I have been wondering why WxMaxima team does not follow a similar path as IPython project. there are many new possibilities besides maxima, including R, Julia, python family, CERN ROOT/cling, Octave, SciLab... It shouldn't be impossible to modify the GUI in a way to connect to other language interpreters as well and turn into a language agnostic notebook or IDE for mathematical scripting languages. suggested name: WxNotebook :)

gunterkoenigsmann commented 7 years ago

Cool! I take that as a big praise to the wxMaxima team ;-)

Will add that as feature request: Currently there are many things in wxMaxima that are specific to maxima, namely the syntax highlighting, the communication with maxima and most (if not all) of the wizards and menu items.

...but if one finds a way to introduce an abstraction layer that allows the magic behind c++ to determine which language-specific set of functions is intended to be used - or even better: If the code could be made configurable perhaps using xml-snippets like it is don in Notepad++... ...if one is really determined to do it it might be possible to apply wxMaxima's worksheet-based approach to other programming languages, as well.

Kind regards, Gunter.

Foadsf commented 7 years ago

Hi @gunterkoenigsmann happy to see that you liked the idea :) I'm a noob, so please excuse me if what I say is not accurate. After a while I'm seeing some patterns. there are several interpreted languages which are being used within the math community:

and within each community there are attempts to make GUIs :

what makes WxMaxima to stand out are:

there are also numerous plugins for editors such as Atom, Vim, Emacs... for syntax highlighting, snippets, linting... there should be a possibility to add the feature to use those addons instead of writing new ones.

there are just a few feature I wish to be added to WxMaxima before moving towards a language agnostic notebook IDE. one of them is the workspace (variable-watch window)

pkulchenko commented 6 years ago

I've attempted something similar in another wxwidgets-based application I've been developing (in Lua using wxlua wrapper): https://github.com/pkulchenko/ZeroBraneStudio. It started as a Lua IDE, but now has support for syntax highlighting for 110+ languages and allows for flexible customization, debugging, and execution of Lua-based apps. For example, it supports debugging of GSL Shell, along with live coding for it: http://notebook.kulchenko.com/zerobrane/gsl-shell-debugging-with-zerobrane-studio.

I'm curious, what wxwidgets component is used to create the main control in wxmaxima: http://andrejv.github.io/wxmaxima/images/linux_2.jpg? Is it "simply" drawing all the elements on DC surface (with the main code in EditorCell.cpp)?

gunterkoenigsmann commented 6 years ago

It is using wxScrolledCanvas: This class provides the scrollbars and MathCtrl::OnPaint() if some part of the window needs drawing. wxScrolledCanvas is intelligent enough to recognize that after scrolling or resizing the window part of the old window contents can be moved to a new window position and OnPeint() needs only to redraw the window portions that weren't visible before moving or resizing the window.

OnPaint then can use wxScrolledCanvas' function CalcUnscrolledPosition() in order to find out which part of the worksheet the to-be-redrawn part of the window is. And it doesn't draw directly into the wxGCDC OnPaint() is offered, but into a bitmap first: This time there is no flicker if first the background is drawn and then the text is drawn over it.

The worksheet is organized as a list of GroupCells that group the EditorCell with the text from the user with the list of corresponding maxima output. Every Math Object that is displayed is a descendant of MathCell. ...and these cells are grouped in two lists: One that groups all elements (that might have sub-elements: For example a parenthesis cell contains a sub-list containing the parenthesis' contents). And one that contains all elements that need to be drawn in the order they have to be drawn (if the parenthesis fits into one line this list just contains the parenthesis cell that knows how a big parenthesis is displayed. If it doesn't the list contains the opening parenthesis as a separate TextCell, the contents of the parenthesis and the TextCell with the closing parenthesis instead).

In-detail documentation of big parts of the code can be found at https://www.peterpall.de/wxMaxima/html/index.xhtml. And I am willing to answer any questions I can.

pkulchenko commented 6 years ago

OnPaint then can use wxScrolledCanvas' function CalcUnscrolledPosition() in order to find out which part of the worksheet the to-be-redrawn part of the window is. And it doesn't draw directly into the wxGCDC OnPaint() is offered, but into a bitmap first: This time there is no flicker if first the background is drawn and then the text is drawn over it.

Yes, I do the same thing (only using wxScrolledWindow instead) for the implementation of the commandBar in the IDE (shown in the top right corner of the main editor: https://studio.zerobrane.com/images/debugging.png). Thank you for the details of the worksheet organization.

KubaO commented 4 years ago

It shouldn't be impossible to modify the GUI in a way to connect to other language interpreters as well and turn into a language agnostic notebook or IDE for mathematical scripting languages.

It's of course not impossible, but it's far from trivial since wxMaxima is a result of incremental development of well over a decade, and a lot of its internals are bug-prone, i.e. modifying them easily creates new bugs. There is still quite a bit of architectural cleanup that is likely necessary before such sweeping changes can have any chance of success without breaking everything.

At the very least, the assumption that wxMaxima is always working on Maxima code (and nothing else) is embedded almost everywhere in the system. As a first step, everything Maxima-specific would need to be factored out. And before that'd be possible without losing sanity, lots of code has to be simplified and refactored, mainly related to I/O - at least for XML. The XML I/O code is not generated, but hand-written, and thus the reading and writing code is spread across many different modules, and is relatively hard to maintain. E.g. the input is mostly in MathParser, but the output is pretty much everywhere.

So, the answer is: in a rather long term - all of this is certainly possible, and I'd personally like wxMaxima to be a good front-end to theorem provers. But in the mean time, there is at least 1000-2000 hours of work needed before it'll be even remotely possible to think about adding another backend than Maxima. It could be done earlier, at the cost of turning everything into even worse spaghetti, and stalling the project.

I'd say that the code right now is barely maintainable, and routine refactorings pick up dead code, latent bugs, code that makes little sense, and similar. There are also still rather serious memory overhead issues, and architectural issues that lead to poor testability. Without the layout and user interaction layers being testable, there's no hope at producing anything good when it comes to support of other languages.

Realistically, I'd say that bringing wxMaxima to a point where other back-ends can be added without heavy drinking is a 1.5-2 man-year effort. By the time this year is over, I'll have donated about 0.7 man-years of my own time into this project. There will still be another man-year ahead before I'd be confident in feasibility of new backends. So - assuming I won't lose interest by then, and assuming I'll be the sole person doing it - the time to think about all this again will be mid-2022 maybe. I'm not certain that I'll do much on that front, though, other than maybe plugging in one other back-end, since I'm more interested in the framework development work - both for wxMaxima's internals, as well as for the user interface layer. To prevent obsolescence, I'd like to bring wxMaxima's canvas to the same display-list backend style that Dear ImGui is using, so that we could get everything rendered by the GPU and at 120FPS.

Your mileage may vary, of course - there are people more productive than myself, I'm sure, but they may have better code bases to play with, too :)