Esempio n. 1
0
	def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
		if lparam==win32con.WM_LBUTTONUP:
			print u"Tık"
			
		elif lparam==win32con.WM_LBUTTONDBLCLK:
                        global kaynak
			print u"Çift Tık"
			self.balonGoster(u"Güncelleniyor...",u"Döviz Kurları (" + kaynak + ")")
                        self.kurlariAl()
                        
			
			#win32gui.DestroyWindow(self.hwnd)

			
		elif lparam==win32con.WM_RBUTTONUP:
			print u"Sağ Tık"
			menu = win32gui.CreatePopupMenu()
			win32gui.AppendMenu( menu, win32con.MF_STRING|win32con.MF_DISABLED, 0, u"Kaynak Seçimi")
			win32gui.AppendMenu( menu, win32con.MF_STRING, 1021, u"T.C.M.B.")
			win32gui.AppendMenu( menu, win32con.MF_STRING, 1022, u"Enpara")
			win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, u"Investing")
			win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, 0, '')
			win32gui.AppendMenu( menu, win32con.MF_STRING, 1099, u"Çıkış" )
			pos = win32gui.GetCursorPos()
			win32gui.SetForegroundWindow(self.hwnd)
			win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
			win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
		return 1
Esempio n. 2
0
 def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_RBUTTONUP:
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu, win32con.MF_STRING, SEARCH_MENU_ID,
                             "Search")
         win32gui.AppendMenu(menu, win32con.MF_STRING, PREFERENCES_MENU_ID,
                             "Preferences")
         win32gui.AppendMenu(menu, win32con.MF_STRING, HELP_MENU_ID, "Help")
         win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 1002, "")
         if maay.globalvars.indexer.isPaused():
             win32gui.AppendMenu(menu, win32con.MF_STRING,
                                 PAUSE_INDEXING_MENU_ID,
                                 "Pause indexing for 15 minutes more")
             win32gui.AppendMenu(menu, win32con.MF_STRING,
                                 RESUME_INDEXING_MENU_ID, "Resume indexing")
         else:
             win32gui.AppendMenu(menu, win32con.MF_STRING,
                                 PAUSE_INDEXING_MENU_ID, "Pause indexing")
         win32gui.AppendMenu(menu, win32con.MF_STRING, EXIT_MENU_ID, "Exit")
         win32gui.SetMenuDefaultItem(menu, SEARCH_MENU_ID, 0)
         pos = win32gui.GetCursorPos()
         # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     elif lparam == win32con.WM_LBUTTONDBLCLK:
         webbrowser.open("http://127.0.0.1:%d/maay/resultspool" %
                         maay.constants.MAAY_PORT,
                         autoraise=1)
     return 1
Esempio n. 3
0
 def get_popup(self):
     menu = win32gui.CreatePopupMenu()
     (item, _) = win32gui_struct.PackMENUITEMINFO(text='Quit',
                                                  wID=self.IDI_QUIT)
     win32gui.InsertMenuItem(menu, 0, 1, item)
     #win32gui.SetMenuDefaultItem(menu, 0, self.IDI_QUIT)
     return menu
Esempio n. 4
0
    def _create_menu(self, menu, menu_options):
        """Generate the popup menu just before drawing.
        This is needed as it recursively runs on submenus.
        """

        for menu_option in menu_options[::-1]:
            if menu_option.get('hidden', False):
                continue

            text = menu_option.get('name', 'Option')
            icon = menu_option.get('icon', None)
            action = menu_option.get('action', None)
            id = menu_option.get('_id')

            #Set icon
            if icon:
                try:
                    icon = self._set_icon_menu(icon)
                except pywintypes.error:
                    icon = None

            #Add menu item
            if id in self.menu_actions_by_id or action is None:
                item, extras = win32gui_struct.PackMENUITEMINFO(text=text,
                                                                hbmpItem=icon,
                                                                wID=id)
                win32gui.InsertMenuItem(menu, 0, 1, item)

            #Add submenu
            else:
                submenu = win32gui.CreatePopupMenu()
                self._create_menu(submenu, action)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=text, hbmpItem=icon, hSubMenu=submenu)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Esempio n. 5
0
	def create_menu(self, menu, menopts):
		# Inserts all items into the popup (again, recursive)
		for opt in menopts:
			if opt[1] != None:
				opt_icon = opt[1].get()
			else:
				opt_icon = None
			mi_fstate = 0
			mi_ftype = 0
			if opt[3]["disabled"]:
				mi_fstate = mi_fstate | win32con.MFS_DISABLED
			if opt[3]["highlight"]:
				mi_fstate = mi_fstate | win32con.MFS_HILITE
			if opt[3]["separator"]:
				mi_ftype = mi_ftype | win32con.MFT_SEPARATOR
			if type(opt[2]) == type([]):
				submenu = win32gui.CreatePopupMenu()
				self.create_menu(submenu, opt[2])
				item, extras = win32gui_struct.PackMENUITEMINFO(
														text=opt[0].get(),
														hbmpItem=opt_icon,
														hSubMenu=submenu,
														fState=mi_fstate,
														fType=mi_ftype,
														wID=opt[-1])
			else:
				item, extras = win32gui_struct.PackMENUITEMINFO(
														text=opt[0].get(),
														hbmpItem=opt_icon,
														fState=mi_fstate,
														fType=mi_ftype,
														wID=opt[-1])
			win32gui.InsertMenuItem(menu, 0, 1, item)
Esempio n. 6
0
 def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_RBUTTONUP:
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu, win32con.MF_STRING,
                             Win32MaayTaskbar.SEARCH_MENU_ID, "Search")
         win32gui.AppendMenu(menu, win32con.MF_STRING,
                             Win32MaayTaskbar.INDEXATION_MENU_ID,
                             "Manage Folders")
         win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 1002, "")
         win32gui.AppendMenu(menu, win32con.MF_STRING,
                             Win32MaayTaskbar.HOMEPAGE_MENU_ID,
                             "Maay Homepage")
         win32gui.SetMenuDefaultItem(menu, Win32MaayTaskbar.SEARCH_MENU_ID,
                                     0)
         pos = win32gui.GetCursorPos()
         # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     elif lparam == win32con.WM_LBUTTONDBLCLK:
         webbrowser.open("http://127.0.0.1:%s/" %
                         self.node.NODE_CONFIG.webserver_port,
                         autoraise=1)
     return 1
Esempio n. 7
0
 def create_menu(self, menu, menu_options):
     for option_text, option_icon, option_Checked, option_action, option_id in menu_options[::
                                                                                            -1]:
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon)
         item_state = None
         if option_Checked is True:
             item_state = win32con.MFS_CHECKED
         if option_id in self.menu_actions_by_id:
             item, extras = win32gui_struct.PackMENUITEMINFO(
                 text=option_text,
                 hbmpItem=option_icon,
                 fState=item_state,
                 wID=option_id)
             win32gui.InsertMenuItem(menu, 0, 1, item)
             if option_id not in self.__menu_extra:
                 self.__menu_extra.setdefault(option_id, extras)
             else:
                 self.__menu_extra[option_id] = extras
         else:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             item, extras = win32gui_struct.PackMENUITEMINFO(
                 text=option_text,
                 hbmpItem=option_icon,
                 fState=item_state,
                 hSubMenu=submenu)
             win32gui.InsertMenuItem(menu, 0, 1, item)
             if option_id not in self.__menu_extra:
                 self.__menu_extra.setdefault(option_id, extras)
             else:
                 self.__menu_extra[option_id] = extras
Esempio n. 8
0
 def notify_callback(hwnd):
     menu = win32gui.CreatePopupMenu()
     win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Generate balloon")
     win32gui.AppendMenu( menu, win32con.MF_STRING, 1025, "Exit")
     pos = win32api.GetCursorPos()
     win32gui.SetForegroundWindow(hwnd)
     win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, hwnd, None)
     win32api.PostMessage(hwnd, win32con.WM_NULL, 0, 0)
Esempio n. 9
0
 def show_menu(self):
     self.menu = win32gui.CreatePopupMenu()
     self.create_menu(self.menu, self.menu_options)
     pos = win32gui.GetCursorPos()
     win32gui.SetForegroundWindow(self.hwnd)
     win32gui.TrackPopupMenu(self.menu, win32con.TPM_LEFTALIGN, pos[0],
                             pos[1], 0, self.hwnd, None)
     win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Esempio n. 10
0
 def show_menu(self):
     menu = win32gui.CreatePopupMenu()
     self.create_menu(menu, self.menu_options)
     pos = win32gui.GetCursorPos()
     # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
     win32gui.SetForegroundWindow(self.hwnd)
     win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                             0, self.hwnd, None)
     win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Esempio n. 11
0
    def _create_unit(self, name):
        if self._curtarget:
            # 現ターゲットは直後に作る新・現ターゲットの親になる.
            # push する名前は新・現ターゲットの名前.
            # (実際に新・現ターゲットを作るのは pop 時だから.)
            self._targetstack.push(self._curtarget, name)

        self._curtarget = win32gui.CreatePopupMenu()
        self._handlelist.append(self._curtarget)
Esempio n. 12
0
 def createMenu(self, items):
     self.menu = win32gui.CreatePopupMenu()
     self.menuitems = []
     for index, (key, value) in enumerate(items):
         # for index, key in enumerate(items):
         # for index, item in items :
         # key = items[index][0], value = items[index][1]
         self.menuitems.append(key)
         win32gui.AppendMenu(self.menu, win32con.MF_STRING, (1023 + index),
                             value)
Esempio n. 13
0
 def __init__(self):
     wx.EvtHandler.__init__(self)
     self.hmenu = win32gui.CreatePopupMenu()
     self.MenuItems = []
     self.Parent = None
     self._menuitems = {}
     # With wxPython 4, calling <EvtHandler>.Destroy() no longer makes the
     # instance evaluate to False in boolean comparisons, so we emulate that
     # functionality
     self._destroyed = False
Esempio n. 14
0
    def RightMB(self):
        menu = win32gui.CreatePopupMenu()
        win32gui.AppendMenu(menu, win32con.MF_STRING, 1023, "Settings")
        win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, "Exit program")

        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        win32gui.SetForegroundWindow(self.hwnd)
        win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                                0, self.hwnd, None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Esempio n. 15
0
 def create_menu(self, menu, menu_options):
     for opt_text, opt_icon, opt_action, opt_id in menu_options[::-1]:
         if  opt_icon:
             opt_icon = self.prep_menu_icon(opt_icon)
         if  opt_id in self.menu_actions_by_id:
             item, extras = win32gui_struct.PackMENUITEMINFO(text=opt_text, hbmpItem=opt_icon, wID=opt_id)
             win32gui.InsertMenuItem(menu, 0, 1, item)
         else:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, opt_action)
             item, extras = win32gui_struct.PackMENUITEMINFO(text=opt_text, hbmpItem=opt_icon, hSubMenu=submenu)
             win32gui.InsertMenuItem(menu, 0, 1, item)
Esempio n. 16
0
def icon_wndproc(hwnd, msg, wp, lp):
    """Window proc for the tray icons"""
    if lp == win32con.WM_LBUTTONDOWN:
        ## popup menu won't disappear if you don't do this
        win32gui.SetForegroundWindow(hwnd)

        curr_desktop = win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)
        curr_desktop_name = win32service.GetUserObjectInformation(
            curr_desktop, win32con.UOI_NAME
        )
        winsta = win32service.GetProcessWindowStation()
        desktops = winsta.EnumDesktops()
        m = win32gui.CreatePopupMenu()
        desktop_cnt = len(desktops)
        ## *don't* create an item 0
        for d in range(1, desktop_cnt + 1):
            mf_flags = win32con.MF_STRING
            ## if you switch to winlogon yourself, there's nothing there and you're stuck
            if desktops[d - 1].lower() in ("winlogon", "disconnect"):
                mf_flags = mf_flags | win32con.MF_GRAYED | win32con.MF_DISABLED
            if desktops[d - 1] == curr_desktop_name:
                mf_flags = mf_flags | win32con.MF_CHECKED
            win32gui.AppendMenu(m, mf_flags, d, desktops[d - 1])
        win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 1, "Create new ...")
        win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 2, "Exit")

        x, y = win32gui.GetCursorPos()
        d = win32gui.TrackPopupMenu(
            m,
            win32con.TPM_LEFTBUTTON | win32con.TPM_RETURNCMD | win32con.TPM_NONOTIFY,
            x,
            y,
            0,
            hwnd,
            None,
        )
        win32gui.PumpWaitingMessages()
        win32gui.DestroyMenu(m)
        if d == desktop_cnt + 1:  ## Create new
            get_new_desktop_name(hwnd)
        elif d == desktop_cnt + 2:  ## Exit
            win32gui.PostQuitMessage(0)
            win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd])
            del window_info[hwnd]
            origin_desktop.SwitchDesktop()
        elif d > 0:
            hdesk = win32service.OpenDesktop(
                desktops[d - 1], 0, 0, win32con.MAXIMUM_ALLOWED
            )
            hdesk.SwitchDesktop()
        return 0
    else:
        return win32gui.DefWindowProc(hwnd, msg, wp, lp)
Esempio n. 17
0
    def OnTaskbarNotify(
        self,
        hwnd,
        msg,
        wparam,
        lparam,
        ):
        if lparam == win32con.WM_LBUTTONUP:
            pass
        elif lparam == win32con.WM_LBUTTONDBLCLK:
            pass
        elif lparam == win32con.WM_RBUTTONUP:
            menu = win32gui.CreatePopupMenu()
            win32gui.AppendMenu(menu, win32con.MF_STRING, 1023,
                                'Toggle Display')
            win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '')
            if self.serverState == self.EnumServerState.STOPPED:
                win32gui.AppendMenu(menu, win32con.MF_STRING, 1024,
                                    'Start Server')
                win32gui.AppendMenu(menu, win32con.MF_STRING
                                     | win32con.MF_GRAYED, 1025,
                                    'Restart Server')
                win32gui.AppendMenu(menu, win32con.MF_STRING
                                     | win32con.MF_GRAYED, 1026,
                                    'Stop Server')
            else:
                win32gui.AppendMenu(menu, win32con.MF_STRING
                                     | win32con.MF_GRAYED, 1024,
                                    'Start Server')
                win32gui.AppendMenu(menu, win32con.MF_STRING, 1025,
                                    'Restart Server')
                win32gui.AppendMenu(menu, win32con.MF_STRING, 1026,
                                    'Stop Server')
            win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '')
            win32gui.AppendMenu(menu, win32con.MF_STRING, 1027,
                                'Quit (pid:%i)' % os.getpid())
            pos = win32gui.GetCursorPos()

            # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp

            win32gui.SetForegroundWindow(self.hwnd)
            win32gui.TrackPopupMenu(
                menu,
                win32con.TPM_LEFTALIGN,
                pos[0],
                pos[1],
                0,
                self.hwnd,
                None,
                )
            win32api.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        return 1
Esempio n. 18
0
 def onRightClick(self):
     menu = win32gui.CreatePopupMenu()
     win32gui.AppendMenu(menu, win32con.MF_STRING,
                         WM_TASKBARNOTIFY_MENUITEM_SHOW, u'显示')
     win32gui.AppendMenu(menu, win32con.MF_STRING,
                         WM_TASKBARNOTIFY_MENUITEM_HIDE, u'隐藏')
     win32gui.AppendMenu(menu, win32con.MF_STRING,
                         WM_TASKBARNOTIFY_MENUITEM_EXIT, u'退出')
     pos = win32gui.GetCursorPos()
     win32gui.SetForegroundWindow(self.hwnd)
     win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                             0, self.hwnd, None)
     win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
