[Fxruby-users] DataTargets, and more about messaging.
Status: Inactive
Brought to you by:
lyle
From: Hugh S. S. E. E. <hg...@dm...> - 2003-06-13 17:12:48
|
Maybe this will help deepen my understanding. I'm building a front end to some "database", which is probably too grand a name for it. So I have a login window. I want to have a button to clear the text fields. I don't see a clear method for FXTextField, but then, I'm using a DataTarget, so that doesn't matter; the two are intimately connected, right? :-) The code below is where I am now. Before adding the @username.handle() commands, the fields cleared on button realease, only to get immediately reset to the non-clear values they just had. Now I get a problem with FXRuby.cpp:781: FXASSERT(type!=SEL_NONE) failed. FXRuby.cpp:781: FXASSERT(type!=SEL_NONE) failed. so this suggests I have really munged the messages. class LoginWindow < FXMatrix def initialize(parent) super(parent, 2, MATRIX_BY_COLUMNS) entry_width = 15 @user = FXDataTarget.new("") # for a string @pass = FXDataTarget.new("") # for a string @userlabel = FXLabel.new(self, "Username:") @username = FXTextField.new(self, entry_width, @user, FXDataTarget::ID_VALUE) @passlabel = FXLabel.new(self, "Passphrase:") @passphrase = FXTextField.new(self, entry_width, @pass, FXDataTarget::ID_VALUE, TEXTFIELD_NORMAL|TEXTFIELD_PASSWD) @login_button = FXButton.new(self, "login") @login_button.connect(SEL_COMMAND) { do_login } @clear_button = FXButton.new(self, "clear") @clear_button.connect(SEL_COMMAND) { |sender, selector, data| @user="" # Blast. That didn't work on it's own. Try this as well: @username.text ="" # No, not good enough. Prod it with a message? @username.handle(@clear_button, SEL_CHANGED, "") # And similarly.... @pass="" @passphrase.text ="" @passphrase.handle(@clear_button, SEL_CHANGED, "") } end def create super @userlabel.create() @username.create() @passlabel.create() @passphrase.create() @login_button.create() @clear_button.create() end def do_login # Convert password to MD5 string. require "md5" key = MD5.new(@pass).hexdigest @pass ="" # Clear this ASAP. # Now look this up. success = false open("passwords", "r") { |pwf| # ... Check the password... # This "state" thing is the current position in a state # machine. loans_tool.state.loginsuccess if success } unless success # set state appropriately loans_tool.state.loginfailure end end end The construction of the GUI itself has been very pleasant. The layouts are working nicely and the diags are helpful. I think when I finally grok this messaging stuff I will really enjoy FXRuby. Hugh |