Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Little post-it widget


  • Please log in to reply
4 replies to this topic
Alexou
  • Members
  • 40 posts
  • Last active: Feb 02 2016 06:39 PM
  • Joined: 10 Aug 2015

Hi,

 

I'm noob with AHK and this is my first little app.

 

It's a simple post-it widget

 

Maybe the script is not really clean, you can give me some suggestions to clean or optimise the script ?

 

#NoEnv
#SingleInstance force


SetWorkingDir %A_ScriptDir%
data=%A_WorkingDir%\data
inifile=%data%\settings.ini
ifnotexist,%inifile%
    {
IniWrite, x200 y200, %IniFile%, window position, gui_position
IniWrite, 13px, %IniFile%, settings, Tsize
IniWrite, Black, %IniFile%, settings, ColorText
IniWrite, 200, %IniFile%, settings, PostitSize
IniWrite, Yellow, %IniFile%, settings, ColorPostit
IniWrite, %data%\postit.png, %IniFile%, settings, ColPostit
IniWrite, 1, %IniFile%, settings, TrayCheck
    }
IniRead, gui_position, %IniFile%, window position, gui_position, Center
IniRead, ColorText, %IniFile%, settings, ColorText
IniRead, Tsize, %IniFile%, settings, Tsize
IniRead, PostitSize, %IniFile%, settings, PostitSize
IniRead, ColorPostit, %IniFile%, settings, ColorPostit
IniRead, ColPostit, %IniFile%, settings, ColPostit
IniRead, TrayCheck, %IniFile%, settings, TrayCheck


FileAppend,%MultiLineInput%,%data%\\edit.txt
FileRead,ReadMultiLineInput,%data%\\edit.txt




PostitSize2:=round(PostitSize/1.14,1)  ;  PostitSize2 is most small than PostitSize


Gui, +Hwndgui_id  ;~ get the window's ID so you can get its position later


Gui, +ToolWindow -Caption +LastFound
CustomColor = bdbdbd
Gui, Color, %CustomColor%
WinSet, TransColor, %CustomColor%


Gui, Add, Picture, w%PostitSize% h%PostitSize% x0 y0 GuiMove vPostit, %ColPostit% 
Gui, Font, s%Tsize%, Comic Sans MS
Gui, Add,text,x10 y15 w%PostitSize2% h%PostitSize2% c%ColorText% BackgroundTrans vtext, %ReadMultiLineInput%


Menu, menu1, Add, Edit Postit, label1
Menu, menu1, Add, Settings, label2
Menu, menu1, Add, Exit, label3


If (TrayCheck = 1) { 
Menu, Tray, Click, 1
Menu, Tray, NoStandard
Menu, Tray, Add, Show PosTux, Open
Menu, Tray, Default, Show PosTux
Menu, Tray, Add, Edit Postit, label1
Menu, Tray, Add, Settings, label2
Menu, Tray, Add, Exit
Menu, Tray, Icon, %data%\Postit-icon.ico
} 
else
{
Menu, Tray, NoIcon
}
Gui, Show,  %gui_position% w%PostitSize% h%PostitSize%, PosTux
return 


uiMove:
PostMessage, 0xA1, 2,,, A 
sleep, 500
WinGetPos, gui_x, gui_y,,, ahk_id %gui_id%
IniWrite, x%gui_x% y%gui_y%, %IniFile%, window position, gui_position
Return




;~ Show the menu when you right-click:
GuiContextMenu:
Menu, menu1, Show, %A_GuiX%, %A_GuiY%
Return




;~ Do something when you click the menu:


label1:
Gui, 2: Add, Edit, x12 y29 w300 h210 vMultiLineInput, %ReadMultiLineInput%
Gui, 2: Add, Button, x202 y249 w100 h30 gEditOk, Ok
Gui, 2: Add, Button, x22 y249 w100 h30 gEditCancel, Cancel
Gui, 2: Add, Text, x12 y9 w260 h20 , Edit your postit
Gui, 2: Show, x673 y316 h290 w325, Edit Postit
Return


