Gtk::Drag.source_set produces [BUG] Segmentation fault

hi,

i want to have some texts on screen, in a way that user can position
them by dragging them with the mouse.
i decided to use Gtk::Label-s on a Gtk::Layout.
when i try to add drag-and-drop to it, it segfaults.

require ‘gtk2’

Gtk.init

@w = Gtk::Window.new
@w.signal_connect(‘destroy’){Gtk.main_quit}
@w.set_default_size(500, 500)

lay=Gtk::Layout.new()

l1=Gtk::Label.new(“test”)
l1.signal_connect(‘drag-begin’){|me,context|
print “drag-begin: “,context.inspect,”\n”
}

lay.put(l1,10,10)

@w.add(lay)

#Gtk::Drag.dest_set(lay,Gtk::Drag::DEST_DEFAULT_ALL,nil,Gdk::DragContext::ACTION_MOVE)
Gtk::Drag.source_set(l1,Gdk::Window::SHIFT_MASK,nil,Gdk::DragContext::ACTION_MOVE)

#@w.show_all

#Gtk.main

the #d lines probably don’t didn’t play part in the issue.

i tried setting the window parameter of l1, didn’t help.

thanks,

balint

Hi,

In [email protected]
“[ruby-gnome2-devel-en] Gtk::Drag.source_set produces [BUG]
Segmentation fault” on Tue, 23 Jan 2007 15:31:56 +0200,
Dobai-Pataky Bálint [email protected] wrote:

i want to have some texts on screen, in a way that user can position
them by dragging them with the mouse.
i decided to use Gtk::Label-s on a Gtk::Layout.
when i try to add drag-and-drop to it, it segfaults.

#Gtk::Drag.dest_set(lay,Gtk::Drag::DEST_DEFAULT_ALL,nil,Gdk::DragContext::ACTION_MOVE)
Gtk::Drag.source_set(l1,Gdk::window::SHIFT_MASK,nil,Gdk::DragContext::ACTION_MOVE)

You don’t need to use Gtk::Drag for this. See
sample/misc/drag-move.rb in Ruby/GTK2.

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

I suggest you that you show a sample script that describes
what you want if you’ll save our time to understand what you
want.

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk::Drag.source_set produces [BUG]
Segmentation fault” on Thu, 25 Jan 2007 16:36:29 +0200,
Dobai-Pataky_Bálint [email protected] wrote:

You don't need to use Gtk::Drag for this. See
sample/misc/drag-move.rb in Ruby/GTK2.

yeah, after i sent this mail, i have found the examples, and understood them.
but they are not the right solution for me, what i want to do is to have a
fixed or a layout and some labels on it, and allow the user to move the labels
with the mouse.

I think the example shows a hint for what you want to do…
Anyway, what about sample/misc/dnd.rb?

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk::Drag.source_set produces [BUG]
Segmentation fault” on Sat, 27 Jan 2007 11:42:39 +0200,
Dobai-Pataky_Bálint [email protected] wrote:

  Dobai-Pataky_Bálint <[email protected]> wrote:
Anyway, what about sample/misc/dnd.rb?

the current state of my Layout class is:

You should show us the Layout class if you want to get more
help.

white path on the theme’d gray background - i thought i should fill the
Drawable with white, but haven’t found the filling method yet.

  • i’ll have to snap the rectangle in movement to a 10x10 pixel grid, so Labels
    may be easily positioned on a line

if you have any ideas regarding, please don’t hold them back :slight_smile:

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

    the current state of my Layout class is:

You should show us the Layout class if you want to get more
help.

thought so :slight_smile:
attaching

