PureBasic Forum
http://forums.purebasic.com/english/

[Module] StringEx (all OS)
http://forums.purebasic.com/english/viewtopic.php?f=27&t=72534
Page 1 of 4

Author:  Thorsten1867 [ Wed Mar 27, 2019 4:55 pm ]
Post subject:  [Module] StringEx (all OS)

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

Author:  Cyllceaux [ Wed Mar 27, 2019 6:47 pm ]
Post subject:  Re: [Module] StringEx (all OS)

First try… and workes great :-)

Author:  ozzie [ Thu Mar 28, 2019 3:09 am ]
Post subject:  Re: [Module] StringEx (all OS)

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.

Author:  Thorsten1867 [ Thu Mar 28, 2019 7:56 am ]
Post subject:  Re: [Module] StringEx (all OS)

Bugfixes

Author:  Lord [ Thu Mar 28, 2019 9:34 am ]
Post subject:  Re: [Module] StringEx (all OS)

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:
    String::Gadget(#StringPW, 225, 19, 100, 20, "Password", String::#Password|String::#ShowButton)

Here the modul example with debug:
Code:
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:
  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:
Quote:
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

Author:  Thorsten1867 [ Thu Mar 28, 2019 11:03 am ]
Post subject:  Re: [Module] StringEx (all OS)

  • Bugfixes
  • Added: Ctrl-Cursor/ Tabulator (AutoComplete)

Author:  Lord [ Thu Mar 28, 2019 2:00 pm ]
Post subject:  Re: [Module] StringEx (all OS)

Hi!
Thorsten1867 wrote:
  • Bugfixes
  • Added: Ctrl-Cursor/ Tabulator (AutoComplete)
No Change to above.
Still blank window in debug mode.

Author:  Thorsten1867 [ Thu Mar 28, 2019 2:18 pm ]
Post subject:  Re: [Module] StringEx (all OS)

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?

Author:  StarBootics [ Thu Mar 28, 2019 4:29 pm ]
Post subject:  Re: [Module] StringEx (all OS)

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

Author:  Lord [ Thu Mar 28, 2019 5:34 pm ]
Post subject:  Re: [Module] StringEx (all OS)

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.

Author:  Thorsten1867 [ Thu Mar 28, 2019 5:40 pm ]
Post subject:  Re: [Module] StringEx (all OS)

Maybe it's a problem with GetActiveWindow().
I have now added the window number in the example.

Author:  Lord [ Thu Mar 28, 2019 7:59 pm ]
Post subject:  Re: [Module] StringEx (all OS)

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

Author:  Lord [ Thu Mar 28, 2019 8:19 pm ]
Post subject:  Re: [Module] StringEx (all OS)

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.

Author:  ozzie [ Fri Mar 29, 2019 4:01 am ]
Post subject:  Re: [Module] StringEx (all OS)

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.)

Author:  mk-soft [ Fri Mar 29, 2019 8:22 am ]
Post subject:  Re: [Module] StringEx (all OS)

UseGadgetList(0) gives the actual handle, object of GadgetList
Code:
;-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

Page 1 of 4 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/