Giter Site home page Giter Site logo

Comments (1)

Damian-2001 avatar Damian-2001 commented on August 29, 2024

It is not so difficult to add this option, I share in case it can help someone.
*Note that on windows >= 10 , "balloon notifications" is equal to "toasted notifications" and they can be implemented in addition to Shell_NotifyIcon, with WinRT api

traybar.py

    def __init__(self, ...):
        ...
        self._balloon_callback = None
        self._balloon_hicon = None

    def show_toast_notification(self, text, title="", icon=None, onclick=None):
        if not self._notify_id:
            self._refresh_icon()
        self._balloon_callback = None
        if onclick and "function" in repr(onclick):
            self._balloon_callback = onclick
        if icon is not None and os.path.isfile(icon):
            if self._balloon_hicon:
                DestroyIcon(self._balloon_hicon)
            icon = encode_for_locale(icon)
            hicon = self._hicon = LoadImage(0, icon, IMAGE_ICON, 128, 128, LR_LOADFROMFILE)
            self._balloon_hicon = hicon
        else:
            hicon = 0
        _notify_id = NotifyBalloonData(hWnd = self._notify_id.hWnd,
                                      uID = self._notify_id.uID,
                                      text = text, 
                                      title = title,
                                      hicon = hicon)
        if not Shell_NotifyIcon(NIM_MODIFY, ctypes.byref(_notify_id)):
            raise Exception("show_toast_notification failed: %s" % ctypes.WinError())

    def _notify(self, hwnd, msg, wparam, lparam):
        if lparam == WM_LBUTTONDBLCLK:
            self._execute_menu_option(self._default_menu_index + SysTrayIcon.FIRST_ID)
        elif lparam == WM_RBUTTONUP:
            self._show_menu()
        elif lparam == WM_LBUTTONUP:
            pass
        elif lparam & 0xffff == NIN_BALLOONUSERCLICK:
            if self._balloon_callback:
                self._balloon_callback()
        return True

win32_adapter.py

NIF_INFO = 16
NIIF_INFO = 1
NIIF_USER = 4
NIIF_ICON_MASK = 15
NIIF_NOSOUND = 16
NIIF_LARGE_ICON = 32
NIN_BALLOONUSERCLICK = (WM_USER + 5)

def NotifyBalloonData(hWnd=0, uID=0, hicon=0, text="", title=""):
    text = encode_for_locale(text)[:256]
    title = encode_for_locale(title)[:64]
    res = NOTIFYICONDATA()
    res.cbSize = ctypes.sizeof(res)
    res.hWnd = hWnd
    res.uID = uID
    res.uFlags = NIF_INFO
    res.szInfo = text
    res.szInfoTitle = title
    if hicon and "hBalloonIcon" in NOTIFYICONDATA._fields_[-1]:
        res.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON | NIIF_ICON_MASK | NIIF_NOSOUND
        res.hBalloonIcon = hicon
    else:
        res.dwInfoFlags = NIIF_INFO | NIIF_NOSOUND
    return res

from infi.systray.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.