-
Notifications
You must be signed in to change notification settings - Fork 7
Zroya2 Development
I did some edits to setup.py file and added PostBuild command. As name suggests, it is called after c module is built. Only one think this command does is calling GenerateStubFile function. It collects all classes and functions from zroya module and creates .pyi file.
This file is required for IDEs to know the module structure so they can give you right autocomplete hints and documentation.
Normally, this file is not required for Python modules, but zroya is an C extension and I was not able to get documentation propagated from C source to generated Python code any other way.
Note: Whole generate_stubs.py file seems as a dirty hack to me. Feel free to send me any idea how to improve it.
Second thing I’ve done today was that I added documentation for C part of zroya. It is readable as HTML doxygen output in /docs.
This update is an important one. Since now, there is a support for callbacks. They are registered to each individual ntoficiation, not to Template
(as it is in WinToastLib).
Parameters starting with on_*
in zroya.show
define a function which should be called, when an event occurs. There are four different events - on_click
(user clicked on the notification), on_action
(user selected an action, currently unsuported), on_dismiss
(notification was dissmissed) and on_fail
(something is wrong).
# t is an instance of zroya.Template
zroya.show(t, on_click=myCallback, on_dismiss=myCallback2, on_fail=myCallback3)
There is a requirement for each callback, to accept certain number of parameters:
def onClickCallback(notificationID: int):
pass
def onActionCallback(notificationID: int, actionID: int):
pass
def onDismissCallback(notificationID: int, reason: zroya.DismissReason):
pass
def onFailCallback(notificationID: int):
pass
I will not discuiss actionID
at the moment, because actions are not implemented yet. What I want to speek about is zroya.DismissReason
class. This class is a kind of bridge between C integer type and Pythons Enum
. Zroya is getting an integer representation of dismiss reason from WinToast. Without reading documentation, working with plain numbers may be complicated. In addition, I don't think it is a pythonic way.
def onDismissCallback(notificationID, reason):
print("Notification #{} was dismissed. Reason: {}".format(reason))
Code above prints something like: "Notification #123456789 was dismissed. Reason: The user dismissed the toast."
. If you want, you may compare reason
with any of zroya.DismissReason
attributes (zroya.DismissReason.User
, zroya.DismissReason.App
, zroya.DismissReason.Expired
).
Apart from callbacks, new method names are introduced. No longer there are multipurpose methods which act differently based on obtained parameters. I added setters and getters for each method of zroya.Template. It makes code of each method more readable and less error prone. And they tend to be more self-explanatory when used.