AutoHotkey Community

It is currently May 27th, 2012, 8:11 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: My Gui -- beginner gui
PostPosted: February 28th, 2006, 7:37 am 
Offline

Joined: September 14th, 2005, 5:21 am
Posts: 21
My Gui by Hotfoot

Designed for the end user or beginner. The user can access favorite text clips, text templates, files, folders, and hyperlinks with a GUI (contains 6 tabs and uses mostly listboxes). The user just needs to modify the files that are created by the script when run.

The script automatically creates a folder called 'My Gui' inside My Documents.
Folders called 'My Files' and 'My Templates' are created inside 'My Gui'.

'Group1.txt' and 'Group2.txt' files are created to hold AHK commands.
'TextClips.txt' is created to hold single-line text clips.
The 'My Templates' folder will hold txt files of multi-line text clips.
The 'My Files' folder is intended to hold shortcuts (or files) for easy access.


Hotkeys:
Control Shift A
or
Shift MButton

Code:
; Generated using SmartGUI Creator 3.5.1

#singleinstance, ignore         ; leave original instance of script running if new instance is started

^+a::           ; Modify this hotkey to your liking
+MButton::    ; Also access GUI with combination Shift and Middle mouse button

; Suspend hotkeys to prevent accidentally triggering again - which causes an error
Suspend, On


; Create files and folders if they don't exist yet

IfNotExist, %UserProfile%\My Documents\My Gui
  FileCreateDir, %UserProfile%\My Documents\My Gui

IfNotExist, %UserProfile%\My Documents\My Gui\TextClips.txt
{
  FileAppend, Sample Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
  FileAppend, `nAnother Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
  FileAppend, `nThird Text Clip, %UserProfile%\My Documents\My Gui\TextClips.txt
}

IfNotExist, %UserProfile%\My Documents\My Gui\My Templates
  FileCreateDir, %UserProfile%\My Documents\My Gui\My Templates

 ;;;;;;;;;;
 ; Create sample clip file. You may delete this command after you have tested it.
 ;;;;;;;;;;
IfNotExist, %UserProfile%\My Documents\My Gui\My Templates\Sample Clip File.txt
{
  FileAppend, This text was pasted from 'Sample Clip File.txt'`nCreate your own text files`nand place them inside the`nMy Documents\My Gui\My Templates folder`nYou may delete this sample clip file `nand the associated commands in My Gui.ahk`nnow that you have tried it, %UserProfile%\My Documents\My Gui\My Templates\Sample Clip File.txt
}
 ;;;;;;;;;;

IfNotExist, %UserProfile%\My Documents\My Gui\My Files
  FileCreateDir, %UserProfile%\My Documents\My Gui\My Files

IfNotExist, %UserProfile%\My Documents\My Gui\Group1.txt
{
  FileAppend, Run C:\, %UserProfile%\My Documents\My Gui\Group1.txt
  FileAppend, `nRun www.autohotkey.com, %UserProfile%\My Documents\My Gui\Group1.txt
  Fileappend, `nRun "C:\Program Files\Internet Explorer\IEXPLORE.EXE" -new "http://www.autohotkey.com/", %UserProfile%\My Documents\My Gui\Group1.txt
}