Esempio n. 19
0
 def on_taskbar_notify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_RBUTTONUP:
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu,
                             self.menu_mindustry_flags[self.game_state],
                             1024, "Show Mindustry Game")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1025,
                             "Exit Notifier")
         pos = win32gui.GetCursorPos()
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     return 1
Esempio n. 20
0
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        # win32gui.SetMenuDefaultItem(menu, 1000, 0)

        try:
            pos = win32gui.GetCursorPos()
            # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
            win32gui.SetForegroundWindow(self.hwnd)
            win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
            win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        except pywintypes.error:
            # Weird PyWin/win32gui bug, just ignore it for now
            pass
 def on_taskbar_notify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_LBUTTONDBLCLK:
         win32gui.DestroyWindow(self.hwnd)
     elif lparam == win32con.WM_RBUTTONUP:
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, "Show timer")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1025, "Settings")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1026, "Exit")
         pos = win32gui.GetCursorPos()
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     return 1
Esempio n. 22
0
    def __init__(self):
        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        #定义一个新的窗口消息
        message_map = {                         #建立函数命令字典,用于窗口回调函数的四个参数
                msg_TaskbarRestart: self.OnRestart,
                win32con.WM_DESTROY: self.OnDestroy,
                win32con.WM_COMMAND: self.OnCommand,
                win32con.WM_USER+20 : self.OnTaskbarNotify,
        }
        self.menu = win32gui.CreatePopupMenu()  #产生一个菜单句柄menu
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1023,
                            "显示/隐藏窗口")  #给菜单添加子项,1027可以一直下去
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1024, "设置")
        win32gui.AppendMenu(self.menu, win32con.MF_STRING, 1025, "退出程序")
        #win32gui.EnableMenuItem(menu,1023,win32con.MF_GRAYED)#是用菜单句柄,对菜单进行操作

        # Register the Window class.
        self.wc = win32gui.WNDCLASS()  #局部变量wc改成窗口类的实例
        hinst = self.wc.hInstance = win32api.GetModuleHandle(None)  #获得程序模块句柄
        self.wc.lpszClassName = ("PythonTaskbarDemo")  #窗口类的类名
        self.wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        #窗口类的style特征,水平重画和竖直重画
        self.wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        self.wc.hbrBackground = win32con.COLOR_WINDOW
        self.wc.lpfnWndProc = message_map  # could also specify a wndproc,给窗口回调函数赋值
        '''这里传进去的其实是函数指针,它里面保存的是我们定义的windowproc的入口地址'''
        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(self.wc)  #用wc将classatom注册为一个窗口类
        except win32gui.error and err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(
            self.wc.lpszClassName,
            "Taskbar Demo",
            style,  #创建一个窗口 
            0,
            0,
            win32con.CW_USEDEFAULT,
            win32con.CW_USEDEFAULT,
            0,
            0,
            hinst,
            None)
        win32gui.UpdateWindow(self.hwnd)  #更新窗口
        self._DoCreateIcons()
        win32gui.PumpMessages()
Esempio n. 23
0
 def _on_taskbar_notify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_LBUTTONUP or lparam == win32con.WM_RBUTTONUP:
         log.error("You right clicked me.")
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1023,
                             "Display Dialog")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1025, "Exit program")
         pos = win32gui.GetCursorPos()
         # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     return 1
Esempio n. 24
0
 def on_rightclick(self, systray):
     #self.change_tooltip("You right clicked me.")
     menu = win32gui.CreatePopupMenu()
     win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "About")
     if len(self.custom_menu_items) > 0:
         for menu_item in self.custom_menu_items.itervalues():
             if callable(menu_item['func']):
                 try:
                     is_checked = menu_item['func'](self, get_state = True)
                 except Exception, e:
                     print e
             else:
                 is_checked = False
             flags = win32con.MF_STRING | (win32con.MF_CHECKED if is_checked else 0)
             win32gui.AppendMenu( menu, flags, menu_item['id'], menu_item['text'])
Esempio n. 25
0
    def create_menu(self, parent_menu, menu_options):
        """ Create Menus """
        for key, (name, action) in menu_options.iteritems():
            # If action is dict, Create sub menu
            if isinstance(action, dict):
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, action)
                item, _ = win32gui_struct.PackMENUITEMINFO(text=name,
                                                           hSubMenu=submenu)
                win32gui.InsertMenuItem(parent_menu, 0, 1, item)

            # Else, create menu entry
            else:
                item, _ = win32gui_struct.PackMENUITEMINFO(text=name, wID=key)
                win32gui.InsertMenuItem(parent_menu, 0, 1, item)
Esempio n. 26
0
 def _show_menu(self):
     self.FIRST_ID = 1023
     self.menu_options = (('종료', None, self.on_quit),)
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     self.menu_options = self._add_ids_to_menu_options(list(self.menu_options))
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     menu = win32gui.CreatePopupMenu()
     self.create_menu(menu, self.menu_options)
     
     pos = win32gui.GetCursorPos()
     win32gui.SetForegroundWindow(self.hwnd)
     win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN,
                             pos[0], pos[1], 0, self.hwnd, None)
     win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
 def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_RBUTTONUP:
         menu = win32gui.CreatePopupMenu()
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, "Show Log")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1026, "About Us")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1027, "Option")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1028,
                             "Upload Offline")
         win32gui.AppendMenu(menu, win32con.MF_STRING, 1025, "Exit program")
         pos = win32gui.GetCursorPos()
         # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
         win32gui.SetForegroundWindow(self.hwnd)
         win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                 pos[1], 0, self.hwnd, None)
         win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
     return 1
Esempio n. 28
0
    def create_menu(self):
        menu = win32gui.CreatePopupMenu()
        item, extras = win32gui_struct.PackMENUITEMINFO(
            text = self.app_state.gettext('Close'),
            hbmpItem=win32con.HBMMENU_MBAR_CLOSE,
            wID=EXIT_COMMAND
        )
        win32gui.InsertMenuItem(
            menu,
            0,
            1,
            item
        )
        win32gui.SetMenuDefaultItem(
            menu,
            EXIT_COMMAND,
            0
        )
        item, extras = win32gui_struct.PackMENUITEMINFO(
            text = self.app_state.gettext('Open'),
            hbmpChecked = None,
            hbmpUnchecked = None,
            wID=OPEN_COMMAND
            )
        win32gui.InsertMenuItem(
            menu,
            0,
            1,
            item
        )

        win32gui.SetForegroundWindow(self.window_id)
        x, y = win32gui.GetCursorPos()
        win32gui.TrackPopupMenu(
            menu,
            win32con.TPM_LEFTALIGN,
            x, y,
            0,
            self.window_id,
            None
        )
        win32gui.PostMessage(
            self.window_id,
            win32con.WM_NULL,
            0,
            0
        )
Esempio n. 29
0
    def OnContextMenu(self, hwnd, msg, wparam, lparam):
        # Get the selected items.
        pidls = []
        n = -1
        while True:
            n = win32gui.SendMessage(self.hwnd_child,
                                     commctrl.LVM_GETNEXTITEM,
                                     n,
                                     commctrl.LVNI_SELECTED)
            if n == -1:
                break
            pidls.append(self.children[n][-1:])

        spt = win32api.GetCursorPos()
        if not pidls:
            print("Ignoring background click")
            return
        # Get the IContextMenu for the items.
        inout, cm = self.folder.GetUIObjectOf(
            self.hwnd_parent, pidls, shell.IID_IContextMenu, 0)
        hmenu = win32gui.CreatePopupMenu()
        sel = None
        # As per 'Q179911', we need to determine if the default operation
        # should be 'open' or 'explore'
        try:
            flags = 0
            try:
                self.browser.GetControlWindow(shellcon.FCW_TREE)
                flags |= shellcon.CMF_EXPLORE
            except pythoncom.com_error:
                pass
            id_cmd_first = 1  # TrackPopupMenu makes it hard to use 0
            cm.QueryContextMenu(hmenu, 0, id_cmd_first, -1, flags)
            tpm_flags = win32con.TPM_LEFTALIGN | win32con.TPM_RETURNCMD | \
                win32con.TPM_RIGHTBUTTON
            sel = win32gui.TrackPopupMenu(hmenu,
                                          tpm_flags,
                                          spt[0], spt[1],
                                          0, self.hwnd, None)
            print("TrackPopupMenu returned", sel)
        finally:
            win32gui.DestroyMenu(hmenu)
        if sel:
            ci = 0, self.hwnd_parent, sel - id_cmd_first, None, None, 0, 0, 0
            cm.InvokeCommand(ci)
Esempio n. 30
0
    def on_tray_notify(self, hwnd, msg, wp, lp):
        if lp == win32con.WM_LBUTTONUP:
            # print "left click"
            # win32gui.SetForegroundWindow(self.hwnd)
            pass
        elif lp == win32con.WM_RBUTTONUP:
            # print "right click"
            menu = win32gui.CreatePopupMenu()
            for cid in sorted(self.commands.keys(), reverse=True):
                name, _ = self.commands[cid]
                win32gui.AppendMenu(menu, win32con.MF_STRING, cid, name)

            pos = win32gui.GetCursorPos()
            win32gui.SetForegroundWindow(self.hwnd)
            win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0],
                                    pos[1], 0, self.hwnd, None)
            win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        return True