[Implemented] Advanced InputRequester()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

[Implemented] Advanced InputRequester()

Post by va!n »

The InputRequester is nice to let the user enter any text and press on OK! But what, if the user dont want enter enythink and want cancel? (as i have read in a turotial "how to create a good GUI", every action should have a cancel option too!

So what about having an advanced InputRequester, like:

Code: Select all

Text$ = InputRequester(Title$, Message$, DefaultText$,#Flags)

Possible Flags:
  #PB_InputRequester_OK             : to have the 'ok' only button
  #PB_InputRequester_OKCancel   : to have 'ok' and 'cancel' buttons

Possible return values are following constants: 
  #PB_InputRequester_OK         : the 'OK' button was pressed
  #PB_InputRequester_Cancel    : the 'Cancel' button was pressed
maybe a flag for PASSWORD, also showing only **** when typing anythink would make sence!?
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

I agree va!n, those things would be nice but it sounds like someone should develop an "Advanced InputRequester" library.

At a minimum the InputRequester and MessageRequester should be enhanced to allow the specification of which Icon to display. Windows, Mac and Linux have some of the same types of icons (question, warning, exclamation) I believe, so it could be cross-platform.

In the meantime, you can create your own simple modal dialog using the new StickyWindow and DisableWindow commands with a StringGadget. The StringGadget #PB_String_Password option would give you the password effect you're looking for.
Last edited by USCode on Wed Mar 01, 2006 8:19 pm, edited 2 times in total.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Advanced InputRequester()

Post by PB »

Been there, asked that:
viewtopic.php?t=16666
:)

Also, see my tip here, which may suffice until Fred can do this natively:
viewtopic.php?p=129817
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Yeah, we need the cancel option!

I made a very simple one:

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$)
  Protected Result$, Window, String, OK, Cancel
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered) 
  If Window And CreateGadgetList(WindowID(Window))
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    Repeat
      If WaitWindowEvent() = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If GetKeyState_(#VK_RETURN) > 1
        Result$ = GetGadgetText(String)
        Break
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure

Input$ = InputRequesterOkCancel("Hello","Enter a string:","")
If Input$
  Debug Input$
EndIf
I like logic, hence I dislike humans but love computers.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Another thing regarding PB's InputRequester:

Please, write "OK", not "Ok". OK? :wink:
(To make the OK-Button matching the Windows-Requester-OK-Buttons)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Advanced InputRequester()

Post by djes »

Thank you! Added close button to your "InputRequesterEx()" (psychological effect)

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$)
  Protected Result$, Window, String, OK, Cancel, Event
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered| #PB_Window_SystemMenu ) 
  If Window
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    Repeat
      Event = WaitWindowEvent() 
      If Event = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If Event = #PB_Event_CloseWindow
        Break
      EndIf
      If GetKeyState_(#VK_RETURN) > 1
        Result$ = GetGadgetText(String)
        Break
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Advanced InputRequester()

Post by djes »

Multiplatform

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$="")
  Protected Result$, Window, String, OK, Cancel, Event
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered| #PB_Window_SystemMenu ) 
  If Window
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    AddKeyboardShortcut(Window, #PB_Shortcut_Return, 1000)
    Repeat
      Event = WaitWindowEvent() 
      If Event = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If Event = #PB_Event_CloseWindow
        Break
      EndIf
      If Event = #PB_Event_Menu
        If EventMenu() = 1000
          Result$ = GetGadgetText(String)
          Break
        EndIf  
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Advanced InputRequester()

Post by c4s »

+1 for the original request!

Especially window width fitting the text width (as MessageRequester()), multiple text lines (as MessageRequester()) and a simple cancel button (as MessageRequester()): http://www.purebasic.fr/english/viewtop ... =3&t=42058
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply