コード例 #1
0
ファイル: win32_toast.py プロジェクト: nnethercote/servo
 def __init__(self):
     # Register window class; it's okay to do this multiple times
     wc = WNDCLASS()
     wc.lpszClassName = "ServoTaskbarNotification"
     wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy}
     self.classAtom = RegisterClass(wc)
     self.hinst = wc.hInstance = GetModuleHandle(None)
コード例 #2
0
 def __init__(self, icon_path, msg_q):
     """Initialize."""
     self.visible = 0
     self.log = []
     self._thread = None
     self.msg_q = msg_q
     self.message_box = Mbox()
     message_map = {
         WM_DESTROY: self.onDestroy,
         WM_USER + 20: self.onTaskbarNotify,
     }
     wc = WNDCLASS()
     hinst = wc.hInstance = GetModuleHandle(None)
     icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
     try:
         self.hicon = LoadImage(hinst, os.path.realpath(icon_path),
                                IMAGE_ICON, 0, 0, icon_flags)
     except Exception as e:
         print(str(e))
         self.hicon = LoadIcon(0, IDI_APPLICATION)
     wc.lpszClassName = str("Trustbase_notification")  #lol
     wc.style = CS_VREDRAW | CS_HREDRAW
     #wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
     wc.hbrBackground = COLOR_WINDOW
     wc.lpfnWndProc = message_map  # could also specify a wndproc.
     classAtom = RegisterClass(wc)
     # Create the Window.
     style = WS_OVERLAPPED | WS_SYSMENU
     self.hwnd = CreateWindow( classAtom, "MITM_alert", style, \
                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, \
                 0, 0, hinst, None)
     UpdateWindow(self.hwnd)
     self.notification_id = 1
     self.show()
コード例 #3
0
ファイル: windows_tools.py プロジェクト: cdgriffith/FastFlix
def show_windows_notification(title, msg, icon_path):
    global tool_window, tool_icon
    from win32api import GetModuleHandle
    from win32con import (
        CW_USEDEFAULT,
        IMAGE_ICON,
        LR_DEFAULTSIZE,
        LR_LOADFROMFILE,
        WM_USER,
        WS_OVERLAPPED,
        WS_SYSMENU,
    )
    from win32gui import (
        NIF_ICON,
        NIF_INFO,
        NIF_MESSAGE,
        NIF_TIP,
        NIM_ADD,
        NIM_MODIFY,
        WNDCLASS,
        CreateWindow,
        LoadImage,
        RegisterClass,
        Shell_NotifyIcon,
        UpdateWindow,
    )

    wc = WNDCLASS()
    hinst = wc.hInstance = GetModuleHandle(None)
    wc.lpszClassName = "FastFlix"
    if not tool_window:
        tool_window = CreateWindow(
            RegisterClass(wc),
            "Taskbar",
            WS_OVERLAPPED | WS_SYSMENU,
            0,
            0,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            0,
            0,
            hinst,
            None,
        )
        UpdateWindow(tool_window)

        icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
        tool_icon = LoadImage(hinst, icon_path, IMAGE_ICON, 0, 0, icon_flags)

        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
        nid = (tool_window, 0, flags, WM_USER + 20, tool_icon,
               "FastFlix Notifications")
        Shell_NotifyIcon(NIM_ADD, nid)

    Shell_NotifyIcon(NIM_MODIFY,
                     (tool_window, 0, NIF_INFO, WM_USER + 20, tool_icon,
                      "Balloon Tooltip", msg, 200, title, 4))
コード例 #4
0
ファイル: win32_toast.py プロジェクト: wenshiqi0/gecko-dev
 def __init__(self):
     # Register window class; it's okay to do this multiple times
     wc = WNDCLASS()
     wc.lpszClassName = 'ServoTaskbarNotification'
     wc.lpfnWndProc = {
         win32con.WM_DESTROY: self.OnDestroy,
     }
     self.classAtom = RegisterClass(wc)
     self.hinst = wc.hInstance = GetModuleHandle(None)
