View previous topic :: View next topic |
Author |
Message |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Sun May 20, 2012 4:09 pm Post subject: GtkD, GtkBuilder and signals |
|
|
I'm trying to use GtkBuilder with GtkD.
I have a xml file made with Glade that connect a signal to destroy event of a window. The program runs and show the window, but I'm getting a waring:
Gtk-WARNING **: Could not find signal handler 'on_main_window_destroy'
I don't know very well Gtk+, and I can't find a example of doing this with GtkD (the builder example it's too stupid, not show nothing about loading a GtkBuilder file with something more complex). So I ask, what I'm doing wrong ?
Here are the files:
d file
Code: |
import gtk.Main, gtk.Builder, gtk.Widget, gdk.Event;
import gtk.MainWindow;
import std.c.process, std.stdio;
void on_window_destroy (Event event, Widget widget) {
Main.exit(0);
}
void main(string[] args) {
Main.init(args);
auto builder = new Builder ();
if (! builder.addFromFile ("main.ui")) {
writefln("Oops, could not create Builder object, check your builder file ;)");
exit(1);
}
builder.connectSignals (null);
Widget w = cast(Widget)builder.getObject ("main_window");
if (w is null) {
writefln("No window?");
exit(1);
}
//w.addOnHide( delegate void(Widget aux){ Main.exit(0); } );
w.show ();
Main.run();
}
|
ui file
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">DEDCPU-16</property>
<signal name="destroy" handler="on_main_window_destroy" swapped="no"/>
<child>
<placeholder/>
</child>
</object>
</interface>
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Mon May 21, 2012 5:21 am Post subject: |
|
|
Auto reply: I was calling bad the function handler
The fixed code that works:
Code: |
import gtk.Main, gtk.Builder, gtk.Widget, gdk.Event;
import gtk.MainWindow;
import gtkc.gtktypes;
import std.c.process, std.stdio, std.conv;
extern (C) void on_main_window_destroy (Event event, Widget widget) {
Main.exit(0);
}
void main(string[] args) {
Main.init(args);
auto builder = new Builder ();
if (! builder.addFromFile ("main.ui")) {
writefln("Oops, could not create Builder object, check your builder file ;)");
exit(1);
}
Widget w = cast(Widget)builder.getObject ("main_window");
if (w is null) {
writefln("No window?");
exit(1);
}
builder.connectSignals (&on_main_window_destroy);
w.show ();
Main.run();
}
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Wed May 30, 2012 2:20 pm Post subject: |
|
|
Now I managed to compile in Windows, but can't find the signals, where in Linux can it.
Code: |
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_close'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_but_prev_clicked'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_but_next_clicked'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_mnu_about_activate'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_close'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_mnu_saveas_activate'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_mnu_open_activate'
(lem1802_fontview.exe:1980): Gtk-WARNING **: Could not find signal handler 'on_mnu_new_activate'
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed May 30, 2012 3:20 pm Post subject: |
|
|
I think you'll need to mark the signal handlers with "export" on windows.
On Linux all symbols are exported by default, but this isn't the case for Windows. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Thu May 31, 2012 12:57 am Post subject: |
|
|
export (Windows) not ?
UPDATE:
I try this:
Code: | version(Windows) {
extern (Windows) void on_close (Event event, Widget widget) {
ev_on_close(event, widget);
}
} else {
extern (C) void on_close (Event event, Widget widget) {
ev_on_close(event, widget);
}
}
void ev_on_close (Event event, Widget widget) {
Main.exit(0);
} |
I'm keep getting the same warnings about not found signals.
I try with extern (System), extern (Windows) and simply extern , nothing works.
I'm building with rdmd last version on Windows 7 x64 with gtk 2.24 runtime and last version of GtkD from git. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Thu May 31, 2012 2:51 pm Post subject: |
|
|
I was thinking:
Code: | extern(C) export void on_close (Event event, Widget widget) {
ev_on_close(event, widget);
} |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Thu May 31, 2012 4:06 pm Post subject: |
|
|
Oh! Thanks! Now it can find nearly all signals alone, except for one (on_close) that are set to main window destroy signal and to mnu_item_close at same time. In Linux this its working, but in Windows not. I don't see a bad typo... |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Jun 02, 2012 7:41 am Post subject: |
|
|
Are there any differences between on_close and the other signal handlers ? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Thu Jun 07, 2012 2:43 pm Post subject: |
|
|
I don't appreciate any difference in the source code or in the UI xml file.
Actually I'm getting this warning at runtime :
(lem1802_fontview.exe:3000): Gtk-WARNING **: Could not find signal handler 'on_mnu_exit_activate'
And a part of code is :
Code: |
...
/**
* Close the App when it's clicked menu exit option
*/
extern (C) export void on_mnu_exit_activate (Event event, Widget widget) {
Main.exit(0);
}
/**
* Show About dialog
*/
extern (C) export void on_mnu_about_activate (Event event, Widget widget) {
win_about.run();
win_about.hide();
}
/**
* Click over Previus button
*/
extern (C) export void on_but_prev_clicked (Event event, Widget widget) {
selected = (selected -1) % 128;
lbl_pos.setLabel(to!string(selected));
update_editor();
dwa.queueDraw();
}
...
|
Also, you can see the original full code at github repo, in particular lem1802_fontview.d |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Jun 09, 2012 3:41 pm Post subject: |
|
|
When i compile the project on Windows, i can see that the signal handler is properly exported in the object file.
There are also no differences between the on_mnu_exit_activate and the other signal handlers. I have no clue why that one handler isn't working. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Zardoz
Joined: 28 May 2011 Posts: 17 Location: Spain
|
Posted: Sat Jun 09, 2012 4:22 pm Post subject: |
|
|
And the most interesting point is that in Linux not have these issue. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Jun 10, 2012 8:18 am Post subject: |
|
|
It looks like a issue with either the compiler or the linker.
The only thing on_mnu_exit_activate doesn't have in common with the other handlers is that it's the first exported symbol in the file.
And that causes it to be placed somewhere it can't be loaded even using LoadLibrary/GetSymbol doesn't return it's address.
When Putting:
Code: | extern(C) export void dummy(){} |
at the top of the source file, gtk no longer complains about the missing symbol. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Jun 10, 2012 8:23 am Post subject: |
|
|
I did some more searching and it seems that the for the exported handlers in the binary, the first one is prefixed with an underscore.
This is because of a bug in optlink:
http://d.puremagic.com/issues/show_bug.cgi?id=3956 |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|