[Module] StringEx (all OS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] StringEx (all OS)

Post by Thorsten1867 »

StringEx - Module (all OS / 64Bit / DPI)
  • AutoComplete function (Return key)
  • Password input with "Show-Button" (shows password only as long as button is pressed)
  • optional button for triggering an event (e.g. delete text)
Image

Download: StringExModule.pbi
Last edited by Thorsten1867 on Fri Dec 20, 2019 3:31 pm, edited 2 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
Cyllceaux
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: [Module] StringEx (all OS)

Post by Cyllceaux »

First try… and workes great :-)
ozzie
Enthusiast
Enthusiast
Posts: 395
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: [Module] StringEx (all OS)

Post by ozzie »

Looks good, but the first click on one of the buttons (show password or delete) is ignored. Need to click a second time for the action to occur.
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Bugfixes
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
Lord
Enthusiast
Enthusiast
Posts: 745
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] StringEx (all OS)

Post by Lord »

Hi!

I got some trouble starting your StringEx-Modul example.

In debug mode there is only an empty window showing up.
Without debug all seems to be allright, all gadgets are there.

I inserted then some debug lines to find out, that the modul
hangs in this line:

Code: Select all

    String::Gadget(#StringPW, 225, 19, 100, 20, "Password", String::#Password|String::#ShowButton)
Here the modul example with debug:

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  
  UsePNGImageDecoder()
  
  #Window  = 0
  
  Enumeration 1
    #String
    #StringEx
    #StringPW
    #StringDel
    #Font
    #Popup
    #Image
    #Menu_Item1
    #Menu_Item2
    #Menu_Item3
    #Menu_Item4
    #Menu_Item5
  EndEnumeration
  
  LoadImage(#Image, "Delete.png")
  
  If OpenWindow(#Window, 0, 0, 460, 60, "Window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    
    If CreatePopupMenu(#Popup)
      MenuItem(#Menu_Item1, "Undo")
      MenuBar()
      MenuItem(#Menu_Item2, "Copy")
      MenuItem(#Menu_Item3, "Cut")
      MenuItem(#Menu_Item4, "Paste")
      MenuBar()
      MenuItem(#Menu_Item5, "Delete")
    EndIf
    
    StringGadget(#String, 15, 19, 90, 20, "")
    ;SetGadgetAttribute(#String, #PB_String_MaximumLength, 5)
   Debug "StringGadget" 
    String::Gadget(#StringEx, 120, 19, 90, 20, "AutoComplete", String::#AutoComplete) ; String::#ShowButton / String::#Numeric / String::#LowerCase / String::#UpperCase / String::#NotEditable / String::#BorderLess
    Debug "String::Gadget(#StringEx)"
    String::AttachPopupMenu(#StringEx, #Popup)
    Debug "PopUp attached"
    ;String::SetAttribute(#StringEx, String::#MaximumLength, 5)
    String::AddWords(#StringEx, "Default Define Declare Degree Debug AutoComplete")
    Debug "AddWords"
    String::Gadget(#StringPW, 225, 19, 100, 20, "Password", String::#Password|String::#ShowButton)
    Debug "String::Gadget(#StringPW)"
    String::Gadget(#StringDel, 340, 19, 100, 20, "Delete this")
    Debug "String::Gadget(#StringDel)"
    String::AddButton(#StringDel, #Image)
    Debug "AddButton(#StringDel)"
    
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #StringDel
              If EventType() = String::#EventType_Button
                String::Clear(#StringDel)
              EndIf
          EndSelect
        Case #PB_Event_Menu
          Select EventMenu()
            Case #Menu_Item1
              String::Undo(#StringEx)
            Case #Menu_Item2
              String::Copy(#StringEx)
            Case #Menu_Item3
              String::Cut(#StringEx)
            Case #Menu_Item4
              String::Paste(#StringEx)
            Case #Menu_Item5
              String::Delete(#StringEx)
          EndSelect
      EndSelect        
    Until Event = #PB_Event_CloseWindow
    
    String::Free(#StringEx)
    
    CloseWindow(#Window)
  EndIf
  
CompilerEndIf
After adding some debug statements in your modul, the last
successful line was:

Code: Select all

  Procedure Gadget(GNum.i, X.i, Y.i, Width.i, Height.i, Content.s="", Flags.i=#False, WindowNum.i=#PB_Default)
    Define Result.i, txtNum
    
    Result = CanvasGadget(GNum, X, Y, Width, Height, #PB_Canvas_Keyboard)
    If Result:Debug "Result= "+result
      
      If GNum = #PB_Any : GNum = Result : EndIf: Debug "GNum="+gnum; <------------here--------------
      
      If AddMapElement(StrgEx(), Str(GNum)):Debug "AddMapElement"
...
...
      EndIf
      Debug "After AddElement()"
    EndIf
    
  EndProcedure


The debug output shows:
StringGadget
Result= 32573484
GNum=2
AddMapElement
ShowPWButton enabled
Windows: GetGadgetFont()
Windows: Color
Before BindGadgetEvent()
finished burron creation
After AddElement()
String::Gadget(#StringEx)
PopUp attached
AddWords
Result= 22744230
GNum=3
Then it hangs. Any ideas?
Tested on Win7x65UltimateSP1, PB5.70LTSx64
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

  • Bugfixes
  • Added: Ctrl-Cursor/ Tabulator (AutoComplete)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
Lord
Enthusiast
Enthusiast
Posts: 745
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] StringEx (all OS)

Post by Lord »

Hi!
Thorsten1867 wrote:
  • Bugfixes
  • Added: Ctrl-Cursor/ Tabulator (AutoComplete)
No Change to above.
Still blank window in debug mode.
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Lord wrote:No Change to above.
Still blank window in debug mode.
I can't understand the mistake because it doesn't occur to me.
Does this happen with my test code or in your own program?
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
User avatar
StarBootics
Enthusiast
Enthusiast
Posts: 695
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: [Module] StringEx (all OS)

Post by StarBootics »

Hello,

When I run the example I get this message : The Debugger executable quit unexpectedly.
Nothing happen without the debugger, I'm under Ubuntu 18.10 x64 and I'm using PureBasic 5.70 LTS

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Lord
Enthusiast
Enthusiast
Posts: 745
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] StringEx (all OS)

Post by Lord »

Thorsten1867 wrote:
Lord wrote:No Change to above.
Still blank window in debug mode.
I can't understand the mistake because it doesn't occur to me.
Does this happen with my test code or in your own program?
See 5 postings above. It's your code included in your module.
It only happens with debugger off, but I didn't try any other code.
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1265
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by Thorsten1867 »

Maybe it's a problem with GetActiveWindow().
I have now added the window number in the example.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]
Lord
Enthusiast
Enthusiast
Posts: 745
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] StringEx (all OS)

Post by Lord »

Hi!
Thorsten1867 wrote:Maybe it's a problem with GetActiveWindow().
I have now added the window number in the example.
No change. Tested the latest version.
See for yourself what it looks like.:
https://bayfiles.com/Y1i9Y9U2m4/2019-03-28-19-51-46_mp4
Image
Lord
Enthusiast
Enthusiast
Posts: 745
Joined: Tue May 26, 2009 2:11 pm

Re: [Module] StringEx (all OS)

Post by Lord »

I did some testing.

I found out, that
1. GetActiveWindow is here never executed, IsWindow(WindowNum) is always #True
2. After inserting a Delay(20) most of the time the Gadgets are created.
A Delay(2) gives a 50:50 chance, that the Gadgeds are showing up und the program
doesn't hang.
Increasing delay time doesn't inrease stability, still sometimes the program hangs.
Image
ozzie
Enthusiast
Enthusiast
Posts: 395
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: [Module] StringEx (all OS)

Post by ozzie »

ozzie wrote:Looks good, but the first click on one of the buttons (show password or delete) is ignored. Need to click a second time for the action to occur.
Works fine now. Many thanks - the 'show password' feature is what I'm particularly interested in. (Windows only.)
User avatar
mk-soft
Addict
Addict
Posts: 3110
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] StringEx (all OS)

Post by mk-soft »

UseGadgetList(0) gives the actual handle, object of GadgetList

Code: Select all

;-TOP

DeclareModule System
  Declare WindowPB(WindowID)
  Declare GadgetPB(GadgetID)
EndDeclareModule

Module System
  
  ;-- Import internal function
  
  ; Force Import Fonts
  ;Global __Dummy = LoadFont(#PB_Any, "", 9) : FreeFont(__Dummy)
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Import ""
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      PB_Object_GetObject( PB_Object , DynamicOrArrayID)
      PB_Window_Objects.i
      PB_Gadget_Objects.i
      PB_Image_Objects.i
      ;PB_Font_Objects.i
    EndImport
  CompilerElse
    ImportC ""
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      PB_Object_GetObject( PB_Object , DynamicOrArrayID)
      PB_Window_Objects.i
      PB_Gadget_Objects.i
      PB_Image_Objects.i
      ;PB_Font_Objects.i
    EndImport
  CompilerEndIf
  
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    ; PB Interne Struktur Gadget MacOS
    Structure sdkGadget
      *gadget
      *container
      *vt
      UserData.i
      Window.i
      Type.i
      Flags.i
    EndStructure
  CompilerEndIf
  
  ; ---------------------------------------------------------------------------------------
  
  Procedure WindowPB(WindowID) ; Find pb-id over handle
    Protected result, window
    result = -1
    PB_Object_EnumerateStart(PB_Window_Objects)
    While PB_Object_EnumerateNext(PB_Window_Objects, @window)
      If WindowID = WindowID(window)
        result = window
        Break
      EndIf
    Wend
    PB_Object_EnumerateAbort(PB_Window_Objects)
    ProcedureReturn result
  EndProcedure
  
  ; ---------------------------------------------------------------------------------------
  
  Procedure GadgetPB(GadgetID) ; Find pb-id over handle
    Protected result, gadget
    result = -1
    PB_Object_EnumerateStart(PB_Gadget_Objects)
    While PB_Object_EnumerateNext(PB_Gadget_Objects, @gadget)
      If GadgetID = GadgetID(gadget)
        result = gadget
        Break
      EndIf
    Wend
    PB_Object_EnumerateAbort(PB_Gadget_Objects)
    ProcedureReturn result
  EndProcedure
  
  ; ---------------------------------------------------------------------------------------
  
EndModule

If OpenWindow(1, 20, 20, 200, 40, "Module System")
  
  Debug "PB-WindowID = " + System::WindowPB(UseGadgetList(0))
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Post Reply