Adding titles, images, and files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

04 Sep 2020, 02:48

To no avail, here is the entire code. Please help find any errors I'm not seeing.. Thank you.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance,Force

OnExit, UpdateFile

SelectedRow := 0

Gui +AlwaysOnTop +resize
Gui, Show, x100 y100 w500 h500

Gui, Add, ListView, sort -ReadOnly grid x10 y5  h360 w400 +hscroll vMyListView gMyListview, Title 
| Year | Image | Movie URL
Gui, Add, Button, section gAddItem, Add Movie Title
Gui, Add, Text, w52 section , Movie Title
Gui, Add, Edit, w100 ys vTitle1 hwndOne
SetEditCueBanner(One, "Title")
Gui, Add, Text, ys, Year
Gui, Add, Edit, w150 ys vYear1 hwndTwo
SetEditCueBanner(Two, "Year")

pathToPic := ""
GUI Add, Button, w65 ys gpushPic, Add Image 
Gui, Add, Picture, w65 h100 ys vNewVar hwndThree, %Newvar%

pathToMovie := ""
GUI Add, Button, w65 ys gpushMovie, Select Movie File 
Gui, Add, edit, w65 h100 ys vplaymovie hwndFour, %playmovie%
Gui, Add, Button, Hidden Default, CLICK

IconWidth    :=  2
IconHeight   := 50
IconBitDepth := 24 ;
InitialCount :=  1 ; The starting Number of Icons available in ImageList
GrowCount    :=  1

ImageListID := DllCall( "ImageList_Create", Int,IconWidth,    Int,IconHeight
                                          , Int,IconBitDepth, Int,InitialCount
                                          , Int,GrowCount )

LV_SetImageList( ImageListID, 1 ) ; 0 for large icons, 1 for small icons

IfExist, MovieList.txt ;Add data from MovieList.txt to ListView
{
	;FileCopy, MovieList.txt, MovieList%A_Now%.txt  ;incremental backup
	Loop, Read, MovieList.txt
	{
		If (A_index = 1 and SubStr(A_LoopReadLine, 1, 1) = "x")
		{
			WinPos := A_LoopReadLine
			Continue
		}
		Else
		{
			Loop, Parse, A_LoopReadLine , CSV
			{
				RowData%A_Index% := A_LoopField
			}
			
			LV_Add("", RowData1,RowData2,RowData3,RowData4)
		}
	}
}


SizeCols()


Menu, MyContextMenu, Add, Edit, EditItem
Menu, MyContextMenu, Add, Delete, DeleteItem
Menu, Tray, Add, Show MovieList, ShowMovieList

IfExist, MovieList.txt
{
     Gui, Show, %WinPos% , MovieList
}
Else
{
     WinGetPos,X1,Y1,W1,H1,Program Manager
     X2 := W1-800
     Gui, Show, x%x2% y50 , MovieList
}


Hotkey, ^!a, ShowMovieList
Return

ShowMovieList:
Gui, Show,, MovieList
Return

MyListView:
If A_GuiEvent = e          ;Finished editing first field of a row
	LV_ModifyCol(2,"Sort")
If A_GuiEvent = ColClick   ;Clicked column header
{
      If A_EventInfo = 2    ;Number of column header clicked
        LV_ModifyCol(2,"SortDesc")
    }
    UpdateFile()
Return

GuiContextMenu:  ; Launched in response to a right-click or press of the Apps key.
if A_GuiControl <> MyListView  ; Display the menu only for clicks inside the ListView.
    Return
  LV_GetText(ColText, A_EventInfo,1)    ;Gather column data in string EditText
  EditText := ColText
  Loop 3
    {
      LV_GetText(ColText, A_EventInfo, A_Index+1)
      EditText := EditText . "|" . ColText
    }
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return

EditItem:          ;Move row from ListView columns into edit fields
  SelectedRow := LV_GetNext()
  StringSplit, RowData, EditText , |
  Loop, 9
    {
      GuiControl, , Rowdata%A_Index%
    }
  GuiControl, ,Button1, Update
Return

DeleteItem:         ;Deletes selected rows
MsgBox, 4100, Delete Movie?, Delete Movie? Click Yes or No?
IfMsgBox No    ;Don't delete
  Return
RowNumber = 0  ; This causes the first iteration to start the search at the top.
Loop
{
    ; Since deleting a row reduces the RowNumber of all other rows beneath it,
    ; subtract 1 so that the search includes the same row number that was previously
    ; found (in case adjacent rows are selected):
    RowNumber := LV_GetNext(RowNumber - 1)
    if not RowNumber  ; The above returned zero, so there are no more selected rows.
        break
    LV_Delete(RowNumber)  ; Clear the row from the ListView.
}
UpdateFile()
Return

AddItem:                 ;Add new or update ListView row
  Gui, Submit, NoHide
  
If SelectedRow = 0
{
	LV_Add("", Trim(Title1),Trim(Year1),Trim(NewVar),Trim(playmovie))
	
	
}
else
{
	LV_Modify(SelectedRow,"", Year1,Title1,NewVar,playmovie)
	LV_ModifyCol(1,"Sort")
	SelectedRow := 0
	GuiControl, ,Button1, Add to list
}

SizeCols()
UpdateFile()
Return

UpdateFile:  ;When exiting
  DetectHiddenWindows On
  UpdateFile()
  ExitApp
Return



GuiSize:  ; Widen or narrow the ListView in response to the user's resizing of the window.
if A_EventInfo = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20)
Return


UpdateFile()    ;Saves data to file when ListView updated
{
	FileDelete, MovieList.txt
	WinGet, Min, MinMax, MovieList
	If Min = -1
		WinRestore, MovieList
	WinGetPos, X, Y, Width, Height, MovieList
	Width -= 16
	Height -= 38
	FileAppend, x%x% y%y% w%Width% h%Height% `n, MovieList.txt
	Loop % LV_GetCount()
     {
		RowNum := A_Index
		Loop, 3
		{
			LV_GetText(Text, RowNum, A_Index)
			TrimText := Trim(Text)
			FileAppend, "%TrimText%"`,, MovieList.txt
		}
		LV_GetText(Text, RowNum, 4)
		TrimText := Trim(Text)
		FileAppend, "%TrimText%"`n, MovieList.txt
     }
}

SizeCols()  ;resize all columns, hide Column 9, Column 10 NoSort
  {
     Loop, 9
       {
          LV_ModifyCol(A_Index,"AutoHdr")
       }
       LV_ModifyCol(9, 0)
       LV_ModifyCol(10,"AutoHdr")
       LV_ModifyCol(10,"NoSort")
}

#IfWinActive, MovieList ; CTRL+A to Select All
^a::LV_Modify(0,"Select")
#IfWinActive



pushPic:
Gui, Submit, NoHide		
FileSelectFile, path, 3, % pathToPic, Select a picture, Pictures (*.png; *.jpeg; *.jpg) ; displays a standard dialog that allows the user to choose a picture
NewVar := % path
GuiControl,, Newvar, %Newvar%
return

pushMovie:
Gui, Submit, NoHide		
FileSelectFile, path2, 3, % pathToMovie, Select Movie File, (*.mp4; ) ; displays a standard dialog that allows the user to choose a picture
playmovie := % path2
GuiControl,, playmovie, %playmovie%
return


ButtonCLICK:
GuiControlGet, FocusedControl, FocusV
if (FocusedControl != "MyListView")
	return
SetTitleMatchMode, 2
run %playmovie%
return


SetEditCueBanner(HWND, Cue)
{
	Static EM_SETCUEBANNER := (0x1500 + 1)
	Return DllCall("User32.dll\SendMessageW", "Ptr", HWND, "Uint", EM_SETCUEBANNER, "Ptr", True, "WStr", Cue)
}

GuiEventEmpty()
{
	GuiControlGet, ConText,, EditCon, Text
	MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
	WinGetClass, ConClass, % "ahk_id" OutputVarControl	
	if ( ConText = "" )
	{
		GuiControl,, EditCon, PlaceHolder
		GuiControl, Disable, EditCon
		OnMessage( 0x111, "" )
	}
}

GuiEventLeave()
{
	MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
	WinGetClass, ConClass, % "ahk_id" OutputVarControl	
	
	if ( ConClass = "Edit" )
	{
		GuiControl,, EditCon
		GuiControl, Enable, EditCon
		Sleep, 1000
		OnMessage( 0x111, "GuiEventEmpty" )	
	}
}
Also, the rows focus correctly when pressing enter on each row. If I add a message box it will show each roll correctly, but it won't show the movies correctly, and I can't see why.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Adding titles, images, and files

04 Sep 2020, 05:04

You should've provided your code from the beginning. Screenshots are nice if it's about visual things like Gui-layout etc. (which should be your next project :silent:), otherwise, they're more or less useless.

This one is working for me (well, within the boundaries of your "interesting" code structure/logic). The concept of starting a video by clicking its entry within the list isn't that intuitive. IMHO, you should go for average Joe's famous little "Start Video Here"-button. Good luck.

Code: Select all

SendMode Input  																	; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  														; Ensures a consistent starting directory.
SetTitleMatchMode, 2
#SingleInstance,Force

OnExit, UpdateFile

SelectedRow := 0

Gui +AlwaysOnTop +resize
Gui, Show, x100 y100 w500 h500

Gui, Add, ListView, sort -ReadOnly grid x10 y5  h360 w400 +hscroll vMyListView gMyListview,% "Title | Year | Image | Movie URL"
Gui, Add, Button, section gAddItem,% "Add Movie Title"
Gui, Add, Text, w52 section ,% "Movie Title"
Gui, Add, Edit, w100 ys vTitle1 hwndOne

SetEditCueBanner(One, "Title")

Gui, Add, Text, ys, Year
Gui, Add, Edit, w150 ys vYear1 hwndTwo

SetEditCueBanner(Two, "Year")

GUI Add, Button, w65 ys gpushPic,% "Add Image" 
Gui, Add, Picture, w65 h100 ys vNewVar hwndThree,% Newvar

Gui, Add, Button, w65 ys gpushMovie,% "Select Movie File" 
Gui, Add, edit, w65 h100 ys vPlyMv hwndFour,% playmovie
Gui, Add, Button, Hidden Default gClick,% "CLICK"

IconWidth    :=  2
IconHeight   := 50
IconBitDepth := 24
InitialCount :=  1 																	; The starting Number of Icons available in ImageList
GrowCount    :=  1

ImageListID := DllCall( "ImageList_Create", Int,IconWidth,    Int,IconHeight
                                          , Int,IconBitDepth, Int,InitialCount
                                          , Int,GrowCount )

LV_SetImageList( ImageListID, 1 )													; 0 for large icons, 1 for small icons


If FileExist("MovieList.txt") {														; Add data from MovieList.txt to ListView
	;FileCopy, MovieList.txt, MovieList%A_Now%.txt									;incremental backup
	Loop, Read, MovieList.txt
		{
		If (A_index = 1 && SubStr(A_LoopReadLine, 1, 1) = "x")	{
			WinPos := A_LoopReadLine
			Continue
			}
		Else 
			{
			Loop, Parse, A_LoopReadLine , CSV
				RowData%A_Index% := A_LoopField
			LV_Add("", RowData1,RowData2,RowData3,RowData4)
			}
		}
	}


SizeCols()

Menu, MyContextMenu, Add, Edit, EditItem
Menu, MyContextMenu, Add, Delete, DeleteItem
Menu, Tray, Add, Show MovieList, ShowMovieList

If FileExist("MovieList.txt") {
    Gui, Show, %WinPos% , MovieList
	}
Else
	{
    WinGetPos,X1,Y1,W1,H1,Program Manager
    X2 := W1-800
    Gui, Show, x%x2% y50 , MovieList
	}


Hotkey, ^!a, ShowMovieList
Return

ShowMovieList:
	Gui, Show,, MovieList
	Return


MyListView:
	If (A_GuiEvent = e)																;Finished editing first field of a row
		LV_ModifyCol(2,"Sort")
	If (A_GuiEvent = ColClick)														;Clicked column header
		{
			If A_EventInfo = 2    ;Number of column header clicked
			LV_ModifyCol(2,"SortDesc")
		}
	UpdateFile()
	Return


GuiContextMenu:																		; Launched in response to a right-click or press of the Apps key.
	If A_GuiControl <> MyListView  													; Display the menu only for clicks inside the ListView.
		Return
	LV_GetText(ColText, A_EventInfo,1)    											;Gather column data in string EditText
	EditText := ColText
	Loop 3
		{
			LV_GetText(ColText, A_EventInfo, A_Index+1)
			EditText := EditText . "|" . ColText
		}
	Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
	Return

EditItem:          																	;Move row from ListView columns into edit fields
	SelectedRow := LV_GetNext()
	StringSplit, RowData, EditText , |
	Loop, 9
		{
			GuiControl, , Rowdata%A_Index%
		}
	GuiControl, ,Button1, Update
	Return

DeleteItem:         																;Deletes selected rows
	MsgBox, 4100, Delete Movie?, Delete Movie? Click Yes or No?
	IfMsgBox No    																	;Don't delete
	  Return
	RowNumber = 0  																	; This causes the first iteration to start the search at the top.
	Loop																			; Since deleting a row reduces the RowNumber of all other rows beneath it,
		{																			; subtract 1 so that the search includes the same row number that was previously
		RowNumber := LV_GetNext(RowNumber - 1)										; found (in case adjacent rows are selected):
		If not RowNumber  															; The above returned zero, so there are no more selected rows.
			Break
		LV_Delete(RowNumber)  														; Clear the row from the ListView.
		}
	UpdateFile()
	Return

AddItem:                 ;Add new or update ListView row
	Gui, Submit, NoHide
	If (SelectedRow = 0)
		LV_Add("", Trim(Title1),Trim(Year1),Trim(NewVar),Trim(mvPath))
	Else {
		LV_Modify(SelectedRow,"", Year1,Title1,NewVar,mvPath)
		LV_ModifyCol(1,"Sort")
		SelectedRow := 0
		GuiControl, ,Button1, Add to list
		}

SizeCols()
UpdateFile()
Return


UpdateFile:																			;When exiting
	DetectHiddenWindows On
	UpdateFile()
	ExitApp
	Return



GuiSize:  																			; Widen or narrow the ListView in response to the user's resizing of the window.
	If (A_EventInfo = 1)  															; The window has been minimized.  No action needed.
		Return
	GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20)							; Otherwise, the window has been resized or maximized. Resize the ListView to match.
	Return


UpdateFile() {																		;Saves data to file when ListView updated
	FileDelete, MovieList.txt
	WinGet, Min, MinMax, MovieList
	If Min = -1
		WinRestore, MovieList
	WinGetPos, X, Y, Width, Height, MovieList
	Width -= 16
	Height -= 38
	FileAppend, x%x% y%y% w%Width% h%Height% `n, MovieList.txt
	Loop % LV_GetCount()
		{
		RowNum := A_Index
		Loop, 3
			{
			LV_GetText(Text, RowNum, A_Index)
			TrimText := Trim(Text)
			FileAppend, "%TrimText%"`,, MovieList.txt
			}
		LV_GetText(Text, RowNum, 4)
		TrimText := Trim(Text)
		FileAppend, "%TrimText%"`n, MovieList.txt
		}
	}


SizeCols() {																		;resize all columns, hide Column 9, Column 10 NoSort
     Loop, 9
       {
          LV_ModifyCol(A_Index,"AutoHdr")
       }
       LV_ModifyCol(9, 0)
       LV_ModifyCol(10,"AutoHdr")
       LV_ModifyCol(10,"NoSort")
	}


#IfWinActive, MovieList																; CTRL+A to Select All
^a::LV_Modify(0,"Select")
#IfWinActive


pushPic:
	Gui, Submit, NoHide		
	FileSelectFile, picPath, 3,, Select a picture, Pictures (*.png; *.jpeg; *.jpg)	; displays a standard dialog that allows the user to choose a picture
	GuiControl,, Newvar,% picPath
	Return


pushMovie:
	Gui, Submit, NoHide		
	FileSelectFile, mvPath, 3,, Select Movie File, (*.mp4; )						; displays a standard dialog that allows the user to choose a movie
	GuiControl,, PlyMv,% mvPath
	Return


Click:
	GuiControlGet, FocusedControl, FocusV
	If (FocusedControl != "MyListView") && (mvPath = "")							; 2nd condition: if movie path isn't existing, skip execution attempt.
		Return
	ToolTip % mvPath																; check if your local (movie's) path is (in)valid.
	Sleep 5000
	ToolTip
	Run,% "vlc.exe """ . mvPath . """ --width=""500"" --height=""400"" "			; running fine (at least for me).
	Return


SetEditCueBanner(HWND, Cue) {
	Static EM_SETCUEBANNER := (0x1500 + 1)
	Return DllCall("User32.dll\SendMessageW", "Ptr", HWND, "Uint", EM_SETCUEBANNER, "Ptr", True, "WStr", Cue)
	}


GuiEventEmpty() {
	GuiControlGet, ConText,, EditCon, Text
	MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
	WinGetClass, ConClass, % "ahk_id" OutputVarControl	
	If ( ConText = "" ) {
		GuiControl,, EditCon, PlaceHolder
		GuiControl, Disable, EditCon
		OnMessage( 0x111, "" )
		}
	}


GuiEventLeave() {
	MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
	WinGetClass, ConClass, % "ahk_id" OutputVarControl	
	
	If ( ConClass = "Edit" ) {
		GuiControl,, EditCon
		GuiControl, Enable, EditCon
		Sleep, 1000
		OnMessage( 0x111, "GuiEventEmpty" )	
		}
	}
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

04 Sep 2020, 05:29

@BoBo

Thank you... It still only plays the same movie. If I put one movie it will play it... but if I put a second movie, then the first movie will link to the 2nd movie and both columbs will play the 2nd movie only. If I had 10 titles, the last title I put in there is what will play for the other 9 titles. So if I play title one, it will play the last title I added.. if I play column 3, 4, 5 and so on, they will play the last movie I entered. If I close it and re open, VLC freaks out and flashes at the top add move.ahk and does nothing but keep showing that at 1K miles an hour lol... It's basically doing the same thing it was doing. Except this time, closing it and opening it, it at least shows the VLC player, but goes haywire. I know it looks tacky now, but I will eventually do some custom work on the interface. Thank you for your helping.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Adding titles, images, and files

04 Sep 2020, 05:47

That means the logic behind your handling of variables needs some further investigation. Why not set mvPath := "" right after you've executed the movie?? :think:
Why your 'click'-attempt isn't updating that variable with every new click?? Check this out.

TBH, I've not added a bunch of videos to the list bc I hate to do it manually - if I could instead drop those files into an "inbox folder", press a button, and let it all update in one go.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

04 Sep 2020, 06:04

Yeah it would be easier, but I wanted to write it so that I can rewrite it to work with programs as well. This is the error I get when I close and open and try and play again.
Attachments
capture15.jpg
capture15.jpg (6.47 KiB) Viewed 430 times
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

04 Sep 2020, 21:21

Okay, the new VLC error.. again, it plays the first time, but not after reloading. If it plays in the beginning, then it should play after it's reloaded?
Attachments
capture17.jpg
capture17.jpg (9.88 KiB) Viewed 411 times
capture16.jpg
capture16.jpg (8.63 KiB) Viewed 413 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Adding titles, images, and files

05 Sep 2020, 00:02

If you're using my script you should see the detected path within a tooltip. An invalid path means invalid data that will drive VLC crazy.
Your "Click to Start" allows executing several instances (double /tripple/... clicks ) at the same time, hence the flickering of VLC (AFAICS, guessing).
IMHO you have to change your concept.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

05 Sep 2020, 07:39

Yeah, the tooltip shows the correct path, so it plays the first time.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: Adding titles, images, and files

05 Sep 2020, 23:00

Okay, well if I put the videos and images in the same directory as the program, the movie plays after reloading it again... only issue is that it only plays the first movie listed. So if I put 10 different titles, it won't play but the first one that is in the list. Not sure why I have to have the script in the same directory, but it works... kinda...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: FanaticGuru, yabab33299 and 143 guests