IfNotExist, %UserProfile%\My Documents\My Gui\Group2.txt
{
  Fileappend, Run %SystemRoot%\system32\notepad.exe, %UserProfile%\My Documents\My Gui\Group2.txt
  Fileappend, `nRun D:\, %UserProfile%\My Documents\My Gui\Group2.txt
}

; End section for creating files and folders



Gosub, MyDisplay   ; Go to Gui commands

Gui, Show, x230 y156 h344 w759, Menu:      ; Display the Gui

SetTimer, DefaultFocus, 77       ; Timer to check which tab has focus
Return


;;;; Below are the commands for the buttons for each tab


TextClips:
if A_GuiControlEvent <> DoubleClick   ; Do nothing when selection is single-clicked/changes
  return
Button1:                   ; If the button is activated, then run the below commands
GuiControlGet, TextClips   ; Retrieve the ListBox's current selection
clipboard = %TextClips%    ; Copy selection to Clipboard
Gui, Destroy               ; Remove Gui
sleep,200
send,^v                    ; Paste item
Suspend, Off
return


TemplateClips:
if A_GuiControlEvent <> DoubleClick   ; Do nothing when selection is single-clicked/changes
  return
Button2:
GuiControlGet, TemplateClips      ; Retrieve the ListBox's current selection.
Gui, Destroy                      ; Remove Gui

 ;  Now read each line and paste into previous window
FileRead, Contents, %UserProfile%\My Documents\My Gui\My Templates\%TemplateClips%
{
 clipboard = %Contents%
 sleep,44
 send,^v
}
Suspend, Off
return


Group1:
if A_GuiControlEvent <> DoubleClick   ; Do nothing when selection is single-clicked/changes
  return
Button3:                      ; Run the below commands when button is activated
GuiControlGet, Group1         ; Retrieve the ListBox's current selection.
Gui, Destroy                  ; Remove Gui

 ;  Copy current selection to a temporary ahk file and execute it
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileAppend, %Group1%, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
Run %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
Suspend, Off
return


Group2:
if A_GuiControlEvent <> DoubleClick
  return
Button4:
GuiControlGet, Group2
Gui, Destroy

    ;  Copy current selection to a temporary ahk file and execute it
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileAppend, %Group2%, %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
Run %UserProfile%\My Documents\My Gui\Temp.ahk
sleep,100
FileDelete, %UserProfile%\My Documents\My Gui\Temp.ahk
Suspend, Off
return


FileLinks:
if A_GuiControlEvent <> DoubleClick
  return
Button5:
GuiControlGet, FileLinks      ; Retrieve the ListBox's current selection.
Gui, Destroy                  ; Remove Gui

    ; If selection is a shortcut, get the file path and run the path
If ext in lnk
{
 FileGetShortcut, %FileLinks%, target
 Run, %target%,, UseErrorLevel
   If ErrorLevel
      MsgBox Could not open "%target%"
 return
}
    ; If selection is not a shortcut, run the file instead
Run, %UserProfile%\My Documents\My Gui\My Files\%FileLinks%,, UseErrorLevel
   if ErrorLevel
      MsgBox Could not open "%FileLinks%"
Suspend, Off
return

DateFormats:
Calendar:
if A_GuiControlEvent <> DoubleClick
  return
Button6:
GuiControlGet, DateFormats
Gui, Destroy
sleep,100

    ; Convert Date and Time according to user selection
If DateFormats = MM/dd/yy
 FormatTime, TimeString, %calendar%,MM/dd/yy

If DateFormats = MMMM dd, yyyy
 FormatTime, TimeString, %calendar%,MMMM dd, yyyy

If DateFormats = yyyy/MM/dd
 FormatTime, TimeString, %calendar%,yyyy/MM/dd

If DateFormats = MMM dd, yyyy
 FormatTime, TimeString, %calendar%,MMM dd, yyyy

If DateFormats = MMM dd, yyyy hh:mmtt
 FormatTime, TimeString, %calendar%,MMM dd, yyyy hh:mmtt

clipboard = %TimeString%  ; Copy formatted date to clipboard
send,^v                   ; Paste from clipboard
Suspend, Off
return




;;;;;;;;;;;;;;;;;
;Gui Commands
;;;;;;;;;;;;;;;;;

MyDisplay:

Gui, font, s11, Arial
Gui, Add, Tab, x6 y7 w740 h330, Text Clips|Template Clips|Files Group 1|Files Group 2|File Links|Date
Gui, Add, ListBox, x16 y37 w630 h300 vTextClips gTextClips
Gui, Add, Button, x656 y37 w80 h30 Default vButton1 gButton1, Paste
Gui, Tab, Template Clips
Gui, Add, ListBox, x16 y37 w630 h300 vTemplateClips gTemplateClips
Gui, Add, Button, x656 y37 w80 h30 vButton2 gButton2, Paste
Gui, Tab, Files Group 1
Gui, Add, ListBox, x16 y37 w630 h300 vGroup1 gGroup1
Gui, Add, Button, x656 y37 w80 h30 vButton3 gButton3, Enter
Gui, Tab, Files Group 2
Gui, Add, ListBox, x16 y37 w630 h300 vGroup2 gGroup2
Gui, Add, Button, x656 y37 w80 h30 vButton4 gButton4, Enter
Gui, Tab, File Links
Gui, Add, ListBox, x16 y37 w630 h300 vFileLinks gFileLinks
Gui, Add, Button, x656 y37 w80 h30 vButton5 gButton5, Enter
Gui, Tab, Date
Gui, Add, MonthCal, x36 y57 w250 h230 vcalendar gcalendar,
Gui, Add, ListBox, x296 y97 w230 h200 vDateFormats gDateFormats, MMM dd, yyyy||yyyy/MM/dd|MM/dd/yy|MMMM dd, yyyy|MMM dd, yyyy hh:mmtt
Gui, Add, Text, x296 y57 w90 h30, Format:
Gui, Add, Button, x536 y97 w100 h30 vButton6 gButton6, Insert
Gui, Submit

 ; Read text from files/folders to fill listboxes
Loop, read, %UserProfile%\My Documents\My Gui\TextClips.txt
{

  %A_Index% = %A_LoopReadLine%
  If A_Index = 1
      GUIControl,, TextClips, |%A_LoopReadLine%|
  Else
      GUIControl,, TextClips, %A_LoopReadLine%
}

Loop, %UserProfile%\My Documents\My Gui\My Templates\*.*
{

  %A_Index% = %A_LoopFileName%
  If A_Index = 1
      GUIControl,, TemplateClips, |%A_LoopFileName%|
  Else
      GUIControl,, TemplateClips, %A_LoopFileName%
}

Loop, read, %UserProfile%\My Documents\My Gui\Group1.txt
{

  %A_Index% = %A_LoopReadLine%
  If A_Index = 1
      GUIControl,, Group1, |%A_LoopReadLine%|
  Else
      GUIControl,, Group1, %A_LoopReadLine%
}

Loop, read, %UserProfile%\My Documents\My Gui\Group2.txt
{

  %A_Index% = %A_LoopReadLine%
  If A_Index = 1
      GUIControl,, Group2, |%A_LoopReadLine%|
  Else
      GUIControl,, Group2, %A_LoopReadLine%
}

Loop, %UserProfile%\My Documents\My Gui\My Files\*.*
{

  %A_Index% = %A_LoopFileName%
  If A_Index = 1
      GUIControl,, FileLinks, |%A_LoopFileName%|
  Else
      GUIControl,, FileLinks, %A_LoopFileName%
}
return


;;;;;;

DefaultFocus:   ; Change the default button according to currently displayed tab
ControlGetFocus, control, Menu:
If control = ListBox1
{
  GuiControl, +Default, Button1
  return
}
If control = ListBox2
{
  GuiControl, +Default, Button2
  return
}
If control = ListBox3
{
  GuiControl, +Default, Button3
  return
}
If control = ListBox4
{
  GuiControl, +Default, Button4
  return
}
If control = ListBox5
{
  GuiControl, +Default, Button5
  return
}
If control = ListBox6
{
  GuiControl, +Default, Button6
  return
}
return

;;;;;;;;;;

GuiClose:
GuiEscape:
Suspend, Off
Gui, Destroy
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2006, 7:44 pm 
Offline

Joined: March 10th, 2006, 7:41 pm
Posts: 89
Thanks, Handy!
I just found out about all this suff and am shocked at how much you can do with it. I wish there were a beginners section or a reference library filled with rudimentary examples. I want to learn more so I can ask educated questions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2006, 2:47 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
crxvfr wrote:
I wish there were a beginners section or a reference library filled with rudimentary examples.
You're standing in it... ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2006, 4:09 am 
Offline

Joined: March 10th, 2006, 7:41 pm
Posts: 89
Well, ...I have much to learn.

Until I get better with arrays and passing variables I'm trying to use lines like these:

Gui, 1:Add, Button, x136 y57 w100 h30,Cancel

which means I have to make all the buttons compatible.

ButtonCancel:
Gui, 1:Cancel
return

I have a feeling if I add another gui with a cancel button, I'll be back to duplicate entry errors. Its hard to find exactly where I should be placing the numbers. I could write a section for every single button but I know theres got to be a step between that and having to learn 10 things in order to do one. Its babysteps for me. The help resources I've found only offer:

Quote:
For windows other than the first, the window's number is used as a prefix for the special labels mentioned above; for example, 2GuiEscape and 2GuiClose would be labels for the second window.

Each script may have up to 99 GUI windows simultaneously. To operate upon a window number other than the default, include a number followed by a colon in front of the sub-command as in these examples:
Gui, 2:Add, Text,, Text for about box.
Gui, 2:Show


This is an excellent program (like wow I'm shocked at the things you can do) and the documentation is very good as well, but theres a gap for absolute newbies. Having dabbled in Pascal, C++, and php, I'm not clueless, just looking for some good examples of the fundemental abc's. I'll be off and running once I can get off my knees.

-edit-
I now have my feet on the ground
http://www.autohotkey.com/forum/viewtop ... 1911#51911


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2007, 10:47 am 
Offline

Joined: March 15th, 2007, 10:14 am
Posts: 5
:D very nice script for beginners... but i got some newbie questions, how do you change the current gui tabs to open folder directories and change the tab's name? and is it possible to delete the "ifnot write mygui folder" portion of the script or better yet change it to another directory? thanks in advance


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 13 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