www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Gtkd how to filter TreeView according to user input

reply Erdem <farukerdemoncel gmail.com> writes:
I'd like to filter Treeview data according to user input. How 
should I do that?

When I run this program it gives segmentation fault error.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.Entry;
import gtk.EditableIF;
import gtk.TreeModelFilter;
import gtk.TreeView;
import gtk.HBox;
import gtk.VBox;
import gtk.Label;
import gtk.ListStore;
import gtk.TreeViewColumn;
import gtk.CellRendererText;
import gtk.TreeModel;
import gtk.TreeIter;

import std.conv;
import std.stdio;

class MyWindow: MainWindow
{
     Box mainBox;
     Entry filterEntry;
     TreeModelFilter filter;
     TreeIter iter;

     this()
     {
         super("TreeView Example");
         setSizeRequest(500, 200);
         filterEntry = new Entry();
         auto filterLabel= new Label("Artist search");
         auto tree = new TreeView();
         auto box = new VBox(false, 0);

         auto dataModel = new ListStore([GType.STRING, 
GType.STRING]);

         auto artistColumn = new TreeViewColumn("Artist", new 
CellRendererText(), "text", 0);
         tree.appendColumn(artistColumn);
         auto songColumn = new TreeViewColumn("Song title", new 
CellRendererText(), "text", 1);
         tree.appendColumn(songColumn);

         iter = dataModel.createIter();
         dataModel.setValue(iter, 0, "This is a test");
         dataModel.setValue(iter, 1, "Sample song");

         iter = dataModel.createIter();
         dataModel.setValue(iter, 0, "This is a test");
         dataModel.setValue(iter, 1, "Another song");

         iter = dataModel.createIter();
         dataModel.setValue(iter, 0, "Another artist");
         dataModel.setValue(iter, 1, "Test song");

         filter = new TreeModelFilter(dataModel, null);
         filter.setVisibleFunc(cast(GtkTreeModelFilterVisibleFunc) 
& filterTree, null, null);

         tree.setModel(filter);

         auto mainBox = new HBox(false, 0);
         mainBox.packStart(filterLabel, false, false, 5);
         mainBox.packStart(filterEntry, true, true, 5);
         box.packStart(mainBox, false, false, 5);
         box.packStart(tree, true, true, 5);

         add(box);

         showAll();
     }

     bool filterTree(GtkTreeModelFilter gtkModel, GtkTreeIter 
gtkIter)
     {
         auto model1 = new TreeModelFilter(&gtkModel, false);
         auto it1 = new TreeIter(&gtkIter, false);
         string artistName = to!string(model1.getValue(it1, 0));

         return true;
     }
     void onFilterEntryTextChanged(EditableIF filterEntry)
     {
         filter.refilter();
     }

     // void onFilterEntryTextChanged(ParamSpec param, ObjectG 
object)
     // {
     //     filter.refilter();
     // }
}

void main(string[] args)
{
     Main.init(args);
     new MyWindow();
     Main.run();
}
Jan 17
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 01/17/2017 01:25 AM, Erdem wrote:

 void main(string[] args)
 {
     Main.init(args);
     new MyWindow();
     Main.run();
 }
I have no experience with Gtkd but the code inside main looks fundamentally wrong. One would expect you to do something with the MyWindow object: auto w = new MyWindow(); And then use 'w' but I don't know how. Ali
Jan 17
parent Erdem <farukerdemoncel gmail.com> writes:
On Tuesday, 17 January 2017 at 19:07:21 UTC, Ali Çehreli wrote:
 On 01/17/2017 01:25 AM, Erdem wrote:

 void main(string[] args)
 {
     Main.init(args);
     new MyWindow();
     Main.run();
 }
I have no experience with Gtkd but the code inside main looks fundamentally wrong. One would expect you to do something with the MyWindow object: auto w = new MyWindow(); And then use 'w' but I don't know how. Ali
Thanks. The problem is already solved. You may look at this thread: http://ddili.org/forum/post/12453 Ben D diline biraz önce göndermiştim :) Erdem
Jan 17