OCaml comes with the Graphics module which allows the use of a graphical window.
Is it possible to open two graphical window, and switch between them ?
The Graphics module provides machine-independent tools but in case of a negative answer, perhaps it would also be interesting to have solutions for different window system, such as X11.
I looked through the Graphics module API and I don't see support for multiple windows. I would assume Graphics was intended as something useful but simple enough to be part of the base OCaml release.
For more complex graphics, it makes sense just to provide OCaml bindings to an existing library. If I go to opam.ocaml.org/packages and search for "graphics" I see a few possibilities.
I have done OpenGL coding in OCaml but in fact I had to build some wrappers for OS-native GUI functionality to create the windows. This was many years ago, however.
The Graphics module is quite limited and is more intended as a simple basic library for teaching purposes. A possible replacement for Graphics might be the tsdl package which is a thin wrapper around the SDL C library which should work on most platforms.
Related
Can anyone point me toward some of the more visually intricate / complicated examples of what can be done with Tkinter? Canvas based widgets and OpenGL please.
Thanks.
There are a couple I think might be interesting;
Py in my eye
tkDocs
There are a couple of things to keep in mind;
Tk is over 25 years old. On X11 it predates things like Freetype. It is still evolving though.
Tk is cross-platform. This implies that it generally cannot use the latest and greatest platform-specific tricks. It has to work with all the platforms it supports.
"Theming" and "skins" are relatively new in GUI toolkits. Some of them (GTK+ comes to mind) had to be re-designed internally to be able to use themes. Tk acquired theming support relatively recently.
Things like transparency are platform dependent, making it difficult for a toolkit to support it on all platforms. E.g. on X11 it requires the rendering extension.
It you want to do really graphics intensive stuff, a GUI toolkit might not be the best tool for the job. A games toolkit like pygame or OpenGL interface might suit your needs better.
There were samples in python-2.7.15 that could represent what you are looking for:
On my Linux install they are located in /usr/doc/python-2.7.15/Demo/tkinter
if you have python3 only, you could maybe look for an older version to download and install, see if the documents get installed.
I would like to use a text-based UI in my Haskell program. I found some bindings for the ncurses library (see also hscurses or ncurses, which one to use?). The hscurses and nanocurses packages are just simple wrappers around the C library, while vty isn't very well documented and a bit ugly (for example mixing snake_case and CamelCase).
The ncurses library on Hackage looks much more pretty and provides API which nicely fits Haskell. The problem is that it doesn't seem to implement some crucial features, like resizing or refreshing the windows.
So my question is:
is there any other Haskell text UI library, either ncurses-based or not, which I missed?
if there isn't anyone, is it possible to extend the ncurses Haskell library to at least support window refreshing and resizing? (this should be probably consulted with the project owner, but I need the solution quickly)
EDIT:
I finally used nscurses without windows (and panels) to avoid the troubles with refreshing them. I had problems with output to bottom-right corner of a window (a very similar issue was reported for Python's ncurses binding). I solved it by not writing there :).
Have you looked at vty-ui? It has a very nice user manual with lots of examples. I believe it's essentially a wrapper around vty.
I've used nanoncurses and hscurses succesfully, my hmp3 app has a binding that was the basis for nanocurses.
No matter what you probably will want a nice high level API. hscurses does have a box abstraction at least.
You'd be fine going with hscurses.
There is another good choice for Text-based user interfaces in haskell;
Brick is written by jtdaugherty, the same person that developed vty-ui which is Deprecated now.
The API is Declarative, which is Better for Presenting a language like Haskell.
also the Documentation was great and complete.
In Ocaml, is there easier ways to write a graphics-based toy programs like deminer (like the one that comes with Windows 95)? I find the only way is to start by scratch using Ocaml's graphics library. There must be better ways around?
There are bindings to the SDL library, that provides more features than Graphics.
There are actually several of them, and I'm not exactly sure which is best:
SdlCaml is a part of the [GLcaml] project
the OcamlSDL library
I think SdlCaml is more bare metal (probably partly automatically generated), and OCamlSDL is an older (but still occasionally updated) library with a larger user base.
Note however that Graphics is simple to use for a start, and you can still move to something more sophisticated later. If you run into speed-of-rendering issues, you have to use double buffering, as explained in the manual.
I'm newbie to haskell.
while wxFreeChart page in wxCode says it supports all wx ports, I have no any idea about how to use it in haskell
It's a C++ library, so you'd have to bind it yourself if you want to use it from Haskell; this is unlikely to be practical, as binding C++ libraries to Haskell is a difficult task. (Indeed, wxHaskell itself is based on a custom "binding" of wxWidgets to pure C.)
You should probably figure out another way to accomplish the same task, or if you really need to use wxFreeChart, write your GUI directly in C++. You could still use Haskell for the core logic using the FFI.
wxWidgets ports aren't relevant here; they're the parts that glue wxWidgets to a windowing system like Windows, GTK+, etc.
If you're not overly tied to wxWidgets, you could check out the Chart library, which can be used with Gtk2Hs. I haven't used it myself, but it seems quite polished.
I'm an author of wxFreeChart. Under "All ports" i meant, Windows, MacOS X, Gtk+, Universal ports.
wxHaskell is not directly supported, and there are no plans to support it. If wxFreeChart will work with wxHaskell, it's great. But, i'm not sure about it.
I'm planning to build a simple, lightweight text editor that combines a great look with keyboard focused input.
I want to have a lot of control over things like antialiasing and all the graphics in general, but I don't care about having a whole library of widgets. Almost the entire UI will be text-based and in the main canvas/window of the app.
Toolkits like GTK and Qt seem like overkill - tons of widgets I don't need and a complex codebase.
Titanium, AIR, and XULRunner are even bigger in some ways - dev would be quick, but that's not exactly the lightweight approach.
Shoes seemed like a nearly perfect fit, but it's a little too small and doesn't support enough events (e.g. no window resize).
What do you think, should I just build it on Cairo/Pango or another graphics library and roll the platform specific stuff myself? I'd rather use a framework of some kind.
Basically all I want is:
good event handling
windowing
menus
drawing with really great type rendering choices
I would love to build this cross-platform from the start.
Even if you use just Cairo/Pango you still need windows on the screen.
The simplest combination would be cairo + pango + GDK (the windowing part of GTK+)
however even in that case you have no menus, and constructing menus with pure Cairo
would be a tough (but not impossible) accomplishment.
If you insist on lightweight and crossplatform then check the following
Fast Light Toolkit
Fox Toolkit
wxWidgets (goes great with Python)
Scintilla is a cross-platfrom source code editing component (based on GTK+) with excellent support for syntax highlighting, code folding, text zooming, and of course all the usual text editing functions; it should be an excellent foundation for a text editor.