FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with Idle and FileChooserDialog?

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
ElZilcho



Joined: 20 Jun 2008
Posts: 7

PostPosted: Wed Jul 23, 2008 8:34 am    Post subject: Problem with Idle and FileChooserDialog? Reply with quote

I am writing an application using gtkd and I am having some problems with using file chooser dialogs. I use them all over the place in my application, but for some reason if I new an Idle object, then they all stop working. Here is what I see when I have an idle function:



The dialog just sits like that, and I can only click the cancel and close buttons, but no files ever appear. Also, all my saved locations don't appear. I am using Ubuntu 8.04, gtkD pre 9, and dmd 1.031. Also, I have been developing this code for a while, and when I was working under Ubuntu 7.10, this worked just fine, but when I upgraded, it stopped working (this may be because of a different version of the compiler/gtkd/something else I did differently. I made a lot of changes before I noticed it. But the idle function and the file chooser dialog were both there in my previous version that worked). None of my other gtk applications quit working in this manner, though. Please let me know if I have messed up somewhere or if this is a bug. Here is some sample code that I put together to demonstrate this. The file chooser code is copy/paste from the demos that ship with gtkd. If you comment out the line "idle = new Idle(&idleCB);" the file chooser dialog comes up and everything works fine.

Code:
import gtk.Main;
import gtk.MainWindow;
import gtk.Idle;
import gtk.FileChooserDialog;
import gtk.Button;

import std.stdio;

class Driver
{
   private MainWindow win;
   private Idle idle;
   
   public void main()
   {
      Main.init(null);
      
      win = new MainWindow("Test Window");
      Button b = new Button("Button");
      b.addOnPressed(&pressButton);
      
      win.add(b);
      win.showAll();
      
      idle = new Idle(&idleCB);
      
      Main.run();
   }
   
   private bool idleCB()
   {
      writef("Idling!\n");
      return true;
   }
   
   private void pressButton(Button b)
   {
      string[] a;
      ResponseType[] r;
      a ~= "Lets go!";
      a ~= "Please don't";
      r ~= ResponseType.GTK_RESPONSE_OK;
      r ~= ResponseType.GTK_RESPONSE_CANCEL;
      FileChooserDialog fcd = new FileChooserDialog("File Chooser", win, FileChooserAction.OPEN, a, r);
      fcd.getFileChooser().setSelectMultiple(true);
      fcd.run();
      fcd.hide();
   }
}

void main()
{
   Driver d = new Driver();
   d.main();
}


this is file main.d, and it is compiled using
Code:
dmd main.d -L-ldl -L-lgtkd
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Jul 23, 2008 1:46 pm    Post subject: Reply with quote

It looks like one of the two has the wrong priority, although the priorities are set by Gtk.

I'll see if i can find an old Ubuntu live cd to test this with an older version of gtk.
Back to top
View user's profile Send private message
ElZilcho



Joined: 20 Jun 2008
Posts: 7

PostPosted: Thu Jul 24, 2008 12:17 pm    Post subject: Reply with quote

Mike Wey wrote:
It looks like one of the two has the wrong priority, although the priorities are set by Gtk.

I'll see if i can find an old Ubuntu live cd to test this with an older version of gtk.


Thanks, this helped me get it working, but it is really a mess to fix. Here is how I solved the problem:

First, I noticed that the comments above most of the functions in the Idle class are deprecated, so this class should probably not use these functions. Instead, it is recommended that you use g_idle_add and g_idle_add_full. These are available in gtkd through the glib.MainLoop class. But, the function g_idle_add_full does not take a delegate. Instead, it takes an extern(C) function pointer, so I can not have my idle function in a class. Also, the g_idle_add_full is normally used with one of the following constants:

G_PRIORITY_HIGH
G_PRIORITY_DEFAULT
G_PRIORITY_HIGH_IDLE
G_PRIORITY_DEFAULT_IDLE
G_PRIORITY_LOW

which are defined in the C headers. I could find no equivalent enum in gtkd (probably GPriority.HIGH, etc. would be consistent with the naming scheme). Instead, the function in glib.MainLoop takes in an int. I looked up the value of the int for the lowest priority for idle from here:

http://www.idt.mdh.se/kurser/cd5040/ht02/gtk/glib/glib-the-main-event-loop.html

and found that it was 300. So this is the source of the 300 in the source code below. I don't know if there is a better way with the current code to set up an idle function at lowest priority. If there is, please let me know.

Code:
import gtk.Main;
import gtk.MainWindow;
import gtk.FileChooserDialog;
import gtk.Button;

import glib.MainLoop;

import std.stdio;

private extern(C) int idleCB(void* data)
{
  writef("Idling!\n");
  return true;
}

class Driver
{
   private MainWindow win;
   
   public void main()
   {
      Main.init(null);
     
      win = new MainWindow("Test Window");
      Button b = new Button("Button");
      b.addOnPressed(&pressButton);
     
      win.add(b);
      win.showAll();
     
     MainLoop.idleAddFull(300, &idleCB, null, null);
     
      Main.run();
   }
   
   private void pressButton(Button b)
   {
      string[] a;
      ResponseType[] r;
      a ~= "Lets go!";
      a ~= "Please don't";
      r ~= ResponseType.GTK_RESPONSE_OK;
      r ~= ResponseType.GTK_RESPONSE_CANCEL;
      FileChooserDialog fcd = new FileChooserDialog("File Chooser", win, FileChooserAction.OPEN, a, r);
      fcd.getFileChooser().setSelectMultiple(true);
      fcd.run();
      fcd.hide();
   }
}

void main()
{
   Driver d = new Driver();
   d.main();
}
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Jul 24, 2008 3:44 pm    Post subject: Reply with quote

It looks like glib.Idle is not implemented in GtkD currently, it probably should be implemented like gtk.Idle.

An Enum for the priorities would go nicely with that.

Added ticket #38
Back to top
View user's profile Send private message
ElZilcho



Joined: 20 Jun 2008
Posts: 7

PostPosted: Fri Jul 25, 2008 7:54 pm    Post subject: Reply with quote

Mike Wey wrote:
It looks like glib.Idle is not implemented in GtkD currently, it probably should be implemented like gtk.Idle.

An Enum for the priorities would go nicely with that.

Added ticket #38


I just wanted to say that I got a chance to test out the broken code above on a brand new Fedora 9 install with dmd 1.030, and it had the same problem I was having on Ubuntu 8.04. So it does look to me like it is a problem with the newer versions of gtk. IMHO since the functions are deprecated and are causing problems with non-deprecated code, perhaps the gtk.Idle class should be removed once the glib.Idle class is implemented.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Jul 27, 2008 8:17 am    Post subject: Reply with quote

for reference: gtk bug 348289 - Filechooser is blocked by higher priority idle

edit: svn r544 adds glib.Idle and an GPriority enum.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group