AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Php assistant

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
neXt



Joined: 19 Mar 2007
Posts: 463

PostPosted: Sun Mar 23, 2008 7:07 pm    Post subject: Php assistant Reply with quote


Code:

#SingleInstance Force
#Persistent
#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.

;get screen resolution
SysGet, X, 16
SysGet, Y, 17

;calculate gui positioning
Xnew := X - 360
Ynew := Y - 205

;read path and browser variables
IniRead workingDirectory, config.ini, general, workingDirectory, select path to working directory
IniRead wwwPath, config.ini, general, wwwPath, select path to www folder
IniRead Browser, config.ini, general, browser, FF
IniRead allowHiding, config.ini, general, allowHiding, 0
IniRead hideFor, config.ini, general, hideFor, 60

;select testing browser
if (Browser = "IE") {
   LaunchIn := A_ProgramFiles . "\Internet Explorer\iexplore.exe"
   rIE = 1
   rFF = 0
}
if (Browser = "FF") {
   LaunchIn := A_ProgramFiles . "\Mozilla Firefox\firefox.exe"
   rFF = 1
   rIE = 0
}
;notepad++ executable in a var
NPlus := A_ProgramFiles . "\Notepad++\notepad++.exe"

;start building GUI
;path
Gui, Add, Text, x7 y31 w90 h20, Working directory:
Gui, Add, Edit, x97 y29 w240 h20, %workingDirectory%
Gui, Add, Text, x7 y7 w90 h20, root path:
Gui, Add, Edit, x97 y4 w240 h20, %wwwPath%

