我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用win32con.MF_SEPARATOR。
def CheckIDLEMenus(self, idle): if self.bSetMenus: return self.bSetMenus = 1 submenu = win32ui.CreatePopupMenu() newitems = idle.GetMenuItems("edit") flags=win32con.MF_STRING|win32con.MF_ENABLED for text, event in newitems: id = bindings.event_to_commands.get(event) if id is not None: keyname = pywin.scintilla.view.configManager.get_key_binding( event, ["editor"] ) if keyname is not None: text = text + "\t" + keyname submenu.AppendMenu(flags, id, text) mainMenu = self.GetSharedMenu() editMenu = mainMenu.GetSubMenu(1) editMenu.AppendMenu(win32con.MF_SEPARATOR, 0, "") editMenu.AppendMenu(win32con.MF_STRING | win32con.MF_POPUP | win32con.MF_ENABLED, submenu.GetHandle(), "&Source Code")
def OnRClick(self,params): menu = win32ui.CreatePopupMenu() # look for a module name line=self._obj_.GetLine().strip() flags=win32con.MF_STRING|win32con.MF_ENABLED if patImport.match(line)==len(line): menu.AppendMenu(flags, ID_LOCATE_FILE, "&Locate %s.py"%patImport.group('name')) menu.AppendMenu(win32con.MF_SEPARATOR); menu.AppendMenu(flags, win32ui.ID_EDIT_UNDO, '&Undo') menu.AppendMenu(win32con.MF_SEPARATOR); menu.AppendMenu(flags, win32ui.ID_EDIT_CUT, 'Cu&t') menu.AppendMenu(flags, win32ui.ID_EDIT_COPY, '&Copy') menu.AppendMenu(flags, win32ui.ID_EDIT_PASTE, '&Paste') menu.AppendMenu(flags, win32con.MF_SEPARATOR); menu.AppendMenu(flags, win32ui.ID_EDIT_SELECT_ALL, '&Select all') menu.AppendMenu(flags, win32con.MF_SEPARATOR); menu.AppendMenu(flags, ID_GOTO_LINE, '&Goto line...') menu.TrackPopupMenu(params[5]) return 0
def GetRightMenuItems(self): # Just override parents ret = [] flags = 0 ret.append((flags, win32ui.ID_EDIT_UNDO, '&Undo')) ret.append(win32con.MF_SEPARATOR) ret.append((flags, win32ui.ID_EDIT_CUT, 'Cu&t')) ret.append((flags, win32ui.ID_EDIT_COPY, '&Copy')) start, end=self.GetSel() if start!=end: ret.append((flags, ID_EDIT_COPY_CODE, 'Copy code without prompts')) if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_UNICODETEXT): ret.append((flags, ID_EDIT_EXEC_CLIPBOARD, 'Execute python code from clipboard')) ret.append((flags, win32ui.ID_EDIT_PASTE, '&Paste')) ret.append(win32con.MF_SEPARATOR) ret.append((flags, win32ui.ID_EDIT_SELECT_ALL, '&Select all')) ret.append((flags, win32ui.ID_EDIT_SELECT_BLOCK, 'Select &block')) ret.append((flags, win32ui.ID_VIEW_WHITESPACE, "View &Whitespace")) return ret
def OnRClick(self, params): menu = win32ui.CreatePopupMenu() flags=win32con.MF_STRING|win32con.MF_ENABLED lineno = self._obj_.LineFromChar(-1) #selection or current line line = self._obj_.GetLine(lineno) regexGrepResult = regexGrep.match(line) charstart, charend = self._obj_.GetSel() if regexGrepResult: self.fnm = regexGrepResult.group(1) self.lnnum = int(regexGrepResult.group(2)) menu.AppendMenu(flags, ID_OPEN_FILE, "&Open "+self.fnm) menu.AppendMenu(flags, ID_ADDCOMMENT, "&Add to source: Comment Tag/#$pycheck_no ..") menu.AppendMenu(flags, ID_ADDPYCHECKNO2, "&Add to source: Specific #$pycheck_no=%(errtext)s ..") menu.AppendMenu(win32con.MF_SEPARATOR) menu.AppendMenu(flags, ID_TRYAGAIN, "&Try Again") menu.AppendMenu(flags, win32ui.ID_EDIT_CUT, 'Cu&t') menu.AppendMenu(flags, win32ui.ID_EDIT_COPY, '&Copy') menu.AppendMenu(flags, win32ui.ID_EDIT_PASTE, '&Paste') menu.AppendMenu(flags, win32con.MF_SEPARATOR); menu.AppendMenu(flags, win32ui.ID_EDIT_SELECT_ALL, '&Select all') menu.AppendMenu(flags, win32con.MF_SEPARATOR); menu.AppendMenu(flags, ID_SAVERESULTS, 'Sa&ve results') menu.TrackPopupMenu(params[5]) return 0
def AddSystemReloadMenu(wnd): if not WndProcManage(wnd): return False hSysMenu = win32gui.GetSystemMenu(wnd.GetHandle(), False) if not hSysMenu: return False win32gui.InsertMenu(hSysMenu, 0, win32con.MF_BYPOSITION | win32con.MF_SEPARATOR, 0, '') win32gui.InsertMenu(hSysMenu, 0, win32con.MF_BYPOSITION, SYS_MENU_RELOAD_MODULES, 'Reload Modules') def HandleSystemMenu(wnd, msg, wparam, lparam): wnd.__class__._reload_modules() return False AddCallback(HandleSystemMenu, wnd, win32con.WM_SYSCOMMAND, SYS_MENU_RELOAD_MODULES, None) return True
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
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
def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags): print "QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags # Query the items clicked on format_etc = win32con.CF_HDROP, None, 1, -1, pythoncom.TYMED_HGLOBAL sm = self.dataobj.GetData(format_etc) num_files = shell.DragQueryFile(sm.data_handle, -1) if num_files>1: msg = "&Hello from Python (with %d files selected)" % num_files else: fname = shell.DragQueryFile(sm.data_handle, 0) msg = "&Hello from Python (with '%s' selected)" % fname idCmd = idCmdFirst items = ['First Python content menu item'] if (uFlags & 0x000F) == shellcon.CMF_NORMAL: # Check == here, since CMF_NORMAL=0 print "CMF_NORMAL..." items.append(msg) elif uFlags & shellcon.CMF_VERBSONLY: print "CMF_VERBSONLY..." items.append(msg + " - shortcut") elif uFlags & shellcon.CMF_EXPLORE: print "CMF_EXPLORE..." items.append(msg + " - normal file, right-click in Explorer") elif uFlags & CMF_DEFAULTONLY: print "CMF_DEFAULTONLY...\r\n" else: print "** unknown flags", uFlags win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_SEPARATOR|win32con.MF_BYPOSITION, 0, None) indexMenu += 1 for item in items: win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_STRING|win32con.MF_BYPOSITION, idCmd, item) indexMenu += 1 idCmd += 1 win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_SEPARATOR|win32con.MF_BYPOSITION, 0, None) indexMenu += 1 return idCmd-idCmdFirst # Must return number of menu items we added.
def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags): print("QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags) # Query the items clicked on format_etc = win32con.CF_HDROP, None, 1, -1, pythoncom.TYMED_HGLOBAL sm = self.dataobj.GetData(format_etc) num_files = shell.DragQueryFile(sm.data_handle, -1) if num_files>1: msg = "&Hello from Python (with %d files selected)" % num_files else: fname = shell.DragQueryFile(sm.data_handle, 0) msg = "&Hello from Python (with '%s' selected)" % fname idCmd = idCmdFirst items = ['First Python content menu item'] if (uFlags & 0x000F) == shellcon.CMF_NORMAL: # Check == here, since CMF_NORMAL=0 print("CMF_NORMAL...") items.append(msg) elif uFlags & shellcon.CMF_VERBSONLY: print("CMF_VERBSONLY...") items.append(msg + " - shortcut") elif uFlags & shellcon.CMF_EXPLORE: print("CMF_EXPLORE...") items.append(msg + " - normal file, right-click in Explorer") elif uFlags & CMF_DEFAULTONLY: print("CMF_DEFAULTONLY...\r\n") else: print("** unknown flags", uFlags) win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_SEPARATOR|win32con.MF_BYPOSITION, 0, None) indexMenu += 1 for item in items: win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_STRING|win32con.MF_BYPOSITION, idCmd, item) indexMenu += 1 idCmd += 1 win32gui.InsertMenu(hMenu, indexMenu, win32con.MF_SEPARATOR|win32con.MF_BYPOSITION, 0, None) indexMenu += 1 return idCmd-idCmdFirst # Must return number of menu items we added.
def getMenuInfo(hMenu, uIDItem): '''Get various info about a menu item. Arguments: hMenu The menu in which the item is to be found. uIDItem The item's index Returns: Menu item information object. This object is basically a 'bunch' (see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308). It will have useful attributes: name, itemCount, submenu, isChecked, isDisabled, isGreyed, and isSeperator Raises: WinGuiAutoError When the requested menu option isn't found. Usage example: submenuInfo = getMenuInfo(hMenu, submenu) hMenu, hMenuItemCount = submenuInfo.submenu, submenuInfo.itemCount''' # An object to hold the menu info class MenuInfo(Bunch): pass menuInfo = MenuInfo() # Menu state menuState = ctypes.windll.user32.GetMenuState(hMenu, uIDItem, win32con.MF_BYPOSITION) if menuState == -1: raise WinGuiAutoError("No such menu item, hMenu=" + str(hMenu) + " uIDItem=" + str(uIDItem)) menuInfo.isChecked = bool(menuState & win32con.MF_CHECKED) menuInfo.isDisabled = bool(menuState & win32con.MF_DISABLED) menuInfo.isGreyed = bool(menuState & win32con.MF_GRAYED) menuInfo.isSeperator = bool(menuState & win32con.MF_SEPARATOR) # ... there are more, but these are the ones I'm interested in # Menu name menuName = ctypes.c_buffer("\000" * 32) ctypes.windll.user32.GetMenuStringA(ctypes.c_int(hMenu), ctypes.c_int(uIDItem), menuName, ctypes.c_int(len(menuName)), win32con.MF_BYPOSITION) menuInfo.name = menuName.value # Sub menu info menuInfo.itemCount = menuState >> 8 if bool(menuState & win32con.MF_POPUP): menuInfo.submenu = ctypes.windll.user32.GetSubMenu(hMenu, uIDItem) else: menuInfo.submenu = None return menuInfo
def getMenuInfo(hMenu, uIDItem): #print "getMenuInfo fuction,hMenu,uIDItem",hMenu,uIDItem '''Get various info about a menu item. Arguments: hMenu The menu in which the item is to be found. uIDItem The item's index Returns: Menu item information object. This object is basically a 'bunch' (see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308). It will have useful attributes: name, itemCount, submenu, isChecked, isDisabled, isGreyed, and isSeperator Raises: WinGuiAutoError When the requested menu option isn't found. Usage example: submenuInfo = getMenuInfo(hMenu, submenu) hMenu, hMenuItemCount = submenuInfo.submenu, submenuInfo.itemCount''' # An object to hold the menu info class MenuInfo(Bunch): pass menuInfo = MenuInfo() # Menu state menuState = ctypes.windll.user32.GetMenuState(hMenu, uIDItem, win32con.MF_BYPOSITION) #print "menuState_MF_BYPOSITION:",ctypes.windll.user32.GetMenuState(hMenu,uIDItem,win32con.MF_BYPOSITION) #print "menuState_MF_BYCOMMAND:",ctypes.windll.user32.GetMenuState(hMenu,uIDItem,win32con.MF_BYCOMMAND) if menuState == -1: raise WinGuiAutoError("No such menu item, hMenu=" + str(hMenu) + " uIDItem=" + str(uIDItem)) menuInfo.isChecked = bool(menuState & win32con.MF_CHECKED) menuInfo.isDisabled = bool(menuState & win32con.MF_DISABLED) menuInfo.isGreyed = bool(menuState & win32con.MF_GRAYED) menuInfo.isSeperator = bool(menuState & win32con.MF_SEPARATOR) # ... there are more, but these are the ones I'm interested in # Menu name menuName = ctypes.c_buffer("\000" * 32) ctypes.windll.user32.GetMenuStringA(ctypes.c_int(hMenu), ctypes.c_int(uIDItem), menuName, ctypes.c_int(len(menuName)), win32con.MF_BYPOSITION) menuInfo.name = menuName.value # Sub menu info menuInfo.itemCount = menuState >> 8 if bool(menuState & win32con.MF_POPUP): menuInfo.submenu = ctypes.windll.user32.GetSubMenu(hMenu, uIDItem) else: menuInfo.submenu = None #print "menuInfo",menuInfo return menuInfo