On Mon, 2004-01-05 at 11:07, Robert Parlett wrote:
> On Monday 05 January 2004 2:44 pm, Steve Wampler wrote:
> > I'm sure someone has a better one (Robert?) but I needed a
> > GUI widget for programs that require username/password
> > access.  I've attached my solution in case anyone is
> > also interested.  Improvements are welcome!
...
> I don't know if this would simplify the password field, but the TextField 
> class has a flag, displaychar, which when non-null will cause asterixes to be 
> displayed in the textfield, as per a typical password field.

A cleaner version taking advantage of Robert's suggestion is
attached.
 
-- 
Steve Wampler -- [EMAIL PROTECTED]
The gods that smiled on your birth are now laughing out loud.
#<p>
#  LoginDialog.icn  -- Provide a simple dialog box for username/password
#    entry.  Masks the password display.
#</p>
#<p>
# <b>Author:</b> Steve Wampler (<i>[EMAIL PROTECTED]</i>)
#</p>
#<p>
#  This file is in the <i>public domain</i>.
#</p>

#<p>
#  Package of simple GUI widgets.
#</p>
package GuiWidgets

#<p>
#  The LoginDialog class provides a simple dialog for entering a username
#  and password.  The display of the password is masked.
#  Once the user clicks the <b>Ok</b> button, the dialog goes away.
#  The methods <b>getUser()</b> and <b>getPW()</b> are then available
#  to obtain the entered username and password, respectively.  Both
#  fail if the user has not clicked the <b>Ok</b> button.
#</p>
class LoginDialog : _Dialog(userField, passwordField,
                     okButton, userLabel, passwordLabel,
                     g_user, g_pw, realPW, validFlag)

   #<p>
   #   <i>Intended for <b>internal use only</b></i>.  Handles the
   #   response to the user pressing the Ok button.
   #</p>
   method handle_okButton(ev)
       if ev.event = &lrelease then {
           g_user := userField.get_contents()
           g_pw   := passwordField.get_contents()
           validFlag := "yes"
           dispose()
           }
   end

   method dialog_event(ev)
       case ev.get_component() of {
           okButton : handle_okButton(ev)
           }
   end

   #<p>
   #   <i>Internal use only.</i>
   #</p>
   method init_dialog()
   end

   #<p>
   #   <i>Internal use only.</i>
   #</p>
   method end_dialog()
   end

   #<p>
   #   <i>Internal use only.</i>
   #</p>
   method setup()
      self.set_attribs("size=190,105", "bg=pale gray")
      userLabel := Label()
      userLabel$set_pos(18, 11)
      userLabel$set_internal_alignment("l")
      userLabel$set_label("User:")
      self$add(userLabel)
      userField := TextField()
      userField$set_pos(75, 8)
      userField$set_size("104", "20")
      userField$set_draw_border()
      userField$set_contents("")
      self$add(userField)
      passwordLabel := Label()
      passwordLabel$set_pos("14", "38")
      passwordLabel$set_internal_alignment("l")
      passwordLabel$set_label("Password:")
      self$add(passwordLabel)
      passwordField := TextField()
      passwordField$set_pos("75", "35")
      passwordField$set_size("104", "20")
      passwordField$set_draw_border()
      passwordField$set_contents("")
      passwordField.displaychar := "yes"
      self$add(passwordField)
      okButton := TextButton()
      okButton$set_pos("81", "72")
      okButton$set_label("Ok")
      okButton$set_internal_alignment("c")
      self$add(okButton)
   end

   #<p>
   #   <i>Internal use only.</i>
   #</p>
   method component_setup()
      self.setup()
   end

   #<p>
   #  If the OK button has been pressed, allow the retrieval of
   #  the username.
   #</p>
   method getUser()
       if \validFlag then
           return g_user
   end

   #<p>
   #  If the OK button has been pressed, allow the retrieval of
   #  the password.
   #</p>
   method getPW()
       if \validFlag then
           return g_pw
   end

   #<p>
   #  Create the login dialog.  Once created, use the <b>show_modal()</b>
   #  method to display.
   #</p>
   initially ()
       self$_Dialog.initially()
       realPW := ""
end

Reply via email to