Skip to content

Commit f6419ae

Browse files
authored
Merge pull request #194 from spyoungtech/menu
Add menu tray icon commands
2 parents 16bb96b + 8755ae2 commit f6419ae

File tree

9 files changed

+153
-3
lines changed

9 files changed

+153
-3
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: build
2020
shell: bash
2121
run: |
22-
python -m pip install --upgrade wheel setuptools build
22+
python -m pip install --upgrade wheel setuptools build unasync tokenize-rt
2323
python -m build
2424
- name: Release PyPI
2525
shell: bash

ahk/_async/engine.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,43 @@ async def show_tooltip(
13671367
async def hide_tooltip(self, which: int = 1) -> None:
13681368
await self.show_tooltip(which=which)
13691369

1370+
async def menu_tray_tooltip(self, value: str) -> None:
1371+
"""
1372+
Change the menu tray icon tooltip that appears when hovering the mouse over the tray icon.
1373+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1374+
1375+
Uses the `Tip subcommand <https://www.autohotkey.com/docs/v1/lib/Menu.htm#Tip>`_
1376+
"""
1377+
1378+
args = [value]
1379+
await self._transport.function_call('AHKMenuTrayTip', args)
1380+
return None
1381+
1382+
async def menu_tray_icon(self, filename: str = '*', icon_number: int = 1, freeze: Optional[bool] = None) -> None:
1383+
"""
1384+
Change the tray icon menu.
1385+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1386+
1387+
Uses the `Icon subcommand <https://www.autohotkey.com/docs/v1/lib/Menu.htm#Icon>`_
1388+
1389+
If called with no parameters, the tray icon will be reset to the original default.
1390+
"""
1391+
args = [filename, str(icon_number)]
1392+
if freeze is True:
1393+
args.append('1')
1394+
elif freeze is False:
1395+
args.append('0')
1396+
await self._transport.function_call('AHKMenuTrayIcon', args)
1397+
return None
1398+
1399+
async def menu_tray_icon_show(self) -> None:
1400+
"""
1401+
Show ('unhide') the tray icon previously hidden by :py:class:`~ahk.directives.NoTrayIcon` directive.
1402+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1403+
"""
1404+
await self._transport.function_call('AHKMenuTrayShow')
1405+
return None
1406+
13701407
# fmt: off
13711408
@overload
13721409
async def sound_beep(self, frequency: int = 523, duration: int = 150) -> None: ...

ahk/_async/transport.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
9595
'AHKImageSearch',
9696
'AHKKeyState',
9797
'AHKKeyWait',
98+
'AHKMenuTrayIcon',
99+
'AHKMenuTrayShow',
100+
'AHKMenuTrayTip',
98101
'AHKMouseClickDrag',
99102
'AHKMouseGetPos',
100103
'AHKMouseMove',
@@ -565,6 +568,12 @@ async def function_call(self, function_name: Literal['AHKRegRead'], args: Option
565568
async def function_call(self, function_name: Literal['AHKRegWrite'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
566569
@overload
567570
async def function_call(self, function_name: Literal['AHKRegDelete'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
571+
@overload
572+
async def function_call(self, function_name: Literal['AHKMenuTrayTip'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
573+
@overload
574+
async def function_call(self, function_name: Literal['AHKMenuTrayIcon'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
575+
@overload
576+
async def function_call(self, function_name: Literal['AHKMenuTrayShow'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
568577

569578
# fmt: on
570579

ahk/_constants.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,25 @@
26032603
return FormatNoValueResponse()
26042604
}
26052605
2606+
AHKMenuTrayTip(ByRef command) {
2607+
value := command[2]
2608+
Menu, Tray, Tip, %value%
2609+
return FormatNoValueResponse()
2610+
}
2611+
2612+
AHKMenuTrayShow(ByRef command) {
2613+
Menu, Tray, Icon
2614+
return FormatNoValueResponse()
2615+
}
2616+
2617+
AHKMenuTrayIcon(ByRef command) {
2618+
filename := command[2]
2619+
icon_number := command[3]
2620+
freeze := command[4]
2621+
Menu, Tray, Icon, %filename%, %icon_number%,%freeze%
2622+
return FormatNoValueResponse()
2623+
}
2624+
26062625
b64decode(ByRef pszString) {
26072626
; TODO load DLL globally for performance
26082627
; REF: https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptstringtobinaryw

ahk/_sync/engine.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,43 @@ def show_tooltip(
13561356
def hide_tooltip(self, which: int = 1) -> None:
13571357
self.show_tooltip(which=which)
13581358

1359+
def menu_tray_tooltip(self, value: str) -> None:
1360+
"""
1361+
Change the menu tray icon tooltip that appears when hovering the mouse over the tray icon.
1362+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1363+
1364+
Uses the `Tip subcommand <https://www.autohotkey.com/docs/v1/lib/Menu.htm#Tip>`_
1365+
"""
1366+
1367+
args = [value]
1368+
self._transport.function_call('AHKMenuTrayTip', args)
1369+
return None
1370+
1371+
def menu_tray_icon(self, filename: str = '*', icon_number: int = 1, freeze: Optional[bool] = None) -> None:
1372+
"""
1373+
Change the tray icon menu.
1374+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1375+
1376+
Uses the `Icon subcommand <https://www.autohotkey.com/docs/v1/lib/Menu.htm#Icon>`_
1377+
1378+
If called with no parameters, the tray icon will be reset to the original default.
1379+
"""
1380+
args = [filename, str(icon_number)]
1381+
if freeze is True:
1382+
args.append('1')
1383+
elif freeze is False:
1384+
args.append('0')
1385+
self._transport.function_call('AHKMenuTrayIcon', args)
1386+
return None
1387+
1388+
def menu_tray_icon_show(self) -> None:
1389+
"""
1390+
Show ('unhide') the tray icon previously hidden by :py:class:`~ahk.directives.NoTrayIcon` directive.
1391+
Does not affect tray icon for AHK processes started with :py:meth:`run_script` or ``blocking=False``
1392+
"""
1393+
self._transport.function_call('AHKMenuTrayShow')
1394+
return None
1395+
13591396
# fmt: off
13601397
@overload
13611398
def sound_beep(self, frequency: int = 523, duration: int = 150) -> None: ...

ahk/_sync/transport.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
8787
'AHKImageSearch',
8888
'AHKKeyState',
8989
'AHKKeyWait',
90+
'AHKMenuTrayIcon',
91+
'AHKMenuTrayShow',
92+
'AHKMenuTrayTip',
9093
'AHKMouseClickDrag',
9194
'AHKMouseGetPos',
9295
'AHKMouseMove',
@@ -546,6 +549,12 @@ def function_call(self, function_name: Literal['AHKRegRead'], args: Optional[Lis
546549
def function_call(self, function_name: Literal['AHKRegWrite'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
547550
@overload
548551
def function_call(self, function_name: Literal['AHKRegDelete'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
552+
@overload
553+
def function_call(self, function_name: Literal['AHKMenuTrayTip'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
554+
@overload
555+
def function_call(self, function_name: Literal['AHKMenuTrayIcon'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
556+
@overload
557+
def function_call(self, function_name: Literal['AHKMenuTrayShow'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
549558

550559
# fmt: on
551560

ahk/templates/daemon.ahk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,25 @@ AHKBlockInput(ByRef command) {
26002600
return FormatNoValueResponse()
26012601
}
26022602

2603+
AHKMenuTrayTip(ByRef command) {
2604+
value := command[2]
2605+
Menu, Tray, Tip, %value%
2606+
return FormatNoValueResponse()
2607+
}
2608+
2609+
AHKMenuTrayShow(ByRef command) {
2610+
Menu, Tray, Icon
2611+
return FormatNoValueResponse()
2612+
}
2613+
2614+
AHKMenuTrayIcon(ByRef command) {
2615+
filename := command[2]
2616+
icon_number := command[3]
2617+
freeze := command[4]
2618+
Menu, Tray, Icon, %filename%, %icon_number%,%freeze%
2619+
return FormatNoValueResponse()
2620+
}
2621+
26032622
b64decode(ByRef pszString) {
26042623
; TODO load DLL globally for performance
26052624
; REF: https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptstringtobinaryw

docs/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,28 @@ ahk = AHK(directives=[NoTrayIcon])
322322

323323
By default, some directives are automatically added to ensure functionality and are merged with any user-provided directives.
324324

325+
## Menu tray icon
326+
327+
As discussed above, you can hide the tray icon if you wish. Additionally, there are some methods available for
328+
customizing the tray icon.
329+
330+
331+
```python
332+
from ahk import AHK
333+
ahk = AHK()
334+
335+
# change the tray icon (in this case, using a builtin system icon)
336+
ahk.menu_tray_icon('Shell32.dll', 174)
337+
# revert it back to the original:
338+
ahk.menu_tray_icon()
339+
340+
# change the tooltip that shows up when hovering the mouse over the tray icon
341+
ahk.menu_tray_tooltip('My Program Name')
342+
343+
# Show the tray icon that was previously hidden by ``NoTrayIcon``
344+
ahk.menu_tray_icon_show()
345+
```
346+
325347
## Registry methods
326348

327349
You can read/write/delete registry keys:

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
}
4242

4343
always_document_param_types = True
44-
typehints_use_signature = True
45-
typehints_use_signature_return = True
4644
html_css_files = [
4745
'css/custom.css',
4846
]

0 commit comments

Comments
 (0)