示例#1
0
def dosearch(docpath, searchstring, settings):
    (docpath, kind, case, word, tut, lib, ref, ext, api) = settings
    books = [(tut, 'tut'), (lib, 'lib'), (ref, 'ref'), (ext, 'ext'),
             (api, 'api')]
    if not case:
        searchstring = string.lower(searchstring)

    if kind == 1:
        patterns = string.split(searchstring)
        all = 1
    elif kind == 2:
        patterns = string.split(searchstring)
        all = 0
    else:
        patterns = [searchstring]
        all = 0  # not relevant

    ospathjoin = os.path.join
    stringlower = string.lower
    status = Status()
    statusset = status.set
    _match = match
    _open = open
    hits = {}
    try:
        if hasattr(MacOS, 'EnableAppswitch'):
            MacOS.EnableAppswitch(0)
        try:
            for do, name in books:
                if not do:
                    continue
                bookpath = ospathjoin(docpath, name)
                if not os.path.exists(bookpath):
                    continue
                files = os.listdir(bookpath)
                for file in files:
                    fullpath = ospathjoin(bookpath, file)
                    if fullpath[-5:] <> '.html':
                        continue
                    statusset(fullpath, len(hits))
                    f = _open(fullpath)
                    text = f.read()
                    if not case:
                        text = stringlower(text)
                    f.close()
                    filehits = _match(text, patterns, all)
                    if filehits:
                        hits[fullpath] = filehits
        finally:
            if hasattr(MacOS, 'EnableAppswitch'):
                MacOS.EnableAppswitch(-1)
            status.close()
    except KeyboardInterrupt:
        pass
    hits = hits.items()
    hits.sort()
    return hits
示例#2
0
文件: Wwindows.py 项目: mmrvka/xbmc
 def mainloop(self):
     if hasattr(MacOS, 'EnableAppswitch'):
         saveyield = MacOS.EnableAppswitch(-1)
     while not self.done:
         #self.do1event()
         self.do1event(
             Events.keyDownMask + Events.autoKeyMask + Events.activMask +
             Events.updateMask + Events.mDownMask + Events.mUpMask, 10)
     if hasattr(MacOS, 'EnableAppswitch'):
         MacOS.EnableAppswitch(saveyield)
示例#3
0
 def write(self, text):
     if hasattr(MacOS, 'EnableAppswitch'):
         oldyield = MacOS.EnableAppswitch(-1)
     try:
         self._buf = self._buf + text
         if '\n' in self._buf:
             self.flush()
     finally:
         if hasattr(MacOS, 'EnableAppswitch'):
             MacOS.EnableAppswitch(oldyield)
示例#4
0
def execstring(pytext, globals, locals, filename="<string>", debugging=0,
                        modname="__main__", profiling=0):
    if debugging:
        import PyDebugger, bdb
        BdbQuit = bdb.BdbQuit
    else:
        BdbQuit = 'BdbQuitDummyException'
    pytext = string.split(pytext, '\r')
    pytext = string.join(pytext, '\n') + '\n'
    W.SetCursor("watch")
    globals['__name__'] = modname
    globals['__file__'] = filename
    sys.argv = [filename]
    try:
        code = compile(pytext, filename, "exec")
    except:
        # XXXX BAAAADDD.... We let tracebackwindow decide to treat SyntaxError
        # special. That's wrong because THIS case is special (could be literal
        # overflow!) and SyntaxError could mean we need a traceback (syntax error
        # in imported module!!!
        tracebackwindow.traceback(1, filename)
        return
    try:
        if debugging:
            PyDebugger.startfromhere()
        else:
            if hasattr(MacOS, 'EnableAppswitch'):
                MacOS.EnableAppswitch(0)
        try:
            if profiling:
                import profile, ProfileBrowser
                p = profile.Profile()
                p.set_cmd(filename)
                try:
                    p.runctx(code, globals, locals)
                finally:
                    import pstats

                    stats = pstats.Stats(p)
                    ProfileBrowser.ProfileBrowser(stats)
            else:
                exec code in globals, locals
        finally:
            if hasattr(MacOS, 'EnableAppswitch'):
                MacOS.EnableAppswitch(-1)
    except W.AlertError, detail:
        raise W.AlertError, detail
示例#5
0
def main():
	echo = EchoServer()
	yield = MacOS.EnableAppswitch(-1)		# Disable Python's own "event handling"
	try:
		echo.mainloop(everyEvent, 0)
	finally:
		MacOS.EnableAppswitch(yield)	# Let Python have a go at events
		echo.close()
示例#6
0
	def mainloop(self, mask = everyEvent, wait = 0):
		saveyield = MacOS.EnableAppswitch(self.yield)
		try:
			while 1:
				try:
					self.do1event(mask, wait)
				except (Application, SystemExit):
					break
		finally:
			MacOS.EnableAppswitch(saveyield)
示例#7
0
 def key(self, char, event):
     (what, message, when, where, modifiers) = event
     if self._enabled and not modifiers & Events.cmdKey or char in Wkeys.arrowkeys:
         if char not in Wkeys.navigationkeys:
             self.checkselection()
         if char == Wkeys.enterkey:
             char = Wkeys.returnkey
         selstart, selend = self.getselection()
         if char == Wkeys.backspacekey:
             if selstart <= (self._inputstart - (selstart <> selend)):
                 return
         self.ted.WEKey(ord(char), modifiers)
         if char not in Wkeys.navigationkeys:
             self.changed = 1
         if char not in Wkeys.scrollkeys:
             self.selchanged = 1
         self.updatescrollbars()
         if char == Wkeys.returnkey:
             text = self.get()[self._inputstart:selstart]
             text = string.join(string.split(text, "\r"), "\n")
             if hasattr(MacOS, 'EnableAppswitch'):
                 saveyield = MacOS.EnableAppswitch(0)
             self._scriptDone = False
             if sys.platform == "darwin":
                 # see identical construct in PyEdit.py
                 from threading import Thread
                 t = Thread(target=self._userCancelledMonitor,
                                 name="UserCancelledMonitor")
                 t.start()
             try:
                 self.pyinteractive.executeline(text, self, self._namespace)
             finally:
                 self._scriptDone = True
             if hasattr(MacOS, 'EnableAppswitch'):
                 MacOS.EnableAppswitch(saveyield)
             selstart, selend = self.getselection()
             self._inputstart = selstart
示例#8
0
文件: PythonIDE.py 项目: mmrvka/xbmc
def init():
    import MacOS
    if hasattr(MacOS, 'EnableAppswitch'):
        MacOS.EnableAppswitch(-1)

    try:
        import autoGIL
    except ImportError:
        pass
    else:
        autoGIL.installAutoGIL()

    from Carbon import Qd, QuickDraw
    Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data)

    import macresource
    import sys, os
    macresource.need('DITL', 468, "PythonIDE.rsrc")
    widgetrespathsegs = [
        sys.exec_prefix, "Mac", "Tools", "IDE", "Widgets.rsrc"
    ]
    widgetresfile = os.path.join(*widgetrespathsegs)
    if not os.path.exists(widgetresfile):
        widgetrespathsegs = [os.pardir, "Tools", "IDE", "Widgets.rsrc"]
        widgetresfile = os.path.join(*widgetrespathsegs)
    refno = macresource.need('CURS', 468, widgetresfile)
    if os.environ.has_key('PYTHONIDEPATH'):
        # For development set this environment variable
        ide_path = os.environ['PYTHONIDEPATH']
    elif refno:
        # We're not a fullblown application
        idepathsegs = [sys.exec_prefix, "Mac", "Tools", "IDE"]
        ide_path = os.path.join(*idepathsegs)
        if not os.path.exists(ide_path):
            idepathsegs = [os.pardir, "Tools", "IDE"]
            for p in sys.path:
                ide_path = os.path.join(*([p] + idepathsegs))
                if os.path.exists(ide_path):
                    break

    else:
        # We are a fully frozen application
        ide_path = sys.argv[0]
    if ide_path not in sys.path:
        sys.path.insert(1, ide_path)
示例#9
0
"""Main TTX application, Mac-only"""

#make sure we don't lose events to SIOUX
import MacOS
MacOS.EnableAppswitch(-1)


def SetWatchCursor():
    import Qd, QuickDraw
    Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data)


def SetArrowCursor():
    import Qd
    Qd.SetCursor(Qd.qd.arrow)


SetWatchCursor()

# a few constants
LOGFILENAME = "TTX errors"
PREFSFILENAME = "TTX preferences"
DEFAULTXMLOUTPUT = ":XML output"
DEFAULTTTOUTPUT = ":TrueType output"

import FrameWork
import MiniAEFrame, AppleEvents
import EasyDialogs
import Res
import macfs
import os
示例#10
0
from addpack import addpack

addpack('Demo')
addpack('bgen')
addpack('evt')
addpack('win')
addpack('ctl')

from Events import *
from Windows import *
from Controls import *

import MacOS

MacOS.EnableAppswitch(0)  # Stop Python from ever getting events itself

everywhere = (-32000, -32000, 32000, 32000)
# NB using 0x7fff doesn't work -- apparently a little slop must be present

print "There are now", len(dir()), "symbols in the name space!"


def main():
    appleid = 1
    ClearMenuBar()
    applemenu = NewMenu(appleid, "\024")
    applemenu.AppendMenu("All about me...;(-")
    applemenu.AddResMenu('DRVR')
    applemenu.InsertMenu(0)
    DrawMenuBar()
示例#11
0
"""PythonSlave.py