GTK Drag-and-drop Validation X11 Cursor lock up within drag_get_data.
Hi, I have been unable to get drag and drop validation working in pygtk. I am out of ideas and would like a second opinion. My goal is to only allow files which contain .jpg to be dropped. Specifically, whenever I call widget.drag_get_data within the drag-motion callback The X11 cursor locks up. Making debugging tedious and aggravating since I have to kill X11 and re launch everything. Here is my source code, I think the issue lies specifically in the drag_motion_cb and drag_data_received_cb methods. I have left the commented out sections I have tried before. Using Google code search searching for drag_get_data doesn't show anyone else doing advanced validation. So I'm guessing others failed as well. I am out of ideas and will end up just using simple DnD in my linux port (without proper validation) if I cannot figure this out. Thanks in advance. = import pygtk pygtk.require('2.0') import gobject import gtk TARGET_TEXT_URI_LIST = 0 drop_targets = [ (text/uri-list, 0, TARGET_TEXT_URI_LIST) ] class TestApp(gobject.GObject): builder = gtk.Builder() window = None button = None def __init__(self): gobject.GObject.__init__(self) assert self.builder != None self.builder.add_from_file(MainWindow.glade); self.window = self.builder.get_object(window1) self.button = self.builder.get_object(button1) self.window.connect(destroy, gtk.main_quit) self.button.drag_dest_set(gtk.DEST_DEFAULT_ALL, drop_targets, gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_LINK|gtk.gdk.ACTION_MOVE) self.button.connect(drag-data-received, self.drag_data_received_cb) self.button.connect(drag-drop, self.drag_drop_cb) self.button.connect(drag-motion, self.drag_motion_cb) self.button.connect(drag-leave, self.drag_leave_cb) self.window.show_all() drop_data_ready = False drop_occurred = False drop_highlight = False drop_data = None def drag_data_received_cb(self,widget,context,x,y,data,info,timestamp): print drag_data_received_cb # Check to see if we have the drop data yet. if False == self.drop_data_ready: # If this is data we expected or can handle, then process it. if TARGET_TEXT_URI_LIST == info and data.get_format() == 8 and data.get_length() 0: self.drop_data = data.get_uris() self.drop_data_ready = True context.drag_status(gtk.gdk.ACTION_COPY, timestamp) # Actual drop handling code. if True == self.drop_occurred: # Reset state. self.drop_occurred = False print RECEIVED DROP,self.drop_data # Notify whether we handled the drop or not. context.finish(True,False,timestamp) # Clean up. self.drag_leave_cb(widget, context, timestamp) return True def drag_drop_cb(self,widget,context,x,y,timestamp): target = widget.drag_dest_find_target(context, widget.drag_dest_get_target_list()) # Is it something we can handle? if target == gtk.gdk.atom_intern(text/uri-list, False): # Tell data recieved handler (do_drag_data_received) we can actually handle the drop. self.drop_occurred = True widget.drag_get_data(context,target,timestamp) # We can handle this data type. return True else: # We cannot handle the drop. return False pass def drag_motion_cb(self,widget,context,x,y,timestamp): if not self.drop_data_ready: widget.drag_get_data(context, gtk.gdk.atom_intern(text/uri-list,False), timestamp) return False target = widget.drag_dest_find_target(context, widget.drag_dest_get_target_list()) if target == gtk.gdk.atom_intern(text/uri-list, False): if True == self.drop_data_ready: pass else: #widget.drag_get_data(context, target, timestamp) pass context.drag_status(gtk.gdk.ACTION_COPY, timestamp) if target == gtk.gdk.atom_intern(text/uri-list, False): if True == self.drop_data_ready: if repr(drop_data).find(.jpg) != -1: # Tell Gdk we can handle this. context.drag_status(gtk.gdk.ACTION_COPY, timestamp) # Draw drop highlight (but only once). if False == self.drop_highlight: widget.drag_highlight() self.drop_highlight = True # Return here, don't fall through. return True else: # Request drag data from the source. widget.drag_get_data(context, target, timestamp) # Fall-through to not allowing. # not something we can handle #context.drag_status(0, timestamp) # Don't allow drop. return True pass def drag_leave_cb(self,widget,context,timestamp): # Cleanup drag data. if True == self.drop_data_ready: self.drop_data = None self.drop_data_ready = False # Un-draw the highlight. if True == self.drop_highlight: widget.drag_unhighlight() self.drop_highlight = False pass gobject.type_register(TestApp) def main(): car =
Re: Drag And Drop - drag-motion cursor lockup? [FIXED]
-draw the highlight. if (TRUE == selfp-drop_highlight) { gtk_drag_unhighlight(widget); selfp-drop_highlight = FALSE; } } } On Thu, Apr 1, 2010 at 8:06 PM, Dan Saul daniel.s...@gmail.com wrote: Hi, I am trying to implement drag and drop. Currently just trying to get the destination working. I have the basics working, but if I attempt to do custom drag-motion validation and I call gtk_drag_get_data() the Xserver locks with a drag cursor. The only way to get out is to Alt-F1 then kill the xserver (just the program doesn't unlock). Has anyone encountered this before? I am probably missing something simple. Here is my code, thanks. Tar'd with build script: http://www.slello.com/tmp/testdnd.tar.gz Dan /*http://www.jirka.org/gob2.1.html*/ %h{ #include gtk/gtk.h %} %{ enum { INFO_DEFAULT = 0, INFO_INT32, INFO_STRING, INFO_ROOTWIN }; static GtkTargetEntry target_list[] = { //{ INTEGER,0, TARGET_INT32 }, //{ STRING, 0, TARGET_STRING }, { text/plain, 0, INFO_STRING }, { text/uri-list, 0, INFO_STRING }, //{ application/x-rootwindow-drop, 0, TARGET_ROOTWIN } }; static guint n_targets = G_N_ELEMENTS (target_list); %} class Test:App from G:Object { private GtkBuilder* builder = {gtk_builder_new()} unrefwith g_object_unref; private GtkWindow* window = NULL; private GtkButton* button = NULL; init(self) { gtk_builder_add_from_file(selfp-builder,MainWindow.glade, NULL); selfp-window = GTK_WINDOW(gtk_builder_get_object(selfp-builder,window1)); selfp-button = GTK_BUTTON(gtk_builder_get_object(selfp-builder,button1)); gtk_builder_connect_signals (selfp-builder, NULL); g_signal_connect (selfp-window, destroy, G_CALLBACK (gtk_main_quit), NULL); gtk_drag_dest_set(GTK_WIDGET(selfp-button), GTK_DEST_DEFAULT_HIGHLIGHT|GTK_DEST_DEFAULT_DROP, target_list, n_targets, GDK_ACTION_COPY); g_signal_connect (GTK_OBJECT(selfp-button), drag-data-received, G_CALLBACK(test_app_do_drag_data_recieved), self); g_signal_connect (GTK_OBJECT(selfp-button), drag-motion, G_CALLBACK(test_app_do_drag_motion), self); gtk_widget_show_all(GTK_WIDGET(selfp-window)); } private gboolean drag_highlight = FALSE; private gboolean drag_pending = FALSE; private void do_drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { g_print(do_drag_motion\n); GdkAtom target; Self* self = SELF(user_data); if (FALSE == selfp-drag_highlight) { selfp-drag_highlight = TRUE; gtk_drag_highlight(widget); } target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) { g_print(1\n); gdk_drag_status (context, 0, time); } else { g_print(2\n); selfp-drag_pending = TRUE; gtk_drag_get_data(widget, context, target, time); //gdk_drag_status(context,GDK_ACTION_COPY,time); } return TRUE; } private void do_drag_data_recieved(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data) { g_print(do_drag_data_recieved\n); Self* self = SELF(user_data); if (selfp-drag_pending) { g_print(asdhfajklshdfljkash\n); gdk_drag_status(context,GDK_ACTION_COPY,time); selfp-drag_pending = FALSE; } else { if (selfp-drag_highlight) { selfp-drag_highlight = FALSE; gtk_drag_unhighlight(widget); } if (NULL != data data-length = 0) { //switch(info) //{ //} g_print(do_drag_data_recieved %u %s\n,info,data-data); } } } } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Drag And Drop - drag-motion cursor lockup?
Hi, I am trying to implement drag and drop. Currently just trying to get the destination working. I have the basics working, but if I attempt to do custom drag-motion validation and I call gtk_drag_get_data() the Xserver locks with a drag cursor. The only way to get out is to Alt-F1 then kill the xserver (just the program doesn't unlock). Has anyone encountered this before? I am probably missing something simple. Here is my code, thanks. Tar'd with build script: http://www.slello.com/tmp/testdnd.tar.gz Dan /*http://www.jirka.org/gob2.1.html*/ %h{ #include gtk/gtk.h %} %{ enum { INFO_DEFAULT = 0, INFO_INT32, INFO_STRING, INFO_ROOTWIN }; static GtkTargetEntry target_list[] = { //{ INTEGER,0, TARGET_INT32 }, //{ STRING, 0, TARGET_STRING }, { text/plain, 0, INFO_STRING }, { text/uri-list, 0, INFO_STRING }, //{ application/x-rootwindow-drop, 0, TARGET_ROOTWIN } }; static guint n_targets = G_N_ELEMENTS (target_list); %} class Test:App from G:Object { private GtkBuilder* builder = {gtk_builder_new()} unrefwith g_object_unref; private GtkWindow* window = NULL; private GtkButton* button = NULL; init(self) { gtk_builder_add_from_file(selfp-builder,MainWindow.glade, NULL); selfp-window = GTK_WINDOW(gtk_builder_get_object(selfp-builder,window1)); selfp-button = GTK_BUTTON(gtk_builder_get_object(selfp-builder,button1)); gtk_builder_connect_signals (selfp-builder, NULL); g_signal_connect (selfp-window, destroy, G_CALLBACK (gtk_main_quit), NULL); gtk_drag_dest_set(GTK_WIDGET(selfp-button), GTK_DEST_DEFAULT_HIGHLIGHT|GTK_DEST_DEFAULT_DROP, target_list, n_targets, GDK_ACTION_COPY); g_signal_connect (GTK_OBJECT(selfp-button), drag-data-received, G_CALLBACK(test_app_do_drag_data_recieved), self); g_signal_connect (GTK_OBJECT(selfp-button), drag-motion, G_CALLBACK(test_app_do_drag_motion), self); gtk_widget_show_all(GTK_WIDGET(selfp-window)); } private gboolean drag_highlight = FALSE; private gboolean drag_pending = FALSE; private void do_drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { g_print(do_drag_motion\n); GdkAtom target; Self* self = SELF(user_data); if (FALSE == selfp-drag_highlight) { selfp-drag_highlight = TRUE; gtk_drag_highlight(widget); } target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) { g_print(1\n); gdk_drag_status (context, 0, time); } else { g_print(2\n); selfp-drag_pending = TRUE; gtk_drag_get_data(widget, context, target, time); //gdk_drag_status(context,GDK_ACTION_COPY,time); } return TRUE; } private void do_drag_data_recieved(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data) { g_print(do_drag_data_recieved\n); Self* self = SELF(user_data); if (selfp-drag_pending) { g_print(asdhfajklshdfljkash\n); gdk_drag_status(context,GDK_ACTION_COPY,time); selfp-drag_pending = FALSE; } else { if (selfp-drag_highlight) { selfp-drag_highlight = FALSE; gtk_drag_unhighlight(widget); } if (NULL != data data-length = 0) { //switch(info) //{ //} g_print(do_drag_data_recieved %u %s\n,info,data-data); } } } } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
g_spawn_async_with_pipes() vs system()
Hi, I am having some trouble getting g_spawn_async_with_pipes to function. What I am trying to do is launch mplayer as a sub process to show a movie in one of my windows (-wid option). Running system() works fine with the generated command line argument, but no such luck with g_spawn_async_with_pipes. To generate the command line I use the following. id MAString m_bin = @/usr/bin/mplayer; int m_wid = (int)GDK_WINDOW_XID([b1 widget]-window); id MAString m_media_file = [@Monster House.vob shellEscapedString]; id MAString m_args = [MAGString stringWithFormat:@%@ -wid %d - msglevel all=9 %@,m_bin,m_wid,m_media_file]; This gives us as an example /usr/bin/mplayer -wid 35651615 -msglevel all=9 'Monster House.vob' If we pass this to system it works fine. system([m_args cString]); However if we try to set this up with g_spawn_async_with_pipes it does not. I must be missing something obvious... The following does launch mplayer, however it states that file is not found. I have already tried putting extra quotes around Monster House.vob in the case that g_spawn_async_with_pipes strips them off before passing them to mplayer, no luck However. int argc; char ** argv; GError * err = NULL; gboolean success = g_shell_parse_argv([m_args cString], argc, argv, err); assert(success == TRUE); success = g_spawn_async_with_pipes(., argv, NULL, 0, NULL, NULL, childPid, in_fd, out_fd, NULL, err); assert(success == TRUE); Any thoughts would be appreciated (or if you know of a tutorial for this function), Dan Saul ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Segmentation fault while using g_thread_init
Hi Aparna, Forgive me if I am wrong, but g_thread_init(NULL); gdk_threads_init(); might duplicate the call. I recall when using gnet (which initiates the threads itself it segfaulted if I called g_thread_init. Perhaps taking one of those out would fix your problem? Dan On 18-Oct-08, at 7:16 AM, Aparna V wrote: g_thread_init(NULL); gdk_threads_init(); ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Gtk Window Screen Boundaries
Hi Gtk Application Development, I am developing a program that is akin to a Dock, is there a way to tell gtk or the xwindow system not to place windows within certain rects (also maximize limits) so that windows do not spawn underneath the windows? I have set the window type hint to Dock but to no avail. If this information is readily available on the internet I have been not been able to find it using search engines. If someone could point me in the right direction it would be much appreciated, Thanks Dan ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
libwnck empty window listing
Hi all, I have been trying to learn how to use libwnck to write a simple application launcher. All has been going good up until the point where I tried to get a listing of the windows, at which time I just get an empty null glist back. Sources: http://www.slello.com/tmp/wnck-test/ http://www.slello.com/tmp/wnck-test.zip Specifically the code that is having the trouble is const GList * ma_external_window_list_new(MAScreen * screen) { assert (screen != NULL); assert (screen-wnck_screen != NULL); GList * screen_window_list = wnck_screen_get_windows_stacked(screen-wnck_screen); assert (screen_window_list != NULL); The wnck_screen instance was previously provided by the `const GList * ma_screen_list_new(void)` function within `mascreen.c`. I only have one gdk display, one gdk screen (regardless I am running this on all), as well no errors are emanated from the api. It just silently fails. However! I must be doing something wrong because avant window navigator successfully I am currently looking through their source code to see what they are doing but I hope someone can see the problem. Thanks Dan ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Shared or dynamic?!
I have only just started with libraries myself, but the best I can explain it to you is this: * Static libraries are hardly different then .o files, except rather then a .o file for each of your source files there is only one, the library. * Dynamic Libraries is any code that must be loaded before the application starts, eg. libc, gtk... This is the type of library you should use 80% of the time. * For the rest you have loadable libraries, basically plugins, flash is a plugin for example. A quick google search got me this page; http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html It appears to have everything you need. G'day, Dan On Wed, 2007-30-05 at 07:59 +0200, Tomasz Jankowski wrote: Hello! I'm going to write network library hardly based on GLib to improve my programming skills. However I haven't wrote any library so far, so I haven't got any experience with it. :( After reading libtool documentation I became a bit confused, because I don't know what kind of library should I build. My library should be linked with program while compilation process, not loaded during runtime, so I thought, that I must build a static library, but libraries such as GTK+ or GLib in /usr/lib directory have *.so prefix. I don't understand it... :( Can someone explain it for my? What kind of library should I build? (Sorry for posting it on this mailing list, but i don't know any reliable source of information. Moreover we can say, that it's someway linked to GTK+ apps programming, because I'm using GLib ;P) ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Run Loop Memory Management
Good day, new to the list and GTK+ in general. I am formerly a Macintosh developer. Currently however I am now working on Objective C bindings for GTK+. I am currently looking at the documentation for the run loop which I have found located at http://developer.gnome.org/doc/GGAD/sec-mainloop.html . My question is, I need to implement the autorelease pool's run loop hook that basically runs once every run loop cycle and frees memory. So far guint gtk_idle_add(GtkFunction function, gpointer data); looks the most promising for this purpose. However, being new to this library I would like to get the opinions of those who are more experianced whether there is a better -- or more appropriate place for me to put this code. Thank you for your time, Dan Saul ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Run Loop Memory Management
On Tue, 2007-29-05 at 16:29 -0700, Brian J. Tarricone wrote: On Tue, 29 May 2007 18:12:57 -0500 Dan Saul wrote: Good day, new to the list and GTK+ in general. I am formerly a Macintosh developer. Currently however I am now working on Objective C bindings for GTK+. I am currently looking at the documentation for the run loop which I have found located at http://developer.gnome.org/doc/GGAD/sec-mainloop.html . My question is, I need to implement the autorelease pool's run loop hook that basically runs once every run loop cycle and frees memory. So far guint gtk_idle_add(GtkFunction function, gpointer data); looks the most promising for this purpose. However, being new to this library I would like to get the opinions of those who are more experianced whether there is a better -- or more appropriate place for me to put this code. You're correct, sorta. For starters, please don't use that reference for new gtk2-based code. That book (while excellent) is old and refers to gtk 1.2, which hasn't been maintained for many years. In gtk 2, gtk_idle_add() has been replaced by g_idle_add(). You can look at the glib reference documentation here: http://developer.gnome.org/doc/API/2.0/glib/ I'm not entirely certain that a function added using g_idle_add() will actually run with every main loop cycle. It may only run when there's a certain level of inactivity, and you might want to use g_idle_add_full() to raise the priority higher. However, are you sure this is the best way to do this? Using an idle function will chew through CPU cycles while the application is otherwise idle (really hurts laptop battery performance, for one thing). Another option is a timeout using g_timeout_add(), but the correct approach would be to add a custom GSource that is only invoked when it needs to be. Actually, you might want to poke around in gdk/quartz/ inside gtk+ SVN. I imagine autorelease pools are used in the MacOSX backend; maybe you can find some hints there as to what's best. -brian On Tue, 2007-29-05 at 16:37 -0700, Brian J. Tarricone wrote: Replying to myself... On Tue, 29 May 2007 16:29:12 -0700 Brian J. Tarricone wrote: Actually, you might want to poke around in gdk/quartz/ inside gtk+ SVN. I imagine autorelease pools are used in the MacOSX backend; maybe you can find some hints there as to what's best. I was curious, so I looked around. It looks like the gdk-quartz backend allocs a new pool at the top of any function that uses quartz/cocoa functions (which may or may not make use of objects that use autorelease), and then releases the pool at the end of the function. Reading up on NSAutoreleasePool, it looks like they're nestable or stackable, in that the most-recently-created pool will always get used when any object receives an 'autorelease' message. It sounds like a bit of extra work on your part, but clearly someone thought this was the right approach, and it feels much more correct to me than running a cleanup function periodically via the main loop. Are NSAutoreleasePools expensive to create and/or tear down? That's the only argument I could see against this method. -brian I thank you for the new reference for me to look at. NSAutoreleasePool is pretty much exactly what you read up on it being. My motivation for creating the pool at the start of the event loop and releasing it at the end is from the source of Apple's NSAutoreleasePool documentation. NSAutoreleasePool objects are automatically created and destroyed in the main thread of applications based on the Application Kit, so your code normally does not have to deal with them. The Application Kit creates a pool at the beginning of the event loop and releases it at the end, thereby periodically releasing any autoreleased objects generated while processing events. Preferably I would be able to write these bindings so that the developer who would be using them could essentially ignore the presence of the pools completely as it is in Apple's implentation. Just to be sure of what you are suggesting; function () { [create pool]; // Do work. [destroy pool]; } Due to the stackable nature of autorelease pools this is completely possible should the developer need it (and I have used it the past when I had a function that created and discarded lots of small objects quickly). However the event loop based pool would catch anything that was missed so as to avoid possible memory leaks. My interpretation may be completely wrong, feel completely free to correct me. -- Dan Saul ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list