2

I am experimenting with D and gtkd. Now, I have this button, and when I click it, I want to start a function in an other widget. How can I do this?

Here is some example Code, that is working, but not yet doing, what I want(when pressing SearchButton, a function in SearchResultsGrid should be called):

import gtk.Button;
import gtk.SearchEntry;
import gtk.Main;
import gtk.MainWindow;

import gtk.VBox;
import gtk.Grid;
import std.stdio;

import gdk.Event;
import gtk.Widget;

void main(string[] args)  {
    Main.init(args);

    MainWindow win = new MainWindow("Example");
    win.setDefaultSize(200, 100);
    Box hbox = new Box(Orientation.HORIZONTAL, 2);

    hbox.add(new SearchButton("Search"));
    hbox.add(new SearchResultsGrid());

    win.add(hbox);

    win.showAll();
    Main.run();
}

class SearchButton : Button {
    this(in string text) {
        super(text);
        modifyFont("Arial", 14);
     }

    private bool search(Event event, Widget widget) {

        return true;
    }}

class StarterButton : Button  {
    this(in string text) {
        super(text);
        modifyFont("Arial", 14);
        addOnButtonRelease(&startProgramm);
    }
    private bool startProgramm(Event event, Widget widget)
    {
        return true;  
    } }
class SearchResultsGrid : Grid     {
    public void showResults()    {
        attach( new StarterButton("Start"), 1,1,1,1);
        attach( new StarterButton("Start2"), 2,1,1,1);
    }}

So, I want to trigger the showResults in SearchResultsGrid, my idea was, to the SearchResultsGrid Object to the SearchButton in the Main function, but this doesn't work.

What would be the/a forseen way to do it?

bytecode77
  • 14,163
  • 30
  • 110
  • 141
jan_w
  • 113
  • 1
  • 6
  • As you can see in this PyGtk example, you need to *connect* a callback (read: function) to the *clicked* signals received on the button: http://www.pygtk.org/pygtk2tutorial/ch-ButtonWidget.html That's how GTK passes *signal* between widgets and enabled communication between *components*. In your code, there's no connection between the Button and the Grid. That's what you're missing. – behnam Mar 15 '15 at 10:07

0 Answers0