signal_connect(‘event’){|me,event|
case event.event_type

It’s better that you connect each signal
(button-press-event, motion-notify-event and
button-release-event) instead of signal_connect('event") and
case - when style.

when Gdk::Event::BUTTON_PRESS

print “press\tx=#{event.x}\ty=#{event.y}\n”

  @xshift=event.x
  @yshift=event.y
  @dragging=true
  @myobject.hide
  @w,@[email protected]_requisition
  parent.bin_window.draw_rectangle(parent.gc,false,@x-1,@y-1,@w+1,@h+1)
  @lastx=@xshift
  @lasty=@yshift
when Gdk::Event::MOTION_NOTIFY

when Gdk::Event::BUTTON_RELEASE

It’s better that you draw on “expose” signal not on
“button-press-event”, “motion-notify-event” and
“button-release-event” signals. So, you just call
parent.queue_draw_area on those signals and wait “expose”
signal is emitted.

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk::Drag.source_set produces [BUG]
Segmentation fault” on Sat, 27 Jan 2007 17:30:36 +0200,
Dobai-Pataky_Bálint [email protected] wrote:

It's better that you draw on "expose" signal not on
"button-press-event", "motion-notify-event" and
"button-release-event" signals. So, you just call
parent.queue_draw_area on those signals and wait "expose"
signal is emitted.

and why is that?

“expose” signal is for redrawing but other signal is not.

anyways, any ideas on the color issue?

parent.queue_draw_area will solve the issue if you specify
correct area.

Please try!

Thank,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk::Drag.source_set produces [BUG]
Segmentation fault” on Sun, 28 Jan 2007 12:28:22 +0200,
Dobai-Pataky_Bálint [email protected] wrote:

okay, this one works, got another problem, my queue works only in a rectangle,
dunno why.
can you please take a look at it?

You need to move your EventBox to a queued area to receive
an expose event.

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Am Sonntag, den 28.01.2007, 15:55 +0200 schrieb Dobai-Pataky Bálint:

Hi,

cause it seems to be a bigger problem :wink: i changed your code a little
bit.

I don’t want to sound harsh but i think, that you don’t understand the
Gdk concepts very well. I suggest to read the Xlib manuals from
O’Reilly. Gdk is very close to the Xlib and so these are the best docs
you can get.

Cheers
detlef

#!/usr/bin/ruby

require ‘gtk2’

class Lay < Gtk::Layout
class LayLabel < Gtk::EventBox
def initialize(text)
@x=0
@y=0
@text=text
@dragging=false
@myobject=Gtk::Label.new(@text)
super()
add(@myobject)

signal_connect(‘event’){|me,event|
if @xorgc.nil? and self.realized?
@xorgc = Gdk::GC.new parent.bin_window
@xorgc.function = Gdk::GC::INVERT
end

case event.event_type


when Gdk::Event::BUTTON_PRESS
  @xshift=event.x
  @yshift=event.y
  @dragging=true
  @w,@[email protected]_requisition
  parent.bin_window.draw_rectangle(@xorgc,false,@x-1,@y-1,@w+1,@h+1)
  @lastx=@xshift
  @lasty=@yshift

when Gdk::Event::MOTION_NOTIFY
  parent.bin_window.draw_rectangle(@xorgc,false,@x+@lastx-@xshift-1,@y

+@lasty-@yshift-1,@w+1,@h+1)
parent.bin_window.draw_rectangle(@xorgc,false,@x
+event.x-@xshift-1,@y+event.y-@yshift-1,@w+1,@h+1)
@lastx=event.x
@lasty=event.y

when Gdk::Event::BUTTON_RELEASE
  @dragging=false
  parent.bin_window.draw_rectangle(@xorgc,false,@x+@lastx-@xshift-1,@y

+@lasty-@yshift-1,@w+1,@h+1)
@x=event.x+@x-@xshift
@y=event.y+@y-@yshift
parent.move(self)
end
}
end
attr_accessor :x
attr_accessor :y
attr_accessor :text
end

def initialize
super
@mygc=nil
@clearmygc=nil
w,h=size
end

def put(gtk_type,x,y)
case gtk_type
when “text”
l=LayLabel.new(“test text”)
l.x=x
l.y=y
end
super(l,x,y)
end
def move(ch,x=ch.x,y=ch.y)
ch.x=x
ch.y=y
super
end
end

lay=Lay.new
lay.put(“text”,100,100)
lay.put(“text”,200,200)
lay.put(“text”,300,300)

@w = Gtk::Window.new
@w.signal_connect(‘destroy’){Gtk.main_quit}
@w.set_default_size(500, 500)
@w.add(lay)
@w.show_all

Gtk.main


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Detlef R. wrote:

Am Sonntag, den 28.01.2007, 15:55 +0200 schrieb Dobai-Pataky Bálint:

Hi,

cause it seems to be a bigger problem :wink: i changed your code a little
bit.

no problem

I don’t want to sound harsh but i think, that you don’t understand the
Gdk concepts very well. I suggest to read the Xlib manuals from
O’Reilly. Gdk is very close to the Xlib and so these are the best docs
you can get.

that has to be true, all i used was the ruby-gtk2 hiki, and i’m learning
this gtk-gdk stuff.
but please enlighten me, what was your invention besides inverting the
color of the rectangle and not drawing one with a defined color? would
you provide an example where the border is red please?
and please consider my previous script, not the one using the expose
event. i just tried that way, as Kou suggested.

class Lay < Gtk::Layout
signal_connect(‘event’){|me,event|
@yshift=event.y
+event.x-@xshift-1,@y+event.y-@yshift-1,@w+1,@h+1)
end
@clearmygc=nil
end
lay.put(“text”,100,100)
Gtk.main

this one works.
in the mean time i got a version working when Label follows the mouse,
not a rectangle.
thanks
balint

Am Sonntag, den 28.01.2007, 18:12 +0200 schrieb Dobai-Pataky Bálint:

but please enlighten me, what was your invention besides inverting the
color of the rectangle and not drawing one with a defined color? would
you provide an example where the border is red please?

If you want to use a special colour for drawing, you also have to
specify the background colour of your drawable. Else if the user has a
theme in use, where the background is red you wouldn’t see your
rectangle at all.

and please consider my previous script, not the one using the expose
event. i just tried that way, as Kou suggested.

From my point of view using queue_draw_area is unnecessary complicated
for this case. You have to invalidate all the areas where your rectangle
moves over while dragging. If you use a very complex layout with many
widgets on them it may make sense.


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV