Jump to content

Saving a GUI


locutus243
 Share

Recommended Posts

I have made a GUI that has several places where the user can enter data. But everytime I open the GUI up then the information is obviously reset to how I specified in my code. (For example I have an input box which has a default value in, I can change the value once I open my GUI but it always reverts to the default when I run the code again.) Is there anyway to change the input boxes etc... and then save the changes in the GUI.

Thanks

Mark

(If I ain't explained this well enough then please let me know and I'll try and make it clearer, its nice you guys are looking at it, I'd hate someone to skate over it just because I cant explain myself properly!!)

Link to comment
Share on other sites

Quick answer is yes. You can save all the values to an ini file using the IniWrite() function and then when you start up your GUI again, read the control values back into your program (after your declarations and before you draw your GUI) using GUICtrlSetData() and IniRead().

Hope that made sense.

Link to comment
Share on other sites

Hi,

Thanks for looking at my post, I appreciate your time and help.

Sounds like your idea works but I'm struggling to put it together in code, a little lost of what goes where in the code to be honest.

I was wondering if it would be possible for anybody to post and example of using the 'IniRead' & 'IniWrite' functions with a Gui. I've looked in the Help Files but it doesn't have any examples of IniRead with Gui's and I have never used the function before, I think an example could be of great help.

Much appreciated

Mark

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate(" My GUI input acceptfile", 320,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateInput ( "", 10,  5, 300, 20)
GUICtrlSetState($file,$GUI_ACCEPTFILES)
GUICtrlSetData($file,IniRead("mydata.ini","files","file1","No File"))
$nofile = GUICtrlCreateInput ("", 10,  35, 300, 20); will not accept drag&drop files
GUICtrlSetData($nofile,IniRead("mydata.ini","files","file2","No File"))
$btn = GUICtrlCreateButton ("Ok", 40,  75, 60, 20)

GUISetState () 

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
       $msg = GUIGetMsg()
       Select
           Case $msg = $btn
                IniWrite("mydata.ini","files","file1",GUICtrlRead($file))
                IniWrite("mydata.ini","files","file2",GUICtrlRead($nofile))
               exitloop
       EndSelect
Wend

mydata.ini would consist of something like

[files]
file1=my file.dat
file2=your file.dat
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 5 weeks later...

Hey guys,

I've had a go at saving whats displayed on my Gui using IniRead and then loading the information when I run my Gui script again but its not loading the information. Also when I save to my .ini file it will only save the latest entry and I want it to save everything thats in my table!

(Its a table that you can amend and then the previous data should appear each time you load it!) Wondered if you could scan over my script and make any suggestions??

Cheers

Mark

#include <GuiConstants.au3>


$List = 0
$read = 112

; GUI
GuiCreate("Sample GUI", 800, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; LIST VIEW
$listView = GuiCtrlCreateListView("Sea|Comp|Katart|Pubn|Title|Start Date|JC Checks|Incoterms Checks|Payment Terms Check|Ready To Implement|", 10, 10, 715, 320)

GuiCtrlCreateLabel("Add a Publication", 10, 335)
$submit = GUICtrlCreateButton("Submit", 690, 340, 70, 30)
$save = GUICtrlCreateButton("Save", 600, 340, 70, 30)
$season = GUICtrlCreateInput("Sea", 10, 355, 40, 20)
$comp = GUICtrlCreateInput("Co", 60, 355, 40, 20)
$kat = GUICtrlCreateInput("Katart", 110, 355, 45, 20)
$Pubn = GUICtrlCreateInput("Pubn", 165, 355, 45, 20)
$Tit = GUICtrlCreateInput("Title", 210, 355, 150, 20)
$Stardate = GUICtrlCreateInput("Start Date", 370, 355, 100, 20)

GUICtrlSetData($List,IniRead("c:\mydata.ini","files","file1",""))

; GUI MESSAGE LOOP
GuiSetState()

While 1
    $sub = GUIGetMsg()
    Select
        Case $sub = -3 Or $sub = -1
            ExitLoop
        Case $sub = $submit
            $read1 = GuiCtrlRead($season)
            $read2 = GuiCtrlRead($comp)
            $read3 = GuiCtrlRead($kat)
            $read4 = GuiCtrlRead($Pubn)
            $read5 = GuiCtrlRead($Tit)
            $read6 = GuiCtrlRead($Stardate)
            
            $List = GuiCtrlCreateListViewItem($read1 & "|" & $read2 & "|" & $read3 & "|" & $read4 & "|" & $read5 & "|" & $read6, $listView)
            GUISetState()
        Case $sub = $save
            MsgBox(0, "TEST", GuiCtrlRead($List))
            IniWrite("c:\mydata.ini","files","file1",GUICtrlRead($List))
            GUISetState()
    EndSelect
WEnd

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Link to comment
Share on other sites

I created an application which is very similar to that. I'm unsure if there is a better way or not (probably there is)...but as the items get added to the listbox, I am also writing them to the ini file. That way when the application closes, you don't have to read all of the current values in your listbox.

Likewise, if you later create a "remove" button, you can have it search for the line in the ini file and remove it just as easily. This way, your listbox is always in sync with the file. Let me know if you would like to see a sample. I'd post it now, but i'm not at home. :P

Hey guys,

I've had a go at saving whats displayed on my Gui using IniRead and then loading the information when I run my Gui script again but its not loading the information. Also when I save to my .ini file it will only save the latest entry and I want it to save everything thats in my table!

(Its a table that you can amend and then the previous data should appear each time you load it!) Wondered if you could scan over my script and make any suggestions??

Cheers

Mark

#include <GuiConstants.au3>
$List = 0
$read = 112

; GUI
GuiCreate("Sample GUI", 800, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; LIST VIEW
$listView = GuiCtrlCreateListView("Sea|Comp|Katart|Pubn|Title|Start Date|JC Checks|Incoterms Checks|Payment Terms Check|Ready To Implement|", 10, 10, 715, 320)

GuiCtrlCreateLabel("Add a Publication", 10, 335)
$submit = GUICtrlCreateButton("Submit", 690, 340, 70, 30)
$save = GUICtrlCreateButton("Save", 600, 340, 70, 30)
$season = GUICtrlCreateInput("Sea", 10, 355, 40, 20)
$comp = GUICtrlCreateInput("Co", 60, 355, 40, 20)
$kat = GUICtrlCreateInput("Katart", 110, 355, 45, 20)
$Pubn = GUICtrlCreateInput("Pubn", 165, 355, 45, 20)
$Tit = GUICtrlCreateInput("Title", 210, 355, 150, 20)
$Stardate = GUICtrlCreateInput("Start Date", 370, 355, 100, 20)

GUICtrlSetData($List,IniRead("c:\mydata.ini","files","file1",""))

; GUI MESSAGE LOOP
GuiSetState()

While 1
    $sub = GUIGetMsg()
    Select
        Case $sub = -3 Or $sub = -1
            ExitLoop
        Case $sub = $submit
            $read1 = GuiCtrlRead($season)
            $read2 = GuiCtrlRead($comp)
            $read3 = GuiCtrlRead($kat)
            $read4 = GuiCtrlRead($Pubn)
            $read5 = GuiCtrlRead($Tit)
            $read6 = GuiCtrlRead($Stardate)
            
            $List = GuiCtrlCreateListViewItem($read1 & "|" & $read2 & "|" & $read3 & "|" & $read4 & "|" & $read5 & "|" & $read6, $listView)
            GUISetState()
        Case $sub = $save
            MsgBox(0, "TEST", GuiCtrlRead($List))
            IniWrite("c:\mydata.ini","files","file1",GUICtrlRead($List))
            GUISetState()
    EndSelect
WEnd

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
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...