EditOk:
Gui, 2: Submit, NoHide
FileDelete,%data%\\edit.txt
FileAppend,%MultiLineInput%,%data%\\edit.txt
FileRead,ReadMultiLineInput,%data%\\edit.txt
GuiControl,, text, %ReadMultiLineInput%
SetTimer, EditOk, 10
sleep, 100
SetTimer, EditOk, off
Gui, 2: Destroy
return


EditCancel:
Gui, 2: Destroy
return


2GuiClose:
Gui, 2: Destroy
return






label2:
Gui, 3: Add, DropDownList, x42 y39 w50 h200 vTsize gTsize, 10px|11px|12px|13px|14px|15px|16px|17px|18px|19px|20px|21px|22px|23px|24px|25px|26px|27px|28px|29px|30px|31px|32px|33px|34px|35px|36px|37px|38px|39px|40px       
GuiControl, 3: Choose, Tsize, |%Tsize%


Gui, 3: Add, DropDownList, x142 y39 w110 h130 vColorText gColorText,  White|Black|Red|Green|Blue|Yellow|Gray 
GuiControl, 3: Choose, ColorText, |%ColorText%


Gui, 3: Add, Slider, x42 y109 w200 h30 gshow_result vPostitSize Range150-500, %PostitSize%
Gui, 3: Add, Text, x120 y140 w260 h15 vScore, %PostitSize%px
Gui, 3: Add, DropDownList, x92 y165 w100 h120 vColorPostit gColorPostit, Yellow|Green|White|Blue|Pink|Orange 
GuiControl, 3: Choose, ColorPostit, |%ColorPostit%


Gui, 3: Add, GroupBox, x12 y14 w260 h60 , Text size and color
Gui, 3: Add, GroupBox, x12 y89 w260 h110 , Postit Size and color
Gui, 3: Add, CheckBox, x14 y200 w150 h30 vTrayCheck gTrayCheck Checked%TrayCheck%, Enable tray icon ?
Gui, 3: Add, Button, x32 y235 w100 h30 gSetCancel, Cancel
Gui, 3: Add, Button, x152 y235 w100 h30 gSetOk, Ok
Gui, 3: Show, x655 y318 h275 w283, Settings
return




Tsize:
Gui, Submit, NoHide
Gui, 1: Font, s%Tsize%
GuiControl, 1: Font, text
GuiControl, 1: Hide, text
GuiControl, 1: Show, text


SetTimer, Tsize, 10
sleep, 100
SetTimer, Tsize, off
return




ColorText:
Gui, Submit, NoHide
Gui, 1: Font, c%ColorText%
GuiControl, 1: Font, text
GuiControl, 1: Hide, text
GuiControl, 1: Show, text


SetTimer, ColorText, 10
sleep, 100
SetTimer, ColorText, off
return




show_result:
Gui, Submit, NoHide
GuiControl,, Score, %PostitSize%px


PostitSize2:=round(PostitSize/1.14,1)
GuiControl,, text w%PostitSize2%


GuiControl, 1: Move, Postit, w%PostitSize% h%PostitSize%
GuiControl, 1: Move, text, w%PostitSize2% h%PostitSize2%
GuiControl, 1: , Postit, %ColPostit%
Gui, 1: Hide
Gui, 1: Show, w%PostitSize% h%PostitSize%
return




ColorPostit:
Gui, Submit, NoHide
if ColorPostit = Yellow
ColPostit = %data%\postit.png


if ColorPostit = Green
ColPostit = %data%\postit-green.png


if ColorPostit =White
ColPostit = %data%\postit-white.png


if ColorPostit =Blue
ColPostit = %data%\postit-blue.png


if ColorPostit =Pink
ColPostit = %data%\postit-pink.png


if ColorPostit =Orange
ColPostit = %data%\postit-orange.png


GuiControl,1:,  Postit, %ColPostit%
return




TrayCheck:
Gui, Submit, NoHide
If (TrayCheck = 1) { 
Menu, Tray, Icon
Menu, Tray, Icon, %data%\Postit-icon.ico
Menu, Tray, Click, 1
Menu, Tray, NoStandard
Menu, Tray, Add, Show PosTux, Open
Menu, Tray, Default, Show PosTux
Menu, Tray, Add, Edit Postit, label1
Menu, Tray, Add, Settings, label2
Menu, Tray, Add, Exit
} 
else
{ 
Menu, Tray, NoIcon
}
return




SetOk:
Gui, Submit, NoHide 
IniWrite, %Tsize%, %IniFile%, settings, Tsize
IniWrite, %ColorText%, %IniFile%, settings, ColorText
IniWrite, %PostitSize%, %IniFile%, settings, PostitSize
IniWrite, %ColorPostit%, %IniFile%, settings, ColorPostit
IniWrite, %ColPostit%, %IniFile%, settings, ColPostit
IniWrite, %TrayCheck%, %IniFile%, settings, TrayCheck
Gui, 3: Destroy
return


SetCancel:
Gui, Submit, NoHide 
IniRead, PostitSize, %IniFile%, settings, PostitSize


PostitSize2:=round(PostitSize/1.14,1)
GuiControl,, text w%PostitSize2%


GuiControl, 1: Move, Postit, w%PostitSize% h%PostitSize%
GuiControl, 1: Move, text, w%PostitSize2% h%PostitSize2%
GuiControl, 1:, Postit, %ColPostit%
Gui, 3: Destroy
return


3GuiClose:
Gui, Submit, NoHide 
IniRead, PostitSize, %IniFile%, settings, PostitSize


PostitSize2:=round(PostitSize/1.14,1)
GuiControl,, text w%PostitSize2%


GuiControl, 1: Move, Postit, w%PostitSize% h%PostitSize%
GuiControl, 1: Move, text, w%PostitSize2% h%PostitSize2%
GuiControl, 1:, Postit, %ColPostit%
Gui, 3: Destroy
return


label3:
ExitApp
return


Open:
reload
return


Exit:
ExitApp
return


GuiClose:
ExitApp

You can download the widget here : http://www.mediafire...eb4x/PosTux.zip

 

Sorry for my poor english

Thanks



DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
I get this error.


---------------------------
temp.ahk
---------------------------
Error: Invalid option.

Specifically: wERROR hERROR

Line#
062: Menu,Tray,Add,Exit
063: Menu,Tray,Icon,%data%\Postit-icon.ico
064: }
065: Else
066: {
067: Menu,Tray,NoIcon
068: }
---> 069: Gui,Show,%gui_position% w%PostitSize% h%PostitSize%,PosTux
070: Return
074: PostMessage,0xA1,2,,,A
075: Sleep,500
076: WinGetPos,gui_x,gui_y,,,ahk_id %gui_id%
077: IniWrite,x%gui_x% y%gui_y%,%IniFile%,window position,gui_position
078: Return
085: Menu,menu1,Show,%A_GuiX%,%A_GuiY%

The current thread will exit.
---------------------------
OK
---------------------------
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

Alexou
  • Members
  • 40 posts
  • Last active: Feb 02 2016 06:39 PM
  • Joined: 10 Aug 2015

Yes, this is normal because you need the data folder... you have to download the widget.

 

You can find here a new version include GDI for better post-it quality.

 

http://www.mediafire.../PosTux-gdi.zip

 

 

the script :

 

#NoEnv
#SingleInstance force
SetWinDelay, -1
SetBatchLines, -1
#include Gdip_All.ahk

SetWorkingDir %A_ScriptDir%
data=%A_WorkingDir%\data
inifile=%data%\settings.ini

FileAppend,%MultiLineInput%,%data%\\edit.txt
FileRead,ReadMultiLineInput,%data%\\edit.txt

Cancel:
IfNotExist,%inifile%
    {
IniWrite, x200 y200, %IniFile%, window position, gui_position
IniWrite, 13px, %IniFile%, settings, Tsize
IniWrite, Black, %IniFile%, settings, ColorText
IniWrite, 200, %IniFile%, settings, PostitSize
IniWrite, Yellow, %IniFile%, settings, ColorPostit
IniWrite, %data%\postit.png, %IniFile%, settings, ColPostit
IniWrite, 1, %IniFile%, settings, TrayCheck
    }
IniRead, gui_position, %IniFile%, window position, gui_position, Center
IniRead, ColorText, %IniFile%, settings, ColorText
IniRead, Tsize, %IniFile%, settings, Tsize
IniRead, PostitSize, %IniFile%, settings, PostitSize
IniRead, ColorPostit, %IniFile%, settings, ColorPostit
IniRead, ColPostit, %IniFile%, settings, ColPostit
IniRead, TrayCheck, %IniFile%, settings, TrayCheck


Global gui_id, gui_x, gui_y, HChild, XChild, YChild
Gui, Main: New, -Caption +ToolWindow +LastFound +OwnDialogs +Hwndgui_id +E0x80000 +LabelGui  
hwnd1 := WinExist()

upd = 0

update:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(pGraphics)
Gdip_Shutdown(pToken)

PostitSize2:=round(PostitSize/1.14,1)  

sFile = %ColPostit%
pToken := Gdip_Startup()
pBitmap:=Gdip_CreateBitmapFromFile(sFile)

Width = %PostitSize%
Height = %PostitSize%
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height )
UpdateLayeredWindow(hwnd1, hdc, , , Width, Height)
SelectObject(hdc, obm)

if (upd = 1){
return
}

Gui, Child: New, -Caption +LastFound +ToolWindow  +HwndHChild +OwnerMain
CustomColor = bdbdbd
Gui, Child: Color, %CustomColor%
WinSet, TransColor, %CustomColor%

Menu, menu1, Add, Edit Postit, label1
Menu, menu1, Add, Settings, label2
Menu, menu1, Add, Exit, label3

If (TrayCheck = 1) { 
Menu, Tray, Click, 1
Menu, Tray, NoStandard
Menu, Tray, Add, Show PosTux, Open
Menu, Tray, Default, Show PosTux
Menu, Tray, Add, Edit Postit, label1
Menu, Tray, Add, Settings, label2
Menu, Tray, Add, Exit
Menu, Tray, Icon, %data%\Postit-icon.ico
} 
else
{
Menu, Tray, NoIcon
}

Gui, Child: Font, s%Tsize%, Comic Sans MS
Gui, Child: Add, text, x10 y15 w%PostitSize2% h%PostitSize2% c%ColorText% BackgroundTrans vtext, %ReadMultiLineInput%

Gui, Main: Show, %gui_position% w%PostitSize% h%PostitSize%
WinGetPos, gui_x, gui_y, W, H, ahk_id %gui_id%
XChild := gui_x + 0, YChild := gui_y + 0

Gui, Child: Show, %gui_position% w%PostitSize% h%PostitSize%

OnMessage(0x0201, "WM_LBUTTONDOWN")
OnMessage(0x0216, "WM_MOVING")
OnMessage(0x0232, "WM_EXITSIZEMOVE")

Return


WM_LBUTTONDOWN() {
   If (A_Gui = "Main")
  PostMessage, 0xA1, 2,,, A   
}
WM_EXITSIZEMOVE() {
   If (A_Gui = "Main")
  WinActivate, ahk_id %HChild%
   gosub uiMove
}
WM_MOVING(W, L) {
   If (A_Gui = "Main") {
      DX := NumGet(L + 0, 0, "Int") - gui_x, DY := NumGet(L + 0, 4, "Int") - gui_y
      WinMove, ahk_id %HChild%, , % (XChild += DX), % (YChild += DY)
      gui_x += DX, gui_y += DY
   }
} 
return

uiMove:
WinGetPos, gui_x, gui_y,,, ahk_id %gui_id%
IniWrite, x%gui_x% y%gui_y%, %IniFile%, window position, gui_position
Return