コード例 #5
0
    def __init__(self):
        """Initialize."""
        message_map = {WM_DESTROY: self.on_destroy, }

        # Register the window class.
        wc = WNDCLASS()
        self.hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = str("PythonTaskbar")  # must be a string
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        self.classAtom = RegisterClass(wc)
コード例 #6
0
    def __init__(self):
        """Initialize."""
        message_map = {WM_DESTROY: self.on_destroy}

        # Register the window class.
        wc = WNDCLASS()
        self.hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = str("PythonTaskbar")  # must be a string
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        self.classAtom = RegisterClass(wc)
コード例 #7
0
ファイル: notify.py プロジェクト: akshayuzade/notify-send
    def __init__(self, message, title):

        message_map = {win32con.WM_DESTROY: self.OnDestroy}
        # Register the Window class.
        wc = WNDCLASS()
        hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbar"
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = RegisterClass(wc)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = CreateWindow(
            classAtom,
            "Taskbar",
            style,
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None,
        )
        UpdateWindow(self.hwnd)
        iconPathName = os.path.abspath(
            os.path.join(sys.path[0], "balloontip.ico"))
        icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
        try:
            hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0,
                              icon_flags)
        except:
            hicon = LoadIcon(0, win32con.IDI_APPLICATION)

        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip")
        Shell_NotifyIcon(NIM_ADD, nid)
        Shell_NotifyIcon(
            NIM_MODIFY,
            (
                self.hwnd,
                0,
                NIF_INFO,
                win32con.WM_USER + 20,
                hicon,
                "Balloon  tooltip",
                message,
                200,
                title,
            ),
        )
        time.sleep(10)
        DestroyWindow(self.hwnd)
        UnregisterClass(classAtom, hinst)
コード例 #8
0
ファイル: toast.py プロジェクト: mitalhp/Flexget
    def windows_notify(self, title, message, config):
        config = self.prepare_config(config)
        try:
            from win32api import GetModuleHandle, PostQuitMessage
            from win32con import (CW_USEDEFAULT, IMAGE_ICON, IDI_APPLICATION,
                                  LR_DEFAULTSIZE, LR_LOADFROMFILE, WM_DESTROY,
                                  WS_OVERLAPPED, WS_SYSMENU, WM_USER)
            from win32gui import (CreateWindow, DestroyWindow, LoadIcon,
                                  LoadImage, NIF_ICON, NIF_INFO, NIF_MESSAGE,
                                  NIF_TIP, NIM_ADD, NIM_DELETE, NIM_MODIFY,
                                  RegisterClass, Shell_NotifyIcon,
                                  UpdateWindow, WNDCLASS)
        except ImportError:
            raise DependencyError(
                __name__, 'pypiwin32',
                'pywin32 module is required for desktop notifications on '
                'windows. You can install it with `pip install pypiwin32`')

        # Register the window class.
        wc = WNDCLASS()
        hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "FlexGetTaskbar"
        if not self.windows_classAtom:
            self.windows_classAtom = RegisterClass(wc)
        style = WS_OVERLAPPED | WS_SYSMENU
        hwnd = CreateWindow(self.windows_classAtom, "Taskbar", style, 0, 0,
                            CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hinst, None)
        UpdateWindow(hwnd)

        hicon = LoadIcon(0, IDI_APPLICATION)
        # Hackily grab the icon from the webui if possible
        icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
        try:
            import flexget.ui
            icon_path = os.path.join(flexget.ui.__path__[0], 'src',
                                     'favicon.ico')
            hicon = LoadImage(hinst, icon_path, IMAGE_ICON, 0, 0, icon_flags)
        except Exception as e:
            log.debug('Error trying to get flexget icon from webui folder: %s',
                      e)

        # Taskbar icon
        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO
        nid = (hwnd, 0, flags, WM_USER + 20, hicon, "FlexGet Notification",
               message, config['timeout'] * 1000, title)
        Shell_NotifyIcon(NIM_ADD, nid)
コード例 #9
0
ファイル: toast.py プロジェクト: tubedogg/Flexget
    def windows_notify(self, title, message, config):
        config = self.prepare_config(config)
        try:
            from win32api import GetModuleHandle, PostQuitMessage
            from win32con import (CW_USEDEFAULT, IMAGE_ICON, IDI_APPLICATION, LR_DEFAULTSIZE, LR_LOADFROMFILE,
                                  WM_DESTROY, WS_OVERLAPPED, WS_SYSMENU, WM_USER)
            from win32gui import (CreateWindow, DestroyWindow, LoadIcon, LoadImage, NIF_ICON, NIF_INFO, NIF_MESSAGE,
                                  NIF_TIP, NIM_ADD, NIM_DELETE, NIM_MODIFY, RegisterClass, Shell_NotifyIcon,
                                  UpdateWindow, WNDCLASS)
        except ImportError:
            raise DependencyError(plugin_name, 'pypiwin32', 'pywin32 module is required for desktop notifications on '
                                                         'windows. You can install it with `pip install pypiwin32`')

        # Register the window class.
        wc = WNDCLASS()
        hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "FlexGetTaskbar"
        if not self.windows_classAtom:
            self.windows_classAtom = RegisterClass(wc)
        style = WS_OVERLAPPED | WS_SYSMENU
        hwnd = CreateWindow(self.windows_classAtom, "Taskbar", style, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hinst,
                            None)
        UpdateWindow(hwnd)

        hicon = LoadIcon(0, IDI_APPLICATION)
        # Hackily grab the icon from the webui if possible
        icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
        try:
            import flexget.ui
            icon_path = os.path.join(flexget.ui.__path__[0], 'src', 'favicon.ico')
            hicon = LoadImage(hinst, icon_path, IMAGE_ICON, 0, 0, icon_flags)
        except Exception as e:
            log.debug('Error trying to get flexget icon from webui folder: %s', e)

        # Taskbar icon
        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO
        nid = (hwnd, 0, flags, WM_USER + 20, hicon, "FlexGet Notification", message, config['timeout'] * 1000, title)
        Shell_NotifyIcon(NIM_ADD, nid)
コード例 #10
0
ファイル: __init__.py プロジェクト: t-o-n-y-p/rssim_old
from abc import ABC
from typing import final

from win32api import GetModuleHandle
from win32con import CW_USEDEFAULT, IMAGE_ICON, LR_DEFAULTSIZE, LR_LOADFROMFILE, WM_USER, \
    WS_OVERLAPPED, WS_SYSMENU
from win32gui import CreateWindow, DestroyWindow, LoadImage, NIF_ICON, NIF_INFO, NIF_MESSAGE, NIF_TIP, NIM_ADD, \
    NIM_MODIFY, NIM_DELETE, RegisterClass, Shell_NotifyIcon, UpdateWindow, WNDCLASS

from i18n import I18N_RESOURCES

_wnd_class = WNDCLASS()
_wnd_class.hInstance = GetModuleHandle(None)
_wnd_class.lpszClassName = 'Railway Station Simulator'
_wnd_class.lpfnWndProc = {}
_wnd_class_instance = RegisterClass(_wnd_class)


class Notification(ABC):
    def __init__(self,
                 logger,
                 caption_key,
                 message_key,
                 current_locale,
                 caption_args=(),
                 message_args=()):
        self.logger = logger
        self.handler = CreateWindow(_wnd_class_instance, "Taskbar",
                                    WS_OVERLAPPED | WS_SYSMENU, 0, 0,
                                    CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
                                    _wnd_class.hInstance, None)
コード例 #11
0
    def __call__(self, summary, message="", timeout=2000, **kwargs):
        tip = kwargs.get("tip", "Balloon tooltip")

        # Register the Window class.
        wc = WNDCLASS()
        hinst = wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbar"
        wc.lpfnWndProc = self.message_map  # could also specify a wndproc.
        classAtom = RegisterClass(wc)

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = CreateWindow(
            classAtom,
            "Taskbar",
            style,
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None,
        )
        UpdateWindow(self.hwnd)

        # Icons managment
        iconPathName = os.path.abspath(
            os.path.join(sys.path[0], "balloontip.ico"))
        icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE

        try:
            hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0,
                              icon_flags)
        except Exception:
            hicon = LoadIcon(0, win32con.IDI_APPLICATION)

        flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip")

        # Notify
        Shell_NotifyIcon(NIM_ADD, nid)
        Shell_NotifyIcon(
            NIM_MODIFY,
            (
                self.hwnd,
                0,
                NIF_INFO,
                win32con.WM_USER + 20,
                hicon,
                tip,
                message,
                timeout,
                summary,
            ),
        )
        # Destroy
        DestroyWindow(self.hwnd)
        classAtom = UnregisterClass(classAtom, hinst)
        return True