-
Recently Browsing 0 members
No registered users viewing this page.
-
Similar Content
-
By t0nZ
I was searching for a way to highlight zones (regions, provinces, counties, etc) on a map, and I don't need super precise maps so I wrote this script, based on picking up black and white maps (2 colors BW .png or .gif tested) and filling them with colors, writing down a sqlite database to associate zones with names (and other data as well), and reuse the map and the DB to display data, in my example reading a simple .txt file.
It's all based on this thread and this other thread.
So I have two modes:
The Map "creation mode" : you provide a map image and you start to pick up colors, set "upper level" region/state, and by clicking on a region you fill it and you name it, and all the data are saved on a sqlite DB (auto-created) when you have the map image and a DB with the correct associations, you can switch the "mode" to "show" (as by .ini file) and the script tries to read a "datafile" showing the zone names listed in datafile. The code:
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icone\mapFlooder.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;MAP Flooder ;(C) NSC 2021 #include <GUIConstants.au3> #include <_GOLLOG.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <Misc.au3> #include <GDIPlus.au3> Opt("mousecoordmode", 2) Global $prgname = "MAP Flooder", $ver = "V.0.7", $Buttoncolor = "0xFF00FF", $MPini = @ScriptDir & "\MapFlooder.ini", $btest Global $dbfullpath, $dbtable, $dbFields, $mapfile, $FloodMode, $datafile Global $HDC, $hBrush, $hGraphics, $obj_orig Global $Pic1, $gui, $width, $height, $bColor, $realtimeCoords, $lastclickcoords, $inputSup, $zonecountNum,$labeltest #Region program Gollog(">>>>>> Start MAP Flooder " & $ver) ctrlini() Gui() SQLiteDBcreate() If $FloodMode = "createdb" Then Gollog("CreateDB Mode") DBFlooder() Else Gollog("Show MAP mode") MapShow("show") EndIf Close() #EndRegion program #Region funcS Func Gui() _GDIPlus_Startup() $Pic1 = _GDIPlus_BitmapCreateFromFile($mapfile) $width = _GDIPlus_ImageGetWidth($Pic1) $height = _GDIPlus_ImageGetHeight($Pic1) If $FloodMode = "createdb" Then $gui = GUICreate($prgname & " " & $ver, $width + 150, $height) $labelLoadedMap = GUICtrlCreateLabel("Loaded Map", $width + 10, 5) $labelLoadedMap2 = GUICtrlCreateLabel(_FileToFileName($mapfile), $width + 10, 25) $labeldim = GUICtrlCreateLabel("Width*Height", $width + 10, 45) $labeldim2 = GUICtrlCreateLabel($width & " * " & $height, $width + 10, 65) $lastclickcoordslabel = GUICtrlCreateLabel("Last Click Coords", $width + 10, 100) $lastclickcoords = GUICtrlCreateLabel("xx - xx", $width + 10, 120, 180, 20) $realtimeCoordslabel = GUICtrlCreateLabel("Real Time Coords", $width + 10, 140) $realtimeCoords = GUICtrlCreateLabel("Real Time Coords", $width + 10, 160, 80, 20) $SuPzonelabel = GUICtrlCreateLabel("Supzone (region-state)", $width + 10, 200) $inputSup = GUICtrlCreateInput("sup", $width + 10, 220, 80, 20) $bColor = GUICtrlCreateButton($Buttoncolor, $width + 10, 250, 130, 30) GUICtrlSetBkColor($bColor, $Buttoncolor) $zonecountlabel = GUICtrlCreateLabel("Done Zone Count:", $width + 10, 320, 100, 20) $zonecountNum = GUICtrlCreateLabel("x", $width + 10, 340, 100, 20) $btest = GUICtrlCreateButton("TEST MAP", $width + 10, 380, 130, 30) $labeltest = GUICtrlCreateLabel("", $width + 10, 420, 130, 30) Else $gui = GUICreate($prgname & " " & $ver, $width, $height) EndIf GUISetState() $HDC = _WinAPI_GetDC($gui) $hGraphics = _GDIPlus_GraphicsCreateFromHDC($HDC) _GDIPlus_GraphicsDrawImageRect($hGraphics, $Pic1, 0, 0, $width, $height) EndFunc ;==>Gui Func MapShow($showmode) ; reading a simple text file with zone names, searching for names in DB and fill the map using stored coordinates If $showmode = "show" Then Local $aLines = FileReadToArray($datafile) Local $iLineCount = @extended EndIf If $showmode = "test" Then $iLineCount = 1 If @error Then MsgBox(48, "MapFlooder", "There was an error reading the data file. @error: " & @error) ; Gollog("There was an error reading the data file. @error: " & @error) Close() Else Gollog("start filling zones") _SQLite_Startup() _SQLite_Open($dbfullpath) ; open Database with zone definitions Local $hQuery, $aRow For $i = 0 To $iLineCount - 1 If $showmode = "show" Then _SQLite_Query(-1, "SELECT * FROM " & $dbtable & " where zone = '" & $aLines[$i] & "' ORDER BY zone ASC;", $hQuery) ; the query EndIf If $showmode = "test" Then _SQLite_Query(-1, "SELECT * FROM " & $dbtable & " ORDER BY zone ASC;", $hQuery) ; the query EndIf While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK $hBrush = DllCall("gdi32.dll", "long", "CreateSolidBrush", "int", $aRow[2]) ; fill color read from DB $obj_orig = DllCall("gdi32.dll", "int", "SelectObject", "int", $HDC, "int", $hBrush[0]) DllCall("gdi32.dll", "int", "FloodFill", "int", $HDC, "int", $aRow[3], "int", $aRow[4], "int", 0x000000) If $showmode = "test" Then GUICtrlSetData($labeltest,$aRow[0]) Sleep(200) GUISetState() EndIf WEnd _SQLite_QueryFinalize($hQuery) Next _SQLite_Close() _SQLite_Shutdown() EndIf While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>MapShow Func DBFlooder() $zonecount = 0 While 1 $mp = MouseGetPos() GUICtrlSetData($realtimeCoords, $mp[0] & " - " & $mp[1]) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $bColor Then colorP() If $msg = $btest Then MapShow("Test") If $mp[0] < $width And $mp[1] < $height And _IsPressed("01") And WinActive($gui) Then $mp = MouseGetPos() GUICtrlSetData($lastclickcoords, $mp[0] & " - " & $mp[1]) $hBrush = DllCall("gdi32.dll", "long", "CreateSolidBrush", "int", $Buttoncolor) ; fill color ok $obj_orig = DllCall("gdi32.dll", "int", "SelectObject", "int", $HDC, "int", $hBrush[0]) DllCall("gdi32.dll", "int", "FloodFill", "int", $HDC, "int", $mp[0], "int", $mp[1], "int", 0x000000) Local $Zone = InputBox("Map Floode", "Zone ?") If $Zone = "" Or @error = 1 Then ; when manage wrong click, possibility to repeat ; set 'temp' color to highlight the 'wrong' click $hBrush = DllCall("gdi32.dll", "long", "CreateSolidBrush", "int", 0x4ccfc6) ; fill color wrong $obj_orig = DllCall("gdi32.dll", "int", "SelectObject", "int", $HDC, "int", $hBrush[0]) DllCall("gdi32.dll", "int", "FloodFill", "int", $HDC, "int", $mp[0], "int", $mp[1], "int", 0x000000) ; restore color $hBrush = DllCall("gdi32.dll", "long", "CreateSolidBrush", "int", $Buttoncolor) ; fill color ok $obj_orig = DllCall("gdi32.dll", "int", "SelectObject", "int", $HDC, "int", $hBrush[0]) Else _SQLite_Startup() _SQLite_Open($dbfullpath) ; open Database Local $SupZone = GUICtrlRead($inputSup) Local $data = '"' & $Zone & '","' & $SupZone & '","' & $Buttoncolor & '",' & $mp[0] & "," & $mp[1] _SQLite_Exec(-1, "INSERT INTO " & $dbtable & "(" & $dbFields & ") VALUES (" & $data & ");") If @error = -1 Then GOLLOG("Error insert record") MsgBox(48, "Error", "insert record") EndIf $zonecount += 1 GUICtrlSetData($zonecountNum, $zonecount) _SQLite_Close() _SQLite_Shutdown() EndIf EndIf WEnd EndFunc ;==>DBFlooder Func Close() Gollog("<<<<<<< closing...") _WinAPI_ReleaseDC($gui, $HDC) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit EndFunc ;==>Close Func SQLiteDBcreate() ;complete path e filename If Not FileExists($dbfullpath) Then GOLLOG("perform SQLite DB creation") Local $dbfolder = _FileToFilePath($dbfullpath) ;Local $dbfile = _FileToFileName($dbfullpath) If Not FileExists($dbfolder) Then DirCreate($dbfolder) ; =====================>>>>> START SQL DLL _SQLite_Startup() _SQLite_Open($dbfullpath) ; open Database ; creating first table If _SQLite_Exec(-1, "CREATE TABLE " & $dbtable & " (" & $dbFields & ");") = $SQLITE_OK Then GOLLOG("DB table - " & $dbtable & " - creation ok") Else GOLLOG("Error creating DB table : " & @error) EndIf _SQLite_Close() _SQLite_Shutdown() Else Gollog("DB already exist") EndIf EndFunc ;==>SQLiteDBcreate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Local $sReturn = StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName Func colorP() ; modified for BGR color GOLLOG("Color Picker") Local $color = _ChooseColor(2) If $color = -1 Then GOLLOG("no color selected") Else Local $sCr = Hex($color, 6) Local $RGB_Buttoncolor = '0x' & StringMid($sCr, 1, 2) & StringMid($sCr, 3, 2) & StringMid($sCr, 5, 2) GUICtrlSetBkColor($bColor, $RGB_Buttoncolor) ; BGR color $Buttoncolor = '0x' & StringMid($sCr, 5, 2) & StringMid($sCr, 3, 2) & StringMid($sCr, 1, 2) GUICtrlSetData($bColor, $Buttoncolor) GOLLOG("new color " & $Buttoncolor & " selected") EndIf EndFunc ;==>colorP Func ctrlini() ;ini read If FileExists($MPini) Then GOLLOG("found: " & $MPini) $mapfile = IniRead($MPini, "map", "mapfile", "") $datafile = IniRead($MPini, "map", "datafile", "") $dbfullpath = IniRead($MPini, "db", "dbfullpath", "") $dbtable = IniRead($MPini, "db", "dbtable", "") $dbFields = IniRead($MPini, "db", "dbfields", "") $FloodMode = IniRead($MPini, "mode", "mode", "") Else GOLLOG($MPini & " NOT found..") Close() EndIf EndFunc ;==>ctrlini #EndRegion funcS All the needed files plus some example (image maps and DBs)
Link to all demo files
To test, copy all in a single folder and adjust the mapflooder.ini, also you can add to you includes the _gollog.au3 (used for log, you can avoid it deleting all Gollog() lines)
-
By MarcoMonte
Hello Everyone,
Hoping someone can help me,
I am totally stuck on this problem,
I cannot reach the textarea and the button in a maps page that I get by clicking on a button in a previus page, the only way I can interact with this is using tab and mouseclick but this is a danger method as you know.
I get the handle by using: $Posizione = _IEAttach("Ricerca Indirizzo su mappa")
then I tried a lot of things but nothing works, can someone give me a hint?
--------------------
WinWait("Ricerca Indirizzo su mappa")
sleep(1000)
$Posizione = _IEAttach("Ricerca Indirizzo su mappa")
WinSetState ("Ricerca Indirizzo su mappa", "", @SW_MAXIMIZE )
WinActivate("Ricerca Indirizzo su mappa")
sleep(500)
;~ $oForm = _IEFormGetObjByName($Posizione, "form1");Punta il Form
$oText = _IEFormElementGetObjByName($Posizione,"indirizzo")
$oText = _IEFormElementGetObjByName($Posizione,"writeAddress")
;~ $LenteTestoMess = _IEFormElementGetValue($oText);Inserisce il PrimoRepertorio nella variabile
;~ _IELinkClickByText($Posizione, $oForm);Clicca su Aggiorna ed invia il form
_IEFormElementSetValue ($oText,"via Ravenna 12" );Completamento campo testo
----------------------------------------------------
Mappa.odt Ricerca Indirizzo su mappa.htm
-
By qsek
Im not sure if this is intended but normally Autoit variables are always passed as copies (except objects i think).
But below i observed an unconsistency when copying maps with nested maps inside.
Issue:
If you create a nested map1 and copy it to a new map2, changing a nested value in map2 will also change the nested value in map1
Dim $player[] Dim $sub[] $player.test1 = 1 $player.test2 = $sub $player.test2.child1 = "org" $player.test2.childext = $sub $player.test2.childext.child1 = "org2" $playerold = $player ; make a copy of the whole map ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original nested value in $player $playerold.test2.child1 = "changed" ; edit a nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF) ; original nested value in $player changed ConsoleWrite("---------------------" & @CRLF) ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player $playerold.test2.childext.child1 = "changed2" ; edit a level2 nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original level1 nested value in $player stayed the same ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player changed
-
By qsek
Can somebody try to reproduce this bug?
It would be helpful to know if this issue appeares on other environments too.
Issue:
Sometimes values of certain keys will return empty even if expicitly assigned a value before.
Conditions:
Map is bigger than ~50 key/values pairs value is being worked with in a Function where a loop is iterating through the Map before retrieving the value there is a isMap/MapKeys/MapAppend/MapRemove check on the Map value. Dim $mMap[] ; Generate random key strings For $i = 0 To 100 $RndKey = "" For $i2 = 0 To 4 $RndKey &= Chr(Random(65,90,1)) Next $mMap[$RndKey] = 999 next ConsoleWrite("-----------1-------------" & @CRLF); Unpredictable blank values MapDisplay1($mMap) ConsoleWrite("-----------2-------------" & @CRLF); ByRef always works MapDisplay2($mMap) ConsoleWrite("-----------3-------------" & @CRLF); not in a function always works For $i In MapKeys($mMap) isMap($mMap[$i]) ConsoleWrite($i&": "&$mMap[$i]&@CRLF) Next Func MapDisplay1( $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ;same problem with isMap($m_Map[$i]), MapKeys($m_Map[$i]), MapAppend/MapRemove but NOT with MapExists($m_Map,$i) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc Func MapDisplay2( ByRef $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc
The value is not lost or overwritten on the global map, only on the local map inside the function.
-
By TheDcoder
Hello Again! I previously stumbled upon a topic asking for maps datatype's instructions... I too wasn't sure what a map is until I tried it... So I am making this topic to help other newbies (and some oldbies) better understand the Maps datatype of AutoIt! Lets start!
A Note for Readers
The maps datatype is still in development and is currently in Alpha Stage (More Risky than Beta) and its unstable, so AutoIt can crash indefinably while using Maps! I can't guarantee if this will be implemented in stable versions, this is a fairly new thing to AutoIt coders & in my honest opinion I don't see any use for it Maps are the best datatype in AutoIt, Very Useful ... Not hurting anyone though . Also the maps datatype is DISABLED IN STABLE VERSIONS, So you need to install the latest beta version of AutoIt to make maps work . If you find any bugs while using a map, please report it in the Official Bug Tracker
Introduction To Maps
Maps are just like arrays, instead they use "keys" to access elements inside them... A key can be either a string or an integer (Other datatypes work too but they are converted to a integer [Equivalent to Int($vKey)] before assignment [Source]). Although Integers don't represent the order of elements in a map unlike in an array...
Declaring Maps
Its similar to declaring an Array:
; This is the only way to declare a map ; You must have a declarative keyword like Dim/Global/Local before the declaration unless the map is assigned a value from a functions return Local $mMap[] ; Don't insert any numbers or strings it! Simple, Isn't it?
Using Maps
Using maps is similar to arrays (again!):
Local $mMap[] ; Lets declare our map first! ; Adding data to maps is easy... ; This is our key ; | ; v $mMap["Key"] = "Value" ; <--- And our value! ; A key is Case-Sensitive meaning "Key" is not same as "key"! $mMap["key"] = "value" ; Not the same as $mMap["Key"]! ; There are 2 different ways to access an element in a map $mMap["Key"] ; 1st Method $mMap.Key ; 2nd Method Enumerating Maps
Its quite easy to enumerate through arrays but what about maps? how can I enumerate through them!?
#include <MsgBoxConstants.au3> ; Lets create our map first Local $mMap[] ; Lets add some information to the map, feel free to modify & add new elements $mMap["Name"] = "Damon Harris" $mMap["Alias"] = "TheDcoder" $mMap["Gender"] = "Male" $mMap["Age"] = 14 $mMap["Location"] = "India" $aMapKeys = MapKeys($mMap) ; MapKeys function returns all the keys in the format of an array Local $sProfile = "Profile of " & $mMap["Name"] & ':' & @CRLF ; We will use this string later For $vKey In $aMapKeys ; We use this to get the keys in a map :) $sProfile &= @CRLF & $vKey & ': ' & $mMap[$vKey] ; Add some details to the profile string using our map! Next MsgBox($MB_ICONINFORMATION + $MB_OK, "Profile", $sProfile) ; Finally display the profile :) It is easy as always
Multi-Dimensional Maps
Now now... I know that you are a little confused that how can an multi-dimensional maps exist... Although I am not 100% sure if its called that but lets continue:
#include <MsgBoxConstants.au3> ; Multi-Dimensional maps are just maps in a map Local $mMapOfMapsvilla[] ; This map will store an other map Local $mParkMap[] ; This Park map will be inserted in the Mapsvilla's map :P $mMapOfMapsvilla["Map Item 1"] = "Town Hall" $mMapOfMapsvilla["Map Item 2"] = "Police Station" $mMapOfMapsvilla["Map Item 3"] = "Shopping Mall" $mMapOfMapsvilla["Map Item 4"] = "Residential Area" $mMapOfMapsvilla["Map Item 5"] = "Park" $mParkMap["Map Item 1"] = "Cottan Candy Stand" $mParkMap["Map Item 2"] = "Public Toilet" $mParkMap["Map Item 3"] = "Woods" $mMapOfMapsvilla.Park = $mParkMap MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla["Map Item 1"]) ; Will display Town Hall MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla.Park["Map Item 1"]) ; Will display Cottan Candy Stand I am sure its easy for you to understand now
Frequently Asked Questions (FAQs) & Their answers
Q #1. Help! My code does not respond to anything (or) I get an "Variable subscript badly formatted" error on the line of declaration...
A. DONT USE F5 or Go, Instead use Alt + F5 or Tools -> Beta Run in SciTE (Make sure that you have Beta installed)
Q #2. Why are you using "m" in-front of every map variable?
A. Best coding Practices: Names of Variables
Q #3. What are "Elements" which you mention frequently???
A. This is a newbie question (I have no intention of insulting you ), so I guess you are new to programming. "Elements" are data slots inside a Map (or an Array), you can imagine elements as individual variable which are stored in a Map. You can access them using "keys", Please refer to "Introduction to Maps" section at the starting of this post
Q #4. Are Maps faster than Arrays?
A. You need to understand that Maps have different purpose than Arrays. Maps are designed to store data dynamically (like storing information for certain controlIDs of GUI) and Arrays are designed to store data in a order (for instance, Storing every character of a string in an element for easy access). If you still want to know then if Maps are faster, then the answer is maybe... Maps are *supposed* (I am not sure ) to be faster in addition of elements (while Arrays are painfully slow while adding or removing elements). Here (Post #24) is a benchmark (Thanks kealper! )
More FAQs coming soon! Feel free to ask a question in the mean while
-
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now