Jump to content

edit control: GUI design and backup contents


atomman
 Share

Recommended Posts

I have a GUI with 2 multi-line edit controls, side by side. I have the left control docked top, left and bottom. Right control is docked top, right and bottom. I want a dragable separator between them which, when dragged horizontally, will make one edit control larger and the other smaller.

Other question, and more importantly...

I'm using the 2 edit controls to input a bunch of text and i want to backup the contents to 2 files (file1.txt, file2.txt), but i don't want to open them. I'm having trouble figuring out how to do this. I've looked at FileOpen, FileWrite, _FileCreate and _FileWriteLog. Basically a sequence like so:

contents of edit control changes

a trigger occurs (While Not WinActive($EditControl), Do...)

read contents (GUICtrlRead)

write contents to file on disk

And while i'm at it...

Is it possible to not have all the contents of an edit control highlighted when focus is lost, then regained?

OH! And another question regarding Koda if i may. Why does Koda insert these lines:

GUICtrlCreateGroup("", -99, -99, 1, 1)

I always delete them with no noticeable consequences, though i left them there in the code below.

Below i left out all the GUI styles because it messed up the post. The form is actually resizable though.

#include <GUIConstants.au3>

$Form = GUICreate("Form", 630, 458, -1, -1)
GUICtrlCreateGroup("", 0, 0, 317, 457)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER)
GUICtrlCreateLabel("TEXT", 10, 17, 29, 18)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Button_Save1 = GUICtrlCreateButton("Save", 46, 13, 53, 21, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Button_Copy1 = GUICtrlCreateButton("Copy", 102, 13, 53, 21, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Edit_TextEditor = GUICtrlCreateEdit("", 4, 40, 309, 413)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", 316, 0, 313, 457)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER)
GUICtrlCreateLabel("HTML", 323, 17, 31, 18)
GUICtrlSetResizing(-1, $GUI_DOCKTOP+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Button_Save2 = GUICtrlCreateButton("Save", 363, 13, 53, 21, 0)
GUICtrlSetResizing(-1, $GUI_DOCKTOP+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Button_Copy2 = GUICtrlCreateButton("Copy", 419, 13, 53, 21, 0)
GUICtrlSetResizing(-1, $GUI_DOCKTOP+$GUI_DOCKHCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$Edit_HtmlEditor = GUICtrlCreateEdit("", 320, 40, 305, 413)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button_Save1
Case $Button_Copy1
Case $Button_Save2
Case $Button_Copy2
EndSwitch
WEnd
Edited by atomman
Link to comment
Share on other sites

How are you going to write to a file without opening it?

Simply close it after you are done writing each time.

Or consider iniwrite() as an alternative.. however that is simply opening and closing the file in the background for you.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Preforming the file operations in the background is fine. I just want the operation hidden from my view. IniWrite doesn't seem to work very well though because it duplicates some entries and leaves some tags ( =, [] ). The text in my edit controls could be just like any text you'd see in a forum post. I'm looking for a way to save it to disk in the event my script bombs.

Link to comment
Share on other sites

I use an "auto save" feature in one of my progs.

However, I do this only every minute.

AdlibEnable("_AutoSave", 60000);this is right before my main loop

Func _AutoSave()
        $Temp = @ScriptDir &"\files\Auto_Save.txt"
        FileDelete($Temp)
        FileWrite($Temp, GUICtrlRead($Edit_Box))
EndFunc

All this happens while I work, and I'm none the wiser.

Link to comment
Share on other sites

I want a dragable separator between them which, when dragged horizontally, will make one edit control larger and the other smaller.

By the way, I'm sure there is a really effective and difficult way of doing this, but...

I once used a slider control to do the same thing. It's simple but undesirable, I'm sure.

;This example works with a GUI that does not resize.
;Otherwise, you will have to adjust with controlgetpos and possibly the windows position

#include <GUIConstants.au3>

$GUI = GUICreate ("Example", 500, 250, -1, -1)
$EditL = GUICtrlCreateEdit("Edit Left", 0, 0, 250, 230)
$EditR = GUICtrlCreateEdit("Edit Right", 250, 0, 250, 230)
$Slider = GUICtrlCreateSlider(0, 230, 500, 20, $TBS_NOTICKS)
GUICtrlSetLimit(-1, 500, 0)
GUICtrlSetData(-1, 250)

GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Slider
            $SPos = GUICtrlRead($Slider)
            $LPos = ControlGetPos($GUI, "", $EditL)
            $RPos = ControlGetPos($GUI, "", $EditR)
            ControlMove($GUI, "", $EditL, 0, 0, $SPos, 230)
            ControlMove($GUI, "", $EditR, $SPos, 0, 500-$SPos, 230)
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
Wend

GUIDelete ()

Exit

It's dirty... but will work.

Edited by The Ape
Link to comment
Share on other sites

Thanks for the help guys!

I figured out a dirty way of doing the saves, but i like yours better Ape.

_FileCreate(@ScriptDir & "\TEXT.txt")
_FileCreate(@ScriptDir & "\HTML.txt")
_FileWriteToLine(@ScriptDir & "\TEXT.txt", 1, $DataText, 1)
_FileWriteToLine(@ScriptDir & "\HTML.txt", 1, $DataHtml, 1)

Your using a slider to resize the edit controls caught my attention! Never saw anything like that before :) I'm very new to all this, so this is something else i can use to discover the possibilities. Thanks!

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