 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Wed Dec 05, 2007 8:02 pm Post subject: On Screen Affirmations / Quotes Display - Beta 1.0 |
|
|
On Screen Affirmations/Quotes Display
Background:
As an ongoing effort to get my non-conscious mind (aka sub-conscious mind although I don't believe there's anything "sub" about it) on the same page as my conscious one, I've always liked having inspirational affirmations/quotes display on my PC screen while working.
Ergo, my efforts to write an On Screen Affirmations ahk script.
Credits:
As an AHK noob, many thanks to this forum, its very helpful members, and others great scripts to get this script where it is. If you wrote any of the code I've hacked together, THANK YOU and please let me know so I can give credit in the readme.txt.
Special thanks to Predated, ahklerner, engunneer and DerRaphael for their expert help to get the script to it's present state. During this effort, they really helped me learn a lot about AHK programming.
Objective:
Create a GUI to randomly display affirmations on screen (OSD), pulled from a delimited text file. Provide user with preference options, via icon tray.
Preferences include:
* Affirmation/Quote File Selection
* Time between display of new random affirmation
* Text Color
* Background Color
* Text Size
* Transparecy (on/off)
* Always on Top (on/off)
* Hide/Show
* Tooltip with ahk and affirmation text file name.
Other Stuff:
* Whether transparency is On/Off, display GUI without caption/border.
* Allow user to move borderless GUI and save xpos/ypos in ini preferences file.
ToDo:
Issues:
* Text Size - GUI needs to auto-size for this feature to work properly, regardless of font size and length of affirmation/quote. Presently hard coded to only handle up to Font size = 20 for two to three lines of text. For now, user must manually modify ahk code to handle larger font size and text length.
Status - Not implemented. There advise in this topic how to implemented, not sure I have the expertise to work it out. Any help always welcome!
Feature Requests
* A new menu item to append to the current selected file the content of the clipboard. This way, if you find a quote you like somewhere (website or whatever), you could easily add it to currently selected file.
Status - Not implemented. My thought on this is to write a separate script or use another app. (i.e. Evernote) to capture affirmations/quotes and allow user to manually add where appropriate to affirmations.txt file. Other ideas how it should be implemented alway welcome!
Completed
Recommended by Andreone:
* Use majekinor's [module] CmnDlg 4.0 - Common Dialogs for StdLib for font and background color picker.
- Status - Implemented in Alpha v.0.20
* Use majekinor's [module] CmnDlg 4.0 for font parameters (font type, style & color)
- Status - Implemented in Alpha v.0.20
Take a look at the code and thanks in advance for any coding help and/or enhancement suggestions.
Code:
Note: without Icon or affirmations.txt files (need to be stored in ...ScriptDir\resources\ folder). For complete package, go to "File Download" at bottom of page.
Affirmations.ahk - v.1.00 Beta
| Code: |
/*
Author: TotalBalance
Beta v 1.00 Affirmations.ahk
*/
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
#Persistent
SetBatchLines -1
DetectHiddenWindows, On
FileSelected = %A_Scriptdir%\Resources\Affirmations.txt
; Create, read/write ini file
IfNotExist, %A_Scriptdir%\Affirmations.ini
{
IniWrite, Center, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, Center, %A_Scriptdir%\Affirmations.ini, Settings, yPos
IniWrite, Verdana, %A_Scriptdir%\Affirmations.ini, Settings, Font_Type
IniWrite, S16 Bold, %A_Scriptdir%\Affirmations.ini, Settings, Font_Style
IniWrite, Black, %A_Scriptdir%\Affirmations.ini, Settings, Font_Color
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniWrite, Red, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
IniWrite, 5min, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
}
IfExist, %A_Scriptdir%\Affirmations.ini
{
IniRead, xPos, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniRead, yPos, %A_Scriptdir%\Affirmations.ini, Settings, yPos
IniRead, Font_Type, %A_Scriptdir%\Affirmations.ini, Settings, Font_Type
IniRead, Font_Style, %A_Scriptdir%\Affirmations.ini, Settings, Font_Style
IniRead, Font_Color, %A_Scriptdir%\Affirmations.ini, Settings, Font_Color
IniRead, Background_Color, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniRead, Transparent, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniRead, Always_On_Top, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniRead, FileSelected, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
IniRead, Affirmation_Timer, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
}
; present user friendly menu tray items for timer options
If InStr(Affirmation_Timer, "msec")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 4
Affirmation_Time *= 1
}
else If InStr(Affirmation_Timer, "sec")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 3
Affirmation_Time *= 1000
}
else If InStr(Affirmation_Timer, "min")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 3
Affirmation_Time *= 60000
}
else If InStr(Affirmation_Timer, "hr")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 2
Affirmation_Time *= 3600000
}
Aff_Full_Path = %FileSelected%
SplitPath, Aff_Full_Path, Aff_File_Name
Gosub, TrayMenu
; Loops through affirmations.txt file and functions to display each affirmation separated by delimiter.
Loop, %FileSelected%
array .= A_LoopFileFullPath "," ; build array
StringTrimRight, array, array, 1
; functions to adjust GUI based on user preferences
Menu, AffTimer, Check, %Affirmation_Timer%
Menu, Transparent, Check, %Transparent%
Menu, Always_On_Top, Check, %Always_On_Top%
If Always_On_Top = On
AlwaysOnTop = +AlwaysOnTop
If Always_On_Top = Off
AlwaysOnTop =
; Handle upto Font size 20 - need to autosize GUI to fit text
GuiHeight = 70
GuiWidth = 550
;Gui display and transparency options
Gui, +LastFound
Gui, Color, %Background_Color%
Gui, Font, %Font_Style% C%Font_Color%, %Font_Type%
If Transparent = Off
{
Gui, +ToolWindow -Caption -Border %AlwaysOnTop%
Gui, Add, Text, w%GuiWidth% h%GuiHeight% Center GuiMove vAffirmation
}
If Transparent = On
{
Gui, -Caption +ToolWindow %AlwaysOnTop%
Gui, Add, Text, w%GuiWidth% h%GuiHeight% BackgroundTrans Center GuiMove vAffirmation
WinSet, TransColor, %Background_Color% 150
}
Gui, Show, x%xPos% y%yPos% NoActivate, Affirmations
SetTimer, GetNext, %Affirmation_Time%
GoSub, GetNext
Return
uiMove:
PostMessage, 0xA1, 2,,, A
; after moving GUI, save new positions to ini file
WinGetPos, xPos, yPos, Width, Height, Affirmations
IniWrite, %xPos%, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\Affirmations.ini, Settings, yPos
Return
;Randomly get next affirmation and check if blank
GetNext:
StringSplit, arrayNo, array,`,
Random, rand, 1, %arrayNo0%
FileRead, quotes,% arrayNo%rand%
Stringsplit, quote, quotes, `%, `r`n
IfBlank:
Random, quoteNo, 1, %quote0%
if (quote%quoteNo% = "")
goto IfBlank
GuiControl,, Affirmation, % quote%quoteNo%
Return
; User Preferences Tray
TrayMenu:
Menu, Tray, Icon , %A_Scriptdir%\Resources\comments.ico, IconNumber, 1
Menu, Tray, Tip, Affirmations`n%Aff_File_Name%
Menu, Tray, MainWindow
Menu, Tray, NoStandard
Menu, Tray, Add, Affirmations, Affirmations
Menu, Tray, Add
Menu, Tray, Add, Select File, AffirmationFile
Menu, Tray, Add
Menu, Tray, Add, Font Selection, Font_Select
Menu, Colors, Add, TextColor
Menu, Colors, Add, BackgroundColor
Menu, Tray, Add, Choose Colors, :Colors
Menu, AffTimer, Add, 100msec
Menu, AffTimer, Add, 1sec
Menu, AffTimer, Add, 10sec
Menu, AffTimer, Add, 30sec
Menu, AffTimer, Add, 1min
Menu, AffTimer, Add, 5min
Menu, AffTimer, Add, 10min
Menu, AffTimer, Add, 20min
Menu, AffTimer, Add, 30min
Menu, AffTimer, Add, 1hr
Menu, Tray, Add, Loop Timer, :AffTimer
Menu, Transparent, Add, On
Menu, Transparent, Add, Off
Menu, Tray, Add, Transparent, :Transparent
Menu, Always_On_Top, Add, On
Menu, Always_On_Top, Add, Off
Menu, Tray, Add, Always on Top, :Always_On_Top
Menu, Tray, Add, Hide, Hide
Menu, Tray, Add, Show, Show
Menu, Tray, Add, Exit, Exit
Menu, Tray, Add
Menu, Tray, Add, Help, Help
Menu, Tray, Add, About, About
Menu, Tray, Disable, Show
Menu, Tray, Default, Affirmations
Return
Affirmations:
Gui, Show, , Affirmations
Return
;Allow user to pick affirmations text file from Windows Explorer
AffirmationFile:
Gui +OwnDialogs
FileSelectedBak := FileSelected
FileSelectFile, FileSelected
If ErrorLevel
FileSelected := FileSelectedBak
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
GoSub, Menu_Change
Return
; Font Preferences
Font_Select:
if !CmnDlg_ChooseFont(Font_Type, Font_Style, Font_Color)
return
IniWrite, %Font_Type%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Type
IniWrite, %Font_Style%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Style
IniWrite, %Font_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Color
Gosub, Menu_Change
Return
; Color Preferences, update ini file
TextColor:
if !CmnDlg_ChooseColor(Font_Color)
return
IniWrite, %Font_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Color
Gosub, Menu_Change
Return
BackgroundColor:
if !CmnDlg_ChooseColor(Background_Color)
return
IniWrite, %Background_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
Gosub, Menu_Change
Return
; Entries for Timer
100msec:
1sec:
10sec:
30sec:
1min:
5min:
10min:
20min:
30min:
1hr:
IniWrite, %A_ThisLabel%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
;Misc. Preference settings
On:
If A_ThisMenu = Transparent
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Off:
If A_ThisMenu = Transparent
IniWrite, Off, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, Off, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Show:
Gui, Show, , Affirmations
Menu, Tray, ToggleEnable, Show
Menu, Tray, ToggleEnable, Hide
Return
Hide:
Gui, Submit, Affirmations
Menu, Tray, ToggleEnable, Hide
Menu, Tray, ToggleEnable, Show
Return
; On any icon tray preferences change, reload script to reflect changes.
Menu_Change:
Reload
Return
; Just holding places for Help & About screens
Help:
MsgBox, 64, Affirmations - Help, To Be Completed Later`n
Return
About:
MsgBox, 64, Affirmations - About, To Be Completed Later`n
Return
; on exit, make sure everything is saved to ini file
Exit:
GuiEscape:
GuiClose:
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
IniWrite, %Font_Type%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Type
IniWrite, %Font_Style%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Style
IniWrite, %Font_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Font_Color
IniWrite, %Background_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniWrite, %Transparent%, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniWrite, %Always_On_Top%, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
WinGetPos, xPos, yPos, Width, Height, Affirmations
IniWrite, %xPos%, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\Affirmations.ini, Settings, yPos
ExitApp
|
File Downloads:
Installation Notes:
* There seems to be a glitch if you upgrade while program is running. Recommend you close down program, delete affirmations.ini file, if it exists, then install upgrade.
* If your using a custom affirmations.txt file, rename it before any upgrade.
* If you have AHK installed and want to run the script, rather than the exe, add the \Lib\*.* directory & files to your AutoHotKey folder.
Beta 1.0 Affirmations.ahk/exe
http://www.autohotkey.net/~TotalBalance/Self-Help%20Scripts/Affirmations_beta_1.0.zip
* Streamlined Timer function (thanks Kudos)
Alpha v.0.50 Affirmations_alpha.ahk/exe - Includes Affirmations.txt and icon files.
* Fixed bug in file selection dialog box (thanks Skan)
* Saved GUI xPos & yPos to ini file immediately after user move GUI _________________ Lars
Last edited by TotalBalance on Thu Jan 10, 2008 1:55 am; edited 51 times in total |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu Dec 06, 2007 3:30 am Post subject: |
|
|
This is nice. Good job. Please consider getting an autohotkey.net account to host your files for the forum. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Thu Dec 06, 2007 3:49 am Post subject: |
|
|
Thanks ahklerner, a compliment from you means a LOT! Couldn't have pulled this one of without your help.
I thought about creating an autohotkey.net account. Help me out here.
I use DivShare because it allows unlimited uploads of almost any file type and up to 200M per upload. Like autohotkey.net it's free. I use it for much more than just AHK scripts.
If the AHK script sharing defatco is to upload to autohotkey.net, I'll do so in support of a great app. and AHK experts like you. It just means some additional overhead on my part to make sure everything is synced between different upload sites. Is this what you recommend? _________________ Lars |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu Dec 06, 2007 3:58 am Post subject: |
|
|
It is completely your preference. I do not know how that particular site works, but the ones I have seen will delete the files if it has not been downloaded within a certain period of time. It just sucks to search for however long and find something you are really interested in and 'poof' the file is not there. Some people are unaware that Titan offers to host the files for the forum. That was the main reason I said anything. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Thu Dec 06, 2007 4:09 am Post subject: |
|
|
Understood. Thanks for the comments.
One of the primary reasons I use DivShare (besides those mentioned above) is it also has some nice extensions that allow me to easily link Wordpress and Facebook posts/entries to referenced files.
Regardless, I've just uploaded zipped file to autohotkey.net and will do so for all future scripts (might need a little help "certifying" they're worthy of public consumption )
I'll update this post with link shortly. _________________ Lars |
|
| Back to top |
|
 |
pockinator
Joined: 06 Dec 2007 Posts: 33
|
Posted: Thu Dec 06, 2007 3:46 pm Post subject: |
|
|
TotalBalance, thanks so much for this! I have been looking for something like this for a long time. I've always wanted to create something like this but my programming skills are less than amateur.
Here's a quick note: I've noticed that when Transparency is set to "On", the selected background color still shows through as sort of a very thin border around each letter of the text. I have posted a screenshot for a better idea of what's going on. This occurs regardless of what the text color and the background color are set to. Here I have the text color set to lime, the background is set to red, and transparent is set to on.
Is there a setting that I may have overlooked in changing? That's very possible.
Thanks for all your help and for a fantastic script! |
|
| Back to top |
|
 |
pockinator
Joined: 06 Dec 2007 Posts: 33
|
Posted: Thu Dec 06, 2007 4:13 pm Post subject: |
|
|
I was playing around with changing the font in the script and noticed a tiny syntax error that wouldn't allow the font to be adjusted.
The line that contains this:
| Code: | | Gui, Font, s%Text_Size% C%Text_Color% %Font_Type% %Font_Style% |
...should look like this:
| Code: | | Gui, Font, s%Text_Size% C%Text_Color% %Font_Style%, %Font_Type% |
Just a simple comma missing, that's all. Thanks again for a great script!  |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Thu Dec 06, 2007 4:23 pm Post subject: |
|
|
Hi pockinator,
Thanks for your kind words. Really the credit should go to this forum and a few members listed above for some great script examples & help to work from.
Looking at your screenshot, replicating a Red background/Green Text Color - correct?, increase text size, etc. I can't replicate your issue.
It makes me wonder if the issue is display driver related? That's just a guess.
Is anyone else experiencing what pockinator's screenshot shows? Any ideas from others more knowledgeable than me on how to help troubleshoot or modify the code to fix? _________________ Lars |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Thu Dec 06, 2007 4:34 pm Post subject: |
|
|
| Quote: | I was playing around with changing the font in the script and noticed a tiny syntax error that wouldn't allow the font to be adjusted.
The line that contains this:
Code (Copy):
Gui, Font, s%Text_Size% C%Text_Color% %Font_Type% %Font_Style%
...should look like this:
Code (Copy):
Gui, Font, s%Text_Size% C%Text_Color% %Font_Style%, %Font_Type% |
Thanks for the catch! I've just modified the code and will republish shortly. Did that fix the issue you where having? _________________ Lars |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Thu Dec 06, 2007 5:23 pm Post subject: |
|
|
pockinator,
I think your problem is that you have ClearType (Anti-Aliasing) turned on, which make softer edges to fonts, but also causes that side effect (because the background color is modified slightly to make the smooth font). The modified background now no longer matches the transparency color, so is not hidden. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
pockinator
Joined: 06 Dec 2007 Posts: 33
|
Posted: Thu Dec 06, 2007 6:21 pm Post subject: |
|
|
| TotalBalance wrote: | | Did that fix the issue you where having? |
No, it didn't fix the color issue.
| engunneer wrote: | | I think your problem is that you have ClearType (Anti-Aliasing) turned on, which make softer edges to fonts, but also causes that side effect (because the background color is modified slightly to make the smooth font). The modified background now no longer matches the transparency color, so is not hidden. |
That's true, I do have it turned on. Is there a way to deactivate ClearType solely for this one particular script? I do like having ClearType on for everything else. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Thu Dec 06, 2007 8:56 pm Post subject: |
|
|
I'm not sure. I think it's a system wide setting. There was a recent article on lifehacker telling you how to turn it on and off. I didn't read closely enough to notice if they mentioned a way to make it program specific. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Andreone
Joined: 20 Jul 2007 Posts: 257 Location: Paris, France
|
Posted: Thu Dec 06, 2007 9:14 pm Post subject: |
|
|
Original idea Nice.
As you requested, here's some ideas:
- why limit the color choices? You could use majekinor's [module] CmnDlg 4.0 - Common Dialogs for StdLib and use the standard color picker.
- same thing about the font parameters (font type & size)
- a new menu item to append to the current selected file the content of the clipboard. This way, if you find a quote you like somewhere (website or whatever), you could easily add it to your favorite ones.
That's all I see for now.
Thanks |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Thu Dec 06, 2007 9:37 pm Post subject: |
|
|
| Quote: | As you requested, here's some ideas:
- why limit the color choices? You could use majekinor's [module] CmnDlg 4.0 - Common Dialogs for StdLib and use the standard color picker.
- same thing about the font parameters (font type & size)
- a new menu item to append to the current selected file the content of the clipboard. This way, if you find a quote you like somewhere (website or whatever), you could easily add it to your favorite ones. |
All great ideas and agree they should all be implemented. Thanks!
The only challenge is I'm not really a programmer so I'll have to do some research and very likely "dip into the well" for help from some of the ahk gurus who hang out here.
Of course, if anyone wants to take a crack at implementing the above, or some part of it, by all mean do  _________________ Lars |
|
| Back to top |
|
 |
Andreone
Joined: 20 Jul 2007 Posts: 257 Location: Paris, France
|
Posted: Thu Dec 06, 2007 10:19 pm Post subject: |
|
|
| Code: | SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
#Persistent
SetBatchLines -1
DetectHiddenWindows, On
FileSelected = %A_Scriptdir%\Resources\Affirmations.txt
; Create, read/write ini file
IfNotExist, %A_Scriptdir%\Affirmations.ini
{
IniWrite, Center, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, Center, %A_Scriptdir%\Affirmations.ini, Settings, yPos
IniWrite, Black, %A_Scriptdir%\Affirmations.ini, Settings, Text_Color
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniWrite, 16, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
IniWrite, Red, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
IniWrite, 5min, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
}
IfExist, %A_Scriptdir%\Affirmations.ini
{
IniRead, xPos, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniRead, yPos, %A_Scriptdir%\Affirmations.ini, Settings, yPos
IniRead, Text_Color, %A_Scriptdir%\Affirmations.ini, Settings, Text_Color
IniRead, Background_Color, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniRead, Text_Size, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
IniRead, Transparent, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniRead, Always_On_Top, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniRead, FileSelected, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
IniRead, Affirmation_Timer, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
}
; present user friendly menu tray items for timer options
If InStr(Affirmation_Timer, "msec")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 4
Affirmation_Time *= 1
}
else If InStr(Affirmation_Timer, "sec")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 3
Affirmation_Time *= 1000
}
else If InStr(Affirmation_Timer, "min")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 3
Affirmation_Time *= 60000
}
else If InStr(Affirmation_Timer, "hr")
{
StringTrimRight, Affirmation_Time, Affirmation_Timer, 2
Affirmation_Time *= 3600000
}
Aff_Full_Path = %FileSelected%
SplitPath, Aff_Full_Path, Aff_File_Name
Gosub, TrayMenu
; Loops through affirmations.txt file and functions to display each affirmation separated by delimiter.
Loop, %FileSelected%
array .= A_LoopFileFullPath "," ; build array
StringTrimRight, array, array, 1
; functions to adjust GUI based on user preferences
Menu, AffTimer, Check, %Affirmation_Timer%
Menu, Transparent, Check, %Transparent%
Menu, TextSize, Check, %Text_Size%
Menu, Always_On_Top, Check, %Always_On_Top%
;~ Menu, TextColor, ToggleEnable, %Text_Color_Check%
;~ Menu, BackgroundColor, ToggleEnable, %Background_Color_Check%
If Always_On_Top = On
AlwaysOnTop = +AlwaysOnTop
If Always_On_Top = Off
AlwaysOnTop =
If Text_Size = 12
GuiHeight = 40
If Text_Size = 16
GuiHeight = 50
If Text_Size = 20
GuiHeight = 70
If Text_Size = 24
GuiHeight = 90
If Text_Size = 28
GuiHeight = 110
If Text_Size = 32
GuiHeight = 130
If Text_Size = 36
GuiHeight = 160
; future version to include font type & style options in Preferences
Font_Type = Verdana
Font_Style = Bold
;Gui functions to handle transparency options
Gui, +LastFound
Gui, Color, %Background_Color%
Gui, Font, s%Text_Size% C%Text_Color% %Font_Style%, %Font_Type%
If Transparent = Off
{
Gui, +ToolWindow -Caption -Border %AlwaysOnTop%
Gui, Add, Text, w550 h%GuiHeight% Center GuiMove vAffirmation
}
If Transparent = On
{
Gui, -Caption +ToolWindow %AlwaysOnTop%
Gui, Add, Text, w550 h%GuiHeight% BackgroundTrans Center GuiMove vAffirmation
WinSet, TransColor, %Background_Color% 150
}
Gui, Show, x%xPos% y%yPos% NoActivate, Affirmations
SetTimer, GetNext, %Affirmation_Time%
GoSub, GetNext
Return
uiMove:
PostMessage, 0xA1, 2,,, A
Return
;Randomly get next affirmation and check if blank
GetNext:
StringSplit, arrayNo, array,`,
Random, rand, 1, %arrayNo0%
FileRead, quotes,% arrayNo%rand%
Stringsplit, quote, quotes, `%, `r`n
IfBlank:
Random, quoteNo, 1, %quote0%
if (quote%quoteNo% = "")
goto IfBlank
GuiControl,, Affirmation, % quote%quoteNo%
Return
; User Preferences Tray
TrayMenu:
Menu, Tray, Icon , %A_ScriptDir%\Resources\comments.ico, IconNumber, 1
Menu, Tray, Tip, Affirmations`n%Aff_File_Name%
Menu, Tray, MainWindow
Menu, Tray, NoStandard
Menu, Tray, Add, Affirmations, Affirmations
Menu, Tray, Add
Menu, Tray, Add, Select File, AffirmationFile
Menu, Tray, Add
Menu, AffTimer, Add, 100msec
Menu, AffTimer, Add, 1sec
Menu, AffTimer, Add, 10sec
Menu, AffTimer, Add, 30sec
Menu, AffTimer, Add, 1min
Menu, AffTimer, Add, 5min
Menu, AffTimer, Add, 10min
Menu, AffTimer, Add, 20min
Menu, AffTimer, Add, 30min
Menu, AffTimer, Add, 1hr
Menu, Tray, Add, Loop Timer, :AffTimer
Menu, Colors, Add, TextColor
Menu, Colors, Add, BackgroundColor
Menu, Tray, Add, Choose Colors, :Colors
Menu, TextSize, Add, 12
Menu, TextSize, Add, 16
Menu, TextSize, Add, 20
Menu, TextSize, Add, 24
Menu, TextSize, Add, 28
Menu, TextSize, Add, 32
Menu, TextSize, Add, 36
Menu, Tray, Add, Text Size, :TextSize
Menu, Transparent, Add, On
Menu, Transparent, Add, Off
Menu, Tray, Add, Transparent, :Transparent
Menu, Always_On_Top, Add, On
Menu, Always_On_Top, Add, Off
Menu, Tray, Add, Always on Top, :Always_On_Top
Menu, Tray, Add, Hide, Hide
Menu, Tray, Add, Show, Show
Menu, Tray, Add, Exit, Exit
Menu, Tray, Add
Menu, Tray, Add, Help, Help
Menu, Tray, Add, About, About
Menu, Tray, Disable, Show
Menu, Tray, Default, Affirmations
Return
Affirmations:
Gui, Show, , Affirmations
Return
;Allow user to pick affirmations text file from Windows Explorer
AffirmationFile:
Gui +OwnDialogs
FileSelectFile, FileSelected
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
GoSub, Menu_Change
Return
; Color Preferences, update ini file
TextColor:
if !CmnDlg_ChooseColor(Text_Color)
return
IniWrite, %Text_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Text_Color
Gosub, Menu_Change
Return
BackgroundColor:
if !CmnDlg_ChooseColor(Background_Color)
return
IniWrite, %Background_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
Gosub, Menu_Change
Return
; Entries for Timer
; 1/10 sec
100msec:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 1 sec.
1sec:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 10 sec
10sec:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 30 sec.
30sec:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 1min
1min:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 5min
5min:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 10min
10min:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
;20 min.
20min:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 30min
30min:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
; 01hr
1hr:
IniWrite, %A_ThisMenuItem%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_Timer
Gosub, Menu_Change
Return
;Entries for Text Size
12:
IniWrite, 12, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
16:
IniWrite, 16, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
20:
IniWrite, 20, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
24:
IniWrite, 24, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
28:
IniWrite, 28, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
32:
IniWrite, 32, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
36:
IniWrite, 36, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
Gosub, Menu_Change
Return
;Misc. Preference settings
On:
If A_ThisMenu = Transparent
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, On, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Off:
If A_ThisMenu = Transparent
IniWrite, Off, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, Off, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Show:
Gui, Show, , Affirmations
Menu, Tray, ToggleEnable, Show
Menu, Tray, ToggleEnable, Hide
Return
Hide:
Gui, Submit, Affirmations
Menu, Tray, ToggleEnable, Hide
Menu, Tray, ToggleEnable, Show
Return
; On any icon tray preferences change, save GUI position and reload script to reflect changes.
Menu_Change:
WinGetPos, xPos, yPos, Width, Height, Affirmations
IniWrite, %xPos%, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\Affirmations.ini, Settings, yPos
Reload
Return
; Just holding places for Help & About screens
Help:
MsgBox, 64, Affirmations - Help, To Be Completed Later`n
Return
About:
MsgBox, 64, Affirmations - About, To Be Completed Later`n
Return
; on exit, make sure everything is saved to ini file
Exit:
GuiClose:
IniWrite, %Text_Size%, %A_Scriptdir%\Affirmations.ini, Settings, Text_Size
IniWrite, %Text_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Text_Color
IniWrite, %Transparent%, %A_Scriptdir%\Affirmations.ini, Settings, Transparent
IniWrite, %Always_On_Top%, %A_Scriptdir%\Affirmations.ini, Settings, Always_On_Top
IniWrite, %Background_Color%, %A_Scriptdir%\Affirmations.ini, Settings, Background_Color
IniWrite, %FileSelected%, %A_Scriptdir%\Affirmations.ini, Settings, Affirmation_File
WinGetPos, xPos, yPos, Width, Height, Affirmations
IniWrite, %xPos%, %A_Scriptdir%\Affirmations.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\Affirmations.ini, Settings, yPos
ExitApp | Here's the implementation of custom colors (text and background). You need to download and put in your stdlib Majekinor' script I mentioned in my previous mail.
I have removed the lines corresponding to the text and background menu creation and item checking. There's one menu "Colors" with two sub-items Text and Background.
I replaced all color labels by two labels (one for the text and one for the background).
With this example, you can see that using common dialogs are easy (again, thanks to Majekinor ). I let you deal with the font face and size.
About the saving the clipboard content, look at the FileAppend command. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|