bahtea Posted April 5, 2010 Share Posted April 5, 2010 (edited) i'm one with no programming backgrounds. i've read a lot from the forum posts, yet, this obstacle is clearly beyond me. all i could accomplish so far is to automate some tasks. i'm involved in a scripture translation work--accent marking, to be precise. i know that the kind of tool i'm about to ask for is possible through autoit but i just can't manage to code it myself. this is the only place i know of where i may make requests of this kind. allow me: a1. the program should be visible (always on top) like orbit downloader's drop box (because i have disabled my windows' tray), OR minimizable to the taskbar OR TSR-like. a2. my work platform is ms office word. but it ought to work elsewhere too. a3. i'm dealing with vowels only. the main task: b1. using a hotkey, find a vowel starting from the cursor point on, highlight it. b2. determine its case. b3. replace it (case-sensitive) with a hotkey. b4. find the next vowel. replace it with what? this is the detailed (and hard) part (i guess): c1. there are basically 6 symbols--3 for long vowels; 3 for short. c2. hit F6, for instance, to insert this diacritical sign: Â (circumflex) F7 for À (grave) F8 for Á (acute) etc. for maximum ease of use, all functions should be possible through assignable/customizable hotkeys (single-key hotkeys should be fine). if somebody could write it out for me, that'd be more than i could hope for. else, i'd love to get tips/directions so that i can attempt the coding myself. the benefits possible in terms of output is beyond any reckoning. thank you. hope i won't get flamed for such a request. Edited April 5, 2010 by bahtea Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 bahtea,Welcome to the AutoIt forum. We do not normally do requests, but this looked like fun. Besides, "the benefits possible in terms of output is beyond any reckoning" means I will certainly count it as my "good deed" for the day - even if I cannot imagine what these benefits might be. This script does not meet all your requirements, but goes a fair way towards them:- a1-3: It will stay on top because it is a stand-alone app which works with text files. It does NOT work inside Word or any other app.- b1-4: You use a Start button to begin rather than a HotKey - other than that you have them all.- c1-2: I am not too sure what you want here - I have assumed that all vowels can be replaced by their case equivalent with any of the 3 accents or left alone. The 4 HotKeys to do this are:F5 - Skip this vowel F6 - Add a circumflex accent to the existing vowel F7 - Add a grave accent to the existing vowel F8 - Add an acute accent to the existing vowelSo, how to use it:Save the main text you wish to edit as a .txt file in the same folder as the script. Run the script - it will ask you to select the file to edit. Once the file is loaded, place the cursor at the point from which you wish the search to start and press "Start". The script highlights the vowels and you use the HotKeys F5-F8 to skip/change them. Pressing "Save" saves the current text, overwriting the existing file, and asks if you want to exit. If not, then the file is reloaded and a new start position can be set. When there are no more vowels to find, the script tells you and saves the file.expandcollapse popup#include <GUIConstantsEx.au3> #Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> #Include <WindowsConstants.au3> Global $sText, $iActChar = 1, $iFirstChar = 0, $sCurrChar = "" ; Set HotKeys HotKeySet("{F5}", "_Skip") HotKeySet("{F6}", "_Circumflex") HotKeySet("{F7}", "_Grave") HotKeySet("{F8}", "_Acute") ; Choose a file to edit Global $sFile = FileOpenDialog("Select file to edit", @ScriptDir, "Files (*.txt)", 3) ; Create a GUI Global $hGUI = GUICreate("Test", 1000, 800) Global $hEdit = GUICtrlCreateEdit($sText, 10, 10, 980, 740) GUICtrlSetFont(-1, 14, Default, Default, "Courier New") Global $hLabel_Line = GUICtrlCreateLabel("", 10, 770, 100, 20) Global $hLabel_Col = GUICtrlCreateLabel("", 120, 770, 100, 20) Global $hStart_Button = GUICtrlCreateButton("Start", 810, 760, 80, 30) Global $hSave_Button = GUICtrlCreateButton("Save", 910, 760, 80, 30) Global $hDummy = GUICtrlCreateDummy() GUISetState() ; Load file and set defaults _Load_File() _GUICtrlEdit_SetSel($hEdit, 0, 0) ; Wait until start position set _Start_Select() ; Run through file While 1 ; Look for next vowel StringRegExp($sText, "(?i)[a|e|i|o|u]", 1, $iActChar) ; If none left - save file and exit If @error Then MsgBox(64, "End of file", "There are no more vowels to change") _Write_File() Exit EndIf ; Get position for next match $iActChar = @extended ; Read vowel found Global $sCurrChar = StringMid($sText, $iActChar - 1, 1) ; Set selection to highlight vowel _GUICtrlEdit_SetSel($hEdit, $iActChar - 2, $iActChar - 1) ; Show line and column at bottom of GUI Global $iActLine = _GUICtrlEdit_LineFromChar($hEdit) ; Show line GUICtrlSetData($hLabel_Line, "Line: " & $iActLine + 1) ; Calculate and show column GUICtrlSetData($hLabel_Col, "Col : " & $iActChar - _GUICtrlEdit_LineIndex($hEdit, $iActLine) - 1) ; Ensure selected vowel is always in view While _GUICtrlEdit_GetFirstVisibleLine($hEdit) + 15 < $iActLine ; Skip it too close to end If _GUICtrlEdit_GetLineCount($hEdit) - $iActLine < 20 Then ExitLoop ; Scroll down 1 line _GUICtrlEdit_Scroll($hEdit, $SB_LINEDOWN) WEnd While 1 Switch GUIGetMsg() ; [X] Case $GUI_EVENT_CLOSE Exit ; Used to move on when a char is changed Case $hDummy ExitLoop ; Save file Case $hSave_Button ; Write the changed file _Write_File() ; Ask about exit If MsgBox(36, "Exit?", "Do you want to exit now?") = 6 Then Exit ; Reread file and reset all defaults _Load_File() GUICtrlSetState($hEdit, $GUI_FOCUS) GUICtrlSetState($hStart_Button, $GUI_ENABLE) ; Select start position - default is last selection _Start_Select() ExitLoop EndSwitch WEnd WEnd Func _Skip() ; Activate the dummy to break out of the loop GUICtrlSendToDummy($hDummy) EndFunc Func _Circumflex() ; Call replace function with offset of 2 _Replace_Char(2) EndFunc Func _Grave() ; Call replace function with offset of 0 _Replace_Char(0) EndFunc Func _Acute() ; Call replace function with offset of 1 _Replace_Char(1) EndFunc Func _Replace_Char($iAdd) Local $sNewChar ; Get ASCII value of found vowel Local $iAscCurrChar = Asc($sCurrChar) ; Select replacement depending on case and letter Switch $iAscCurrChar ; A, a Case 65, 97 $sNewChar = Chr($iAscCurrChar + 127 + $iAdd) ; E, I, O, e, i, o Case 69, 73, 79, 101, 105, 111 $sNewChar = Chr($iAscCurrChar + 131 + $iAdd) ; U, u Case 85, 117 $sNewChar = Chr($iAscCurrChar + 132 + $iAdd) EndSwitch ; Replace the vowel in the text $sText = StringReplace($sText, $iActChar - 1, $sNewChar, 1) ; Reload the text into teh edit and reset the selection GUICtrlSetData($hEdit, $sText) _GUICtrlEdit_SetSel($hEdit, $iActChar - 2, $iActChar - 1) ; Activate the dummy to break out of the loop GUICtrlSendToDummy($hDummy) EndFunc Func _Start_Select() While 1 Switch GUIGetMsg() ; [X] Case $GUI_EVENT_CLOSE Exit ; Start position set Case $hStart_Button GUICtrlSetState($hEdit, $GUI_FOCUS) ; Get start position $aArray = _GUICtrlEdit_GetSel($hEdit) ; Set SRE offset $iActChar = $aArray[0] GUICtrlSetState($hStart_Button, $GUI_Disable) ExitLoop EndSwitch WEnd EndFunc Func _Load_File() ; Read and load text $sText = FileRead($sFile) GUICtrlSetData($hEdit, $sText) ; Set defaults $iActChar = 1 $iFirstChar = 0 $sCurrChar = "" EndFunc Func _Write_File() ; Open and overwrite existing file Local $hFile = FileOpen($sFile, 2) FileWrite($hFile, GUICtrlRead($hEdit)) FileClose($hFile) EndFuncI hope it is somewhere near what you wanted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bahtea Posted April 5, 2010 Author Share Posted April 5, 2010 hello, MVP Melba23, your reply brings me too much excitement to post any reasonable comment. i'll be back in a day or two. for now, inexpressible thanks!! Link to comment Share on other sites More sharing options...
bahtea Posted April 8, 2010 Author Share Posted April 8, 2010 salute, Melba23! this is a real pro at work. you're so very right, this script does not meet all my requirements, but goes a fair way towards them: 1. the editing point does not really follow the cursor's position. it only takes up from its last position. 2. there is no word wrap. the current slider's behaviour is too cumbersome to put to heavy use. to edit any vowel beyond the current page boundary requires manual slider dragging. 3. ability to work with other text editors/word processors, esp ms office word will take it to the next level. whatever, your work has provided one with the platform on which to start building. i'll try to customise it to fit my needs and IF i succeed will come back to post. my gratitude again! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 8, 2010 Moderators Share Posted April 8, 2010 bahtea,Glad you like the script. Taking your points in turn:- 1. Once you have started changing vowels, you moving the cursor has no effect - the hightlight just moves to the next vowel when you have pressed a HotKey F5-F8. If you want to move to another section of the text, press "Save" and do not exit when asked. Then you can reposition the cursor where you wish to recommence and press "Start" to begin changing vowels again. You did ask to move from vowel to vowel in your points b1-b4, by the way. - 2. This new script now scrolls horizontally so you should not have to move the horizontal scroll bar when changing vowels. - 3. Not going there! Here is the new version for you to try:expandcollapse popup#include <GUIConstantsEx.au3> #Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> #Include <WindowsConstants.au3> Opt("TrayIconDebug", 1) Global $sText, $iActChar = 1, $iFirstChar = 0, $sCurrChar = "", $iScrollMoves = 0 ; Set HotKeys HotKeySet("{F5}", "_Skip") HotKeySet("{F6}", "_Circumflex") HotKeySet("{F7}", "_Grave") HotKeySet("{F8}", "_Acute") ; Choose a file to edit Global $sFile = FileOpenDialog("Select file to edit", @ScriptDir, "Files (*.txt)", 3) ; Create a GUI Global $hGUI = GUICreate("Test", 1000, 800) Global $hEdit = GUICtrlCreateEdit($sText, 10, 10, 980, 740) GUICtrlSetFont(-1, 14, Default, Default, "Courier New") Global $hLabel_Line = GUICtrlCreateLabel("", 10, 770, 100, 20) Global $hLabel_Col = GUICtrlCreateLabel("", 120, 770, 100, 20) Global $hStart_Button = GUICtrlCreateButton("Start", 810, 760, 80, 30) Global $hSave_Button = GUICtrlCreateButton("Save", 910, 760, 80, 30) Global $hDummy = GUICtrlCreateDummy() GUISetState() ; Load file and set defaults _Load_File() _GUICtrlEdit_SetSel($hEdit, 0, 0) ; Wait until start position set _Start_Select() ; Run through file While 1 ; Look for next vowel StringRegExp($sText, "(?i)[a|e|i|o|u]", 1, $iActChar) ; If none left - save file and exit If @error Then MsgBox(64, "End of file", "There are no more vowels to change") _Write_File() Exit EndIf ; Get position for next match $iActChar = @extended ; Read vowel found Global $sCurrChar = StringMid($sText, $iActChar - 1, 1) ; Set selection to highlight vowel _GUICtrlEdit_SetSel($hEdit, $iActChar - 2, $iActChar - 1) ; Show line and column at bottom of GUI Global $iActLine = _GUICtrlEdit_LineFromChar($hEdit) ; Show line GUICtrlSetData($hLabel_Line, "Line: " & $iActLine + 1) ; Calculate and show column Local $iColumn = $iActChar - _GUICtrlEdit_LineIndex($hEdit, $iActLine) - 1 GUICtrlSetData($hLabel_Col, "Col : " & $iColumn) ; Ensure selected vowel is always in view vertically While _GUICtrlEdit_GetFirstVisibleLine($hEdit) + 15 < $iActLine ; Skip it too close to end If _GUICtrlEdit_GetLineCount($hEdit) - $iActLine < 20 Then ExitLoop ; Scroll down 1 line _GUICtrlEdit_Scroll($hEdit, $SB_LINEDOWN) WEnd ; Ensure selected vowel is always in view horizontally If $iColumn > 75 + $iScrollMoves Then ; Scroll right if too far over _GUICtrlEdit_LineScroll($hEdit, 50, 0) $iScrollMoves += 50 EndIf If $iColumn < 25 + $iScrollMoves Then ; Scroll back to keep in view if too far to left While $iScrollMoves > $iColumn _GUICtrlEdit_LineScroll($hEdit, -50, 0) $iScrollMoves -= 50 WEnd EndIf While 1 Switch GUIGetMsg() ; [X] Case $GUI_EVENT_CLOSE Exit ; Used to move on when a char is changed Case $hDummy ExitLoop ; Save file Case $hSave_Button ; Write the changed file _Write_File() ; Ask about exit If MsgBox(36, "Exit?", "Do you want to exit now?") = 6 Then Exit ; Reread file and reset all defaults _Load_File() GUICtrlSetState($hEdit, $GUI_FOCUS) GUICtrlSetState($hStart_Button, $GUI_ENABLE) ; Select start position - default is last selection _Start_Select() ExitLoop EndSwitch WEnd WEnd Func _Skip() ; Activate the dummy to break out of the loop GUICtrlSendToDummy($hDummy) EndFunc Func _Circumflex() ; Call replace function with offset of 2 _Replace_Char(2) EndFunc Func _Grave() ; Call replace function with offset of 0 _Replace_Char(0) EndFunc Func _Acute() ; Call replace function with offset of 1 _Replace_Char(1) EndFunc Func _Replace_Char($iAdd) Local $sNewChar ; Get ASCII value of found vowel Local $iAscCurrChar = Asc($sCurrChar) ; Select replacement depending on case and letter Switch $iAscCurrChar ; A, a Case 65, 97 $sNewChar = Chr($iAscCurrChar + 127 + $iAdd) ; E, I, O, e, i, o Case 69, 73, 79, 101, 105, 111 $sNewChar = Chr($iAscCurrChar + 131 + $iAdd) ; U, u Case 85, 117 $sNewChar = Chr($iAscCurrChar + 132 + $iAdd) EndSwitch ; Replace the vowel in the text $sText = StringReplace($sText, $iActChar - 1, $sNewChar, 1) ; Reload the text into teh edit and reset the selection GUICtrlSetData($hEdit, $sText) _GUICtrlEdit_SetSel($hEdit, $iActChar - 2, $iActChar - 1) ; Activate the dummy to break out of the loop GUICtrlSendToDummy($hDummy) EndFunc Func _Start_Select() While 1 Switch GUIGetMsg() ; [X] Case $GUI_EVENT_CLOSE Exit ; Start position set Case $hStart_Button GUICtrlSetState($hEdit, $GUI_FOCUS) ; Get start position $aArray = _GUICtrlEdit_GetSel($hEdit) ; Set SRE offset $iActChar = $aArray[0] GUICtrlSetState($hStart_Button, $GUI_Disable) ExitLoop EndSwitch WEnd EndFunc Func _Load_File() ; Read and load text $sText = FileRead($sFile) GUICtrlSetData($hEdit, $sText) ; Set defaults $iActChar = 1 $iFirstChar = 0 $sCurrChar = "" EndFunc Func _Write_File() ; Open and overwrite existing file Local $hFile = FileOpen($sFile, 2) FileWrite($hFile, GUICtrlRead($hEdit)) FileClose($hFile) EndFuncHave fun! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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