April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | "Andrei Alexandrescu" <SeeWebsiteForEmail@erdani.org> wrote in message news:ine1bu$14mv$1@digitalmars.com... > On 4/4/11 8:36 PM, Nick Sabalausky wrote: >> "Daniel Gibson"<metalcaedes@gmail.com> wrote in message news:inddni$kmi$3@digitalmars.com... >>> >>> I don't know if wee need yet another GUI library. >>> Are you sure Qt and DWT aren't good enough? >>> >> >> AIUI: >> >> DWT doesn't support D2 (neither does wxD). > > I understand DWT does support D2 on Windows as of today: > > http://hg.dsource.org/projects/dwt2/rev/9f4c18c268b2 > Neat-o. (I think I need some new superlatives...) | |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | "Andrej Mitrovic" <andrej.mitrovich@gmail.com> wrote in message news:mailman.3183.1301973158.4748.digitalmars-d@puremagic.com... > > Oh btw, I just found a cool trick today to figure out in what directory an app resides. E.g. if you invoke "gcc.exe" and you want to know where it's installed. Add this batch file to your path: > > @setlocal > @set P2=.;%PATH% > @for %%e in (%PATHEXT%) do @for %%i in (%~n1%%e) do @if NOT > "%%~$P2:i"=="" echo %%~$P2:i > > Then just run `where myapp.exe`, and it shows you the full path. Heh, sweet. Batch trickery. That really takes me back. That seems a useful tool, too. | |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | BTW, before I gave up on it, I tried a lot of things and made some progress in a few areas. I actually came very close to getting a C++ object, compiled with mingw's gcc, to link into D. If you use coff2omf (included in the commercial Digital Mars package), you can get the object files all in the same format. Then, run implib (with the free DM compiler package IIRC) on the mingw DLLs to make some .lib files. Then link it all together... almost works. The next problem is getting the correct C++ runtime objects in and initialized... and that's where I gave up on it. A similar, but much simpler approach, was to have g++ put out a shared library. Then do implib on it to get a .lib to pass to optlink. Boom, the program works as long as you bundle that .dll g++ made in there too. To communicate with your C++, use extern(C) functions. To have C++ call back into D, pass it an extern(c) function pointer. When I did my own Qt, I put the Qt event loop in its own thread (created with std.concurrency.spawn), using D's message passing to communicate with it and Qt signals/slots to keep the thread straight on the C++ side. Took a little setup code, but actually worked pretty well once it was up and running. Tip though: don't actually cast things to immutable when passing messages! The compiler's complaints are there for a reason. Follow the rules, and it's fairly simple and very reliable in my experience. g++ -ogui.dll -shared mycplusplus.cpp implib /s gui.dll gui.lib dmd mydapp.d gui.lib | |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 4/5/11, Nick Sabalausky <a@a.a> wrote:
> Hmm, I really wish DMD had a cmdline param to specify a library to be passed to the linker rather than needing to use "-L". Makes it impossible to write a cross-platform DMD command for anything that requires linking to a lib.
But you can pass .lib files directly to DMD, I don't understand why people use -L.
| |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | Nick Sabalausky wrote: > Should "pragma(lib, nameoflib);" work, or was that just a special > thing in bu(il)d? Yes, that should work. I use it in my curl and mysql modules which I use with straight DMD (as well as my own little build tool, which simply downloads referenced modules from my http server and builds the dmd command line automatically. http://arsdnet.net/dcode/build.d ) > That should help. It does seem that QtD could *really* use some D-ification, though. Absolutely. That's one reason why I actually prefer my later approach of doing my own approach - one version of my D windowing system plan. Here's some snippets from the program written in it (it's closed source commercial for a client company, so can't post the whole thing): // it uses runtime Qt Designer loading to avoid the long // process of porting all that code. Acts as a "release // valve" if you will from the limitations of my system. // the .ui file is created straight from the C++ tool auto window = new QtUicWidget(import("stb.ui")); window.show(); // thanks to some opDispatch magic though, it feels almost // like a regular class, though you need to do dynamic casts auto accountBox = cast(TreeWidget) window.accountBox; // Arrays of delegates let you handle events. A few // different signatures for handlers are allowed. // (it's actually a struct emulating a delegate array) window.accountProvider.textChanged ~= (Variant[] args) { // snip } // unrelated by cool: my DataObject system works with sqlite too, along with mysql and postgres (to a limited extent)! auto db = openDBAndCreateIfNotPresent("stb.db", import("stb.sql") [...] // qtConnect is another one of my escape valves // if I don't offer a D wrapper, you can still access // Qt events via strings, with extensions for D // delegates! qtConnect(dialog.getKeyButton, "clicked()", { dwsapp.openBrowser("http://mysite.com"); }); The thing above is implemented via a bunch of helper objects on the C++ side, put into a QSignalMapper. It actually leaks a little memory since there's no facility to delete the C++ object, but it was too convenient to have. You can also connect C++ signals to C++ slots directly, using the same string syntax, just like in QtD. I found the delegates so much more useful though that I always used them in this app. // a technique I first started using in Javascript that // I also use in D now too - a function creates a delegate // so it can be called in a loop, closing over the loop var void delegate() makeTextChanged(Item i, string id) { // Menu items are Actions, like in C++, but the delegate // is provided right there. auto newAccountAction = new Action("&New Account", { newAccount("", "New Account"); }); // property syntax for get/set newAccountAction.icon = new Image(cast(bytes) import("add.png")); // another escape valve - access C++ objects dynamically // It actually builds wrapper objects at runtime from the // .ui file so you can use the D extensions on it too window.actions["action_About"].triggered ~= { // Qt supports CSS, so I did that here too, extending it // for HSL colors (it was mentioned on the newsgroup and // I liked it!) window.setStyleSheet(fixupStylesheetHsl(` // the C++ event loop is put into a separate gui thread // all wrapped up in this call: int retv = dws.eventLoop(); Like I've said before about the dws, I really want to make it work with a shitty javascript front end too - and made some progress in an earlier version - but the Qt got more attention here since I needed it for a work project and was under the clock. Hence, the escape valves and relatively limited native functions. But, like with all my D libraries, I do keep the copyright on all of it, even when it's done directly for work, so I could clean this up for release. It uses some C++0x features in the DLL code, so it might be a pain to compile, but I could distribute binaries; it's about 1 MB, negligble next to Qt itself. It works on both Windows and Linux. | |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Andrej Mitrovic wrote:
> I don't understand why people use -L.
I pass the .libs directly on Windows, but I don't think it works on Linux... not sure actually though.
But pragma(lib) definitely works on both!
| |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | I wrote:
> I found the delegates so
> much more useful though that I always used them in this app.
Correction: I did use some Qt -> Qt connections, but they were all created in the Qt Designer instead of in the D code. Since the .ui file is loaded up by Qt's own parser (with me inputting hooks at the places needed to make them work with the D bridge classes), it's functions all work, including signal/slot connections made in the gui.
| |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | Michel Fortin wrote: > It would also be nice to be able to load an image from a file, but that's a little more complicated. I have some .bmp and .png loading written up too. Doesn't implement every feature of either format, but enough to get by. From my program: import arsd.bmp; void main() { auto i = new BMP("lol.bmp"); // loading from file i.display(); // display it to the screen } Alternatively, make one with arrays: void main() { auto i = new Image(255, 255); for(int b = 0; b < h; b++) for(int a = 0; a < w; a++) i.setPixel(a,b,Color(255,a,0)); // truecolor i.display(); } You can also write out to a file or to a memory array (should probably be some kind of lazy range). When combined with cgi.d, that means you can output images to the web browser like so: http://arsdnet.net/cgi-bin/gradient?h=100&w=100&c1=ff0000&c2=00ff00 No need for external libraries - my png read/write is homegrown in D. (which is why it doesn't implement the full standard, but it's also much smaller and simpler to use than something that does) It doesn't offer much for drawing - it's just a memory array and a few of my ancient DOS routines ported over, but it's a start. I'll see about cleaning it up for a release next chance I get. | |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On 4/4/2011 9:25 PM, Michel Fortin wrote:
> On 2011-04-04 19:55:44 -0400, Adam Ruppe <destructionator@gmail.com> said:
>
>> Michel Fortin wrote:
>>> On the other hand, one thing that is missing right now, in D and in
>>> most languages, is a standard way to display graphics.
>>
>> Actually, I wrote something to do that last year, but I thought
>> it was too trivial to share.
>>
>> What you do is just draw some RGB stuff to a big memory buffer. Then
>> you can save as bmp, png, or create a window to display it.
>>
>> There was no interaction with the window, except closing it. You'd
>> pop up the window so the user can review the picture, then he closes
>> it and your program continues where it left off.
>>
>> Changing it to allow some updating and interaction shouldn't be
>> too hard.
>>
>> It worked for both win32 and x11, no libraries required.
>
> Reminds me of David Simcha's plot2kill, which also has such a layer on
> top of which it implements plot drawing.
> <http://www.dsource.org/projects/plot2kill>
Right. Plot2kill defines an abstraction layer over the drawing functionality of a GUI library (lines, rectangles, text, etc.), so that the code for drawing a plot is strongly decoupled from the GUI library. So far this has proven successful on GtkD and DFL.
However, Plot2kill also defines a default plot window, which allows for things like saving the plot interactively, zooming in on subplots and, in the GtkD incarnation, customizing several aspects of the plot interactively. For this stuff, I didn't even try to abstract away the GUI library because it seemed self-evident to me that creating this massive and brittle an adapter layer was a bad idea, and the lesser of two evils would be to just write an independent default plot window for each library.
| |||
April 05, 2011 Re: GUI library for D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | "Andrej Mitrovic" <andrej.mitrovich@gmail.com> wrote in message news:mailman.3178.1301970383.4748.digitalmars-d@puremagic.com... > On 4/5/11, Nick Sabalausky <a@a.a> wrote: >> After all, I >> *really* want to get around to making my own web browser (based off >> either >> Mozilla or Chromium) - I'm getting really fed up with the current state >> of >> available web browsers. Well, and the web as a whole (god I fucking hate >> the >> web), but one step at a time, I guess). > > I'll be the first to install it. > > Btw, there's a full web browser example in the QtD sources. But it has to be ported to D2. And then you have to deal with any eventual bugs along the way. :] Ha! I may not need to do much after all: I was just looking through Wikipedia's giant list of browsers, found a few that looked potentially promising, tried them all and...well, was mostly disappointed. But the *last* one I had left to try I've been really impressed with so far: Arora (Qt/WebKit) http://code.google.com/p/arora/ I've only tried it breifly, but the UI is *actually nice*! Only modern browser out there with a UI that isn't absolutely horrid. I didn't even see *one* instance of invisible-text on my light-on-dark system, which is unbeleivavly rare among all software these days. And it has a lot of essential stuff built in, like ad blocking, disableable JS, and a "ClickToFlash" which I haven't tried out yet. There's still a few things it seems like it might be missing, like equivalents to NoScript, BetterPrivacy and maybe DownloadHelper and DownThemAll, but most of those are less important to me, and even as it is right now it's a damn good start. Maybe I could add some of that remaining stuff, or heck, maybe even port the whole thing to D ;) | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply