def tryGtk3Import(): """Try GObject inspection to retrieve GTK (probably only works with GTK 3 and above) """ global gi, Gtk, Gdk, loadedGtkMajor import sys # First step: Try to load gi module try: import gi except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Import GI in GtkHacks.py" .format(WX_GTK_VER_STRING)) return # Second step: Load required GTK version try: gi.require_version('Gtk', WX_GTK_VER_STRING) from gi.repository import Gtk, Gdk loadedGtkMajor = WX_GTK_MAJOR # Success except: # Failed: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Import GTK (version {0}) by GI in GtkHacks.py" .format(WX_GTK_VER_STRING)) # Problem now: gi polluted sys.modules so that subsequent # gtk imports would fail. # Cleaning hack: for m in ('glib', 'gobject', 'gio', 'gtk', 'gtk.gdk'): try: if sys.modules.has_key(m) and \ isinstance(sys.modules[m], gi._DummyStaticModule): del sys.modules[m] except: ExceptionLogger.logOptionalComponentException( "Cleaning after GI, module name {0} in GtkHacks.py" .format(m))
def OnExit(self): from . import Ipc self.getInsertionPluginManager().taskEnd() if self.removeAppLockOnExit: try: os.remove(os.path.join(self.globalConfigSubDir, "AppLock.lock")) except: # OSError, ex: traceback.print_exc() # TODO Error message! try: Ipc.stopCommandServer() except: traceback.print_exc() if ExceptionLogger._exceptionOccurred and hasattr(sys, 'frozen'): wx.MessageBox(_("An error occurred during this session\nSee file %s") % os.path.join(ExceptionLogger.getLogDestDir()), "Error", style = wx.OK) return 0
# from wxHelper import * from . import MiscEvent from .Utilities import DUMBTHREADSTOP from .wxHelper import GUI_ID, XrcControls, autosizeColumn, wxKeyFunctionSink from .WikiPyparsing import buildSyntaxNode try: from .EnchantDriver import Dict from . import EnchantDriver except (AttributeError, ImportError, WindowsError): import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize enchant driver (spell checking)") Dict = None # traceback.print_exc() # WindowsError may happen if an incomplete enchant installation is found # in the system from .DocPages import AliasWikiPage, WikiPage class SpellCheckerDialog(wx.Dialog): def __init__(self, parent, ID, mainControl,
# import WindowsHacks try: import WindowsHacks except: if SystemInfo.isWindows(): traceback.print_exc() WindowsHacks = None try: import GtkHacks except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize GTK hacks in OsAbstract.py") GtkHacks = None # Define startFile if SystemInfo.isWindows(): if SystemInfo.isWinNT() and SystemInfo.isUnicode() and WindowsHacks: startFile = WindowsHacks.startFile else: def startFile(mainControl, link): os.startfile(mbcsEnc(link, "replace")[0]) else: def startFile(mainControl, link): # We need mainControl only for this version of startFile() startPath = mainControl.getConfig().get("main", "fileLauncher_path", u"")
from .Configuration import MIDDLE_MOUSE_CONFIG_TO_TABMODE from . import OsAbstract from . import DocPages from .TempFileSet import TempFileSet from . import PluginManager # Try and load webkit renderer try: import WikiHtmlViewWK except: import ExceptionLogger ExceptionLogger.logOptionalComponentException("Initialize webkit HTML renderer") WikiHtmlViewWK = None # Try and load Windows IE renderer if isWindows(): try: import WikiHtmlViewIE except: import ExceptionLogger ExceptionLogger.logOptionalComponentException("Initialize IE HTML renderer") WikiHtmlViewIE = None else: WikiHtmlViewIE = None
# GtkHacks for the Clipboard Catcher try: import LinuxHacks except: if SystemInfo.isLinux(): traceback.print_exc() LinuxHacks = None try: import GtkHacks except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize GTK hacks in OsAbstract.py") GtkHacks = None # Define startFile if SystemInfo.isWindows(): if SystemInfo.isWinNT() and SystemInfo.isUnicode() and WindowsHacks: startFile = WindowsHacks.startFile else: def startFile(mainControl, link): os.startfile(mbcsEnc(link, "replace")[0]) else: def startFile(mainControl, link): # We need mainControl only for this version of startFile()
from ctypes import c_int, c_uint, c_long, c_ulong, c_ushort, c_char, c_char_p, \ c_wchar_p, c_byte, byref, create_string_buffer, create_unicode_buffer, \ c_void_p, string_at, sizeof, Structure # , WindowsError from . import SystemInfo libc = ctypes.CDLL('libc.so.6', use_errno=True) # Based on "bits/sched.h", see e.g. http://code.woboq.org/gcc/include/bits/sched.h.html # and http://linux.die.net/man/2/sched_setaffinity try: sched_setaffinity = libc.sched_setaffinity sched_getaffinity = libc.sched_getaffinity except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Link to sched_setaffinity() in LinuxHacks.py") sched_setaffinity = None sched_getaffinity = None # int sched_setaffinity(pid_t pid, size_t cpusetsize, # cpu_set_t *mask); # Naming is based on the C definitions, sometimes with less leading underscores # than in original code size_t = c_ulong _cpu_mask = c_ulong _CPU_SETSIZE = 1024 _NCPUBITS = 8 * sizeof(_cpu_mask)
#? del __builtin__ # create a Trace object # import trace # __builtins__["tracer"] = trace.Trace( # ignoredirs=[sys.prefix, sys.exec_prefix], # trace=1, # count=0) import ExceptionLogger ExceptionLogger.startLogger(VERSION_STRING) # import faulthandler # faulthandler.dump_traceback_later(20, repeat=True) # ## import hotshot # ## _prof = hotshot.Profile("hotshot.prf") def _putPathPrepends(): """ Process file "binInst.ini" in installation directory, if present. The file is created by the Windows binary installer (Inno Setup) and contains adjustments to the installation, namely additional ZIP-files to add to sys.path. """
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)
del __builtin__ # create a Trace object # import trace # __builtins__["tracer"] = trace.Trace( # ignoredirs=[sys.prefix, sys.exec_prefix], # trace=1, # count=0) import ExceptionLogger ExceptionLogger.startLogger(VERSION_STRING) # ## import hotshot # ## _prof = hotshot.Profile("hotshot.prf") def _putPathPrepends(): """ Process file "binInst.ini" in installation directory, if present. The file is created by the Windows binary installer (Inno Setup) and contains adjustments to the installation, namely additional ZIP-files to add to sys.path. """ parser = ConfigParser.RawConfigParser() try: f = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
import os, os.path from time import time, localtime import datetime import string, glob, traceback from pwiki.WikiExceptions import * # TODO make normal import from pwiki import SearchAndReplace try: import pwiki.sqlite3api as sqlite import DbStructure from DbStructure import createWikiDB, WikiDBExistsException except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize external sqlite for original_sqlite/WikiData.py") sqlite = None # finally: # pass from pwiki.StringOps import getBinCompactForDiff, applyBinCompact, longPathEnc, \ longPathDec, binCompactToCompact, fileContentToUnicode, utf8Enc, utf8Dec, \ uniWithNone, loadEntireTxtFile, Conjunction, lineendToInternal from pwiki.StringOps import loadEntireFile, writeEntireFile, \ iterCompatibleFilename, getFileSignatureBlock, guessBaseNameByFilename, \ createRandomString, pathDec from ..BaseWikiData import BasicWikiData, SqliteWikiData, FileWikiData import Consts
from . import SystemInfo libc = ctypes.CDLL('libc.so.6', use_errno=True) # Based on "bits/sched.h", see e.g. http://code.woboq.org/gcc/include/bits/sched.h.html # and http://linux.die.net/man/2/sched_setaffinity try: sched_setaffinity = libc.sched_setaffinity sched_getaffinity = libc.sched_getaffinity except: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Link to sched_setaffinity() in LinuxHacks.py") sched_setaffinity = None sched_getaffinity = None # int sched_setaffinity(pid_t pid, size_t cpusetsize, # cpu_set_t *mask); # Naming is based on the C definitions, sometimes with less leading underscores # than in original code size_t = c_ulong _cpu_mask = c_ulong _CPU_SETSIZE = 1024 _NCPUBITS = 8 * sizeof (_cpu_mask)
from os.path import exists, join, basename import os, os.path from time import time, localtime import datetime import string, glob, traceback try: # tracer.runctx('import gadfly', globals(), locals()) import gadfly except ImportError: import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize gadfly for original_gadfly/WikiData.py") gadfly = None # finally: # pass if gadfly is not None: import DbStructure from DbStructure import createWikiDB import Consts from pwiki.WikiExceptions import * # TODO make normal import? from pwiki import SearchAndReplace from pwiki.StringOps import longPathEnc, longPathDec, utf8Enc, utf8Dec, BOM_UTF8, \ fileContentToUnicode, loadEntireTxtFile, loadEntireFile, \
from . import MiscEvent from .Utilities import DUMBTHREADSTOP from .wxHelper import GUI_ID, XrcControls, autosizeColumn, wxKeyFunctionSink from .WikiPyparsing import buildSyntaxNode try: from .EnchantDriver import Dict from . import EnchantDriver except (AttributeError, ImportError, WindowsError): import ExceptionLogger ExceptionLogger.logOptionalComponentException( "Initialize enchant driver (spell checking)") Dict = None # traceback.print_exc() # WindowsError may happen if an incomplete enchant installation is found # in the system from .DocPages import AliasWikiPage, WikiPage class SpellCheckerDialog(wx.Dialog): def __init__(self, parent, ID, mainControl, title=None, pos=wx.DefaultPosition, size=wx.DefaultSize,