def buildColorsSubmenu(): """ Returns tuple (color sub menu, dict from menu id to color name) """ colorMap = {} colorsMenu = wx.Menu() colorsMenu1 = wx.Menu() colorsMenu.AppendMenu(wx.NewId(), u'A-L', colorsMenu1) colorsMenu2 = wx.Menu() colorsMenu.AppendMenu(wx.NewId(), u'M-Z', colorsMenu2) # Set showColored to False if we are on Win 95/98/ME and use an unicode build # of wxPython because it would crash then showColored = not (wx.GetOsVersion()[0] == wxWIN95 and isUnicode()) for cn in _COLORS: # ["BLACK"]: colorsSubMenu = None translatedColorName = _(cn) if translatedColorName[0] <= 'L': colorsSubMenu = colorsMenu1 ## elif translatedColorName[0] <= 'Z': else: colorsSubMenu = colorsMenu2 menuID = wx.NewId() colorMap[menuID] = cn menuItem = wx.MenuItem(colorsSubMenu, menuID, translatedColorName, translatedColorName) if showColored: cl = wx.NamedColour(cn) menuItem.SetBackgroundColour(cl) # if color is dark, text should be white # (checking green component seems to be enough) if cl.Green() < 128: menuItem.SetTextColour(wx.WHITE) colorsSubMenu.AppendItem(menuItem) return (colorsMenu, colorMap)
Version 0.5 """ # Version Info __version__ = "0.5" import wx import webbrowser # Let's see if we can add few nice shadows to our tooltips (Windows only) _libimported = None if wx.Platform == "__WXMSW__": osVersion = wx.GetOsVersion() # Shadows behind menus are supported only in XP if osVersion[1] > 5 or (osVersion[1] == 5 and osVersion[2] >= 1): try: # Try Mark Hammond's win32all extensions import win32api import win32con import win32gui import winxpgui _libimported = "MH" except ImportError: _libimported = None else: _libimported = None # Define a bunch of predefined colour schemes...
Return if running on Mac OSX """ return '__WXMAC__' in wx.PlatformInfo def isLinux(): """ Return if running on Linux system """ try: return os.uname()[0] == "Linux" except AttributeError: return False _ISWIN9x = wx.GetOsVersion()[0] == wxWIN95 _ISWINNT = wx.GetOsVersion()[0] == wxWINDOWS_NT def isWin9x(): """ Returns True if OS is Windows 95/98/ME """ return _ISWIN9x def isWinNT(): """ Returns True if OS is Windows NT/2000/XP... """ return _ISWINNT
def findDirs(): """ Returns tuple (wikiAppDir, globalConfigDir) """ from os.path import dirname wikiAppDir = None if not wikiAppDir and not hasattr(sys, 'frozen'): wikiAppDir = dirname(os.path.abspath(getsourcefile(lambda:0))) # We are in WikidPad/lib/pwiki, go up two levels wikiAppDir = dirname(dirname(wikiAppDir)) isWindows = (wx.GetOsVersion()[0] == wxWIN95) or \ (wx.GetOsVersion()[0] == wxWINDOWS_NT) # try: if not wikiAppDir: wikiAppDir = dirname(os.path.abspath(sys.argv[0])) if not wikiAppDir: wikiAppDir = r"C:\Program Files\WikidPad" globalConfigDir = None # This allows to keep the program with config on an USB stick if os.path.exists(pathEnc(os.path.join(wikiAppDir, CONFIG_FILENAME))): globalConfigDir = wikiAppDir elif os.path.exists(pathEnc(os.path.join(wikiAppDir, "." + CONFIG_FILENAME))): globalConfigDir = wikiAppDir else: globalConfigDir = os.environ.get("HOME") if not (globalConfigDir and os.path.exists(pathEnc(globalConfigDir))): # Instead of checking USERNAME, the user config dir. is # now used globalConfigDir = wx.StandardPaths.Get().GetUserConfigDir() # For Windows the user config dir is "...\Application data" # therefore we go down to "...\Application data\WikidPad" if os.path.exists(pathEnc(globalConfigDir)) and isWindows: try: realGlobalConfigDir = os.path.join(globalConfigDir, "WikidPad") if not os.path.exists(pathEnc(realGlobalConfigDir)): # If it doesn't exist, create the directory os.mkdir(pathEnc(realGlobalConfigDir)) globalConfigDir = realGlobalConfigDir except: traceback.print_exc() # finally: # pass if not globalConfigDir: globalConfigDir = wikiAppDir # mbcs decoding if wikiAppDir is not None: wikiAppDir = mbcsDec(wikiAppDir, "replace")[0] if globalConfigDir is not None: globalConfigDir = mbcsDec(globalConfigDir, "replace")[0] ExceptionLogger.setLogDestDir(globalConfigDir) return (wikiAppDir, globalConfigDir)