Announcement

Collapse
No announcement yet.

Image load

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Image load

    I have listbox and pictures folder.
    If i select some item on listbox it loads picture related to the given item.
    I have the following code to do that:

    Code:
    if ListBox.IsItemSelected("ListBox1", 1) then Image.Load("Image1", _SourceFolder .."\\"..INIFile.GetValue("PICS\\showpics.ini", "png", "1"));
    end
    if ListBox.IsItemSelected("ListBox1", 2) then Image.Load("Image1", _SourceFolder .."\\"..INIFile.GetValue("PICS\\showpics.ini", "png", "2"));
    end
    if ListBox.IsItemSelected("ListBox1", 3) then Image.Load("Image1", _SourceFolder .."\\"..INIFile.GetValue("PICS\\showpics.ini", "png", "3"));
    end
    and so on
    The showpics.ini file contains a lot of lines may be 100-500...
    I would like to make short code to do the same action as shown abowe
    ​Can I ask experts for help to make a short code please?

  • #2
    Have a look at what you can do with the listbox itself ... The listbox is populated with the list of files, I don't know what you are putting into the list box but it has two items, Text and Data. If you have populated it with a name of something, like the png file dexcription say CAT (the text element) and the data is say 6 you can get either back on selection then use the data to load the image.
    It might make it easier if you have a checked text box (Settings - CHECKBOX LIST) so you click the tick box for an item then step through the list of items to find the checked item. Read the value then open the image file.
    I've done something like this to pick a drive unit from a list, this does include fixed, removable and networked remote drives, click to select from the list box and then use that drive. I've chopped out the bits that might be of use to you.
    PHP Code:
    -- In the ONCHECK events tab
    -- Count the number of items
    local nCount 
    ListBox.GetCheckedCount("ListBox1"BST_CHECKED);
    -- 
    Check somethings selected
    if (nCount >= 0then
    -- Loop through the items
        local tChecked 
    ListBox.GetChecked("ListBox1"BST_CHECKED);
        for 
    1nCount do
    -- 
    Get the selected item
            local sFilePath 
    ListBox.GetItemText("ListBox1"tChecked[i]);
    -- 
    Just for this snippet do something with it which is display it in a text box
    -- In your case use the value to display the clicked file
            Input
    .SetText("Input1"sFilePath);
        
    end
    end​ 
    Not a solution to your request but a pointer to a way to do it without many individual enteries.

    Comment


    • #3
      Originally posted by Nickj View Post
      Have a look at what you can do with the listbox itself ... The listbox is populated with the list of files, I don't know what you are putting into the list box but it has two items, Text and Data. If you have populated it with a name of something, like the png file dexcription say CAT (the text element) and the data is say 6 you can get either back on selection then use the data to load the image.
      It might make it easier if you have a checked text box (Settings - CHECKBOX LIST) so you click the tick box for an item then step through the list of items to find the checked item. Read the value then open the image file.
      I've done something like this to pick a drive unit from a list, this does include fixed, removable and networked remote drives, click to select from the list box and then use that drive. I've chopped out the bits that might be of use to you.
      PHP Code:
      -- In the ONCHECK events tab
      -- Count the number of items
      local nCount 
      ListBox.GetCheckedCount("ListBox1"BST_CHECKED);
      -- 
      Check somethings selected
      if (nCount >= 0then
      -- Loop through the items
      local tChecked 
      ListBox.GetChecked("ListBox1"BST_CHECKED);
      for 
      1nCount do
      -- 
      Get the selected item
      local sFilePath 
      ListBox.GetItemText("ListBox1"tChecked[i]);
      -- 
      Just for this snippet do something with it which is display it in a text box
      -- In your case use the value to display the clicked file
      Input
      .SetText("Input1"sFilePath);
      end
      end​ 
      Not a solution to your request but a pointer to a way to do it without many individual enteries.
      Thank you for trying help me!
      I tried to make it as you show abowe but always without success.
      To load listbox i use this:
      Page on show
      PHP Code:
      local tFiles Folder.Find(_SourceFolder.."Install""*.exe"falsenil);
      tDirs File.Find("Install""*.exe"falsefalsenil);
      if 
      tDirs then
      for 1#tDirs do
      ListBox.AddItem("ListBox1"String.Mid(tDirs[i], String.ReverseFind(tDirs[i], ""false) + 1, -1), tDirs[i]);
      end
      end 


      To make ini file to show pics i use this:
      Page on show
      PHP Code:
      ​tFiles File.Find("PICS""*.png"falsefalsenil);
      if 
      tFiles then
      for 1#tFiles do
      INIFile.SetValue("PICS\\showpics.ini""png"itFiles[i]);
      end
      end 


      And finally showpics.ini looks like:
      [png]
      1=PICS\somename.png
      2=PICS\somename.png
      3=PICS\somename.png
      ...
      ​So i think its difficult to create the working code for that action, but i will try again.
      if I can't write a new working code, then I will use the old code, that's that.
      Thank you!

      Comment


      • #4
        Hi adam2014, you really should study more on your paths

        Try this adapted from my other example
        INI _Pics.apz

        Cheers

        Comment


        • #5
          Originally posted by colc View Post
          Hi adam2014, you really should study more on your paths

          Try this adapted from my other example

          Cheers
          Very nice code !
          I will use it in my project. Thank you!
          you really should study more on your paths
          Not only, I must study more than it

          But i don't understand what can it load images without creating ini file.
          I changed paths directory:
          PHP Code:
          ListBox.DeleteItem("ListBox1", -1);
          sFilename _SourceFolder.."\\Install\\select.ini"
          tFiles File.Find("Install""*.png"falsefalsenil);
          if 
          tFiles then
          for 1#tFiles do
          sPath String.SplitPath(tFiles[i]);
          PICS sPath.Filename
          INIFile
          .SetValue(sFilename"png"iPICS); --I didn't find ini file when i load the project, but it works fine!
          ListBox.AddItem("ListBox1", PICS,tFiles[i] );
          end
          end 
          There is one problem, since the listbox is filled with pictures from your code, then my code is filled with exe files from my code and it is not possible to use both in my main function of filling the listbox with exe files.
          So what i did, i moved all png files to folder "Install" where is all exe files located.
          I renamed all png files with the same name as exe files. For example stockfish_15.1.exe and stockfish_15.1.png

          ​Now i use only your code on page on show
          Second problem:
          if i select something from listbox to install i use this code on button install:
          PHP Code:
          local tChecked ListBox.GetChecked("ListBox1"BST_CHECKED);
          if 
          tChecked then
          for 1#tChecked do
          INIFile.SetValue("Install\\Install.ini""run"iListBox.GetItemText("ListBox1"tChecked[i]));
          end
          end 


          And it creates install.ini without extention like
          [run]
          1=Abrok_6.0
          2=Admete_1.5.0
          3=Ai_27.0_ad9b

          To use after it must be like this
          [run]
          1=Abrok_6.0.exe
          2=Admete_1.5.0.exe
          3=Ai_27.0_ad9b.exe​

          Now i am looking for solution.
          When Install.ini created out i must use bat script to add extention .exe in the end for each line
          After i must compare Install.ini with another ini file already created with switches keys, to make it like:
          [run]
          1=Abrok_6.0.exe /silent
          2=Admete_1.5.0.exe /s
          3=Ai_27.0_ad9b.exe /verysilent
          and so on.
          I have script and it works fine.

          Finally i will add the last command to install:

          PHP Code:
          _getArgs = function (s)
          assert(type(s) == 'string')
          local tRet = {};
          String.TrimLeft(snil);
          local nPos String.Find(s' ');
          if (
          nPos ~= -1then
          return String.Mid(s1, (nPos 1)), String.Mid(s, (nPos 1), -1);
          end
          return s;
          end
          --====
          File.RunEx = function (s)
          local sFileNamesArgs _getArgs(s);
          if 
          sArgs then
          File
          .Run("Install\"..sFileName, sArgs, "", SW_SHOWNORMAL, true);
          else
          File.Run("
          Install\"..sFileName, "", "", SW_SHOWNORMAL, true);
          end
          end
          --====
          tValueNames = INIFile.GetValueNames("
          Install\\Install.ini", "run");
          if tValueNames then
          for i = 1, #tValueNames do
          local sRun1 = INIFile.GetValue("
          Install\\Install.ini", "run", tValueNames[i]);
          if sRun1 ~= '' then File.RunEx(sRun1);
          end
          end
          end 
          So this code will install everything from install.ini from up till down

          So my question:
          Where is the way to creat install.ini as i mentioned abowe with .exe
          I cant figure out how and what to change here
          INIFile.SetValue("Install\\Install.ini", "run", i, ListBox.GetItemText("ListBox1", tChecked[i]));
          Just need add .exe in the end of all lines.
          I can do it but with bat cmd etc...​​

          Comment


          • #6
            adam2014,

            INIFile.SetValue("Install\\Install.ini", "run", i, ListBox.GetItemText("ListBox1", tChecked[i]));
            Just need add .exe in the end of all lines.​
            My friend you are trying to set the ini file values from the TEXT in the listbox where as I wrote the INI file from the onshow where you are searching for files in the directory

            when using split path - you can get Drive / Folder / Filename / Extension

            Try this - INI _EXEs.apz

            Comment


            • #7
              Originally posted by colc View Post
              adam2014,



              My friend you are trying to set the ini file values from the TEXT in the listbox where as I wrote the INI file from the onshow where you are searching for files in the directory

              when using split path - you can get Drive / Folder / Filename / Extension

              Try this - [ATTACH]n309858[/ATTACH]
              Thank you very much Colc!
              Your code is working great and i found it very usefull !
              So what i put this code to listbox on select
              PHP Code:
              tbSel ListBox.GetSelected("ListBox1");
              if 
              tbSel then
              sPicPath 
              ListBox.GetItemData("ListBox1"tbSel[1]);
              Image.Load("Image1"sPicPath);
              end 
              and this page on show
              PHP Code:
              ListBox.DeleteItem("ListBox1", -1);
              sFilename _SourceFolder.."\\Install\\select.ini"
              tFiles File.Find("Install""*.png"falsefalsenil);
              if 
              tFiles then
              for 1#tFiles do
              sPath String.SplitPath(tFiles[i]);
              PICS sPath.Filename
              INIFile
              .SetValue(sFilename"png"iPICS);
              ListBox.AddItem("ListBox1"PICS,tFiles[i] );
              end
              end 
              Images and *.exe files in the same folder "Install"

              Button Install uses this code
              PHP Code:
              local WSI ListBox.GetChecked("ListBox1"BST_CHECKED);
              if 
              not WSI then
              Dialog
              .TimedMessage("WSI""Please check something to install..."2000MB_ICONNONE);
              else
              --==========================
              local tUnChecked ListBox.GetChecked("ListBox1"BST_UNCHECKED);
              if 
              tUnChecked then
              for #tUnChecked, 1, -1 do
              ListBox.DeleteItem("ListBox1"tUnChecked[i]);
              end
              end
              --Make ini file to run installers and to load images
              local tChecked 
              ListBox.GetChecked("ListBox1"BST_CHECKED);
              if 
              tChecked then
              for 1#tChecked do
              INIFile.SetValue("Install\\wsi.ini""run"iListBox.GetItemText("ListBox1"tChecked[i])); --Ini file to run setups
              INIFile
              .SetValue("Install\\wsip.ini""run"iListBox.GetItemText("ListBox1"tChecked[i])); --Ini file to show pics during install
              INIFile
              .SetValue("Install\\wsin.ini""run"iListBox.GetItemText("ListBox1"tChecked[i])); --Ini file to show the setup names in progress bar during install
              end
              end
              --Make checked count to ProgressBar
              num_checked 
              ListBox.GetCheckedCount("ListBox1"BST_CHECKED);
              if 
              num_checked then
              INIFile
              .SetValue("Docs\\wsi.uci""PROG""SET"num_checked);
              end
              --Make and Run Batch file to customize file wsi.ini
              bud 
              RichText.GetText("WSI_INI"false);
              TextFile.WriteFromString("Docs\\WSI_INI.bat"budfalse);
              Application.Sleep(1000);
              Shell.Execute("Docs\\WSI_INI.bat""open"""""SW_HIDEtrue);
              -- 
              Find and replace the text
              contents 
              TextFile.ReadToString("Install\\wsi.ini");
              new_contents String.Replace(contents"[run].exe""[run]"true);
              TextFile.WriteFromString("Install\\wsi.ini"new_contentsfalse);
              -- 
              Find and replace the text
              contents 
              TextFile.ReadToString("Install\\wsip.ini");
              new_contents String.Replace(contents"[run].png""[run]"true);
              TextFile.WriteFromString("Install\\wsip.ini"new_contentsfalse);
              -- 
              Find and replace the text
              contents 
              TextFile.ReadToString("Install\\wsip.ini");
              new_contents String.Replace(contents"=""=Install"true);
              TextFile.WriteFromString("Install\\wsip.ini"new_contentsfalse);
              --
              Application.Sleep(500);
              File.Delete("Docs\\WSI_INI.bat"falsefalsefalsenil);
              Application.Minimize();
              Page.ClickObject("xButton1"); --reload listbox before going on
              Application
              .Sleep(1000);
              result DialogEx.Show("Dialog1"truenilnil);
              end 
              ​Dialog uses this code
              PHP Code:
              ​​Image.Load("Image1""Docs\\wsi.png");
              Progress.SetRange("Status"0INIFile.GetValue("Docs\\wsi.uci""PROG""SET"));
              --==
              _getArgs = function (s)
              assert(type(s) == 'string')
              local tRet = {};
              String.TrimLeft(snil);
              local nPos String.Find(s' ');
              if (
              nPos ~= -1then
              return String.Mid(s1, (nPos 1)), String.Mid(s, (nPos 1), -1);
              end
              return s;
              end
              --==
              File.RunEx = function (s)
              local sFileNamesArgs _getArgs(s);
              if 
              sArgs then
              File
              .Run("Install\"..sFileName, sArgs, "", SW_SHOWNORMAL, true);
              else
              File.Run("
              Install\"..sFileName, "", "", SW_SHOWNORMAL, true);
              end
              end
              --==
              tValueNames = INIFile.GetValueNames("
              Install\\wsi.ini", "run");
              tPngNames = INIFile.GetValueNames("
              Install\\wsip.ini", "run");
              tNames = INIFile.GetValueNames("
              Install\\wsin.ini", "run");
              if tValueNames then
              for i = 1, #tValueNames do
              nCurrentPos = Progress.GetCurrentPos("
              Status");
              Progress.SetText("
              Status", INIFile.GetValue(_SourceFolder .."\\Install\\wsin.ini", "run", tNames[i]));
              Image.Load("
              Image1", _SourceFolder .."\"..INIFile.GetValue("Install\\wsip.ini", "run", tPngNames[i]));
              local sRun1 = INIFile.GetValue("
              Install\\wsi.ini", "run", tValueNames[i]);
              if sRun1 ~= '' then File.RunEx(sRun1);
              Progress.SetCurrentPos("
              Status", nCurrentPos + 1);
              Application.Sleep(500);
              end
              end
              Image.Load("
              Image1", "Docs\\wsi.png");
              Progress.SetText("
              Status", "Completed!");
              File.Delete("
              Install\\*.ini");
              File.Delete("
              Docs\\*.uci");
              Application.Sleep(5000);
              end
              Application.Restore();
              result = DialogEx.Close(0); 
              Installs checked applications.
              Colc i will send you project later...
              Thank you!!!


              Comment

              Working...
              X