Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: WxPerl Login Dialog

by PodMaster (Abbot)
on Sep 10, 2003 at 21:32 UTC ( #290538=note: print w/ replies, xml ) Need Help??


in reply to WxPerl Login Dialog

Since you're using a wxFrame, and subsequently on Show(1)ing, simply SetFocus after you show (if you're concerned, but I wouldn't worry about it).

On the other hand, it seems to me like you should be subclassing wxDialog, and you using ->ShowModal(). Also, you may wish to pass style along the lines of wxCAPTION|wxSYSTEM_MENU and maybe add a cancel button (goes along with the whole dialog idea).

Also, a good name for this baby would be Wx::Perl::LoginWindow (in the tradition of Wx::Perl::Carp,Wx::Perl::TreeChecker ... it's Mattia approved ;D)

And on a final note, instead of those comments at the bottom, I think code might be better (:

package main; unless( caller ){ if( @ARGV ) { LoginDialog->get_login(\my ($user, $passwd)); die "USER $user\n\nPASS $passwd\n\n"; } else { # Use defaults if available: my ($user, $passwd); # Default either one if desired $user = 'username'; unless ($user and $passwd) { # require LoginDialog LoginDialog->get_login(\($user, $passwd)); } } }

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.


Comment on Re: WxPerl Login Dialog
Download Code
Re: Re: WxPerl Login Dialog
by runrig (Abbot) on Sep 10, 2003 at 23:02 UTC
    Thanks for your comments. As you may guess, I've barely started with Wx, so I didn't even notice Wx::Dialog yet :-) Now that I've tried it, there seems to be a problem with not creating any top level window within Wx::App::OnInit. I have this:
    sub OnInit { my $self = shift; $$cancel = LoginWindow->new( $user, $passwd, undef, # Parent window -1, # Window id 'Login', # Title [200,200], # position X, Y [200,150], # size X, Y wxCAPTION | wxSYSTEM_MENU )->ShowModal; }
    If ShowModal returns true, the app hangs, if it returns false, then I get this error from this code within Wx::App:
    my $ret = Wx::_App::Start($this,$this->can('OnInit')); Wx::_croak( 'OnInit must return a true return value' ) unless $ret || Wx::wxMAC(); # why does OnInit always return 0 on M +ac?
    In the WxWindows documentation, it says to return a false value from OnInit to exit the application. I don't know why WxPerl would require a true value; it seems like a bug to me. I think I would like to just set $$cancel and then return false from OnInit unconditionally.

    Update: Ahh, if I wrap the call to the App constructor in an eval, I don't get the error message, and I can filter for that particular message in $@, but I still think returning false from OnInit should be perfectly valid.

      If ShowModal returns true, the app hangs...
      That's because you've turned control over to wxWindows, but there is nothing telling the app to die (basically, you need to $app->SetTopWindow($dialog) if you want the application to exit when the window is destroyed).

      but I still think returning false from OnInit should be perfectly valid.
      I'd say I agree with you (even though I've never had the need/urge to do that), but I suspect there might be a real good reason for this (a carp would be fine with me -- you should definetly inquire on the list).

      update: I almost forgot, it's called wxPerl, not WxPerl ;)

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        There is a perfectly good situation when you want OnInit to return false imho. I use it myself in pVoice, where I use the SingleInstanceChecker. If there is already another copy of pVoice running, I let OnInit return false, so the application dies.

        Jouke Visser, Perl 'Adept'
        Using Perl to help the disabled: pVoice and pStory

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://290538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-12-27 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls