Jump to content

@compacting pattern Expr


Deye
 Share

Recommended Posts

Hi,

Had to many trial tries in the process of Getting:
lines beginnings :
^local
^Global
^\$
conditional to a "=" coming next (not lines with other statements "if" or "then" .etc)
All lines with "GUICtrl"

in compacting merge, include:
 '(?:GUICtrl).*'  with  '(?:^local|Global|\$).*[=].*' and  Stop collecting when "GUISetState" line has been reached

since my progress with this wasn't significant, I'm placing it here for now,  Maybe someone already got a good pattern for this and can share ..

Until then will try again tomorrow ..

Thanks

Deye

 

Link to comment
Share on other sites

Sorry folks, didn't find a spare moment up till now to even give some reply

@FrancescoDiMuro,

It needs Just line capturing maybe only to skip all (if begins with) "local ", "Global " and get everything starting from ^\$

Not sure what I was trying where It looked as I was getting close to something that works, but then upon testing with different GUI scripts it would give out: or unwanted entries or wouldn't produce an array at all ..

So this definitely needs to be a good stable pattern that will work on with every GUI script Or I will have to make it through more tries and see what eats the bait, Right now I'm a bit distracted to try anything ,  We'll see ..

Still, if anyone wants to add some examples of what they have tried that seems to work\look right, Then feel free to paste it here,  I will be happy to test ..

Thanks 

Deye

Link to comment
Share on other sites

Need to get my head aired  anyways .. try this 

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>

Global $data = FileRead(@ScriptFullPath)

$a = StringRegExp($data, '(?:^local|Global|\$).*[=].*', 3) ;merge this one
_ArrayDisplay($a)

$a = StringRegExp($data, '(?:GUICtrl).*', 3) ;with this one
_ArrayDisplay($a)

Exit

; GUI
$hGUI = GUICreate("Sample GUI", 400, 400)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; MENU
Local $sMenu1 = "Menu&One"
Local $sMenu2 = "Menu&Two"
GUICtrlCreateMenu($sMenu1)
GUICtrlCreateMenu($sMenu2)
GUICtrlCreateMenu("MenuTh&ree")
GUICtrlCreateMenu("Menu&Four")

; CONTEXT MENU
Local $iContextMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuItem("Context Menu", $iContextMenu)
GUICtrlCreateMenuItem("", $iContextMenu) ; Separator
GUICtrlCreateMenuItem("&Properties", $iContextMenu)

; PIC
GUICtrlCreatePic("logo4.gif", 0, 0, 169, 68)
GUICtrlCreateLabel("Sample Pic", 75, 1, 53, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)


; AVI
GUICtrlCreateAvi("SampleAVI.avi", 0, 180, 10, 32, 32, $ACS_AUTOPLAY)
GUICtrlCreateLabel("Sample avi", 175, 50)
GUICtrlSetBkColor(-1, 0x00FF00)


; TAB
GUICtrlCreateTab(240, 0, 150, 70)
GUICtrlCreateTabItem("One")

GUICtrlCreateTabItem("Two")
GUICtrlCreateLabel("Sample Tab with tabItems", 250, 40)
GUICtrlCreateTabItem("Three")
GUICtrlCreateLabel("Tab with tabItems", 250, 40)
GUICtrlCreateTabItem("")

; COMBO
GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)

; PROGRESS
GUICtrlCreateProgress(60, 80, 150, 20)
GUICtrlSetData(-1, 60)
GUICtrlCreateLabel("Progress:", 5, 82)

; EDIT
GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 110, 150, 70)

; LIST
GUICtrlCreateList("", 5, 190, 100, 90)
GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
Local $iconName = 0
; ICON
Local $icon11 = GUICtrlCreateIcon("explorer.exe", $iconName, 175, 120)
GUICtrlCreateLabel("Icon", 180, 160, 50, 20)

; LIST VIEW
Local $iListView = GUICtrlCreateListView("Sample|ListView|", 110, 190, 110, 80)
GUICtrlCreateListViewItem("A|One", $iListView)
GUICtrlCreateListViewItem("B|Two", $iListView)
GUICtrlCreateListViewItem("C|Three", $iListView)

; GROUP WITH RADIO BUTTONS
Local $Group = GUICtrlCreateGroup("Sample Group", 230, 120)
GUICtrlCreateRadio("Radio One", 250, 140, 80)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateRadio("Radio Two", 250, 165, 80)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

; UPDOWN
GUICtrlCreateLabel("UpDown", 350, 115)
GUICtrlCreateInput("42", 350, 130, 40, 20)
GUICtrlCreateUpdown(-1)

; LABEL
GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
GUICtrlSetBkColor(-1, 0x00FF00)

; SLIDER
GUICtrlCreateLabel("Slider:", 235, 215)
GUICtrlCreateSlider(270, 210, 120, 30)
GUICtrlSetData(-1, 30)

; INPUT
GUICtrlCreateInput("Sample Input Box", 235, 255, 130, 20)

; DATE
GUICtrlCreateDate("", 5, 280, 200, 20)
GUICtrlCreateLabel("(Date control expands into a calendar)", 10, 305, 200, 20)

; BUTTON
GUICtrlCreateButton("Sample Button", 10, 330, 100, 30)

; CHECKBOX
GUICtrlCreateCheckbox("Checkbox", 130, 335, 80, 20)
GUICtrlSetState(-1, $GUI_CHECKED)

; TREEVIEW ONE
Local $iTreeView_1 = GUICtrlCreateTreeView(210, 290, 80, 80)
Local $iTreeItem = GUICtrlCreateTreeViewItem("TreeView", $iTreeView_1)
GUICtrlCreateTreeViewItem("Item1", $iTreeItem)
GUICtrlCreateTreeViewItem("Item2", $iTreeItem)
GUICtrlCreateTreeViewItem("Foo", -1)
GUICtrlSetState($iTreeItem, $GUI_EXPAND)

; TREEVIEW TWO
Local $iTreeView_2 = GUICtrlCreateTreeView(295, 290, 103, 80, BitOR($TVS_CHECKBOXES, $TVS_LINESATROOT))
GUICtrlCreateTreeViewItem("TreeView", $iTreeView_2)
GUICtrlCreateTreeViewItem("With", $iTreeView_2)
GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $iTreeView_2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTreeViewItem("Style", $iTreeView_2)

; GUI MESSAGE LOOP
GUISetState(@SW_SHOW)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Link to comment
Share on other sites

@Deye
Something like this? :)

Spoiler
#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>

Global $data = FileRead(@ScriptFullPath)

$a = StringRegExp($data, '(?im)(^(?:Global|Local|\$\S+)\s*[^=]+=[^\n]+|^GUI(?!SetState)[^(]+\([^)]+\))', 3)
If @error Then MsgBox(0, '', @error)
_ArrayDisplay($a)

Exit

; GUI
$hGUI = GUICreate("Sample GUI", 400, 400)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; MENU
Local $sMenu1 = "Menu&One"
Local $sMenu2 = "Menu&Two"
GUICtrlCreateMenu($sMenu1)
GUICtrlCreateMenu($sMenu2)
GUICtrlCreateMenu("MenuTh&ree")
GUICtrlCreateMenu("Menu&Four")

; CONTEXT MENU
Local $iContextMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuItem("Context Menu", $iContextMenu)
GUICtrlCreateMenuItem("", $iContextMenu) ; Separator
GUICtrlCreateMenuItem("&Properties", $iContextMenu)

; PIC
GUICtrlCreatePic("logo4.gif", 0, 0, 169, 68)
GUICtrlCreateLabel("Sample Pic", 75, 1, 53, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)


; AVI
GUICtrlCreateAvi("SampleAVI.avi", 0, 180, 10, 32, 32, $ACS_AUTOPLAY)
GUICtrlCreateLabel("Sample avi", 175, 50)
GUICtrlSetBkColor(-1, 0x00FF00)


; TAB
GUICtrlCreateTab(240, 0, 150, 70)
GUICtrlCreateTabItem("One")

GUICtrlCreateTabItem("Two")
GUICtrlCreateLabel("Sample Tab with tabItems", 250, 40)
GUICtrlCreateTabItem("Three")
GUICtrlCreateLabel("Tab with tabItems", 250, 40)
GUICtrlCreateTabItem("")

; COMBO
GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)

; PROGRESS
GUICtrlCreateProgress(60, 80, 150, 20)
GUICtrlSetData(-1, 60)
GUICtrlCreateLabel("Progress:", 5, 82)

; EDIT
GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 110, 150, 70)

; LIST
GUICtrlCreateList("", 5, 190, 100, 90)
GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
Local $iconName = 0
; ICON
Local $icon11 = GUICtrlCreateIcon("explorer.exe", $iconName, 175, 120)
GUICtrlCreateLabel("Icon", 180, 160, 50, 20)

; LIST VIEW
Local $iListView = GUICtrlCreateListView("Sample|ListView|", 110, 190, 110, 80)
GUICtrlCreateListViewItem("A|One", $iListView)
GUICtrlCreateListViewItem("B|Two", $iListView)
GUICtrlCreateListViewItem("C|Three", $iListView)

; GROUP WITH RADIO BUTTONS
Local $Group = GUICtrlCreateGroup("Sample Group", 230, 120)
GUICtrlCreateRadio("Radio One", 250, 140, 80)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateRadio("Radio Two", 250, 165, 80)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

; UPDOWN
GUICtrlCreateLabel("UpDown", 350, 115)
GUICtrlCreateInput("42", 350, 130, 40, 20)
GUICtrlCreateUpdown(-1)

; LABEL
GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
GUICtrlSetBkColor(-1, 0x00FF00)

; SLIDER
GUICtrlCreateLabel("Slider:", 235, 215)
GUICtrlCreateSlider(270, 210, 120, 30)
GUICtrlSetData(-1, 30)

; INPUT
GUICtrlCreateInput("Sample Input Box", 235, 255, 130, 20)

; DATE
GUICtrlCreateDate("", 5, 280, 200, 20)
GUICtrlCreateLabel("(Date control expands into a calendar)", 10, 305, 200, 20)

; BUTTON
GUICtrlCreateButton("Sample Button", 10, 330, 100, 30)

; CHECKBOX
GUICtrlCreateCheckbox("Checkbox", 130, 335, 80, 20)
GUICtrlSetState(-1, $GUI_CHECKED)

; TREEVIEW ONE
Local $iTreeView_1 = GUICtrlCreateTreeView(210, 290, 80, 80)
Local $iTreeItem = GUICtrlCreateTreeViewItem("TreeView", $iTreeView_1)
GUICtrlCreateTreeViewItem("Item1", $iTreeItem)
GUICtrlCreateTreeViewItem("Item2", $iTreeItem)
GUICtrlCreateTreeViewItem("Foo", -1)
GUICtrlSetState($iTreeItem, $GUI_EXPAND)

; TREEVIEW TWO
Local $iTreeView_2 = GUICtrlCreateTreeView(295, 290, 103, 80, BitOR($TVS_CHECKBOXES, $TVS_LINESATROOT))
GUICtrlCreateTreeViewItem("TreeView", $iTreeView_2)
GUICtrlCreateTreeViewItem("With", $iTreeView_2)
GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $iTreeView_2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTreeViewItem("Style", $iTreeView_2)

; GUI MESSAGE LOOP
GUISetState(@SW_SHOW)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

or this  :)

$a = StringRegExp($data, '(?ims)^\h*(?|(?:local|Global)\h+(\N+)|((?|\$|GUICtrl[cs])\N+))(?=.*guisetstate)', 3)

Checking the "=" is not mandatory as "Local $array[3][2]" or "Local $var" are valid declarations
Note that it won't work clean for multiple declarations on the same line "Local $var1 = 1, $var2 = 2, $var3 = 3"

Link to comment
Share on other sites

Also multiline statements are another block. Assign() is still another one.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Just a few Observation points:

I think I may after all need to leave the declarations "Global|local" as a way to distinguish these lines later on processing
Not mention earlier: a bonus in Francesco's example is that the pattern takes care of trailing comments but wont work if a line begins with a declaration , probably will need to merge in something fro that too

in mikell's example: took care of all I had pointed out but misses out the "GUISetIcon" line (Thought "GUICtrlC" was the only wild card needed)

will probably also want to add something to skip lines between #cs And #ce  for example : "(?m)#cs([\s\S]*?)#ce(*SKIP)(?!)"

Thanks so far

Deye

 

Link to comment
Share on other sites

I'm Not sure if what I'm aiming to do will work with all GUI scripts, didn't yet come to the part where "if then else" exist in the GUI building phase
So I will post a bigger part of all I needed with this (if easy for you to follow without me needing to detail..)

maybe I'm not aware of other easier ways to execute the gui in the building part  but the array needs to follow up all the evals

Gui_Script.zip

The eventual reason for executing the GUI like that is that I need to test ways to reboot the GUI with different line orders were for example: when moving any controls into other tabs (maybe in for a future guituner..)
@ building the array primarily: to first get all values under the right (col)category's for easy reading on wards

Thanks
Deye

Link to comment
Share on other sites

Edit: Removed none relevant comments

On 3/29/2019 at 3:56 PM, mikell said:

Note that it won't work clean for multiple declarations on the same line "Local $var1 = 1, $var2 = 2, $var3 = 3"

What can be a  suggested way to capture and affirm and make them go into new separate lines ( if starts with Local|Global ..etc)

for removing trailing comments I just added   $data = StringRegExpReplace($data, '(?m)\;\N.*', "")  think it works Ok ..

Thanks again

Deye

Edited by Deye
Link to comment
Share on other sites

@Deye

Sorry for not replying.

I downloaded the attached script last week, but I am quite busy at the moment , so I don't have so much spare time to look at it.

If you could explain in detail what you are trying to do with your script, then it would be helpful :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

FrancescoDiMuro, 
NP, You are pardoned ;)

In gross the script executes GUI commands read from the array and at the same time pulls all GUI info to a new array that sorts all the commands
The script is very RAW organic 🍄 but visible to understand what is done in a few lines

Thanks
Deye

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...