I couldn''t figure out why my message-handler does not work. My test
code is at the end of this email.
Case 1:
The ''data'' argument to the message handler comes out as an
integer instead of my ruby string "joke". Can''t I pass any
ruby object? I''ve seen fxruby doc appendix C, where it is recommended
to query the sender instead of interpreting the data. Is this the answer,
don''t pass data when sending message?
Case 2:
This connect target is never executed. What did I do wrong?
I''m certain I must have misunderstood something here. I''d be
happy if you can explain or point me to a doc or faq.
Many thanks in advance
-andre
(fxruby 1.6.18, fox 1.6, ruby 1.8.7)
class Label < FXLabel
include Responder2
include Responder
attr_accessor :target
def initialize *args
super
identifier :ID_FUNNY
# Enable either case 1 or 2
# Case 1:
FXMAPFUNC SEL_COMMAND, ID_FUNNY, ''funny''
# End of case 1
# Case 2:
connect SEL_COMMAND do
puts "In Connect"
end
# End of case 2
end
def funny sender, selector, data
puts "Data is #{data}"
end
end
app = FXApp.new "a", "b"
win = FXMainWindow.new app, "c", :width => 40, :height => 300
frame = FXVerticalFrame.new win
label = Label.new frame, "Label"
button = FXButton.new frame, "Button"
button.connect SEL_COMMAND do
label.handle b1, FXSEL(SEL_COMMAND, Label::ID_FUNNY, "joke")
app.create
app.run
_________________________________________________________________
See how Windows Mobile brings your life together?at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/fxruby-users/attachments/20090217/66f93a56/attachment-0001.html>
On Mon, Feb 16, 2009 at 7:20 PM, Andreas S <andreas_s at hotmail.com> wrote:> I couldn''t figure out why my message-handler does not work. My test code is > at the end of this email. > > Case 1: > The ''data'' argument to the message handler comes out as an integer instead > of my ruby string "joke". Can''t I pass any ruby object?No, you can''t pass any Ruby object; it needs to be the kind of data that the target object is expecting for the message type and selector. It appears that you''re wanting to change the label''s text whenever the button is pressed, right? In that case, you''d want to do something like: button.connect(SEL_COMMAND) do label.text = "joke" end> I''ve seen fxruby doc appendix C, where it is recommended to query the sender instead of > interpreting the data. Is this the answer, don''t pass data when sending > message?Yes, that''s probably the best way for most cases.> Case 2: > This connect target is never executed. What did I do wrong?You''re calling connect(SEL_COMMAND) in the Label''s initialize() method, which means you''re calling connect(SEL_COMMAND) on the label itself. If the label widget actually sent a SEL_COMMAND to its target, the code in this block would get executed, but because the label doesn''t send out any messages, this is basically inoperative code.> I''m certain I must have misunderstood something here. I''d be happy if you > can explain or point me to a doc or faq.If you check the FOX web site: http://www.fox-toolkit.org/ you''ll find some documentation on how targets and messages work. (The FOX web site seems to be down at the moment, but perhaps it will be back online by the time you read this.) There is also a good discussion of these topics in the FXRuby book from the Pragmatic Programmers: http://www.pragprog.com/titles/fxruby/fxruby Hope this helps, Lyle
> Date: Tue, 17 Feb 2009 09:19:41 -0600 > From: lyle at lylejohnson.name > > > Case 2: > > This connect target is never executed. What did I do wrong? > > You''re calling connect(SEL_COMMAND) in the Label''s initialize() > method, which means you''re calling connect(SEL_COMMAND) on the label > itself. If the label widget actually sent a SEL_COMMAND to its target, > the code in this block would get executed, but because the label > doesn''t send out any messages, this is basically inoperative code. >I have a line in my test where I call my label''s handle method: label = Label.new frame, "Label" button = FXButton.new frame, "Button" button.connect SEL_COMMAND do label.handle button, FXSEL(SEL_COMMAND, Label::ID_FUNNY, "joke") end Shouldn''t this do the trick? I''ve used this approach in my code before. For example, in my table, I made Ctrl-A to select all cells and I did it by sending message to table''s corner button, simulating a click (the snippet is at the end of this email, in case you''d like to know). I believe this is the answer you gave in an old thread I found when googling about simulating button click. I tried to replace that Label with FXButton which will print something when it is clicked. It does print it when I click it, but simulating a click still doesn''t do it. Thanks, Lyle. I appreciate you help. -andre class MyTable < FXTable def initialize *args super connect SEL_KEYPRESS do |sender, selector, event| if event.state & CONTROLMASK != 0 case event.code when KEY_a cornerButton.handle self, FXSEL(SEL_LEFTBUTTONPRESS, 0), event cornerButton.handle self, FXSEL(SEL_LEFTBUTTONRELEASE, 0), event end end end end ... end _________________________________________________________________ Get more out of the Web. Learn 10 hidden secrets of Windows Live. http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20090217/9f6cf5be/attachment.html>
On Tue, Feb 17, 2009 at 1:15 PM, Andreas S <andreas_s at hotmail.com> wrote:> I have a line in my test where I call my label''s handle method: > > label = Label.new frame, "Label" > button = FXButton.new frame, "Button" > button.connect SEL_COMMAND do > label.handle button, FXSEL(SEL_COMMAND, Label::ID_FUNNY, "joke") > end > > Shouldn''t this do the trick?No. Generally speaking, the FXLabel widget doesn''t respond to SEL_COMMAND.> I''ve used this approach in my code before. For example, > in my table, I made Ctrl-A to select all cells and I did it by sending > message to table''s corner button, simulating a click (the snippet is at the end of this email, > in case you''d like to know). I believe this is the answer you gave in an old thread I > found when googling about simulating button click.Right. The FXButton widget *does* respond to SEL_LEFTBUTTONPRESS and SEL_LEFTBUTTONRELEASE messages. But it''s a different widget than the FXLabel widget. Different behavior.> I tried to replace that Label with FXButton which will print something when > it is clicked. It does print it when I click it, but simulating a click still doesn''t do > it.Could we back up a step or two? What is it that you''re actually trying to accomplish? Are you trying to change the label''s text whenever a button is pressed, or what?
Hi Lyle, I''m grateful for your patience.> Date: Tue, 17 Feb 2009 14:04:56 -0600 > From: lyle at lylejohnson.name > > No. Generally speaking, the FXLabel widget doesn''t respond to SEL_COMMAND. > > > I''ve used this approach in my code before... > > Right. The FXButton widget *does* respond to SEL_LEFTBUTTONPRESS and > SEL_LEFTBUTTONRELEASE messages. But it''s a different widget than the > FXLabel widget. Different behavior. >Oh, I overlooked the selector TYPE. I was looking for how to add selector ID and I found it, but I''ve forgotten about selector TYPE. Please forgive my stupidity.> > I tried to replace that Label with FXButton which will print something when > > it is clicked. It does print it when I click it, but simulating a click still doesn''t do > > it. >After some tinkering, I found how to simulate that b1 click to trigger that ''puts "button1"'' b1 = FXButton.new(self, "Button1") b1.connect(SEL_COMMAND) { puts "button1" } # This never triggers b1 SEL_COMMAND FXButton.new(self, "Button2").connect(SEL_COMMAND) { b1.handle self, FXSEL(SEL_COMMAND,0), nil } # This does FXButton.new(self, "Button2").connect(SEL_COMMAND) do b1.handle self, FXSEL(SEL_LEFTBUTTONPRESS,0), nil b1.handle self, FXSEL(SEL_LEFTBUTTONRELEASE,0), nil end> Could we back up a step or two? What is it that you''re actually trying > to accomplish? Are you trying to change the label''s text whenever a > button is pressed, or what?In part, I''m exploring what I can or can''t do. This particular issue caught my interest because it looks like I have incorrect understanding and I wish to be corrected. The other part is my users asked me to improve my tool by allowing them to define bind keys. This got me looking at FXAccel. The following sample is from FXAccel#addAccel rdoc: hotKey = fxparseAccel("Ctrl+S") accelTable.addAccel(hotKey, doc, FXSEL(SEL_COMMAND, MyDocument::ID_SAVE)) Seems like I can only associate a hot key with a message, not a block. That''s why I''m looking into adding message selectors and handlers and my curiosity, for why my message handler doesn''t work, won''t leave my mind at peace. (I haven''t been successful using FXAccelTable, but that''s a different issue) My understanding was, given a list of selector types and ids, supported by a widget, widget#handle for FXSEL(TYPE,ID) will cause the widget to send FXSEL(TYPE,ID) to its target. But from what I gathered, one cannot be certain about that, as my button example shows. I might not be able to rely on FXAccelTable to define bind keys, since #addAccel can only associate one hot key to one message type-id. -andre _________________________________________________________________ Stay up to date on your PC, the Web, and your mobile phone with Windows Live. http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20090218/0c1d816d/attachment.html>
On Feb 17, 2009, at 6:25 PM, Andreas S wrote:> The other part is my users asked me to improve my tool by allowing > them to define bind keys. > This got me looking at FXAccel. The following sample is from > FXAccel#addAccel rdoc: > hotKey = fxparseAccel("Ctrl+S") > accelTable.addAccel(hotKey, doc, FXSEL(SEL_COMMAND, > MyDocument::ID_SAVE)) > Seems like I can only associate a hot key with a message, not a > block. That''s why I''m looking > into adding message selectors and handlers and my curiosity, for why > my message handler doesn''t > work, won''t leave my mind at peace. (I haven''t been successful using > FXAccelTable, but that''s a > different issue) > > My understanding was, given a list of selector types and ids, > supported by a widget, widget#handle > for FXSEL(TYPE,ID) will cause the widget to send FXSEL(TYPE,ID) to > its target. But from what I > gathered, one cannot be certain about that, as my button example > shows.Your understanding is correct; the problem is that the FXButton widget doesn''t respond to FXSEL(SEL_COMMAND, 0). This fact is unfortunately not documented anywhere (other than in the FOX source code itself). FXButton does, in contrast, respond to FXSEL(SEL_LEFTBUTTONPRESS, 0) and FXSEL(SEL_LEFTBUTTONRELEASE, 0).> I might not be able to rely on FXAccelTable to define bind keys, > since #addAccel can only associate > one hot key to one message type-id.I know that I ran into some problem trying to support FXAccel#addAccel with blocks. I think the problem was that FXAccelTable#addAccel expects two arguments at the end (one for the "down" keypress and one for the "up" keypress), but we can only pass one block, and so I wasn''t sure how to handle the association. It occurs to me that I *might* be able to offer a different-looking API, something like: addAccelUp(hotKey, target) do |sender, sel, ptr| ... end addAccelDown(hotKey) do |sender, sel, ptr| ... end or something like that... Hope this helps, Lyle -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20090220/1b976c11/attachment-0001.html>
Melton, Ryan
2009-Mar-25 19:12 UTC
[fxruby-users] Segmentation Fault involving FXMessageBox and sockets
I''ve been experiencing a strange crash that involves using
FXMessageBox, and having another thread that is interacting with a socket.
Attached is the code that very quickly crashes for me after pressing the
"Press Me" button. Note that the program will run forever until the
MessageBox is shown. (I believe the same issue also exists with the File
choosers.)
My system specs:
Windows XP SP2
Ruby 1.8.6 p0
FXRuby 1.6.17
Can anyone else recreate this on your system?
Thanks,
Ryan
require ''rubygems''
require ''fox16''
include Fox
require ''socket''
require ''thread''
class CrashMe < FXMainWindow
def initialize (app, title)
# Call the base class initializer first
super(app, title)
# Create a Vertical Frame for the application''s contents
@frame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN)
button = FXButton.new(@frame, "Press Me").connect(SEL_COMMAND,
method(:handle_button_1))
# Create thread to accept connections
Thread.new do
sockets = []
#Create a socket to accept connections from clients
addr = Socket.pack_sockaddr_in(9999, Socket::INADDR_ANY)
listen_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
listen_socket.bind(addr)
listen_socket.listen(5)
loop do
socket, address = listen_socket.accept()
sockets << socket
end
end
# Create client
Thread.new do
loop do
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
addr = Socket.pack_sockaddr_in(9999, ''127.0.0.1'')
socket.connect(addr)
loop do
begin
socket.recvfrom_nonblock(65542)
rescue => error
end
sleep(0.01)
end
end
end
end
def handle_button_1 (sender, sel, data)
FXMessageBox.warning(self, MBOX_OK, ''Warning!'',
''Are you sure?'')
end
def self.run
# Make application
application = FXApp.new("NA", "NA")
# Make window
window = self.new(application, "Title")
window.show
# Create the application windows
application.create
# Run the application
application.run
end # def self.run
end # class CrashMe
CrashMe.run
This message and any enclosures are intended only for the addressee. Please
notify the sender by email if you are not the intended recipient. If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful. Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/fxruby-users/attachments/20090325/51372e06/attachment-0001.html>
Lyle Johnson
2009-Mar-26 02:28 UTC
[fxruby-users] Segmentation Fault involving FXMessageBox and sockets
On Mar 25, 2009, at 2:12 PM, Melton, Ryan wrote:> I?ve been experiencing a strange crash that involves using > FXMessageBox, and having another thread that is interacting with a > socket. > Attached is the code that very quickly crashes for me after pressing > the ?Press Me? button. Note that the program will run forever until > the > MessageBox is shown. (I believe the same issue also exists with the > File choosers.) > > My system specs: > Windows XP SP2 > Ruby 1.8.6 p0 > FXRuby 1.6.17 > > Can anyone else recreate this on your system?Yes, I can reproduce it on OS X, using Ruby 1.8.6p237 and FXRuby 1.6.19. I''ve just filed a bug report and will look into it as soon as I can (though patches are welcome, as always!) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20090325/36ce123b/attachment.html>