Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic glade interface to D class #263

Open
Aphexus opened this issue Mar 17, 2019 · 3 comments
Open

Automatic glade interface to D class #263

Aphexus opened this issue Mar 17, 2019 · 3 comments

Comments

@Aphexus
Copy link

Aphexus commented Mar 17, 2019

I've written some code for automatically dealing with glade interfaces in D. Essentially it parses the glade interfaces(manually, so it is fragile) and builds a D class that corresponds to the elements in the interface and automatically handles much of the boilerplate code:

https://ufile.io/8znx4
http://www.filedropper.com/interfacegladetest


module InterfaceGladeTest;
import mGtkD_All;

class cMainAppContext : GtkBase!("test.glade")

} __gshared cMainAppContext MainAppContext = new cMainAppContext();

int main(string[] args)
{
MainAppContext = New!cMainAppContext();

_gtk.Main.init(args);
MainAppContext.Init();

// Initalize GUI
with(_gtk) with(MainAppContext)
{
	MainWindow.showAll();
	Main.run();
}
return 0;

}

This, when set up properly, will display the the interface. One can access the glade interface elements directly in D from the class MainAppContext by their name in the glade interface.

e.g.,

MainAppContext.label

One can also use the @ symbol in the id to replace it with the root GtkWindow, GtkApplicationWindow, GtkDialog id(to shorten writing names in glade). ! will be replaced with the type.

e.g., an id of @Label under a GTKWindow named MyWindow would become

MainAppContext.MyWindow.MyWindowlabel

@MikeWey
Copy link
Member

MikeWey commented Mar 25, 2019

Looks interesting, if it can be made lass fragile.

@Aphexus
Copy link
Author

Aphexus commented Apr 5, 2019

Sell, that is your job! ;) It's going to be fragile parsing the code the way it does. Not really worth writing a full blown grammar parser for it. The other code might be a little hacky but it does work.

Since glade isn't changing much the code should work in for good enough for most people and since it provides big reduction in boiler plating it's probably worth it... but you are welcome to take the idea and write something better. I haven't had a huge issue with it though, in fact, I don't think I've had it fail once, although I have not stressed much either.

It's better to have it around for people to use and then if it fails to scrap it and go to manual mode then only have manual mode as an option.

@lpcvoid
Copy link

lpcvoid commented Jul 6, 2019

Could you please reupload? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants