AutoHotkey Community

It is currently May 27th, 2012, 6:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: February 2nd, 2010, 6:22 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
I'm trying to make a video directory of sorts that will easily list what videos are in a specific folder and play them. Please check out the code:
Code:
VideoList:
Gui +ToolWindow
gui, font, s26, Verdana
Gui, Color, 000050
Gui, Add, Picture, w298 h-1 x0 y0, gPoster
Gui, Add, ListView, Background000050 cWhite -E0x200 -Multi -hdr Sort x300 y2 r11 w700 gMyListView,Video Title


LV_ModifyCol(1,700)

Gui, Show, w1000 h540, Video Directory

Loop
{
ifnotexist, %DrvLtr%:\Portable
   {
   Gui,Destroy
   Goto DriveDetect
   }

Gui, Show, NA w1004 h540, Video Directory


; Gather a list of file names from a folder and put them into the ListView:



Loop, %DrvLtr%:\Portable\*.avi
    LV_Add("", A_LoopFileName)
Loop, %DrvLtr%:\Portable\*.wmv
    LV_Add("", A_LoopFileName)



Sleep, 60000
LV_Delete()


}

return

MyListView:

;If a title is selected by either using the arrow keys to scroll or by a SingleClick, show movie's poster
if A_GuiEvent = SingleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    GuiControl,, Poster, %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg

   ;Following is for troubleshooting purpose
   IfExist %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
      PosterIs = It's there
    TrayTip,Video Directory, Poster: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg`nIs it there? %PosterIs%
      PosterIs = It's NOT there

}

;if the ENTER Key is pressed, start a movie
if A_GuiEvent = ENTER
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    TrayTip,Video Directory, Starting: "%DrvLtr%:\Portable\%RowText%"
   Run, %DrvLtr%:\Portable\%RowText%, Max
}

 
;if a title is DoubleClicked, start a movie
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    TrayTip,Video Directory, Starting: "%DrvLtr%:\Portable\%RowText%"
   Run, %DrvLtr%:\Portable\%RowText%, Max
}


Return



GuiClose:
ExitApp

Now... this works. If I double click on any given title, the video will play, but I want it to do more. I want it to show an image for each video that I either single click on or scroll down to with the arrow keys. I also want to be able to press the ENTER key instead of double clicking to start a video.
Can anyone tell me what I've done wrong?
Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2010, 8:06 pm 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
A couple of things:

to show your jpg change your code to:
Code:
Gui, Add, Picture, w298 h-1 x0 y0 vPoster  ;note the v


then for the click, double click or arrow up/down action use something like:
Code:
MyListView:
if (a_guievent = "K") OR (A_GuiEvent = "Normal")
{
   tmprw:=LV_GetNext("","F")
   LV_GetText(RowText, tmprw)  ; Get the text from the row's first field.
   run, %dfltfldr%\%RowText%, , Max
   StringTrimRight, RowText, RowText, 4
   GuiControl,, Poster, %dfltfldr%\Movie Posters\%RowText%.jpg
}
Return

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2010, 8:34 pm 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
to ignore non-navigation keys in the "guievent" use:
Code:
if (a_guievent = "K" && (a_eventinfo = 33 || a_eventinfo = 34 || a_eventinfo = 35 || a_eventinfo = 36 || a_eventinfo = 38 || a_eventinfo = 40)) OR (A_GuiEvent = "Normal")


page up is 33
page down is 34
arrow up is 38
arrow down is 40
home is 36
end is 35

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 7:03 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
Here is my new and improved code:
Code:
VideoList:
RowText = no file.jpg
Gui -Border
gui, font, s13, Verdana
Gui, Add, Button, w98 x600 y0, Re&fresh
Gui, Add, Button, w98 x700 y0, Re&Boot
Gui, Add, Button, w98 x800 y0, &Hibernate
Gui, Add, Button, w98 x900 y0, &Exit
gui, font, s30, Verdana
Gui, Color, 000050
Gui, Add, ListView, Background000050 cWhite -E0x200 AltSubmit -Multi -hdr Sort x300 y35 r9 w725 gMyListView,Video Title
gui, font, s8, Verdana
Gui, Add, Text, cGray w550 x2 y1 vSelectedFile,File: none
Gui, Add, Picture, x5 y35 vPoster



LV_ModifyCol(1,725)


Gui, Show, NA w1004 h450, Video Directory

AddTitles:
Loop, %DrvLtr%:\Portable\*.avi
    LV_Add("", A_LoopFileName)
Loop, %DrvLtr%:\Portable\*.wmv
    LV_Add("", A_LoopFileName)


Loop
{
ifnotexist, %DrvLtr%:\Portable
   {
   Gui,Destroy
   Goto DriveDetect
   }
}




return

MyListView:
TrayTip, Video Directory, Event type: %A_GuiEvent%

if (a_guievent = "K") OR (A_GuiEvent = "Normal")
{
   tmprw:=LV_GetNext("","F")
   LV_GetText(RowText, tmprw)  ; Get the text from the row's first field.
   ;StringTrimRight, RowText, RowText, 4
   ifexist %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
      IsIt = Does Exist
  ; TrayTip, Video Directory, File: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg`n%IsIt%
      IsIt =
   GuiControl,, Poster, %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
   GuiControl,, SelectedFIle, File: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
}

if (a_guievent = 13) OR (A_GuiEvent = "DoubleClick")
   run, %DrvLtr%:\Portable\%RowText%, , Max


Return
ButtonRefresh:
LV_Delete()
Goto, AddTitles

ButtonReboot:
Shutdown, 2
MsgBox, Video Directory, Rebooting the system.
ExitApp

ButtonHibernate:
; Call the Windows API function "SetSuspendState" to have the system suspend or hibernate.
; Windows 95/NT4: Since this function does not exist, the following call would have no effect.
; Parameter #1: Pass 1 instead of 0 to hibernate rather than suspend.
; Parameter #2: Pass 1 instead of 0 to suspend immediately rather than asking each application for permission.
; Parameter #3: Pass 1 instead of 0 to disable all wake events.
DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
MsgBox, Video Directory, Hibernating the system.
return


ButtonExit:
GuiClose:
ExitApp


All works great except for the stinkin ENTER key doesn't register as an event. Does anybody have a solution


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 8:42 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
from the helpfile topic ListView G-label Notifications

Quote:
However, the Enter keystroke is not received; to receive it, use a default button as described below.
To detect when the user has pressed Enter while a ListView has focus, use a default button (which can be hidden if desired). For example:


Code:
Gui, Add, Button, Hidden Default, OK
...
ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl <> MyListView
    return
MsgBox % "Enter was pressed. The focused row number is " . LV_GetNext(0, "Focused")
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2010, 4:30 am 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
If Mylistview does not have the focus, the Enter key will not do anything. In order for the listview to regain focus use:
Code:
ButtonOK:
ControlFocus, SysListView321, Video Directory
focusedrow := LV_GetNext(0, "Focused")
run, %DrvLtr%:\Portable\%focusedrow%, Max
return

obviously nothing happens if no row has the focus.

If Mylistview does have the focus, pressing enter does not do anything unless a row has the focus. If one of the rows has the focus, it got that focus by getting a (double) mouse click or after an arrow/page up/down and the run, ... code was already executed.

In other words, the Enter key has limited use. A better way imho is to give the listview the focus and leave the focus there. I.e. do not allow the other controls to get the focus. Use "-tabstop" for buttons and edit controls, and include code to have the listview regain the focus.

I have a small image viewer that keeps the focus on the listview. It has a search function, but it always gives the focus back to the listview. So I do not need the hidden default button. Hope this helps.

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2011, 8:43 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Hmmm. I can trap double clicks but can't seem to trap anything else. Here's the my test case. (Running on windows 7) What am I forgetting to do?
Code:
Gui, Add, ListView, gMyListView, Thing 1|Thing 2|Thing 3
Gui,show
LV_Add("",1,2,3)
LV_Add("",4,5,6)
LV_Add("",7,8,9)
return

MyListView:
if A_GuiEvent = DoubleClick
  msgbox Double Click
else if (a_guievent = "K" && (a_eventinfo = 33 || a_eventinfo = 34 || a_eventinfo = 35 || a_eventinfo = 36 || a_eventinfo = 38 || a_eventinfo = 40)) OR (A_GuiEvent = "Normal")
  Msgbox Other Stuff
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2011, 8:55 am 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
Try:
Code:
Gui, Add, ListView, gMyListView altsubmit, Thing 1|Thing 2|Thing 3

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2011, 11:29 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Thanks. This (sorta) works. I'm getting what seems to be a bunch of spurious calls to the handler that I'm trying to figure out but this helps.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2011, 4:33 pm 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
It shouldn't sorta work... It should work without a hitch. In your example, because of the msgbox action, the first click of the double click triggers the single click message box, but with the other actions this should not be a problem.

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2011, 5:49 pm 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Maybe that's it. Seems when the Gui is created/shown it gets called.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, Exabot [Bot], JSLover and 62 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group