;~ Show the menu when you right-click:
GuiContextMenu:
Menu, menu1, Show, %A_GuiX%, %A_GuiY%
Return

;~ Do something when you click the menu:

label1:
Gui, 2: Destroy
Gui, 2: Add, Edit, x12 y29 w300 h210 vMultiLineInput, %ReadMultiLineInput%
Gui, 2: Add, Button, x202 y249 w100 h30 gEditOk, Ok
Gui, 2: Add, Button, x22 y249 w100 h30 gEditCancel, Cancel
Gui, 2: Add, Text, x12 y9 w260 h20 , Edit your postit
Gui, 2: Show, , Edit Postit
Return

EditOk:
Gui, 2: Submit, NoHide
FileDelete,%data%\\edit.txt
FileAppend,%MultiLineInput%,%data%\\edit.txt
FileRead,ReadMultiLineInput,%data%\\edit.txt
GuiControl, Child:, text, %ReadMultiLineInput%
Gui, 2: Destroy
return

EditCancel:
Gui, 2: Destroy
return

2GuiClose:
Gui, 2: Destroy
return

label2:
Gui, 3: Destroy
IniRead, gui_position, %IniFile%, window position, gui_position, Center

Gui, 3: Add, DropDownList, x42 y39 w50 h200 vTsize gTsize, 10px|11px|12px|13px|14px|15px|16px|17px|18px|19px|20px|21px|22px|23px|24px|25px|26px|27px|28px|29px|30px|31px|32px|33px|34px|35px|36px|37px|38px|39px|40px       
GuiControl, 3: Choose, Tsize, %Tsize%

Gui, 3: Add, DropDownList, x142 y39 w110 h130 vColorText gColorText,  White|Black|Red|Green|Blue|Yellow|Gray 
GuiControl, 3: Choose, ColorText, %ColorText%

Gui, 3: Add, Slider, x42 y109 w200 h30 gshow_result vPostitSize Range150-500, %PostitSize%
Gui, 3: Add, Text, x120 y140 w260 h15 vScore, %PostitSize%px
Gui, 3: Add, DropDownList, x92 y165 w100 h120 vColorPostit gColorPostit, Yellow|Green|White|Blue|Pink|Orange 
GuiControl, 3: Choose, ColorPostit, %ColorPostit%

Gui, 3: Add, GroupBox, x12 y14 w260 h60 , Text size and color
Gui, 3: Add, GroupBox, x12 y89 w260 h110 , Postit Size and color
Gui, 3: Add, CheckBox, x14 y200 w150 h30 vTrayCheck gTrayCheck Checked%TrayCheck%, Enable tray icon ?
Gui, 3: Add, Button, x32 y235 w100 h30 gSetCancel, Cancel
Gui, 3: Add, Button, x152 y235 w100 h30 gSetOk, Ok
sleep, 100
Gui, 3: Show, h275 w283, Settings
return

Tsize:
Gui, Submit, NoHide
Gui, Child: Font, s%Tsize%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text
return

ColorText:
Gui, Submit, NoHide
Gui, Child: Font, c%ColorText%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text
return

show_result:
Gui, Submit, NoHide
GuiControl,, Score, %PostitSize%px
PostitSize2:=round(PostitSize/1.14,1)
GuiControl, Child: Move, text, w%PostitSize2% h%PostitSize2%
Gui, Child: Hide
Gui, Child: Show, w%PostitSize% h%PostitSize% 
Gui, Main: Hide
Gui, Main: Show, w%PostitSize% h%PostitSize% 
upd = 1
gosub update
return

ColorPostit:
Gui, Submit, NoHide
if ColorPostit = Yellow
ColPostit = %data%\postit.png

if ColorPostit = Green
ColPostit = %data%\postit-green.png

if ColorPostit =White
ColPostit = %data%\postit-white.png

if ColorPostit =Blue
ColPostit = %data%\postit-blue.png

