Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP!!]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP!!]

Post by ositoMalvado » 08 Dec 2022, 11:53

Hi guys, the same as title, and what i need explained in comments into code, also u can copy/paste run and try it to watch what i mean

Code: Select all

Gui, Add, ListView, x5 y5 vlv1 r20 w160 gMyListView,ToAdd ;left listview
Gui, Add, ListView, x170 y5 vlv2 r20 w160 gMyListView,Added ;right listview
Gui, ListView, lv1 ;selecting left listview

global RandomStrings:={} ;new array for test
Loop, 20{ ;setting array
    i:=A_Index
    Random, quant, 3, 8
    Loop, % quant{
        Random, rand, 0, 9
        RandomStrings[i]:=RandomStrings[i] rand
    }
} ;end setup array

Loop, % RandomStrings.MaxIndex(){ ;adding items to the left list
    LV_Add(1, RandomStrings[A_Index])
}

LV_ModifyCol(1,"160 Left") ;fix size lv1
Gui, ListView, lv2 ;selecting right listview
LV_ModifyCol(1,"160 Left") ;fix size lv2
Gui, ListView, lv1 ;return to main listview
Gui, Show ;showing gui

return ;end init

MyListView:
if (A_GuiEvent = "DoubleClick") ;   when i double click any item,
;                                  i want to move to the other list
;                                   and vice versa
;                                   i get some, but it is buggy, not working well
;                                   need help here please
{
    LV_GetText(RowText, A_EventInfo)
    if (RowText=="ToAdd"||RowText=="Added"||RowText=="")
        Return
    ToolTip You double-clicked row number %A_EventInfo%. Text: "%RowText%"
    LV_Delete(A_EventInfo)
    if(A_GuiControl=="lv1"&&RowText!=""){
        Gui, ListView, lv2
        LV_Add(2, Rowtext)
        Gui, ListView, lv1
    }else{
        Gui, ListView, lv1
        LV_Add(1, Rowtext)
        Gui, ListView, lv2
    }
}
return

GuiClose:  
ExitApp

My WEB some useful stuff

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP

Post by flyingDman » 08 Dec 2022, 12:59

Does this work?:

Code: Select all

Gui, Add, ListView, x5 y5 vlv1 r20 w160 gMyListView,ToAdd 								;left listview
Loop, 20
    {
	str := ""
	Random, quant, 3, 8
    Loop, % quant
		{
		Random, rand, 0, 9
		str .= rand
		}
	LV_add("",str)
	} 																					;end setup array
LV_ModifyCol(1,"160 Left") 																;fix size lv1
Gui, Add, ListView, x170 y5 vlv2 r20 w160 gMyListView,Added 							;right listview
LV_ModifyCol(1,"160 Left") 																;fix size lv2
Gui, Show 																				;showing gui
return 																					;end init

MyListView:
GuiControlGet, oVar, Focus
Gui, ListView, % oVar = "SysListView321" ? "lv1" : "lv2"
if (A_GuiEvent = "DoubleClick")
	{
    LV_GetText(RowText, A_EventInfo)
	if !(RowText=="ToAdd"||RowText=="Added"||RowText=="")
		{
		LV_Delete(A_EventInfo)
		Gui, ListView, % oVar = "SysListView321" ? "lv2" : "lv1"
        LV_Add("", Rowtext)
		}
	}
return

GuiClose:
ExitApp
Edit: simplified some more
Edit: I do not believe you need if !(RowText=="ToAdd"||RowText=="Added"||RowText==""). You can simplify some more.
Note: if you have other listviews in the gui - i.e. other than SysListView321 and SysListView322, you'll need to make sure that you identify the correct ones.
14.3 & 1.3.7

User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

Re: Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP

Post by ositoMalvado » 08 Dec 2022, 14:54

@flyingDman
It worked perfectly, I done my script to make easily any PROMPT to create with stable diffusion/midjourney/dalle2, etc.
Just type what u want to write and add prompts u want, you can generate the final prompt and use it to generate AI artwork, or just save it to a txt file

U CAN USE "F1" TO POPUP GUI GENERATOR

U CAN USE RIGHT CLICK ON TRAY ICON TO MODIFY PROMPTS U WANT TO APPEAR, GENERATE PROMPTS, OPEN PROMPT SAVED FOLDER AND EXIT.

First i made it Spanish version, so quickly moded it to do english ver for all who read this, thanks for all.

HERE ARE THE PROMPTS
https://lithi.io/file/pD4O.ahk

Code: Select all

#Persistent
#SingleInstance, force
SetTitleMatchMode, 2
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
SetWorkingDir, A_WorkingDir
Menu, Tray, NoStandard
Menu, Tray, Add,Make Prompt,crearGui
Menu, Tray, Add,Setup Prompts,PROMPTS
Menu, Tray, Add,Open Saved Prompts,openFolderPrompt
Menu, Tray, Add
Menu, Tray, Add,Exit,Exit
Menu, Tray, Tip,Prompt Generator
Gui, Add, Text, x5 y5, Type something:
Gui, Add, Checkbox, x220 y5 vCheckb1, Strenght (:100)?
Gui, Add, Edit, x5 vPromptGui w325
Gui, Add, ListView, x5 y50 vlv1 r20 w160 gMyListView,Prompts 		
global saving:=false
Loop, Read, % A_scriptdir "\prompts.txt"
{
   LV_add("",A_LoopReadLine)
} 																					;end setup array
LV_ModifyCol(1,"160 Left") 																;fix size lv1
Gui, Add, ListView, x170 y50 vlv2 r20 w160 gMyListView,Added prompts 							;right listview
LV_ModifyCol(1,"160 Left") 																;fix size lv2
Gui, add, button, gSubGui x5 y430, Generate PROMPT
Gui, add, button, gSave x220 y430, Save PROMPT
If !FileExist(A_scriptdir "\saved")
   FileCreateDir, % A_scriptDir "\saved"
