UnitasEwokis

Save and load TreeView form ini

19 posts in this topic

Hi guys,

i'm playing GuildWars and so i wanted to create a TreeView-Checklist with all the things, one has unlocked for that game. Therefore i need to create a GUI with a TreeView with checkboxes. The content of the TreeView should be loaded form a file, and saved to this file. I searched for a solution, but didn't find anything helpful, except this one. But i need to save the TreeView too after changes were made.

My current TreeView looks like this, but there is a LOT of content to add, this is just for preview, who many subtrees i need.

CODE
; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author: pHoeniX

;

; Script Function:

; GW Checklist

;

; ----------------------------------------------------------------------------

#include <GUIConstants.au3>

#include <file.au3>

GUICreate("GW Checklist PvP",320,640, 100,100)

$menu = GuiCtrlCreateMenu("Menü")

$save = GuiCtrlCreateMenuItem("Speichern", $menu)

$load = GUICtrlCreateMenuItem("Laden", $menu)

$overview = GuiCtrlCreateTreeView(10,10, 300,600, BitOr($TVS_CHECKBOXES,$TVS_DISABLEDRAGDROP,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_HASBUTTONS)) ;

$runes = GuiCtrlCreateTreeViewItem("Runen", $overview)

$warrior_runes = GuiCtrlCreateTreeViewItem("Krieger", $runes)

$strength_runes = GuiCtrlCreateTreeViewItem("Stärke", $warrior_runes)

$strength_minor = GuiCtrlCreateTreeViewItem("kleine", $strength_runes)

$strength_major = GuiCtrlCreateTreeViewItem("große", $strength_runes)

$strength_superior = GuiCtrlCreateTreeViewItem("überlegene", $strength_runes)

$sword_runes = GuiCtrlCreateTreeViewItem("Schwertbeherrschung", $warrior_runes)

$sword_minor = GuiCtrlCreateTreeViewItem("kleine", $sword_runes)

$sword_major = GuiCtrlCreateTreeViewItem("große", $sword_runes)

$sword_superior = GuiCtrlCreateTreeViewItem("überlegene", $sword_runes)

$axe_runes = GuiCtrlCreateTreeViewItem("Axtbeherrschung", $warrior_runes)

$hammer_runes = GuiCtrlCreateTreeViewItem("Hammerbeherrschung", $warrior_runes)

$tactics_runes = GuiCtrlCreateTreeViewItem("Taktik", $warrior_runes)

$ranger_runes = GuiCtrlCreateTreeViewItem("Waldläufer", $runes)

$expertise_runes = GuiCtrlCreateTreeViewItem("Fachkenntnis", $ranger_runes)

$marksmanship_runes = GuiCtrlCreateTreeViewItem("Treffsicherheit", $ranger_runes)

$wilderness_runes = GuiCtrlCreateTreeViewItem("Überleben in der Wildnis", $ranger_runes)

$beast_runes = GuiCtrlCreateTreeViewItem("Tierbeherrschung", $ranger_runes)

$monk_runes = GuiCtrlCreateTreeViewItem("Mönch", $runes)

$divine_runes = GuiCtrlCreateTreeViewItem("Gunst der Götter", $monk_runes)

$healing_runes = GuiCtrlCreateTreeViewItem("Heilgebete", $monk_runes)

$protection_runes = GuiCtrlCreateTreeViewItem("Schutzgebete", $monk_runes)

$smite_runes = GuiCtrlCreateTreeViewItem("Peinigungsgebete", $monk_runes)

$necromancer_runes = GuiCtrlCreateTreeViewItem("Nekromant", $runes)

$mesmer_runes = GuiCtrlCreateTreeViewItem("Mesmer", $runes)

$elementalist_runes = GuiCtrlCreateTreeViewItem("Elementarmagier", $runes)

$assassin_runes = GuiCtrlCreateTreeViewItem("Assassine", $runes)

$ritualist_runes = GuiCtrlCreateTreeViewItem("Ritualist", $runes)

$paragon_runes = GuiCtrlCreateTreeViewItem("Paragon", $runes)

$dervish_runes = GuiCtrlCreateTreeViewItem("Derwisch", $runes)

$skills = GuiCtrlCreateTreeViewItem("Fertigkeiten", $overview)

$warrior_skills = GuiCtrlCreateTreeViewItem("Krieger", $skills)

$strenght_skills = GuiCtrlCreateTreeViewItem("Stärke", $warrior_skills)

$strenght_skills_elite = GuiCtrlCreateTreeViewItem("Elite", $strenght_skills)

$bulls_charge = GuiCtrlCreateTreeViewItem("Angriff des Bullen", $strenght_skills_elite)