if ColorPostit =Pink
ColPostit = %data%\postit-pink.png

if ColorPostit =Orange
ColPostit = %data%\postit-orange.png

upd = 1
gosub update
return

TrayCheck:
Gui, Submit, NoHide
If (TrayCheck = 1) { 
Menu, Tray, Icon
Menu, Tray, Icon, %data%\Postit-icon.ico
Menu, Tray, Click, 1
Menu, Tray, NoStandard
Menu, Tray, Add, Show PosTux, Open
Menu, Tray, Default, Show PosTux
Menu, Tray, Add, Edit Postit, label1
Menu, Tray, Add, Settings, label2
Menu, Tray, Add, Exit
} 
else
{ 
Menu, Tray, NoIcon
}
return

SetOk:
IniWrite, %Tsize%, %IniFile%, settings, Tsize
IniWrite, %ColorText%, %IniFile%, settings, ColorText
IniWrite, %PostitSize%, %IniFile%, settings, PostitSize
IniWrite, %ColorPostit%, %IniFile%, settings, ColorPostit
IniWrite, %ColPostit%, %IniFile%, settings, ColPostit
IniWrite, %TrayCheck%, %IniFile%, settings, TrayCheck
Gui, 3: Destroy
return

SetCancel:
Gui, 3: Destroy
IniRead, ColorText, %IniFile%, settings, ColorText
IniRead, Tsize, %IniFile%, settings, Tsize
IniRead, PostitSize, %IniFile%, settings, PostitSize
IniRead, ColorPostit, %IniFile%, settings, ColorPostit
IniRead, ColPostit, %IniFile%, settings, ColPostit
IniRead, TrayCheck, %IniFile%, settings, TrayCheck

Gui, Submit, NoHide
Gui, Child: Font, s%Tsize%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text

Gui, Child: Font, c%ColorText%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text

GuiControl,, Score, %PostitSize%px
PostitSize2:=round(PostitSize/1.14,1)
GuiControl, Child: Move, text, w%PostitSize2% h%PostitSize2%
Gui, Child: Hide
Gui, Child: Show, w%PostitSize% h%PostitSize% 
Gui, Main: Hide
Gui, Main: Show, w%PostitSize% h%PostitSize% 
upd = 1
gosub update
return

3GuiClose:
Gui, 3: Destroy
IniRead, ColorText, %IniFile%, settings, ColorText
IniRead, Tsize, %IniFile%, settings, Tsize
IniRead, PostitSize, %IniFile%, settings, PostitSize
IniRead, ColorPostit, %IniFile%, settings, ColorPostit
IniRead, ColPostit, %IniFile%, settings, ColPostit
IniRead, TrayCheck, %IniFile%, settings, TrayCheck

Gui, Submit, NoHide
Gui, Child: Font, s%Tsize%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text

Gui, Child: Font, c%ColorText%
GuiControl, Child: Font, text
GuiControl, Child: Hide, text
GuiControl, Child: Show, text

GuiControl,, Score, %PostitSize%px
PostitSize2:=round(PostitSize/1.14,1)
GuiControl, Child: Move, text, w%PostitSize2% h%PostitSize2%
Gui, Child: Hide
Gui, Child: Show, w%PostitSize% h%PostitSize% 
Gui, Main: Hide
Gui, Main: Show, w%PostitSize% h%PostitSize% 
upd = 1
gosub update
return

label3:
ExitApp
return

Open:
reload
return

Exit:
ExitApp
return

GuiClose:
ExitApp

But you also need the data folder.



DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
I downloaded the widget and ran your script. I have no idea what your script does that the widget doesn't already do. The right click menu of both your script and the widget are identical.

Did you create that widget? If not what is its name?
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

Alexou
  • Members
  • 40 posts
  • Last active: Feb 02 2016 06:39 PM
  • Joined: 10 Aug 2015
Yes i create that widget. that is a simply post-it widget. nothing new here.
i'm juste happy to share my widget.  :D