global men
if !FileExist(A_scriptDir "\prompts.txt")
   UrlDownloadToFile, https://lithi.io/file/pD4O.ahk, % A_scriptDir "\prompts.txt"
return 																					;end init

Save:
   saving:=true
   gosub, SubGui
   men2:=men
   if men==""||men2==""
      Return
   Loop, parse, % men2, % "||"
   {
      men2:=A_LoopField
      Break
   }
   finalDir:=A_scriptdir "\saved\" A_YYYY "-" A_MM "-" A_DD "_" men2 ".txt"
   if men!=""
      FileAppend, %men%, % finalDir
   ToolTip, Saved!!!
   SetTimer, tolkill, 1000
Return

tolkill:
   ToolTip
Return
Exit:
ExitApp

crearGui:
   Gui, Show, xCenter yCenter,Prompt Generator
Return

ocultar:
   Gui, Submit, Hide
Return

openFolderPrompt: 
   Run , % A_scriptdir "\saved"
Return

PROMPTS:
   Run, % A_ScriptDir "\prompts.txt"
Return

f1::
   gosub, crearGui
Return

SubGui:
   Gui, Submit, Nohide
   If (PromptGui=="")
      return
   Gui, ListView, lv2
   men:=""
   Loop, % LV_GetCount(){
      LV_GetText(tempvar, A_Index)
      men.=A_Index==1? tempvar : ", " tempvar
   }
   men:=Checkb1==1?PromptGui ":100 || " men:PromptGui " || " men
   clipboard:=men
   if !saving
      MsgBox,, Exito!, Done! Prompt saved to CLIPBOARD, press Ctrl+V to paste generated PROMPT`n`n%men%
   Else
      saving:=false
Return

MyListView:
   GuiControlGet, oVar, Focus
   Gui, ListView, % oVar = "SysListView321" ? "lv1" : "lv2"
   if (A_GuiEvent = "DoubleClick")
   {
      LV_GetText(RowText, A_EventInfo)
      if (RowText=="Prompts"||RowText=="Added Prompts"||RowText=="")
         Return
      LV_Delete(A_EventInfo)
      if(A_GuiControl=="lv1"&&RowText!=""){
         Gui, ListView, lv2
         LV_Add(2, Rowtext)
         Gui, ListView, lv1
      }else{
         Gui, ListView, lv1
         LV_Add(1, Rowtext)
         Gui, ListView, lv2
      }
   }
return

GuiClose:
ExitApp

GoogleTranslate(str, from := "auto", to := "en") {
   static JS := CreateScriptObj(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")

   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1]) {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   static http
   ComObjError(false)
   if !http
   {
      http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
      ( proxy && http.SetProxy(2, proxy) )
      http.open("GET", "https://translate.google.com", true)
      http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
      http.send()
      http.WaitForResponse(-1)
   }
   http.open("POST", "https://translate.googleapis.com/translate_a/single?client=gtx"
   ; or "https://clients5.google.com/translate_a/t?client=dict-chrome-ex"
   . "&sl=" . sl . "&tl=" . tl . "&hl=" . tl
   . "&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=0&ssel=0&tsel=0&pc=1&kc=1"
   . "&tk=" . JS.("tk").(str), true)

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
Return http.responsetext
}

URIEncode(str, encoding := "UTF-8") {
   VarSetCapacity(var, StrPut(str, encoding))
   StrPut(str, &var, encoding)

   while code := NumGet(Var, A_Index - 1, "UChar") {
      bool := (code > 0x7F || code < 0x30 || code = 0x3D)
      UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
   }
Return UrlStr
}

GetJScript()
{
   script =
   (
   var TKK = ((function() {
      var a = 561666268;
      var b = 1526272306;
      return 406398 + '.' + (a + b);
   })());

   function b(a, b) {
      for (var d = 0; d < b.length - 2; d += 3) {
         var c = b.charAt(d + 2),
      c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
      c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
      a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
   }
return a
}

function tk(a) {
   for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
      var c = a.charCodeAt(f);
   128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ?
   (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240,
   g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
}
a = h;
for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
   a = b(a, "+-3^+b+-f");
a ^= Number(e[1]) || 0;
0 > a && (a = (a & 2147483647) + 2147483648);
a `%= 1E6;
return a.toString() + "." + (a ^ h)
}
)
Return script
}

CreateScriptObj() {
   static doc, JS, _JS
   if !doc {
      doc := ComObjCreate("htmlfile")
      doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
      JS := doc.parentWindow
      if (doc.documentMode < 9)
         JS.execScript()
      _JS := ObjBindMethod(JS, "eval")
   }
Return _JS
}
My WEB some useful stuff

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP

Post by flyingDman » 09 Dec 2022, 01:01

This seems to have little to do with the topic of the thread. You should create a new thread / topic.
14.3 & 1.3.7

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Help with 2 listviews, i want items from 1st listview move to 2nd listview and vice versa, with double click!! [HELP

Post by BoBo » 09 Dec 2022, 01:05

flyingDman wrote:
09 Dec 2022, 01:01
This seems to have little to do with the topic of the thread. You should create a new thread / topic.
FYI. Topic has been split for that reason.
Rgds,
Bo

Newly created/separated topic/thread: viewtopic.php?f=76&t=111344

Post Reply

Return to “Ask for Help (v1)”