Sign in to follow this  
Followers 0
gseller

Dynamic Tab Creation From an ini

8 posts in this topic

#1 ·  Posted (edited)

Hey All, I wanted to post my first contribution. This will create Tabs in a GUI from the sections in an ini file. I hope this will be of use to someone. I searched all over and could not find anything on it. I did get some ideas and thank you to masonje found here: Dynamic Button Creation... Thank You masonje

Here is the file to try out DynamicTabsFromINI.au3

Feedback would be Greatly Apreciated...

#include <GUIConstants.au3>
  
  $iniFile = @ScriptDir & "\IP.ini";Reads ini file in general
  $iniSections = IniReadSectionNames($iniFile);Reads ini section names for tabs
  
  $seH = "5";horizontal positioning of each section in ini file
  $seL = "5";vertical positioning of each section in ini file
  ;Creating the GUI
  $GUIForm = GUICreate("GUI Name", 633, 447, 193, 115)
  $Group1 = GUICtrlCreateGroup("Your Group Box", 16, 16, 601, 417, -1, $WS_EX_TRANSPARENT)
  $Tab1 = GUICtrlCreateTab(25, 48, 583, 377)
  GUICtrlSetState(-1,$GUI_SHOW)
  GUICtrlCreateTabItem("")
  GUICtrlCreateGroup("", -99, -99, 1, 1)
  GUISetState(@SW_SHOW)
  
  If @error Then
       MsgBox(4096, "", "Error occurred, probably no INI file.");Shows error if there is no ini file
  Else
  
       For $i = 1 To $iniSections[0];Setting up the dynamic tabs
           if $iniSections[$i] <> "Setup" then
               $tabName = $iniSections[$i]
               GUICtrlCreateTab($tabName, $seH + 15, $seL * 110,$WS_MAXIMIZE,$WS_EX_TRANSPARENT )
  $tab0=GUICtrlCreateTabitem ($tabName)
           EndIf
       Next
  EndIf
  
  GUISetState()
  While 1
       $msg = GUIGetMsg()
       Switch $msg
           Case $GUI_EVENT_CLOSE
               ExitLoop
              
       EndSwitch
  WEnd

Here is an example ini

[section 1]
        swt1=123.456.789.100
        swt1=123.456.789.101
        swt1=123.456.789.102
        swt1=123.456.789.103
        
        [section 2]
        swt1=123.456.789.100
        swt1=123.456.789.101
        swt1=123.456.789.102
        swt1=123.456.789.103
        
        [section 3]
        swt1=123.456.789.100
        swt1=123.456.789.101
        swt1=123.456.789.102
        swt1=123.456.789.103
Edited by gesller

Share this post


Link to post
Share on other sites



I think the idea is cool

In fact, I bet I could use this in a few places.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Haha Gesller,

I got a bit carried away

; Original http://www.autoitscript.com/forum/index.php?showtopic=46805
; Additions by JohnBailey (don't blame gesller for dumb ideas)

#include <GUIConstants.au3>
;#include <Array.au3>; here for testing purposes
 
Global $iniFile = FileOpenDialog('Open INI file',@ScriptDir,'INI (*.ini)'); Pick the Ini
If @error Then
    Exit
Endif
; $iniFile = @ScriptDir & "\IP.ini";Reads ini file in general
$iniSections = IniReadSectionNames($iniFile);Reads ini section names for tabs
$seH = "5";horizontal positioning of each section in ini file
$seL = "5";vertical positioning of each section in ini file

;Creating the GUI
$GUIForm = GUICreate("GUI Name", 633, 447, 193, 115)
$Group1 = GUICtrlCreateGroup("Your Group Box", 16, 16, 601, 417, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(25, 48, 583, 377)
GUICtrlSetState(-1,$GUI_SHOW)
GUICtrlCreateTabItem("")
GUICtrlCreateGroup("", -99, -99, 1, 1)
 
If @error Then
   MsgBox(4096, "", "Error occurred, probably no INI file.");Shows error if there is no ini file
Else
    For $i = 1 To $iniSections[0];Setting up the dynamic tabs
        If $iniSections[$i] <> "Setup" then
            $tabName = $iniSections[$i]
            GUICtrlCreateTab($tabName, $seH + 15, $seL * 110,$WS_MAXIMIZE,$WS_EX_TRANSPARENT )
            Local $tab0=GUICtrlCreateTabitem ($tabName)
            
            Local $iniReadSection2DArray = IniReadSection ($iniFile,$iniSections[$i])
            Local $2DArraySize = $iniReadSection2DArray[0][0]
            Local $a = GUICtrlCreateListView("Element|Value",150,100,300,300)
            Assign('LV_'&$i,$a,1); Allows this ListView to be referenced after the loop(s)
            For $x = 1 to $2DArraySize
                GUICtrlCreateListViewItem($iniReadSection2DArray[$x][0]&'|'&$iniReadSection2DArray[$x][1],Eval('LV_'&$i))
            Next
        EndIf
    Next
EndIf
GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
             
    EndSwitch
WEnd

example ini

[section 1]
swt1=123.456.789.100
swt1=123.456.789.101
swt1=123.456.789.102
swt1=123.456.789.103
        
[section 2]
swt2=123.456.789.104
swt2=123.456.789.105
swt2=123.456.789.106
swt2=123.456.789.107
        
[section 3]
User43=123.456.789.108
User85=123.456.789.109
Manuel=123.456.789.110
Marcus=123.456.789.111
Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites

Dynamic Tab Creation...

Well... Well...

And, for dynamic delete? How-to?

Share this post


Link to post
Share on other sites

Nice JohnBailey.. Just seen your post.. cool I like it...

Share this post


Link to post
Share on other sites

Looks like its been a year or so since this got noticed. I like the idea. Do you have a screen shot of it running. I don't think its compatible with the current version. I got the errors below. Can this be turned into an editor as well. I have an application in mind. Your help could jump start this for me.

Thanks

post-14267-1225739558_thumb.jpg

Share this post


Link to post
Share on other sites

Just missing some constants.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$iniFile = @ScriptDir & "\IP.ini";Reads ini file in general
$iniSections = IniReadSectionNames($iniFile);Reads ini section names for tabs

$seH = "5";horizontal positioning of each section in ini file
$seL = "5";vertical positioning of each section in ini file
;Creating the GUI
$GUIForm = GUICreate("GUI Name", 633, 447, 193, 115)
$Group1 = GUICtrlCreateGroup("Your Group Box", 16, 16, 601, 417, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(25, 48, 583, 377)
GUICtrlSetState(-1, $GUI_SHOW)
GUICtrlCreateTabItem("")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.");Shows error if there is no ini file
Else

    For $i = 1 To $iniSections[0];Setting up the dynamic tabs
        If $iniSections[$i] <> "Setup" Then
            $tabName = $iniSections[$i]
            GUICtrlCreateTab($tabName, $seH + 15, $seL * 110, $WS_MAXIMIZE, $WS_EX_TRANSPARENT)
            $tab0 = GUICtrlCreateTabItem($tabName)
        EndIf
    Next
EndIf

GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

Share this post


Link to post
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
Sign in to follow this  
Followers 0