Esempio n. 1
0
	def _DoCreateIcons(self):
		hinst =  win32api.GetModuleHandle(None)
		iconPathName = os.path.realpath("icon.ico")
		#iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "pyc.ico" ))
		'''
		if not os.path.isfile(iconPathName):
			iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "DLLs", "pyc.ico" ))
		if not os.path.isfile(iconPathName):
			iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "..\\PC\\pyc.ico" ))
		'''
		#if os.path.isfile(iconPathName):
		icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
		hicon = win32gui.LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
		'''
		else:
			print "ikon bulunamadı, default ikon kullanılıyor"
			hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
		'''
		flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
		nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, u"Uyku Modu")
		try:
			win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
			win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, \
                         (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER+20,\
                          hicon, "Balloon  tooltip",u"Kullanmak için sağ tıklayın",200,u"Uyku Modu Değiştirici"))
		except win32gui.error:
			print u"İkon eklenemedi - explorer çalışıyor mu?"
Esempio n. 2
0
 def __init__(self, title, msg):
     message_map = {
         win32con.WM_DESTROY: self.OnDestroy,
     }
     # Register the Window class.
     wc = win32gui.WNDCLASS()
     hinst = wc.hInstance = win32api.GetModuleHandle(None)
     wc.lpszClassName = "PythonTaskbar"
     wc.lpfnWndProc = message_map  # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(wc)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar", style, 0,
                                       0, win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT, 0, 0,
                                       hinst, None)
     win32gui.UpdateWindow(self.hwnd)
     iconPathName = os.path.abspath(icon)
     icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
     try:
         hicon = win32gui.LoadImage(hinst, iconPathName,
                                    win32con.IMAGE_ICON, 0, 0,
                                    icon_flags)
     except:
         hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
     nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
            "tooltip")
     win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
          "Balloon tooltip", title, 200, msg))
     win32gui.DestroyWindow(self.hwnd)
Esempio n. 3
0
    def refresh_icon(self, is_init=True, trayMsg=None):
        hinst = win32gui.GetModuleHandle(None)
        # try to find custom icon file
        if os.path.isfile(self.icon):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, self.icon, win32con.IMAGE_ICON, 0,
                                       0, icon_flags)
        # if the custom icon not found, using default
        else:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id:
            message = win32gui.NIM_MODIFY
        else:
            message = win32gui.NIM_ADD
        self.notify_id = (self.hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE
                          | win32gui.NIF_TIP, win32con.WM_USER + 20, hicon,
                          self.hover_text)
        win32gui.Shell_NotifyIcon(message, self.notify_id)
        if not is_init:
            if not (trayMsg and isinstance(trayMsg, TrayMessage)):
                raise ValueError(
                    '"{}" except a "winsystray.TrayMessage" object, but gaven "{}".'
                    .format(trayMsg,
                            type(trayMsg).__name__))
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_MODIFY,
                (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
                 trayMsg.app, trayMsg.msg, 200, trayMsg.title))
Esempio n. 4
0
 def show(self):
     nid = self._build_nid_default()
     if self.__alive:
         win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)
     else:
         win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
         self.__alive = True
Esempio n. 5
0
    def __init__(self, title, message, icon_path=None):  # noqa: D107
        try:
            import win32con
        except ImportError as e:  # noqa: F841
            logger.debug(
                'Failed to import win32con: {e}'.format_map(locals()))
            return
        try:
            import win32gui
        except ImportError as e:  # noqa: F841
            logger.debug(
                'Failed to import win32gui: {e}'.format_map(locals()))
            return

        wc, class_atom = NotificationWindow._create_window_class()

        # create the window
        hwnd = win32gui.CreateWindow(
            NotificationWindow._class_atom,
            'Colcon notification',  # window class name
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,  # style
            0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
            0, 0, NotificationWindow._wc.hInstance, None)
        win32gui.UpdateWindow(hwnd)

        # load icon image
        try:
            if icon_path is None:
                # use fall back
                raise Exception()
            hicon = win32gui.LoadImage(
                NotificationWindow._wc.hInstance, icon_path,
                win32con.IMAGE_ICON, 0, 0,
                win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE,  # flags
            )
        except Exception:  # noqa: B902
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # show the notification
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (hwnd, 0, flags, win32con.WM_USER + 20, hicon, 'tooltip')
        try:
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_ADD, nid)
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_MODIFY, (
                    hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
                    'Balloon  tooltip', message, 200, title))
        except Exception as e:  # noqa: F841
            logger.debug(
                'Failed to show the notification: {e}'.format_map(locals()))
        else:
            # wait a while before destroying the window
            time.sleep(5)
        finally:
            win32gui.DestroyWindow(hwnd)
Esempio n. 6
0
    def OnDestroy(self, hwnd, msg, wparam, lparam):

        if DEBUG: print(sys._getframe(0).f_code.co_name)

        nid = (self.hwnd, 0)
        win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
        win32gui.PostQuitMessage(0)  # Terminate the app.
Esempio n. 7
0
    def OnDestroy(self, hwnd, msg, wparam, lparam):

        nid = (self.hwnd, 0)

        win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)

        win32gui.PostQuitMessage(0)  # Terminate the app.
Esempio n. 8
0
 def set_icon(self, icon):
     self.logger.info('set_icon: %r' % icon)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self._hwnd, 0, win32gui.NIF_ICON,
          0, icon))
     return
Esempio n. 9
0
    def refresh_icon(self, **data):

        if DEBUG: print(sys._getframe(0).f_code.co_name)

        hinst = win32gui.GetModuleHandle(None)
        if os.path.isfile(self.icon): # 尝试找到自定义图标
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst,
                                       self.icon,
                                       win32con.IMAGE_ICON,
                                       0,
                                       0,
                                       icon_flags)
        else: # 找不到图标文件 - 使用默认值
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id: message = win32gui.NIM_MODIFY
        else: message = win32gui.NIM_ADD
        self.notify_id = (self.hwnd,
                          0,
                          win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                          win32con.WM_USER+20,
                          hicon,
                          self.hover_text)
        win32gui.Shell_NotifyIcon(message, self.notify_id)
Esempio n. 10
0
def new_icon(hdesk,desktop_name):
    """ Runs as a thread on each desktop to create a new tray icon and handle its messages """ 
    global id
    id=id+1
    hdesk.SetThreadDesktop()
    ## apparently the threads can't use same hinst, so each needs its own window class
    windowclassname='PythonDesktopManager'+desktop_name
    wc = win32gui.WNDCLASS()
    wc.hInstance = win32api.GetModuleHandle(None)
    wc.lpszClassName = windowclassname
    wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS
    wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
    wc.hbrBackground = win32con.COLOR_WINDOW
    wc.lpfnWndProc = icon_wndproc
    windowclass = win32gui.RegisterClass(wc)
    style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
    hwnd = win32gui.CreateWindow(windowclass, 'dm_'+desktop_name, win32con.WS_SYSMENU,
                    0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                    0, 0, wc.hInstance, None)
    win32gui.UpdateWindow(hwnd)
    flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
    notify_info = (hwnd, id, flags, win32con.WM_USER+20, hicon, 'Desktop Manager (%s)' %desktop_name)
    window_info[hwnd]=notify_info
    ## wait for explorer to initialize system tray for new desktop
    tray_found=0
    while not tray_found:
        try:
            tray_found=win32gui.FindWindow("Shell_TrayWnd",None)
        except win32gui.error:
            traceback.print_exc
            time.sleep(.5)
    win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info)
    win32gui.PumpMessages()
Esempio n. 11
0
    def refresh(s, title='', msg='', time=500):
        '''刷新托盘图标
           title 标题
           msg   内容,为空的话就不显示提示
           time  提示显示时间'''
        hinst = win32gui.GetModuleHandle(None)
        if os.path.isfile(s.icon):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, s.icon, win32con.IMAGE_ICON, 0,
                                       0, icon_flags)
        else:  # 找不到图标文件 - 使用默认值
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if s.notify_id:
            message = win32gui.NIM_MODIFY
        else:
            message = win32gui.NIM_ADD

        s.notify_id = (
            s.hwnd,
            0,  # 句柄、托盘图标ID
            win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
            | win32gui.NIF_INFO,
            # 托盘图标可以使用的功能的标识
            win32con.WM_USER + 20,
            hicon,
            s.hover_text,  # 回调消息ID、托盘图标句柄、图标字符串
            msg,
            time,
            title,  # 提示内容、提示显示时间、提示标题
            win32gui.NIIF_INFO  # 提示用到的图标
        )
        win32gui.Shell_NotifyIcon(message, s.notify_id)
Esempio n. 12
0
    def __init__(self, tip, ico, items):

        if not ico: raise

        self._callbacks = dict()
        self._keys = []
        self._tip = tip
        self._ico = ico
        self._items = items

        windowClass = win32gui.WNDCLASS()
        windowClass.hInstance = win32gui.GetModuleHandle(None)
        windowClass.lpszClassName = "5ea86490-d4ec-11e1-9b23-0800200c9a66"
        windowClass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        windowClass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        windowClass.hbrBackground = win32con.COLOR_WINDOW
        windowClass.lpfnWndProc = {
            win32con.WM_COMMAND: self._commandCallback,
            win32con.WM_USER + 20: self._notifyCallback
        }

        self._hwnd = win32gui.CreateWindow(
            win32gui.RegisterClass(windowClass), windowClass.lpszClassName,
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU, 0, 0,
            win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0,
            windowClass.hInstance, None)

        win32gui.Shell_NotifyIcon(
            win32gui.NIM_ADD,
            (self._hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE
             | win32gui.NIF_TIP, win32con.WM_USER + 20,
             win32gui.LoadImage(
                 win32gui.GetModuleHandle(None), os.path.abspath(self._ico),
                 win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE
                 | win32con.LR_DEFAULTSIZE), self._tip))
Esempio n. 13
0
 def _run(self, quiet: bool = False):
     message_map = {con32.WM_DESTROY: self._onDestroy, }
     # register the window class
     wc = gui32.WNDCLASS()
     self._hinst = wc.hInstance = gui32.GetModuleHandle(None)
     wc.lpszClassName = 'PythonBalloontip'
     wc.lpfnWndProc = message_map
     self._classAtom = gui32.RegisterClass(wc)
     # create the window
     style = con32.WS_OVERLAPPED | con32.WS_SYSMENU
     self._hwnd = gui32.CreateWindow(self._classAtom, 'Taskbar', style, 0, 0, con32.CW_USEDEFAULT,
                                     con32.CW_USEDEFAULT, 0, 0, self._hinst, None)
     gui32.UpdateWindow(self._hwnd)
     try:
         timeout = float(self.timeout)
         if timeout <= 0:
             raise ValueError(
                 "the 'timeout' parameter must be greater than 0")
     except Exception as e:
         self._showError(e, 'exit')
         return
     self._infoFlags = gui32.NIIF_NOSOUND if quiet else 0
     if not self._getIcon():
         return
     flags = gui32.NIF_ICON | gui32.NIF_MESSAGE | gui32.NIF_TIP | gui32.NIF_INFO
     nid = (self._hwnd, 0, flags, con32.WM_USER + 20, self._hicon,
            "Balloontip", self.msg, 200, self.title, self._infoFlags)
     gui32.Shell_NotifyIcon(gui32.NIM_ADD, nid)
     sleep(timeout)
     gui32.DestroyWindow(self._hwnd)
     gui32.UnregisterClass(self._classAtom, self._hinst)
Esempio n. 14
0
 def sendnotification(self, title, msg):
     hicon = self.get_icon(self.icon)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
          "Balloon tooltip", msg, 200, title),
     )
Esempio n. 15
0
 def __init__(self,
              title,
              click_callback,
              exit_callback,
              command_callback=None,
              iconPathName=None):
     self.title = title[:127]
     self.click_callback = click_callback
     self.exit_callback = exit_callback
     self.command_callback = command_callback
     self.current_icon = None
     self.closed = False
     self._message_id = win32con.WM_USER + 20  #a message id we choose
     # Register the Window class.
     self.hinst = win32NotifyIcon.wc.hInstance
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(win32NotifyIcon.classAtom, self.title+" StatusIcon Window", style, \
     0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
     0, 0, self.hinst, None)
     win32gui.UpdateWindow(self.hwnd)
     self.current_icon = self.win32LoadIcon(iconPathName)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_ADD,
         self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE
                       | win32gui.NIF_TIP))
Esempio n. 16
0
    def __SetBalloonTip(self, hicon, title, msg, msec, flags):

        # translate flags
        infoFlags = 0

        if flags & wx.ICON_INFORMATION:
            infoFlags |= win32gui.NIIF_INFO
        elif flags & wx.ICON_WARNING:
            infoFlags |= win32gui.NIIF_WARNING
        elif flags & wx.ICON_ERROR:
            infoFlags |= win32gui.NIIF_ERROR

        # Show balloon
        lpdata = (
            self.__GetIconHandle(),  # hWnd
            99,  # ID
            win32gui.NIF_MESSAGE | win32gui.NIF_INFO
            | win32gui.NIF_ICON,  # flags: Combination of NIF_* flags
            0,  # CallbackMessage: Message id to be pass to hWnd when processing messages
            hicon,  # hIcon: Handle to the icon to be displayed
            '',  # Tip: Tooltip text
            msg,  # Info: Balloon tooltip text
            msec,  # Timeout: Timeout for balloon tooltip, in milliseconds
            title,  # InfoTitle: Title for balloon tooltip
            infoFlags  # InfoFlags: Combination of NIIF_* flags
        )
        win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, lpdata)

        self.SetIcon(
            self.icon, self.tooltip
        )  # Hack: because we have no access to the real CallbackMessage value
Esempio n. 17
0
 def show_balloon(self, title, text, timeout=1):
     self.logger.info('show_balloon: %r, %r' % (title, text))
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self._hwnd, 0, win32gui.NIF_INFO,
          0, 0, '', text, timeout, title, win32gui.NIIF_INFO))
     return
Esempio n. 18
0
 def set_text(self, text):
     self.logger.info('set_text: %r' % text)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self._hwnd, 0, win32gui.NIF_TIP,
          0, 0, text))
     return
Esempio n. 19
0
 def OnDestroy(self, hwnd, msg, wparam, lparam):
     nid = (self.hwnd, 0)  #tuple of our window's handle and zero(?)
     # implements our settings and deletes (win32gui.NIM_DELETE)
     # our window (nid)
     win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
     win32gui.PostQuitMessage(0)  # Terminate the app.
     self.CLstate = -1
Esempio n. 20
0
 def close(self):
     if not self._hwnd:
         return
     win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, (self._hwnd, 0))
     win32gui.DestroyWindow(self._hwnd)
     win32gui.PostQuitMessage(0)
     self._hwnd = None
Esempio n. 21
0
 def __init__(self,
              title,
              move_callbacks,
              click_callback,
              exit_callback,
              command_callback=None,
              iconPathName=None):
     self.title = title[:127]
     self.current_icon = None
     # Register the Window class.
     self.hinst = NIwc.hInstance
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(NIclassAtom, self.title+" StatusIcon Window", style, \
         0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
         0, 0, self.hinst, None)
     win32gui.UpdateWindow(self.hwnd)
     self.current_icon = self.LoadImage(iconPathName)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_ADD,
         self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE
                       | win32gui.NIF_TIP))
     #register callbacks:
     win32NotifyIcon.live_hwnds.add(self.hwnd)
     win32NotifyIcon.move_callbacks[self.hwnd] = move_callbacks
     win32NotifyIcon.click_callbacks[self.hwnd] = click_callback
     win32NotifyIcon.exit_callbacks[self.hwnd] = exit_callback
     win32NotifyIcon.command_callbacks[self.hwnd] = command_callback
Esempio n. 22
0
    def _DoCreateIcons(self):
        # Try and find a custom icon
        hinst = win32api.GetModuleHandle(None)
        iconPathName = os.path.abspath(
            os.path.join(os.path.split(sys.executable)[0], "pyc.ico"))
        if not os.path.isfile(iconPathName):
            # Look in DLLs dir, a-la py 2.5
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "DLLs", "pyc.ico"))
        if not os.path.isfile(iconPathName):
            # Look in the source tree.
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "..\\PC\\pyc.ico"))
        if os.path.isfile(iconPathName):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, iconPathName,
                                       win32con.IMAGE_ICON, 0, 0, icon_flags)
        else:
            print("Can't find a Python icon file - using default")
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
               "Python Demo")
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            print("Failed to add the taskbar icon - is explorer running?")
Esempio n. 23
0
 def onRightClick(self):
     #NIF_INFO flag below enables balloony stuff
     flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_INFO
     #define the icon properties (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/notifyicondata.asp)
     nid = (self.hwnd, 0, flags, win32con.WM_USER+20, self.hicon, "", "Balloon Message", 10, "Balloon", win32gui.NIIF_INFO)
     #change our already present icon ...
     win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)
Esempio n. 24
0
    def _set_icon(self, icon_path=None):
        """Load the tray icon.

        Doesn't appear to be editable once it's been set.
        TODO: Look at http://www.brunningonline.net/simon/blog/archives/SysTrayIcon.py.html on how to edit it.
        """

        #Load icon as an image
        try:
            if icon_path is None or not os.path.isfile(icon_path):
                raise TypeError
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hinst = win32api.GetModuleHandle(None)
            hicon = win32gui.LoadImage(hinst, icon_path, win32con.IMAGE_ICON,
                                       0, 0, icon_flags)

        #Fallback to default windows icon
        except TypeError:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, TRAY_EVENT, hicon, self.program_name)
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            # but keep running anyway - when explorer starts, we get the
            # TaskbarCreated message.
            pass

        self.logger.debug('Set tray icon.')
Esempio n. 25
0
 def showBalloon(self, title, msg):
     flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_INFO
     #define the icon properties (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/notifyicondata.asp)
     nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon, "", msg,
            10, title, win32gui.NIIF_INFO)
     #change our already present icon ...
     win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)
Esempio n. 26
0
    def create_icon(self, icon="icon.ico"):
        # If default icon exists, use it
        if os.path.isfile(icon):
            hinst = win32gui.GetModuleHandle(None)
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON, 0, 0,
                                       icon_flags)

        # No icon was found, using system default
        else:
            print "Can't find icon file - using default."
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # Add icon to system tray
        if self.notify_id: message = win32gui.NIM_MODIFY
        else: message = win32gui.NIM_ADD

        # Create Tray and add to Taskbar
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        self.notify_id = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
                          "willSpeak")
        try:
            win32gui.Shell_NotifyIcon(message, self.notify_id)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit before the taskbar has been created.
            # When explorer starts, we get the TaskbarCreated message.
            print "Failed to add the taskbar icon - is explorer running?"
Esempio n. 27
0
    def __init__(self):
        # 注册一个窗口类
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32gui.GetModuleHandle(None)
        wc.lpszClassName = "PythonRecordScreen"
        wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy}
        classAtom = win32gui.RegisterClass(wc)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, "PythonRecordScreen",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)

        icon = os.path.join(
            os.path.abspath(os.path.dirname(__file__)) + 'ico.ico')
        if os.path.isfile(icon):

            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON, 0, 0,
                                       icon_flags)
        else:

            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        nid = (self.hwnd, 0, win32gui.NIF_ICON, win32con.WM_USER + 20, hicon,
               "PythonRecordScreen")
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
Esempio n. 28
0
    def __init__(self, app_state, target_url='', icon_path='icon.ico'):
        self.app_state = app_state
        self.target_url = target_url
        self.message_id = win32con.WM_USER+20
        self.window_id = self.create_window()
        # load the icon

        self.icon = win32gui.LoadImage(
            None,
            icon_path,
            win32con.IMAGE_ICON,
            0,
            0,
            win32con.LR_LOADFROMFILE
        )
        # set tray icon properties
        self.notify_id = (
            self.window_id,
            0,
            win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
            self.message_id,
            self.icon,
            # NOTE: This is a comment about `GeoBox`
            self.app_state.gettext('GeoBox'),
        )
        win32gui.Shell_NotifyIcon(
            win32gui.NIM_ADD,
            self.notify_id
        )
        log.debug('Tray icon attached')
        self.timer_id = timer.set_timer(1000, self.check_for_shutdown)
Esempio n. 29
0
 def run(self):
     self.initialize()
     while not self.terminate:
         win32gui.PumpWaitingMessages()
         self.doUpdates()
         sleep(0.1)
     win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, (self.hwnd, 0))
Esempio n. 30
0
    def draw_icon(self, icon):

        # Try and find a custom icon
        hinst = win32gui.GetModuleHandle(None)

        if os.path.isfile(icon):

            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            self.hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON,
                                            0, 0, icon_flags)

        else:

            logging.warning("Can't find icon file - using default.")
            self.hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id:

            message = win32gui.NIM_MODIFY

        else:

            message = win32gui.NIM_ADD

        self.notify_id = (self.hWindow, 0, win32gui.NIF_ICON
                          | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                          win32con.WM_USER + 20, self.hicon, self.hoverText)

        win32gui.Shell_NotifyIcon(message, self.notify_id)