;buttons
Gui, Add, Button, x6 y126 w110 h30, Run Php Script
Gui, Add, Button, x6 y156 w110 h30, New Php File
Gui, Add, Button, x116 y126 w110 h30, Open Working`nDirectory
Gui, Add, Button, x116 y156 w110 h30, Php Help
Gui, Add, Button, x227 y126 w110 h30, Set Working`nDirectory
Gui, Add, Button, x227 y156 w110 h30, Set www`nFolder

Gui, Add, GroupBox, x2 y52 w180 h70, Browser Selection
Gui, Add, Radio, x25 y75 w110 h20 Checked%rIE% gSelectIE, Internet Explorer
Gui, Add, Radio, x37 y94 w60 h20 Checked%rFF% gSelectFF, Fire Fox

Gui, Add, GroupBox, x182 y52 w155 h70, Autohide
Gui, Add, CheckBox, x191 y75 w60 h20 Checked%allowHiding% vallowHiding gHide_or_not, Enable
Gui, Add, Edit, x207 y96 w50 h20 gSetTime vhideFor, %hideFor%
Gui, Add, Text, x268 y99 w50 h20, Seconds


Gui, Show, x%Xnew% y%Ynew% h191 w344, PHP Assistant
Gui +AlwaysOnTop +ToolWindow

;disable hiding timer control
GuiControl, Enable%allowHiding%, %hideFor%
   
;autohide timer
SetTimer CheckActivity, 1000
Return
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
GuiClose:
ExitApp
;-----------------------------------------------------------------------
Hide_or_not:
Gui Submit, NoHide
IniWrite %allowHiding%, config.ini, general, allowHiding
GuiControl, Enable%allowHiding%, %hideFor%

return
;-----------------------------------------------------------------------
SetTime:
Gui Submit, NoHide
IniWrite %hideFor%, config.ini, general, hideFor

return
;-----------------------------------------------------------------------
;turn IE into your testing browser
SelectIE:
IniWrite IE, config.ini, general, Browser
LaunchIn := A_ProgramFiles . "\Internet Explorer\iexplore.exe"

return
;-----------------------------------------------------------------------
;turn FF into your testing browser
SelectFF:
IniWrite FF, config.ini, general, Browser
LaunchIn := A_ProgramFiles . "\Mozilla Firefox\firefox.exe"

return
;-----------------------------------------------------------------------
;launch files dropped on the GUI
GuiDropFiles:
;remove "root" path from a file path
StringReplace DroppedFile, A_GuiEvent, %wwwPath%\,
;turn forward slashes into backslashes
DroppedFile := RegExReplace(DroppedFile, "\\", "/")
DroppedFile := RegExReplace(DroppedFile, "^\/", "")
OpenIt := "http://localhost/" . DroppedFile
run %LaunchIn% %OpenIt%

return
;-----------------------------------------------------------------------
;set working directory path
ButtonSetWorkingDirectory:
FileSelectFolder, workingDirectory, C:\, 3

If ErrorLevel
   return

IniWrite %workingDirectory%, config.ini, general, workingDirectory
GuiControl,, Edit1, %workingDirectory%

return
;-----------------------------------------------------------------------
;set "root" path
ButtonSetwwwFolder:
FileSelectFolder, wwwPath, C:\, 0

If ErrorLevel
   return

IniWrite %wwwPath%, config.ini, general, wwwPath
GuiControl,, Edit2, %wwwPath%

return
;-----------------------------------------------------------------------
;run last modified file
ButtonRunPhpScript:
IniRead workingDirectory, config.ini, general, workingDirectory
IniRead wwwPath, config.ini, general, wwwPath

if (wwwPath = "") or (wwwPath = "select path to www folder") {
   MsgBox path to www folder must be specified first.
return
}

;get last modified file through "LastFile" function (line: 214)
CurrentPHPFile := LastFile(workingDirectory, "php")
;remove "root" path from a file path
StringReplace Folder, workingDirectory, %wwwPath%,

if InStr(Folder, "\")
   Folder := RegExReplace(Folder, "\\", "/")

;turn forward slashes into backslashes
Folder := RegExReplace(Folder, "^\/", "")
OpenIt := "http://localhost/" . Folder . "/" . CurrentPHPFile
run %LaunchIn% %OpenIt%

return
;----------------------------------------------------------------------
;create php new file
ButtonNewPhpfile:
;input box creation/positioning
YforInput := Ynew - 105
InputBox NewFile, New File,,, 130, 100, %Xnew%, %YforInput%

If (NewFile = "") or ErrorLevel
   return

ScriptTitle = %NewFile%
NewFile = %workingDirectory%\%NewFile%

;create a script with html tags in file
FileAppend,
(
<html>
   <head>
      <title>%ScriptTitle%</title>
   </head>
   <body>
   <?php

   ?>
   </body>
</html>
), %NewFile%.php

loop {
   IfExist %NewFile%.php
      break
}
sleep 1000
IfExist %NPlus%
   run %NPlus% %NewFile%.php
else
   run %NewFile%.php

return
;----------------------------------------------------------------------
;open working wirectory
ButtonOpenWorkingDirectory:
run %workingDirectory%

return
;----------------------------------------------------------------------
;php help
ButtonPhpHelp:
run %LaunchIn% http://www.php.net/manual/en/

return
;----------------------------------------------------------------------
;last modified file function
LastFile(path,ext) {
  LastModified =
  FileName =
  Loop %Path%\*.%ext%, 1
  {
    If (A_LoopFileTimeModified > LastModified)
    {
      LastModified := A_LoopFileTimeModified
      FileName := A_LoopFileName
    }
  }
  Return %FileName%
}
;----------------------------------------------------------------------
;script activity timer
CheckActivity:
if (allowHiding) {
   IfWinNotActive PHP Assistant
   {
      sNotActiveState := A_TickCount
      hideIt := A_TickCount - sNotActiveState + hideFor * 1000
      loop {
         ifWinActive PHP Assistant
            break

         if (A_TickCount - sNotActiveState >= hideIt) {
            WinMinimize PHP Assistant
         return
         }
      }
   }
}
return


I'm studying Php at the moment and to simplify my studying i wrote this assistant.

Usage:
root path - path to your localhost
working directory - working directory
Browser Selection - choose which browser to launch your scripts in
Autohide - autohides Php assistant when inactive for selected period of time.
Run Php Script - run last modified script in working directory
new Php File - create new *.php, creates file with <html><head> and <body> already in it
Open Working Directory - Open Working Directory
Php Help - official Php docs on the web
You also can drag n drop files on the GUI to lauch scripts.


Last edited by neXt on Sun Mar 23, 2008 10:55 pm; edited 4 times in total
Back to top
View user's profile Send private message
daonlyfreez



Joined: 16 Mar 2005
Posts: 745
Location: Berlin

PostPosted: Sun Mar 23, 2008 8:30 pm    Post subject: Reply with quote

Very nice example of clear and useful scripting.

Please post a screenshot, it will allow visitors to get a better grasp of what the script is about.

Cool
_________________
(sorry, homesite offline atm)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
BoBoĻ
Guest





PostPosted: Sun Mar 23, 2008 8:47 pm    Post subject: Reply with quote

Side note. Check out a (~standalone) command line tool which will compile/embbed php scripts/projects into standalone executables.
[Bambalam - PHP exe Compiler/Embedder]

Might be worth to connect it to your tool. Cool
Have fun.
Back to top
neXt



Joined: 19 Mar 2007
Posts: 463

PostPosted: Sun Mar 23, 2008 8:52 pm    Post subject: Reply with quote

Thanks!
Since it was getting on my nerves when i was reading or surfing, I added 1 more feature to it: If it's not active for about a minute, it auto hides itself. Very Happy

screenshot and modified script is in the original post.

Thanks Bobo, i'm new to Php so i'll definitely check it out Very Happy
Back to top
View user's profile Send private message
neXt



Joined: 19 Mar 2007
Posts: 463

PostPosted: Sun Mar 23, 2008 10:56 pm    Post subject: Reply with quote

added timer control.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group