digitalmars.D.learn - problem extracting data from GtkSourceView using Gtkd
- Chris Bare (24/24) Jan 14 2019 I would have posted this in the Gtkd forum, but it has been down
- Neia Neutuladh (4/6) Jan 14 2019 You shouldn't need to new these. `out` means that the function is going ...
- Mike Wey (6/35) Jan 15 2019 Your code looks correct, and when copying it into the GtkD sourceview
- Chris Bare (45/45) Jan 16 2019 Weird, the code does work in my program during startup, but when
- Mike Wey (5/7) Jan 17 2019 The onShutdown callback is run after the GTK main loop terminates, so
- Chris Bare (5/5) Jan 17 2019 I think I finally figured it out.
I would have posted this in the Gtkd forum, but it has been down for a while. I'm porting a GTK2/C program to Gtkd. I'm trying to read the data from a GtkSourceView, but when I try to get the bounds, it's always zero. Here's the c version that works: GtkSourceBuffer *bf; GtkTextIter start, end; int len; bf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w.mainTxt)); gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER(bf), &start, &end); data = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(bf), &start, &end, FALSE); Here's what I tried in D: SourceBuffer bf; auto start = new TextIter(); auto end = new TextIter(); bf = this.mainTxt.getBuffer (); bf.getBounds (start, end); string str = bf.getText (start, end, false); getBounds is defined as: getBounds(out TextIter start, out TextIter end) Is there something I'm doing wrong? Any suggestions on what else to try?
Jan 14 2019
On Mon, 14 Jan 2019 22:52:48 +0000, Chris Bare wrote:auto start = new TextIter(); auto end = new TextIter();You shouldn't need to new these. `out` means that the function is going to overwrite the variables. Other than that, I'm not sure.
Jan 14 2019
On 14-01-2019 23:52, Chris Bare wrote:I would have posted this in the Gtkd forum, but it has been down for a while. I'm porting a GTK2/C program to Gtkd. I'm trying to read the data from a GtkSourceView, but when I try to get the bounds, it's always zero. Here's the c version that works: GtkSourceBuffer *bf; GtkTextIter start, end; int len; bf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w.mainTxt)); gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER(bf), &start, &end); data = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(bf), &start, &end, FALSE); Here's what I tried in D: SourceBuffer bf; auto start = new TextIter(); auto end = new TextIter(); bf = this.mainTxt.getBuffer (); bf.getBounds (start, end); string str = bf.getText (start, end, false); getBounds is defined as: getBounds(out TextIter start, out TextIter end) Is there something I'm doing wrong? Any suggestions on what else to try?Your code looks correct, and when copying it into the GtkD sourceview demo str does indeed hold the text displayed in the GtkSourceview. Do you have a more complete example we could look at? -- Mike Wey
Jan 15 2019
Weird, the code does work in my program during startup, but when I call the same function from Application.onShutdown it gets the 0 results. Are the widgets destroyed before onShutdown? Here's a stripped down version my Application subclass: int main (string[] args) { auto application = new SpiralApp(); application.run(args); return(0); } class SpiralApp: Application { MainWin win; this () { super("com.bareflix.spiral", ApplicationFlags.NON_UNIQUE); addOnActivate(&onActivate); addOnStartup(&onStartup); addOnShutdown(&onShutdown); } void onActivate(GioApplication application) { win = new MainWin(); this.addWindow (win.spiral); win.spiral.showAll(); notepadList = new NotepadList (dir); activePad = notepadList.front (); activePad.activate (); // this sets the text in the GtkSourceView win.getMainTxt (); // this retrieves the text correctly } void onShutdown(GioApplication application) { // this returns a blank string. I don't do anything in the UI, just // start it up and then exit with the window manager win.getMainTxt (); notepadList.write (); activePad.save (); info ("on shutdown here"); } } Any ideas?
Jan 16 2019
On 17-01-2019 00:31, Chris Bare wrote:Are the widgets destroyed before onShutdown?The onShutdown callback is run after the GTK main loop terminates, so most objects would be finalized. -- Mike Wey
Jan 17 2019
I think I finally figured it out. I think the GTKapplication shutdown signal is called after the window has been destroyed. If I attach a handler to the window's destroy signal, then I am able to get the data from the sourceView.
Jan 17 2019