$defy_pain = GuiCtrlCreateTreeViewItem("Schmerz trotzen", $strenght_skills_elite)

$strenght_skills_non = GuiCtrlCreateTreeViewItem("Normale", $strenght_skills)

$i_will_avenge_you = GuiCtrlCreateTreeViewItem("Ich werde euch rächen", $strenght_skills_non)

$bersercer_stance = GuiCtrlCreateTreeViewItem("Berserker-Haltung", $strenght_skills_non)

$sword_skills = GuiCtrlCreateTreeViewItem("Schwert", $warrior_skills)

$axe_skills = GuiCtrlCreateTreeViewItem("Axt", $warrior_skills)

$hammer_skills = GuiCtrlCreateTreeViewItem("Hammer", $warrior_skills)

$tactics_skills = GuiCtrlCreateTreeViewItem("Taktik", $warrior_skills)

$ranger_skills = GuiCtrlCreateTreeViewItem("Waldläufer", $skills)

$upgrades = GuiCtrlCreateTreeViewItem("Aufrüstungen", $overview)

GUISetState (@SW_SHOW)

While 1

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

Exit

ElseIf $msg = $save Then

;;;; save function ;;;;

ElseIf $msg = $load Then

;;;; load function ;;;;

EndIf

WEnd

And is it possible, that a box is automatically checked, if all subboxes are checked? Or that all subboxes get checked, if a box is checked?

Would be very nice, if anyone had an idea, how to solve this.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I suggest you to use plain TXT file instead of INI.

At each line will be one line from TreeView precceded with number of @TAB chars correspond to level of treeview item.

Such TXT can be also easy edited by hand when needed.

Here is code snippet for load/save such treeview from my very old Delphi project for show/edit family tree:

procedure TForm1.FormCreate(Sender: TObject);
var
  Pole : array[0..255] of TTreeNode;
  Memo: TMemo;
  Radek: string;
  I, Level: Integer;
begin
  Memo := TMemo.Create (self);
  Memo.Parent := self;
  Memo.Visible := false;
  Memo.Width := 1000;
  Memo.Lines.LoadFromFile ('rodokmen.txt');
  Self.Caption := Memo.Lines[0];
  Application.Title := Memo.Lines[0];

  for I := 2 to Memo.Lines.Count - 1 do begin
    Radek := Memo.Lines[I];
    Level := 1;
    while Radek[Level] = #9 do Inc(Level);
    Dec(Level);
    Radek := Trim(Radek);
    if Level = 0 then
      Pole[Level] := TreeView1.Items.Add (nil, Radek)
    else
      Pole[Level] := TreeView1.Items.AddChild (Pole[Level-1], Radek);
  end; {for}
  Memo.Free;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var CurItem: TTreeNode;
    Memo: TMemo;
    S : string;
