Jump to content

Looking to improve RichEdit performance


icuurd12b42
 Share

Recommended Posts

hiya everyone. I just got AutoIT 4 days ago and I just completed my first business application. I really like AutoIT, it brings me back to my golden days as far as the GUI techniques are concerned.

Anyway, I have a problem with sluggish code to format my Rich Edit box content and was wondering if there is a better way of dealing with this.

I have a text file that I read like so:

...
local $File = FileOpen($filename, 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open message file")
Else
     _GUICtrlRichEdit_PauseRedraw($RichEdit)
_GUICtrlRichEdit_SetText($RichEdit, "")
local $txt = ""
local $ct = 0
local $bubble = ""
local $from = ""

$Line = FileReadLine ($file)
local $reading = not (@error = -1)

while ($reading)

if $ct = 0 then
$Bubble = $line
AddText(@LF,$MsgCol,4)
AddText($line & @LF ,$MsgCol,12)
elseif $ct = 1 then
AddText($line & @LF, $DateCol,10)
elseif $ct = 2 then
AddText($line & ", ", $NameCol,10)
AddText("To: ",$NameHCol,10)
elseif $ct = 3 then
AddText($line & " ",$NameCol,10)
AddText("From: ",$NameHCol,10)
$from = $line
EndIf

$ct = $ct+1
if $ct= 4 then
$ct = 0
EndIf

$Line = FileReadLine ($file)
$reading = not (@error = -1)

wend
_GuiCtrlRichEdit_Deselect($RichEdit)

_GUICtrlRichEdit_ResumeRedraw($RichEdit)
     FileClose($file);

the problem I have is the content of the file, consisting of plain text lines, is reversed, and I have to show the end of the file first and the begining last.

originally I was using a simple text box and simply did

txt = line & txt

in the loop, effectively reversing the stings order then I would add txt to the edit box in one shot

But people did not like the yuky edit bot and wanted me to format the text, font wize and color wise

Turned out the solution was possible with the rich edit box but the process is very slow. Here is the AddText function

; add text to the rich edit box, txt, color, fontsize
func AddText($txt,$clr,$sz)
_GUICtrlRichEdit_GotoCharPos($RichEdit, 0)

_GUICtrlRichEdit_InsertText($RichEdit,$txt)
_GUICtrlRichEdit_SetSel($RichEdit, 0, StringLen($txt))
_GuiCtrlRichEdit_SetCharColor($RichEdit, $clr)
_GUICtrlRichEdit_SetFont($RichEdit, $sz)

EndFunc

I half expected some slow down, but not to the point it takes 10 seconds to format 200 lines

It there a faster way? I'm thinking rtf... where I could put back my original concept and sent the entore content, rtf formated, in one shot to the control...

Sorry, the forum nuked my code formating...

Edited by icuurd12b42
Link to comment
Share on other sites

please post full code to get efficient replies

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

The only code missing the the creation of the richedit...

Global $RichEdit = _GUICtrlRichEdit_Create($hWnd, "", 45, 6+25+25+25, $WindowW-45-6, $WindowH-6-25-25-25-6, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL));

_GUICtrlRichEdit_SetUndoLimit($RichEdit, 0);

_GUICtrlRichEdit_SetReadOnly($RichEdit, True);

and the color variables

local $col[3]

$col[0] = 0

$col[1] = 0

$col[2] = 0

global $NameHCol = _ColorSetCOLORREF($col)

$col[0] = 0

$col[1] = 0

$col[2] = 164

global $NameCol = _ColorSetCOLORREF($col)

$col[0] = 0

$col[1] = 128

$col[2] = 128

global $DateCol = _ColorSetCOLORREF($col)

$col[0] = 128

$col[1] = 0

$col[2] = 128

global $MsgCol = _ColorSetCOLORREF($col)

Link to comment
Share on other sites

I found out the rtf codes and figured out a streamline rtf format for the rich edit so I could go back to the original method of inverted insertion.

local $File = FileOpen($filename, 0)
    ; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open message file")
    Else
        ;Name: and To; color is \cf1 in rtf
        local $NameHCol = "\red0\green0\blue0;"
        ;Name and to content color is \cf2 in rtf
        local $NameCol =  "\red0\green0\blue164;"
        ;Data color is \cf3 in rtf
        local $DateCol = "\red0\green128\blue128;"
        ;Msg color is \cf4 in rtf
        local $MsgCol = "\red128\green0\blue128;"

        local $DocHeader = "{\rtf1\ansi\deff0{\colortbl;" & $NameHCol & $NameCol & $DateCol & $MsgCol &"}"
        local $DocFooter = "}"
        local $DocBody = "";
        ;$DocBody =   "\cf1Name: \cf2Gilles \cf1To: \cf2Daniel \cf3 \tab 2012/10.10 12:45:24\line\cf4 \tab \fs24 This is message1\line \fs16";
        ;$DocBody = $DocBody & "\cf1Name: \cf2Gilles \cf1To: \cf2Daniel \cf3 \tab 2012/10.10 12:45:24\line\cf4 \tab \fs24 This is message2\line \fs16";
        ;_GUICtrlRichEdit_SetText($RichEdit, $DocHeader & $DocBody & $DocFooter)

        _GUICtrlRichEdit_PauseRedraw($RichEdit)
        ;_GUICtrlRichEdit_SetText($RichEdit, "")

        local $ct = 0
        local $bubble = ""
        local $from = ""

        $Line = FileReadLine ($file)
        local $reading = not (@error = -1)

        while ($reading)

            if $ct = 0 then
                $Bubble = $line
                ;AddText(@LF,$MsgCol,4)
                ;AddText($line & @LF ,$MsgCol,12)
                $DocBody = "\cf4 \tab \fs24 " & $line &"\line \fs16" & $DocBody
            elseif $ct = 1 then
                ;AddText($line & @LF, $DateCol,10)
                $DocBody = " \cf3 \tab " & $line &"\line" & $DocBody
            elseif $ct = 2 then
                ;AddText($line & ", ", $NameCol,10)
                ;AddText("To: ",$NameHCol,10)
                $DocBody = " \cf1To: \cf2" & $line & $DocBody
            elseif $ct = 3 then
                ;AddText($line & " ",$NameCol,10)
                ;AddText("From: ",$NameHCol,10)
                $DocBody = "\cf1Name: \cf2" & $line & $DocBody
                $from = $line
            EndIf

            $ct = $ct+1
            if $ct= 4 then
                $ct = 0
            EndIf

            $Line = FileReadLine ($file)
            $reading = not (@error = -1)

        wend
        ;_GuiCtrlRichEdit_Deselect($RichEdit)
        _GUICtrlRichEdit_SetText($RichEdit, $DocHeader & $DocBody & $DocFooter)
        _GUICtrlRichEdit_ResumeRedraw($RichEdit)

        FileClose($file);
        PlayAlert($Sound);
        GUISetState(@SW_RESTORE)
        ToolTip ( StringMultiLine($Bubble,60) ,$WindowX+100 ,$WindowY+150 ,$from, 1, 5)
    EndIf

Sorry for the trouble!

Link to comment
Share on other sites

To update on this, I managed to crash AutoIt with large files... 1.5 meg. actually that's not large at all... Not sure if it's the box, the api or even by entire rtf buffer, a global string variable.. So I ended up limiting the number of line in the box, meaning I also used less string space in the global string.

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