GTKD - Application crashes - or not? [Coedit]

TheDGuy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 16 08:57:36 PDT 2016


On Thursday, 16 June 2016 at 10:14:47 UTC, Basile B. wrote:
>
> from args[0] you can get the base bath and since your css is 
> relative to the base path:
>
>     string cssPath = "test.css";
>     CssProvider provider = new CssProvider();
>     provider.loadFromPath(cssPath);
>
>
> add something like
>
>     import std.path;
>     basePath = args[0].dirName;
>
>     string cssPath = basePath ~ "\" ~ "test.css";
>
> and you can remove all the stuff in the Run options.

But i don't call my CSS file in the main-function but instead i 
call it in the MainWindow:

import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
import glib.GException;

class Window : MainWindow{
     this(int width, int height, string title){
         super(title);
         setDefaultSize(width, height);
         Button btn = new Button("Test");
         btn.setName("CssName");

         string cssPath = "test.css";

         CssProvider provider = new CssProvider();
         provider.loadFromPath(cssPath);

         Display display = Display.getDefault();
         Screen screen = display.getDefaultScreen();
         StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

         add(btn);
         showAll();
     }
}

void main(string[] args){
     Main.init(args);
     auto win = new Window(250,250,"Tutorial");
     Main.run();
}


More information about the Digitalmars-d-learn mailing list