Python win32con.TPM_LEFTALIGN Examples

The following are 13 code examples of win32con.TPM_LEFTALIGN(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32con , or try the search function .
Example #1
Source File: win32gui_taskbar.py    From ironpython2 with Apache License 2.0 9 votes vote down vote up
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
        if lparam==win32con.WM_LBUTTONUP:
            print "You clicked me."
        elif lparam==win32con.WM_LBUTTONDBLCLK:
            print "You double-clicked me - goodbye"
            win32gui.DestroyWindow(self.hwnd)
        elif lparam==win32con.WM_RBUTTONUP:
            print "You right clicked me."
            menu = win32gui.CreatePopupMenu()
            win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog")
            win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello")
            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 
Example #2
Source File: SysTrayIcon.py    From LIFX-Control-Panel with MIT License 7 votes vote down vote up
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        # win32gui.SetMenuDefaultItem(menu, 1000, 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) 
Example #3
Source File: win32gui_menu.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
        if lparam==win32con.WM_RBUTTONUP:
            print "You right clicked me."
            # display the menu at the cursor pos.
            pos = GetCursorPos()
            SetForegroundWindow(self.hwnd)
            TrackPopupMenu(self.hmenu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
            PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        elif lparam==win32con.WM_LBUTTONDBLCLK:
            print "You double-clicked me"
            # find the default menu item and fire it.
            cmd = GetMenuDefaultItem(self.hmenu, False, 0)
            if cmd == -1:
                print "Can't find a default!"
            # and just pretend it came from the menu
            self.OnCommand(hwnd, win32con.WM_COMMAND, cmd, 0)
        return 1 
Example #4
Source File: tray.py    From MouseTracks with GNU General Public License v3.0 6 votes vote down vote up
def show_menu(self):
        """Draw the popup menu."""
        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)
        self.logger.debug('Menu displayed.') 
Example #5
Source File: __init__.py    From pyrexecd with MIT License 6 votes vote down vote up
def _notify(klass, hwnd, msg, wparam, lparam):
        self = klass._instance[hwnd]
        if lparam == win32con.WM_LBUTTONDBLCLK:
            menu = self.get_popup()
            wid = win32gui.GetMenuDefaultItem(menu, 0, 0)
            if 0 < wid:
                win32gui.PostMessage(hwnd, win32con.WM_COMMAND, wid, 0)
        elif lparam == win32con.WM_RBUTTONUP:
            menu = self.get_popup()
            pos = win32gui.GetCursorPos()
            win32gui.SetForegroundWindow(hwnd)
            win32gui.TrackPopupMenu(
                menu, win32con.TPM_LEFTALIGN,
                pos[0], pos[1], 0, hwnd, None)
            win32gui.PostMessage(hwnd, win32con.WM_NULL, 0, 0)
        elif lparam == win32con.WM_LBUTTONUP:
            pass
        return True 
Example #6
Source File: systray.py    From OpenBazaar-Installer with MIT License 6 votes vote down vote up
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        # win32gui.SetMenuDefaultItem(menu, 1000, 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) 
Example #7
Source File: gui_win.py    From ComicStreamer with Apache License 2.0 6 votes vote down vote up
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        #win32gui.SetMenuDefaultItem(menu, 1000, 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) 
Example #8
Source File: winapi.py    From gui-o-matic with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _show_menu( self ):
        menu = win32gui.CreatePopupMenu()
        for action in self.menu_actions:
            if action:
                flags = win32con.MF_STRING
                if not action.sensitive:
                    flags |= win32con.MF_GRAYED
                win32gui.AppendMenu( menu, flags, action.get_id(), action.label )
            else:
                win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, 0, '' )
        
        pos = win32gui.GetCursorPos()
        
        win32gui.SetForegroundWindow( self.window_handle )
        win32gui.TrackPopupMenu( menu,
                                 win32con.TPM_LEFTALIGN | win32con.TPM_BOTTOMALIGN,
                                 pos[ 0 ],
                                 pos[ 1 ],
                                 0,
                                 self.window_handle,
                                 None )
        win32gui.PostMessage( self.window_handle, win32con.WM_NULL, 0, 0 ) 
Example #9
Source File: coloreditor.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def OnRClick(self,params):
		menu = win32ui.CreatePopupMenu()
		self.AppendMenu(menu, "&Locate module", "LocateModule")
		self.AppendMenu(menu, flags=win32con.MF_SEPARATOR)
		self.AppendMenu(menu, "&Undo", "EditUndo")
		self.AppendMenu(menu, '&Redo', 'EditRedo')
		self.AppendMenu(menu, flags=win32con.MF_SEPARATOR)
		self.AppendMenu(menu, 'Cu&t', 'EditCut')
		self.AppendMenu(menu, '&Copy', 'EditCopy')
		self.AppendMenu(menu, '&Paste', 'EditPaste')
		self.AppendMenu(menu, flags=win32con.MF_SEPARATOR)
		self.AppendMenu(menu, '&Select all', 'EditSelectAll')
		self.AppendMenu(menu, 'View &Whitespace', 'ViewWhitespace', checked=self.SCIGetViewWS())
		self.AppendMenu(menu, "&Fixed Font", "ViewFixedFont", checked = self._GetColorizer().bUseFixed)
		self.AppendMenu(menu, flags=win32con.MF_SEPARATOR)
		self.AppendMenu(menu, "&Goto line...", "GotoLine")

		submenu = win32ui.CreatePopupMenu()
		newitems = self.idle.GetMenuItems("edit")
		for text, event in newitems:
			self.AppendMenu(submenu, text, event)

		flags=win32con.MF_STRING|win32con.MF_ENABLED|win32con.MF_POPUP
		menu.AppendMenu(flags, submenu.GetHandle(), "&Source code")

		flags = win32con.TPM_LEFTALIGN|win32con.TPM_LEFTBUTTON|win32con.TPM_RIGHTBUTTON
		menu.TrackPopupMenu(params[5], flags, self)
		return 0 
Example #10
Source File: shell.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu)

        pos = win32gui.GetCursorPos()
        win32gui.SetForegroundWindow(self.shell.main_frame.hwnd)
        win32gui.TrackPopupMenu(menu,
                                win32con.TPM_LEFTALIGN,
                                pos[0],
                                pos[1],
                                0,
                                self.shell.main_frame.hwnd,
                                None) 
Example #11
Source File: shell_view.py    From ironpython2 with Apache License 2.0 4 votes vote down vote up
def OnContextMenu(self, hwnd, msg, wparam, lparam):
        # Get the selected items.
        pidls = []
        n = -1
        while 1:
            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) 
Example #12
Source File: taskbar_widget.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 
Example #13
Source File: shell_view.py    From Email_My_PC with MIT License 4 votes vote down vote up
def OnContextMenu(self, hwnd, msg, wparam, lparam):
        # Get the selected items.
        pidls = []
        n = -1
        while 1:
            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)