Ensuring Specific Checkbox in a Dialogue is CHECKED

Started by MT_MANC, September 14, 2024, 12:43:32 PM

Previous topic - Next topic

MT_MANC

Trying to create .WBT script to ensure "Match case" and "Regular expression" checkboxes are CHECKED in the attached F8 dialogue in TextPad v9. My scriptcode lines below are not working as I suspect the x y, width co-ords are not correct (?) The Checkbox Control Ref guide suggests (I think) that these co-ords can these be ignored/overridden by specifying the number of Tab presses required to focus on each checkbox ? (5 Tabs and 6 Tabs respectively) ?

Rep002=`004,004,046,DEFAULT,CHECKBOX,"CheckBox_Case",Match case,"Check 2",1,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Rep003=`004,004,046,DEFAULT,CHECKBOX,"CheckBox_Regex",Regular expression,"Check 3",1,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

Attached: TextPad "Replace" dialogue screenshot:  You cannot view this attachment.


Any pointers on how to correct this code gratefully received

JTaylor

Make sure CheckBox_Case and CheckBox_RegEx variables are set to 1 if you want them set on launch of Dialog.   I would recommend reading through the documentation for DialogControlGEt(), DialogControlSet() and DialogProcOptions().   I think those will do everything you have asked about.  You shouldn't need to deal with TABS or Coordinates, if this is a WinBatch Dialog.

Jim

kdmoyers

The way I read it, that's not what OP is asking.  I think he's trying to manipulate the Search dialog in the Textpad editor program, which sounds like a tricky proposition. I'd try it but I'm a Notepad++ guy.
The mind is everything; What you think, you become.

MT_MANC

Most kind

Hopefully, image of TextPad Dialogue I am trying to manipulate is now visible. From docs, it seems the following should CHECK the Regular expression checkbox but doesnt seem to work ? I have tried various permutations with/without speech marks, space etc to no avail !
DialogControlSet("Replace","Regular expression",@dcCheck,1)
Replace Dialogue in Textpad

Context: I am actually trying to do a Search & Replace in Textpad v9 (Replace "Break" string with Carriage Return Regex \n) but need final two checkboxes to be checked beforehand.
Any further thoughts on required tweaks to Code line above appreciated

JTaylor

Apologies, the dialog code you posted threw me off track.

The Control Manager Extender may do what you need.  Assuming I am not confused, again.

If you run RoboScripter, it will produce the code, if it can do it.

Jim

td

TextPad appears to be regular Win32 applications with common controls so Control Manager should be able to automate the UI.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

MT_MANC

Most kind
Managed to adapt some Example script code to return the State of the "Regular expression" checkbox using cCheckbox (so can replicate for "Match case" checkbox too) but not sure how best to then ensure that both checkboxes are actually left checked ?) Presumably will require an "If" statement and maybe some version of the <dlg-variable> command shown in my first post ?

   
; WBT to check Regex checkbox in Textpad Replace Dialogue
    AddExtender("wwctl44i.dll",0,"wwctl64i.dll")
    ;  ---------------------------------------------------- TEXTPAD   
    Run("C:\Program Files\TextPad 9\TEXTPAD.EXE", "")
    SendKey("{F8}")        ; Send F8 to open the "Replace" dialog
    TimeDelay(1)
    title = 'Replace'
    WinWaitExist(title, 5)
    hwnd = DllHwnd(title)
    ControlHandle = cWndbyname(hwnd,`Regular expression`)
    result = cCheckbox(ControlHandle, -1) ; Examines a checkbox
    Switch result
      Case 0
          Pause('Check box is...','Not Checked')
          Break
      Case 1
          Pause('Check box is...','Checked')
          Break
      Case 2
          Pause('Check box is...','Grayed (not disabled)')
          Break
    EndSwitch
    ; INSERT REQUIRED CODE TO ENSURE BOTH "Match case" & "Regular expression" CHECKBOXES ARE CHECKED
    Exit

Any thoughts on required Insert code ?

spl

Just curious? Does the code presume a file has been previously loaded? Would think you could load/parse/save with standard processes and not even need the TextPad GUI.
Stan - formerly stanl [ex-Pundit]

MT_MANC

Hi spl - thanks for reply
No, no file loaded (yet) in the code snippet I showed; this comes after I have set the checkboxes (and then I do various global Search & Replaces using Textpad Replace dialogue). I am upgrading from (previous) manual operations in Textpad so just looking to automate an existing, regular, mundane task in first instance (as I learn more about WB capabilities)
Most kind

td

Quote from: MT_MANC on September 16, 2024, 08:37:31 AMMost kind
Managed to adapt some Example script code to return the State of the "Regular expression" checkbox using cCheckbox (so can replicate for "Match case" checkbox too) but not sure how best to then ensure that both checkboxes are actually left checked ?) Presumably will require an "If" statement and maybe some version of the <dlg-variable> command shown in my first post ?

   
; WBT to check Regex checkbox in Textpad Replace Dialogue
    AddExtender("wwctl44i.dll",0,"wwctl64i.dll")
    ;  ---------------------------------------------------- TEXTPAD   
    Run("C:\Program Files\TextPad 9\TEXTPAD.EXE", "")
    SendKey("{F8}")        ; Send F8 to open the "Replace" dialog
    TimeDelay(1)
    title = 'Replace'
    WinWaitExist(title, 5)
    hwnd = DllHwnd(title)
    ControlHandle = cWndbyname(hwnd,`Regular expression`)
    result = cCheckbox(ControlHandle, -1) ; Examines a checkbox
    Switch result
      Case 0
          Pause('Check box is...','Not Checked')
          Break
      Case 1
          Pause('Check box is...','Checked')
          Break
      Case 2
          Pause('Check box is...','Grayed (not disabled)')
          Break
    EndSwitch
    ; INSERT REQUIRED CODE TO ENSURE BOTH "Match case" & "Regular expression" CHECKBOXES ARE CHECKED
    Exit