begin
  Memo := TMemo.Create (self);
  Memo.Parent := self;
  Memo.Visible := false;
  Memo.Width := 1000;
  Memo.Lines.Add(Self.Caption);
  Memo.Lines.Add('');

  CurItem := TreeView1.Items.GetFirstNode;
  while CurItem <> nil do
  begin
    SetLength(S,CurItem.Level);
    FillChar(S[1],CurItem.Level,#9);
    Memo.Lines.Add(S + CurItem.Text);
    CurItem := CurItem.GetNext;
  end;
  try
    Memo.Lines.SaveToFile ('rodokmen.txt');
  except
    on Exception do; {ignoruje jakoukoli chybu a nedela nic}
  end; {try}
  Memo.Free;
end;

For Treeview operations (get level, etc.) use Auto3Lib library from PauliA

EDIT: here is link about that

Edited by Zedna

Share this post


Link to post
Share on other sites

Sry, but i can't read Delphi, but i'll try to get the other link to work. But i have enormous problems, 'cause I'm using the german version of Windows and a lot of scripts aren't working.

Share this post


Link to post
Share on other sites

I haven't too much time to write it for you from scratch.

So make some start, post your code here and describe concrete problems.

Then somebody surely will help you ...

That shouldn't sound ungrateful. Sry, i you missunderstood me, i'm glad for your answer.

Share this post


Link to post
Share on other sites

That shouldn't sound ungrateful. Sry, i you missunderstood me, i'm glad for your answer.

Just in case you didn't find an answer yet, I wanted to let you know that I'll be releasing an update to Auto3Lib shortly that will have SaveToFile and LoadFromFile methods for TreeViews. Might release this later on today depending on how the final testing goes.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Just in case you didn't find an answer yet, I wanted to let you know that I'll be releasing an update to Auto3Lib shortly that will have SaveToFile and LoadFromFile methods for TreeViews. Might release this later on today depending on how the final testing goes.

Dude, that would be just too great. :P Thx in advance, i'm looking forward to the final release.

Share this post


Link to post
Share on other sites

Just in case you didn't find an answer yet, I wanted to let you know that I'll be releasing an update to Auto3Lib shortly that will have SaveToFile and LoadFromFile methods for TreeViews. Might release this later on today depending on how the final testing goes.

Hey PauliA you are the KING :P

Could you add this Save/Load also for ListView and ListBox? I'm just now working on application for general copy data from external TreeView/ListView/Listbox controls (user clicks on them) and save it to Clipboard/File in plain TXT format (Tab delimited), ListView also with column names.

I can make it myself but take it as idea for your great Library :D

Share this post


Link to post
Share on other sites

Hey PauliA you are the KING :P

Could you add this Save/Load also for ListView and ListBox? I'm just now working on application for general copy data from external TreeView/ListView/Listbox controls (user clicks on them) and save it to Clipboard/File in plain TXT format (Tab delimited), ListView also with column names.

I can make it myself but take it as idea for your great Library :D

I put out the new release. Let me know if you have any questions/problems. I'll put the Save/Load functions on "The List" for the next releases :) Check the TreeView demo out to see if this type of save format is acceptable for the other controls.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Hi, the save function works great, but i have problems with the load funtion.

It doesn't work, not even in your example (TreeView2.au3). Always, i'm clicking [Load] it crashes with message "_TreeView_LoadFromFile: -4"

Share this post


Link to post
Share on other sites

Hi, the save function works great, but i have problems with the load funtion.

It doesn't work, not even in your example (TreeView2.au3). Always, i'm clicking [Load] it crashes with message "_TreeView_LoadFromFile: -4"

I see the problem. I'll put out a fix for this in the next release. If this is something you need immediately, PM me and I'll send you the patched code.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

... in the next release.

If this is something you need immediately...

Depends on, how the next release will be ;-)

I have to implement all the content, so i need time anyways.

Edited by UnitasEwokis

Share this post


Link to post
Share on other sites

I put out the new release. Let me know if you have any questions/problems. I'll put the Save/Load functions on "The List" for the next releases :P Check the TreeView demo out to see if this type of save format is acceptable for the other controls.

Thanks PaulIA

For my purposes I will make my own format. But your way is good in it's generality. So by me your format could be used also for other controls.

Only one thing: when you make code for item states you may then code also item level directly to number instead of several spaces but it's subjective. I prefer several tabs but maybe in your code it could be the same as other item properties.

Share this post


Link to post
Share on other sites

Thanks PaulIA

For my purposes I will make my own format. But your way is good in it's generality. So by me your format could be used also for other controls.

Only one thing: when you make code for item states you may then code also item level directly to number instead of several spaces but it's subjective. I prefer several tabs but maybe in your code it could be the same as other item properties.

Actually, I did the layout that way so that you could open the file and view the contents with the level indention. Sort of a visual representation of the TreeView in text format. I figured this would be easiest for the n00bs to debug. If I'd have done this for myself, the file would have been in binary format.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Only one thing: when you make code for item states you may then code also item level directly to number instead of several spaces but it's subjective. I prefer several tabs but maybe in your code it could be the same as other item properties.

I read the items in and out with a trailing "#" and spaces, based on an idea from valuater.

That makes it easy to identify the level (stringInStr) and also to edit in an editor or editorbox. The Treeview I need mainly for PDF handling. With above format it is easy to read Adobes PDF bookmarks out and in, with some translations for the different programms, which can be used to influence(read/write) PDF bookmarks.

However, thank for your work on this item, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites

Zedna, thank very much, I was looking for this wich xml, but having problems on load xml. So this will help me a lot.

regards from Blumenau, SC, Brazil.

Share this post


Link to post
Share on other sites

FlavioBlumenau,

Welcome to the AutoIt forums.

Did you notice that the post above yours in this thread dates from some 9 years ago?

Please do not necro-post like this again - particularly just to say "thanks". If you have a similar question just open a new thread and link to the old one if it is absolutely necessary for understanding the problem. We ask you to do this for two main reasons:

  1. The language advances and the functionality might well be included in core or UDF code by now.
  2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.

Thanks in advance for your cooperation.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

*looks left ...*looks right* ...

 

PARTIES IN THE UNLOCKED NECROTHREAD LIKE A ZOMBIE!


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Sigh,

I thought that posting in, but not locking, the thread would be sufficient - obviously zombies (particularly of the blue-winged type) cannot take a hint. And so.....

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.