Any thoughts on required Insert code ?


What you refer to as "<dlg-variable> command" is valid as a line in a WIL Dialog Template and has nothing to do with manipulating another application's UI.

You can use the cCheckBox button to both set and check the state of a checkbox.

A link to the online version of the functions documentation:
https://docs.winbatch.com/mergedProjects/ControlManager/CTRLMGR/CTRLMGR_C__006.htm
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Quote from: MT_MANC on September 16, 2024, 09:32:18 AMHi spl - thanks for reply
No, no file loaded (yet) in the code snippet I showed; this comes after I have set the checkboxes (and then I do various global Search & Replaces using Textpad Replace dialogue). I am upgrading from (previous) manual operations in Textpad so just looking to automate an existing, regular, mundane task in first instance (as I learn more about WB capabilities)
Most kind

Without shooting myself in the foot, if you want to learn more about WB capabilities, especially with search and replace, you might consider posting a text sample with the search/replace goal. I know I would be more than willing to  make code suggestions, and am sure others would refine any of those efforts.

[EDIT] and to be clear, TextPad only reads text files, but if you are looking for search/replace within a .pdf document that will probably require an addtional itextsharp.dll but still easily coded.
Stan - formerly stanl [ex-Pundit]

kdmoyers

Yes, as others have indicated, if you are controlling textpad because you want to
do some search/replace ops on some text files, wbt can do that handily on it's own.
Your entire program may collapse to a few lines of wbt.  Example:


    ObjectClrOption("useany","System")

    text = fileget("myfile.txt")

    opt = ObjectClrType("System.Text.RegularExpressions.RegexOptions", 1)
    re = "sally" ; our regular expression
    reg = ObjectClrNew("System.Text.RegularExpressions.Regex",re, opt)

    text = reg.Replace(text, "fred") ; change to fred

    fileput("myfile.txt")

    exit
The mind is everything; What you think, you become.

spl

Quote from: kdmoyers on September 17, 2024, 10:50:48 AMYes, as others have indicated, if you are controlling textpad because you want to
do some search/replace ops on some text files, wbt can do that handily on it's own.
Your entire program may collapse to a few lines of wbt.

Nice example Kirby.  You can also use regex patterns to replace text, using either WB's CLR
ObjectClrOption("useany","System")
Pattern = "\d{4}:\d{2}:\d{2}_"
Text="2017:02:05_ trace2017.02-2018.05.log":@TAB:"2/5/2017 to 5/5/2018":@CRLF:"2017:02:05_ trace20170816.log":@TAB:"2/5/2017 to 8/16/2017":@CRLF:"2017:02:05_ trace20180505.log":@TAB:"2/5/2017 to 5/5/2018":@CRLF:"2017:08:16_ trace20171221_001508.log":@TAB:"8/16/2017 to 12/20/2017":@CRLF:"2017:12:21_ trace20180504.log":@TAB:"12/21/2017 to 5/10/2018":@CRLF:"2018:05:05_ trace2018.05-2019.02.log":@TAB:"5/5/2018 to 2/14/2019":@CRLF:"2018:05:05_ trace20180928.log":@TAB:"5/5/2018 to 9/28/2018":@CRLF:"2018:09:29_ trace20190214_001818.log"
oReg = ObjectClrNew('System.Text.RegularExpressions.Regex',Pattern)
oReg.CacheSize = ObjectType("ui2",30) ;2-byte unsigned integer.
newText = oReg.Replace(Text,"")
Message("Return after Replace",newText)
oReg=0

or older COM component VBScript
oRegex = CreateObject("VBScript.RegExp")
oRegex.Global = 1
oRegex.Multiline = 1
oRegex.IgnoreCase = 1
sTxt = "2017:02:05_ trace2017.02-2018.05.log":@TAB:"2/5/2017 to 5/5/2018":@CRLF:"2017:02:05_ trace20170816.log":@TAB:"2/5/2017 to 8/16/2017":@CRLF:"2017:02:05_ trace20180505.log":@TAB:"2/5/2017 to 5/5/2018":@CRLF:"2017:08:16_ trace20171221_001508.log":@TAB:"8/16/2017 to 12/20/2017":@CRLF:"2017:12:21_ trace20180504.log":@TAB:"12/21/2017 to 5/10/2018":@CRLF:"2018:05:05_ trace2018.05-2019.02.log":@TAB:"5/5/2018 to 2/14/2019":@CRLF:"2018:05:05_ trace20180928.log":@TAB:"5/5/2018 to 9/28/2018":@CRLF:"2018:09:29_ trace20190214_001818.log"
oRegex.Pattern = "\d{4}:\d{2}:\d{2}_"
If oRegex.Test(sTxt)
   result = oRegex.Execute(sTxt)
   result = oRegex.Replace(sTxt,"")
EndIf
Message("",result)
oRegex = 0 ;Close object
Exit
Stan - formerly stanl [ex-Pundit]