Exemple #1
0
 def execstring(self, pytext, globals, locals, file, modname):
     tracebackwindow.hide()
     # update windows
     W.getapplication().refreshwindows()
     if self.run_as_main:
         modname = "__main__"
     if self.path:
         dir = os.path.dirname(self.path)
         savedir = os.getcwd()
         os.chdir(dir)
         sys.path.insert(0, dir)
     self._scriptDone = False
     if sys.platform == "darwin":
         # On MacOSX, MacPython doesn't poll for command-period
         # (cancel), so to enable the user to cancel a running
         # script, we have to spawn a thread which does the
         # polling. It will send a SIGINT to the main thread
         # (in which the script is running) when the user types
         # command-period.
         from threading import Thread
         t = Thread(target=self._userCancelledMonitor,
                         name="UserCancelledMonitor")
         t.start()
     try:
         execstring(pytext, globals, locals, file, self.debugging,
                         modname, self.profiling)
     finally:
         self._scriptDone = True
         if self.path:
             os.chdir(savedir)
             del sys.path[0]
 def __init__(self, possize, title="", minsize=None, maxsize=None,
                 tabbable=1, show=1, fontsettings=None):
     import W
     if fontsettings is None:
         fontsettings = W.getdefaultfont()
     self._fontsettings = fontsettings
     W.SelectableWidget.__init__(self, possize)
     self._globalbounds = l, t, r, b = self.getwindowbounds(possize, minsize)
     self._bounds = (0, 0, r - l, b - t)
     self._tabchain = []
     self._currentwidget = None
     self.title = title
     self._parentwindow = self
     self._tabbable = tabbable
     self._defaultbutton = None
     self._drawwidgetbounds = 0
     self._show = show
     self._lastrollover = None
     self.hasclosebox = 1
     # XXX the following is not really compatible with the
     #  new (system >= 7.5) window procs.
     if minsize:
         self._hasgrowbox = 1
         self.windowkind = self.windowkind | 8
         l, t = minsize
         if maxsize:
             r, b = maxsize[0] + 1, maxsize[1] + 1
         else:
             r, b = 32000, 32000
         self.growlimit = (l, t, r, b)
     else:
         self._hasgrowbox = 0
         if (self.windowkind == 0 or self.windowkind >= 8) and self.windowkind < 1000:
             self.windowkind = self.windowkind | 4
     FrameWork.Window.__init__(self, W.getapplication())
    def openscript(self, path, modname):
        import os

        if path[-3:] == ".py":
            W.getapplication().openscript(path, modname=modname)
        elif path[-4:] in [".pyc", ".pyo"]:
            W.getapplication().openscript(path[:-1], modname=modname)
        else:
            W.Message("Can't edit '%s'; it might be a shared library or a .pyc file." % modname)
Exemple #4
0
def findeditor(topwindow, fromtop = 0):
    wid = MyFrontWindow()
    if not fromtop:
        if topwindow.w and wid == topwindow.w.wid:
            wid = topwindow.w.wid.GetNextWindow()
    if not wid:
        return
    app = W.getapplication()
    if app._windows.has_key(wid): # KeyError otherwise can happen in RoboFog :-(
        window = W.getapplication()._windows[wid]
    else:
        return
    if not isinstance(window, Editor):
        return
    return window.editgroup.editor
 def openselection(self):
     import os
     sel = self.getselection()
     for index in sel:
         (key, value, arrow, indent) = self[index]
         if arrow:
             self.children.append(Browser(value))
         elif type(value) == types.StringType and '\0' not in value:
             editor = self._parentwindow.parent.getscript(value)
             if editor:
                 editor.select()
                 return
             elif os.path.exists(value) and os.path.isfile(value):
                 if MacOS.GetCreatorAndType(value)[1] in ('TEXT', '\0\0\0\0'):
                     W.getapplication().openscript(value)
Exemple #6
0
    def __init__(
        self, possize, text="", callback=None, inset=(3, 3), fontsettings=None, tabsettings=(32, 0), readonly=0
    ):
        if fontsettings is None:
            import W

            fontsettings = W.getdefaultfont()
        Wbase.SelectableWidget.__init__(self, possize)
        self.temptext = text
        self.ted = None
        self.selection = None
        self.oldselection = None
        self._callback = callback
        self.changed = 0
        self.selchanged = 0
        self._selected = 0
        self._enabled = 1
        self.wrap = 1
        self.readonly = readonly
        self.fontsettings = fontsettings
        self.tabsettings = tabsettings
        if type(inset) <> TupleType:
            self.inset = (inset, inset)
        else:
            self.inset = inset
def FrontWindowInsert(stuff):
    if not stuff:
        return
    if type(stuff) <> StringType:
        raise TypeError, 'string expected'
    import W
    app = W.getapplication()
    wid = MyFrontWindow()
    if wid and app._windows.has_key(wid):
        window = app._windows[wid]
        if hasattr(window, "insert"):
            try:
                window.insert(stuff)
                return
            except:
                pass
    import EasyDialogs
    if EasyDialogs.AskYesNoCancel(
                    "Can't find window or widget to insert text into; copy to clipboard instead?",
                    1) == 1:
        from Carbon import Scrap
        if hasattr(Scrap, 'PutScrap'):
            Scrap.ZeroScrap()
            Scrap.PutScrap('TEXT', stuff)
        else:
            Scrap.ClearCurrentScrap()
            sc = Scrap.GetCurrentScrap()
            sc.PutScrapFlavor('TEXT', 0, stuff)
Exemple #8
0
def seteditorprefs(fontsettings, tabsettings, windowsize):
    import MacPrefs
    prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
    prefs.pyedit.fontsettings = fontsettings
    prefs.pyedit.tabsettings = tabsettings
    prefs.pyedit.windowsize = windowsize
    prefs.save()
 def writeprefs(self):
     prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
     prefs.console.show = self.isvisible()
     prefs.console.windowbounds = self.getbounds()
     prefs.console.fontsettings = self.consoletext.getfontsettings()
     prefs.console.tabsettings = self.consoletext.gettabsettings()
     prefs.save()
 def writeprefs(self):
     if self.w is not None:
         prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
         prefs.output.show = self.w.isvisible()
         prefs.output.windowbounds = self.w.getbounds()
         prefs.output.fontsettings = self.w.outputtext.getfontsettings()
         prefs.output.tabsettings = self.w.outputtext.gettabsettings()
         prefs.save()
Exemple #11
0
 def writeprefs(self):
     import MacPrefs
     self.getparmsfromwindow()
     prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
     prefs.searchengine.casesens = self.parms["casesens"]
     prefs.searchengine.wrap = self.parms["wrap"]
     prefs.searchengine.wholeword = self.parms["wholeword"]
     prefs.save()
 def __init__(self, title = "Traceback"):
     app = W.getapplication()  # checks if W is properly initialized
     self.title = title
     self.w = None
     self.closed = 1
     self.start = 0
     self.lastwindowtitle = ""
     self.bounds = (360, 298)
 def syntaxedit(self):
     try:
         value, (filename, lineno, charno, line) = self.value
     except:
         filename = ""
         lineno = None
     if not filename and self.lastwindowtitle:
         filename = self.lastwindowtitle
     elif not filename:
         filename = "<unknown>"
     self.syntaxclose()
     if lineno:
         if charno is None:
             charno = 1
         W.getapplication().openscript(filename, lineno, charno - 1)
     else:
         W.getapplication().openscript(filename)
Exemple #14
0
 def picksize(self):
     app = W.getapplication()
     editor = findeditor(self)
     if editor is not None:
         width, height = editor._parentwindow._bounds[2:]
         self.w.xsize.set(repr(width))
         self.w.ysize.set(repr(height))
     else:
         raise W.AlertError, "No edit window found"
    def __init__(self):
        prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
        try:
            (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine
        except:
            (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine = \
                    ("", 0, 0, 0, 1, 1, 0, 0, 0)

        if docpath and not verifydocpath(docpath):
            docpath = ""

        self.w = W.Window((400, 200), "Search the Python Documentation")
        self.w.searchtext = W.EditText((10, 10, -100, 20), callback = self.checkbuttons)
        self.w.searchbutton = W.Button((-90, 12, 80, 16), "Search", self.search)
        buttons = []

        gutter = 10
        width = 130
        bookstart = width + 2 * gutter
        self.w.phraseradio = W.RadioButton((10, 38, width, 16), "As a phrase", buttons)
        self.w.allwordsradio = W.RadioButton((10, 58, width, 16), "All words", buttons)
        self.w.anywordsradio = W.RadioButton((10, 78, width, 16), "Any word", buttons)
        self.w.casesens = W.CheckBox((10, 98, width, 16), "Case sensitive")
        self.w.wholewords = W.CheckBox((10, 118, width, 16), "Whole words")
        self.w.tutorial = W.CheckBox((bookstart, 38, -10, 16), "Tutorial")
        self.w.library = W.CheckBox((bookstart, 58, -10, 16), "Library reference")
        self.w.langueref = W.CheckBox((bookstart, 78, -10, 16), "Lanuage reference manual")
        self.w.extending = W.CheckBox((bookstart, 98, -10, 16), "Extending & embedding")
        self.w.api = W.CheckBox((bookstart, 118, -10, 16), "C/C++ API")

        self.w.setdocfolderbutton = W.Button((10, -30, 100, 16), "Set doc folder", self.setdocpath)

        if docpath:
            self.w.setdefaultbutton(self.w.searchbutton)
        else:
            self.w.setdefaultbutton(self.w.setdocfolderbutton)

        self.docpath = docpath
        if not docpath:
            docpath = "(please select the Python html documentation folder)"
        self.w.docfolder = W.TextBox((120, -28, -10, 16), docpath)

        [self.w.phraseradio, self.w.allwordsradio, self.w.anywordsradio][kind].set(1)

        self.w.casesens.set(case)
        self.w.wholewords.set(word)
        self.w.tutorial.set(tut)
        self.w.library.set(lib)
        self.w.langueref.set(ref)
        self.w.extending.set(ext)
        self.w.api.set(api)

        self.w.open()
        self.w.wholewords.enable(0)
        self.w.bind('<close>', self.close)
        self.w.searchbutton.enable(0)
Exemple #16
0
def _makefontmenu():
    """helper for font menu"""
    if FontMenu.menu is not None:
        return
    import W
    FontMenu.menu = Wapplication.Menu(W.getapplication().menubar, 'Foo', -1)
    W.SetCursor('watch')
    for i in range(FontMenu.menu.menu.CountMenuItems(), 0, -1):
        FontMenu.menu.menu.DeleteMenuItem(i)
    FontMenu.menu.menu.AppendResMenu('FOND')
Exemple #17
0
 def domenu_save_as(self, *args):
     path = EasyDialogs.AskFileForSave(message='Save as:', savedFileName=self.title)
     if not path:
         return 1
     self.showbreakpoints(0)
     self.path = path
     self.setinfotext()
     self.title = os.path.split(self.path)[-1]
     self.wid.SetWTitle(self.title)
     self.domenu_save()
     self.editgroup.editor.setfile(self.getfilename())
     app = W.getapplication()
     app.makeopenwindowsmenu()
     if hasattr(app, 'makescriptsmenu'):
         app = W.getapplication()
         fsr, changed = app.scriptsfolder.FSResolveAlias(None)
         path = fsr.as_pathname()
         if path == self.path[:len(path)]:
             W.getapplication().makescriptsmenu()
Exemple #18
0
    def __init__(
        self, possize, text="", align=TextEdit.teJustLeft, fontsettings=None, backgroundcolor=(0xFFFF, 0xFFFF, 0xFFFF)
    ):
        if fontsettings is None:
            import W

            fontsettings = W.getdefaultfont()
        Wbase.Widget.__init__(self, possize)
        self.fontsettings = fontsettings
        self.text = text
        self.align = align
        self._backgroundcolor = backgroundcolor
Exemple #19
0
 def open(self):
     import W
     Dialog.open(self)
     self.app = W.getapplication()
     self.done = 0
     Menu.HiliteMenu(0)
     app = self.parent
     app.enablemenubar(0)
     try:
         self.mainloop()
     finally:
         app.enablemenubar(1)
Exemple #20
0
def geteditorprefs():
    import MacPrefs
    prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
    try:
        fontsettings = prefs.pyedit.fontsettings
        tabsettings = prefs.pyedit.tabsettings
        windowsize = prefs.pyedit.windowsize
    except:
        fontsettings = prefs.pyedit.fontsettings = ("Geneva", 0, 10, (0, 0, 0))
        tabsettings = prefs.pyedit.tabsettings = (8, 1)
        windowsize = prefs.pyedit.windowsize = (500, 250)
        sys.exc_traceback = None
    return fontsettings, tabsettings, windowsize
def installconsole(defaultshow = 1):
    global console
    prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
    if not prefs.console or not hasattr(prefs.console, 'show'):
        prefs.console.show = defaultshow
    if not hasattr(prefs.console, "windowbounds"):
        prefs.console.windowbounds = (450, 250)
    if not hasattr(prefs.console, "fontsettings"):
        prefs.console.fontsettings = ("Monaco", 0, 9, (0, 0, 0))
    if not hasattr(prefs.console, "tabsettings"):
        prefs.console.tabsettings = (32, 0)
    console = PyConsole(prefs.console.windowbounds, prefs.console.show,
                    prefs.console.fontsettings, prefs.console.tabsettings, 1)
Exemple #22
0
 def __init__(self):
     self.visible = 0
     self.w = None
     self.parms = {  "find": "",
                             "replace": "",
                             "wrap": 1,
                             "casesens": 1,
                             "wholeword": 1
                     }
     import MacPrefs
     prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
     if prefs.searchengine:
         self.parms["casesens"] = prefs.searchengine.casesens
         self.parms["wrap"] = prefs.searchengine.wrap
         self.parms["wholeword"] = prefs.searchengine.wholeword
def installoutput(defaultshow = 0, OutPutWindow = PyOutput):
    global output

    # quick 'n' dirty std in emulation
    sys.stdin = SimpleStdin()

    prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
    if not prefs.output or not hasattr(prefs.output, 'show'):
        prefs.output.show = defaultshow
    if not hasattr(prefs.output, "windowbounds"):
        prefs.output.windowbounds = (450, 250)
    if not hasattr(prefs.output, "fontsettings"):
        prefs.output.fontsettings = ("Monaco", 0, 9, (0, 0, 0))
    if not hasattr(prefs.output, "tabsettings"):
        prefs.output.tabsettings = (32, 0)
    output = OutPutWindow(prefs.output.windowbounds, prefs.output.show,
                    prefs.output.fontsettings, prefs.output.tabsettings)
Exemple #24
0
    def show(self):
        self.visible = 1
        if self.w:
            self.w.wid.ShowWindow()
            self.w.wid.SelectWindow()
            self.w.find.edit.select(1)
            self.w.find.edit.selectall()
            return
        self.w = W.Dialog((420, 150), "Find")

        self.w.find = TitledEditText((10, 4, 300, 36), "Search for:")
        self.w.replace = TitledEditText((10, 100, 300, 36), "Replace with:")

        self.w.boxes = W.Group((10, 50, 300, 40))
        self.w.boxes.casesens = W.CheckBox((0, 0, 100, 16), "Case sensitive")
        self.w.boxes.wholeword = W.CheckBox((0, 20, 100, 16), "Whole word")
        self.w.boxes.wrap = W.CheckBox((110, 0, 100, 16), "Wrap around")

        self.buttons = [        ("Find",                "cmdf",  self.find),
                                ("Replace",          "cmdr",     self.replace),
                                ("Replace all",  None,   self.replaceall),
                                ("Don't find",  "cmdd",  self.dont),
                                ("Cancel",            "cmd.",    self.cancel)
                        ]
        for i in range(len(self.buttons)):
            bounds = -90, 22 + i * 24, 80, 16
            title, shortcut, callback = self.buttons[i]
            self.w[title] = W.Button(bounds, title, callback)
            if shortcut:
                self.w.bind(shortcut, self.w[title].push)
        self.w.setdefaultbutton(self.w["Don't find"])
        self.w.find.edit.bind("<key>", self.key)
        self.w.bind("<activate>", self.activate)
        self.w.bind("<close>", self.close)
        self.w.open()
        self.setparms()
        self.w.find.edit.select(1)
        self.w.find.edit.selectall()
        self.checkbuttons()
Exemple #25
0
import W

# make a non-sizable window
#window = W.Window((200, 200), "Fixed Size")

#  make a sizable window
window = W.Window((200, 300), "Variable Size!", minsize=(200, 200))

# make some edit text widgets
# a scrollbar
window.hbar = W.Scrollbar((-1, -15, -14, 16), max=100)
window.vbar = W.Scrollbar((-15, -1, 16, -14), max=100)
#window.vbar = W.Scrollbar((-15, -1, 1, -14), max = 100)

# open the window
window.open()
Exemple #26
0
 def savesuitcase(self):
     path = putfile("Save font as suitcase:", self.filename, ".suit")
     if path:
         W.SetCursor('watch')
         self.ttFont.save(path, 1)
Exemple #27
0

# helper for HTTPProxy
def de_proxify(data):
    import re
    req_pattern = "GET http://([a-zA-Z0-9-_.]+)(:([0-9]+))?"
    m = re.match(req_pattern, data)
    host, dummy, port = m.groups()
    if not port:
        port = 80
    else:
        port = int(port)
    # change "GET http://xx.xx.xx/yy" into "GET /yy"
    data = re.sub(req_pattern, "GET ", data)
    return (host, port), data


# if we're running "under W", let's register the socket poller to the event loop
try:
    import W
except:
    pass
else:
    W.getapplication().addidlefunc(asyncore.poll)

## testing muck
#testserver = Server(10000, Connection)
#echoserver = Server(10007, Echo)
#httpproxyserver = Server(8088, HTTPProxy, 5)
#asyncore.close_all()
Exemple #28
0
import W
# make a non-sizable window
#window = W.Window((200, 200), "Fixed Size")
#  make a sizable window
window = W.Window((200, 300), "Variable Size!", minsize=(200, 200))
# make some edit text widgets
# a scrollbar
window.hbar = W.Scrollbar((-1, -15, -14, 16), max=100)
window.vbar = W.Scrollbar((-15, -1, 16, -14), max=100)
#window.vbar = W.Scrollbar((-15, -1, 1, -14), max = 100)
# open the window
window.open()

 def edit(self):
     sel = self.w.list.getselection()
     for i in sel:
         filename, lineno, func, line = self.tblist[i]
         W.getapplication().openscript(filename, lineno)
 def close(self):
     prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
     prefs.docsearchengine = self.getsettings()
Exemple #31
0
import W

# define some callbacks
def callback():
    window.close()

def checkcallback(value):
    print "hit the checkbox", value

def radiocallback(value):
    print "hit radiobutton #3", value

def scrollcallback(value):
    widget = window.hbar
    if value == "+":
        widget.set(widget.get() - 1)
    elif value == "-":
        widget.set(widget.get() + 1)
    elif value == "++":
        widget.set(widget.get() - 10)
    elif value == "--":
        widget.set(widget.get() + 10)
    else:  # in thumb
        widget.set(value)
    print "scroll...", widget.get()

def textcallback():
    window.et3.set(window.et1.get())

def cancel():
Exemple #32
0
 def edit(self):
     sel = self.w.list.getselection()
     for i in sel:
         filename, lineno, func, line = self.tblist[i]
         W.getapplication().openscript(filename, lineno)
Exemple #33
0
import W
from Carbon.Controls import *
w = W.Window((200, 200), "Test")
w.c = W.Button((5, 5, 100, 50), "Test")
w.open()
print repr(w.c._control.GetControlData(0, 'dflt'))
str = '\001'
w.c._control.SetControlData(0, 'dflt', str)
Exemple #34
0
    def setupwidgets(self):
        DESCRIPTION_HEIGHT = 140
        INSTALL_POS = -30
        STATUS_POS = INSTALL_POS - (70 + DESCRIPTION_HEIGHT)
        self.w = W.Window((580, 600),
                          "Python Install Manager",
                          minsize=(400, 400),
                          tabbable=0)
        self.w.titlebar = W.TextBox((4, 8, 60, 18), 'Packages:')
        self.w.hidden_button = W.CheckBox((-100, 4, 0, 18), 'Show Hidden',
                                          self.updatestatus)
        data = self.getbrowserdata()
        self.w.packagebrowser = W.MultiList((4, 24, 0, STATUS_POS - 2),
                                            data,
                                            self.listhit,
                                            cols=3)

        self.w.installed_l = W.TextBox((4, STATUS_POS, 70, 12), 'Installed:')
        self.w.installed = W.TextBox((74, STATUS_POS, 0, 12), '')
        self.w.message_l = W.TextBox((4, STATUS_POS + 20, 70, 12), 'Status:')
        self.w.message = W.TextBox((74, STATUS_POS + 20, 0, 12), '')
        self.w.homepage_button = W.Button((4, STATUS_POS + 40, 96, 18),
                                          'View homepage', self.do_homepage)
        self.w.description_l = W.TextBox((4, STATUS_POS + 70, 70, 12),
                                         'Description:')
        self.w.description = W.EditText(
            (74, STATUS_POS + 70, 0, DESCRIPTION_HEIGHT - 4))

        self.w.divline = W.HorizontalLine((0, INSTALL_POS - 4, 0, 0))
        self.w.verbose_button = W.CheckBox((84, INSTALL_POS + 4, 60, 18),
                                           'Verbose')
        self.w.recursive_button = W.CheckBox((146, INSTALL_POS + 4, 120, 18),
                                             'Install dependencies',
                                             self.updatestatus)
        self.w.recursive_button.set(1)
        self.w.force_button = W.CheckBox((268, INSTALL_POS + 4, 70, 18),
                                         'Overwrite', self.updatestatus)
        self.w.user_button = W.CheckBox((340, INSTALL_POS + 4, 140, 18),
                                        'For Current User Only', self.do_user)
        self.w.install_button = W.Button((4, INSTALL_POS + 4, 56, 18),
                                         'Install:', self.do_install)
        self.w.open()
        self.w.description.enable(0)
import re
import W
import os
import MacPrefs
import MacOS
import string
import webbrowser
import EasyDialogs


app = W.getapplication()

_titlepat = re.compile('<title>\([^<]*\)</title>')

def sucktitle(path):
    f = open(path)
    text = f.read(1024) # assume the title is in the first 1024 bytes
    f.close()
    lowertext = text.lower()
    matcher = _titlepat.search(lowertext)
    if matcher:
        return matcher.group(1)
    return path

def verifydocpath(docpath):
    try:
        tut = os.path.join(docpath, "tut")
        lib = os.path.join(docpath, "lib")
        ref = os.path.join(docpath, "ref")
        for path in [tut, lib, ref]:
            if not os.path.exists(path):
Exemple #36
0
 def __init__(self):
     self.w = W.Window((200, 200), 'Activate demo')
     self.w.bind("<activate>", self.my_activate_callback)
     self.w.open()
Exemple #37
0
 def domenu_toggledebugger(self, *args):
     if not self.debugging:
         W.SetCursor('watch')
     self.debugging = not self.debugging
     self.editgroup.editor.togglebreakpoints()
Exemple #38
0
    def __init__(self, creator, eoln):
        self.rv = None
        self.eoln = eoln
        self.w = w = W.ModalDialog((260, 160), 'Save options')
        radiobuttons = []
        w.label = W.TextBox((8, 8, 80, 18), "File creator:")
        w.ide_radio = W.RadioButton((8, 22, 160, 18), "PythonIDE", radiobuttons, self.ide_hit)
        w.interp_radio = W.RadioButton((8, 42, 160, 18), "MacPython-OS9 Interpreter", radiobuttons, self.interp_hit)
        w.interpx_radio = W.RadioButton((8, 62, 160, 18), "PythonLauncher", radiobuttons, self.interpx_hit)
        w.other_radio = W.RadioButton((8, 82, 50, 18), "Other:", radiobuttons)
        w.other_creator = W.EditText((62, 82, 40, 20), creator, self.otherselect)
        w.none_radio = W.RadioButton((8, 102, 160, 18), "None", radiobuttons, self.none_hit)
        w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit)
        w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit)
        w.setdefaultbutton(w.okbutton)
        if creator == 'Pyth':
            w.interp_radio.set(1)
        elif creator == W._signature:
            w.ide_radio.set(1)
        elif creator == 'PytX':
            w.interpx_radio.set(1)
        elif creator == '\0\0\0\0':
            w.none_radio.set(1)
        else:
            w.other_radio.set(1)

        w.eolnlabel = W.TextBox((168, 8, 80, 18), "Newline style:")
        radiobuttons = []
        w.unix_radio = W.RadioButton((168, 22, 80, 18), "Unix", radiobuttons, self.unix_hit)
        w.mac_radio = W.RadioButton((168, 42, 80, 18), "Macintosh", radiobuttons, self.mac_hit)
        w.win_radio = W.RadioButton((168, 62, 80, 18), "Windows", radiobuttons, self.win_hit)
        if self.eoln == '\n':
            w.unix_radio.set(1)
        elif self.eoln == '\r\n':
            w.win_radio.set(1)
        else:
            w.mac_radio.set(1)

        w.bind("cmd.", w.cancelbutton.push)
        w.open()
Exemple #39
0
 def domenu_new(self, *args):
     W.SetCursor('watch')
     import PyEdit
     return PyEdit.Editor()
Exemple #40
0
 def domenu_modulebrowser(self, *args):
     W.SetCursor('watch')
     import ModuleBrowser
     ModuleBrowser.ModuleBrowser()
Exemple #41
0
    def __init__(self):
        prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
        try:
            (docpath, kind, case, word, tut, lib, ref, ext,
             api) = prefs.docsearchengine
        except:
            (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine = \
                    ("", 0, 0, 0, 1, 1, 0, 0, 0)

        if docpath and not verifydocpath(docpath):
            docpath = ""

        self.w = W.Window((400, 200), "Search the Python Documentation")
        self.w.searchtext = W.EditText((10, 10, -100, 20),
                                       callback=self.checkbuttons)
        self.w.searchbutton = W.Button((-90, 12, 80, 16), "Search",
                                       self.search)
        buttons = []

        gutter = 10
        width = 130
        bookstart = width + 2 * gutter
        self.w.phraseradio = W.RadioButton((10, 38, width, 16), "As a phrase",
                                           buttons)
        self.w.allwordsradio = W.RadioButton((10, 58, width, 16), "All words",
                                             buttons)
        self.w.anywordsradio = W.RadioButton((10, 78, width, 16), "Any word",
                                             buttons)
        self.w.casesens = W.CheckBox((10, 98, width, 16), "Case sensitive")
        self.w.wholewords = W.CheckBox((10, 118, width, 16), "Whole words")
        self.w.tutorial = W.CheckBox((bookstart, 38, -10, 16), "Tutorial")
        self.w.library = W.CheckBox((bookstart, 58, -10, 16),
                                    "Library reference")
        self.w.langueref = W.CheckBox((bookstart, 78, -10, 16),
                                      "Lanuage reference manual")
        self.w.extending = W.CheckBox((bookstart, 98, -10, 16),
                                      "Extending & embedding")
        self.w.api = W.CheckBox((bookstart, 118, -10, 16), "C/C++ API")

        self.w.setdocfolderbutton = W.Button((10, -30, 100, 16),
                                             "Set doc folder", self.setdocpath)

        if docpath:
            self.w.setdefaultbutton(self.w.searchbutton)
        else:
            self.w.setdefaultbutton(self.w.setdocfolderbutton)

        self.docpath = docpath
        if not docpath:
            docpath = "(please select the Python html documentation folder)"
        self.w.docfolder = W.TextBox((120, -28, -10, 16), docpath)

        [self.w.phraseradio, self.w.allwordsradio,
         self.w.anywordsradio][kind].set(1)

        self.w.casesens.set(case)
        self.w.wholewords.set(word)
        self.w.tutorial.set(tut)
        self.w.library.set(lib)
        self.w.langueref.set(ref)
        self.w.extending.set(ext)
        self.w.api.set(api)

        self.w.open()
        self.w.wholewords.enable(0)
        self.w.bind('<close>', self.close)
        self.w.searchbutton.enable(0)
Exemple #42
0
    def setupwidgets(self, text):
        topbarheight = 24
        popfieldwidth = 80
        self.lastlineno = None

        # make an editor
        self.editgroup = W.Group((0, topbarheight + 1, 0, 0))
        editor = W.PyEditor((0, 0, -15,-15), text,
                        fontsettings = self.fontsettings,
                        tabsettings = self.tabsettings,
                        file = self.getfilename())

        # make the widgets
        self.popfield = ClassFinder((popfieldwidth - 17, -15, 16, 16), [], self.popselectline)
        self.linefield = W.EditText((-1, -15, popfieldwidth - 15, 16), inset = (6, 1))
        self.editgroup._barx = W.Scrollbar((popfieldwidth - 2, -15, -14, 16), editor.hscroll, max = 32767)
        self.editgroup._bary = W.Scrollbar((-15, 14, 16, -14), editor.vscroll, max = 32767)
        self.editgroup.editor = editor  # add editor *after* scrollbars

        self.editgroup.optionsmenu = W.PopupMenu((-15, -1, 16, 16), [])
        self.editgroup.optionsmenu.bind('<click>', self.makeoptionsmenu)

        self.bevelbox = W.BevelBox((0, 0, 0, topbarheight))
        self.hline = W.HorizontalLine((0, topbarheight, 0, 0))
        self.infotext = W.TextBox((175, 6, -4, 14), backgroundcolor = (0xe000, 0xe000, 0xe000))
        self.runbutton = W.BevelButton((6, 4, 80, 16), runButtonLabels[0], self.run)
        self.runselbutton = W.BevelButton((90, 4, 80, 16), runSelButtonLabels[0], self.runselection)

        # bind some keys
        editor.bind("cmdr", self.runbutton.push)
        editor.bind("enter", self.runselbutton.push)
        editor.bind("cmdj", self.domenu_gotoline)
        editor.bind("cmdd", self.domenu_toggledebugger)
        editor.bind("<idle>", self.updateselection)

        editor.bind("cmde", searchengine.setfindstring)
        editor.bind("cmdf", searchengine.show)
        editor.bind("cmdg", searchengine.findnext)
        editor.bind("cmdshiftr", searchengine.replace)
        editor.bind("cmdt", searchengine.replacefind)

        self.linefield.bind("return", self.dolinefield)
        self.linefield.bind("enter", self.dolinefield)
        self.linefield.bind("tab", self.dolinefield)

        # intercept clicks
        editor.bind("<click>", self.clickeditor)
        self.linefield.bind("<click>", self.clicklinefield)
Exemple #43
0
class BrowserWidget(W.CustomList):

    def __init__(self, possize, object = None, col = 100, closechildren = 0):
        W.List.__init__(self, possize, callback = self.listhit)
        self.object = (None,)
        self.indent = 16
        self.lastmaxindent = 0
        self.closechildren = closechildren
        self.children = []
        self.mincol = 64
        self.setcolumn(col)
        self.bind('return', self.openselection)
        self.bind('enter', self.openselection)
        if object is not None:
            self.set(object)

    def set(self, object):
        if self.object[0] is not object:
            self.object = object,
            self[:] = self.unpack(object, 0)
        elif self._parentwindow is not None and self._parentwindow.wid:
            self.update()

    def unpack(self, object, indent):
        return unpack_object(object, indent)

    def update(self):
        # for now...
        W.SetCursor('watch')
        self.setdrawingmode(0)
        sel = self.getselectedobjects()
        fold = self.getunfoldedobjects()
        topcell = self.gettopcell()
        self[:] = self.unpack(self.object[0], 0)
        self.unfoldobjects(fold)
        self.setselectedobjects(sel)
        self.settopcell(topcell)
        self.setdrawingmode(1)

    def setcolumn(self, col):
        self.col = col
        self.colstr = struct.pack('h', col)
        if self._list:
            sel = self.getselection()
            self.setitems(self.items)
            self.setselection(sel)

    def key(self, char, event):
        if char in (Wkeys.leftarrowkey, Wkeys.rightarrowkey):
            sel = self.getselection()
            sel.reverse()
            self.setdrawingmode(0)
            for index in sel:
                self.fold(index, char == Wkeys.rightarrowkey)
            self.setdrawingmode(1)
        else:
            W.List.key(self, char, event)

    def rollover(self, (x, y), onoff):
        if onoff:
            if self.incolumn((x, y)):
                W.SetCursor('hmover')
            else:
                W.SetCursor('arrow')
Exemple #44
0
 def addrecentfile(self, filename):
     app = W.getapplication()
     app.addrecentfile(filename)
Exemple #45
0
import W

w = W.Window((600, 400), "Ha!", minsize=(240, 200))

w.panes = W.HorizontalPanes((8, 8, -8, -20), (0.6, 0.4))

w.panes.panes = W.VerticalPanes(None, (0.3, 0.4, 0.3))
w.panes.panes.blah1 = W.EditText(None, "eehhh...")
w.panes.panes.blah2 = W.EditText(None, "nou...")
w.panes.panes.blah3 = W.List(None, ["eehhh...", 'abc', 'def'])

w.panes.group = W.Group(None)
w.panes.group.mytext = W.EditText((0, 24, 0, 0), "eehhh...")
w.panes.group.button1 = W.Button((0, 0, 80, 16), "A Button")

w.open()
Exemple #46
0
import W


def twothird(width, height):
    return (8, 8, width - 8, 2 * height / 3 - 4)


def onethird(width, height):
    return (8, 2 * height / 3 + 4, width - 8, height - 22)


def halfbounds1(width, height):
    return (0, 0, width / 2 - 4, height)


def halfbounds2(width, height):
    return (width / 2 + 4, 0, width, height)


window = W.Window((400, 400),
                  "Sizable window with two lists",
                  minsize=(200, 200))

window.listgroup = W.Group(twothird)
window.listgroup.list1 = W.List(halfbounds1, range(13213, 13310))
window.listgroup.list2 = W.List(halfbounds2, range(800, 830))
window.et = W.EditText(onethird, "Wat nu weer?")

window.open()
Exemple #47
0
import W
from Carbon import Windows

w = W.ModalDialog((100, 100))

w.ed = W.EditText((10, 10, 80, 50))
w.ok = W.Button((10, 70, 80, 16), "Ok", w.close)
w.setdefaultbutton(w.ok)
w.open()
Exemple #48
0
 def saveflat(self):
     path = putfile("Save font as flat file:", self.filename, ".TTF")
     if path:
         W.SetCursor('watch')
         self.ttFont.save(path)
# helper for HTTPProxy
def de_proxify(data):
    import re
    req_pattern = "GET http://([a-zA-Z0-9-_.]+)(:([0-9]+))?"
    m = re.match(req_pattern, data)
    host, dummy, port = m.groups()
    if not port:
        port = 80
    else:
        port = int(port)
    # change "GET http://xx.xx.xx/yy" into "GET /yy"
    data = re.sub(req_pattern, "GET ", data)
    return (host, port), data


# if we're running "under W", let's register the socket poller to the event loop
try:
    import W
except:
    pass
else:
    W.getapplication().addidlefunc(asyncore.poll)


## testing muck
#testserver = Server(10000, Connection)
#echoserver = Server(10007, Echo)
#httpproxyserver = Server(8088, HTTPProxy, 5)
#asyncore.close_all()
Exemple #50
0
    def buildinterface(self):
        buttonwidth = 120
        glyphlistwidth = 150
        hmargin = 10
        vmargin = 8
        title = self.filename
        tables = self.ttFont.keys()
        tables.sort()
        self.w = w = W.Window((500, 300), title, minsize=(400, 200))
        w.browsetablebutton = W.Button((hmargin, 32, buttonwidth, 16),
                                       "Browse tableŠ", self.browsetable)
        w.browsefontbutton = W.Button((hmargin, vmargin, buttonwidth, 16),
                                      "Browse fontŠ", self.browsefont)
        w.tablelist = W.List((hmargin, 56, buttonwidth, -128), tables,
                             self.tablelisthit)

        w.divline1 = W.VerticalLine(
            (buttonwidth + 2 * hmargin, vmargin, 1, -vmargin))

        gleft = buttonwidth + 3 * hmargin + 1

        hasGlyfTable = self.ttFont.has_key('glyf')

        glyphnames = self.ttFont.getGlyphNames2(
        )  # caselessly sorted glyph names

        if hasGlyfTable:
            w.glyphlist = GlyphList((gleft, 56, glyphlistwidth, -vmargin),
                                    glyphnames, self.glyphlisthit)

            w.divline2 = W.VerticalLine(
                (buttonwidth + glyphlistwidth + 4 * hmargin + 2, vmargin, 1,
                 -vmargin))

            yMin = self.ttFont['head'].yMin
            yMax = self.ttFont['head'].yMax
            w.gviewer = GlyphViewer(
                (buttonwidth + glyphlistwidth + 5 * hmargin + 3, vmargin,
                 -hmargin, -vmargin), yMin, yMax)

            w.showpoints = W.CheckBox((gleft, vmargin, glyphlistwidth, 16),
                                      "Show points",
                                      self.w.gviewer.toggleshowpoints)
            w.showpoints.set(self.w.gviewer.showpoints)
            w.showlines = W.CheckBox((gleft, vmargin + 24, glyphlistwidth, 16),
                                     "Show lines",
                                     self.w.gviewer.toggleshowlines)
            w.showlines.set(self.w.gviewer.showlines)
        else:
            w.glyphlist = GlyphList((gleft, 56, glyphlistwidth, -vmargin),
                                    glyphnames)
            w.noGlyphTable = W.TextBox((gleft, vmargin, -20, 20),
                                       "no 'glyf' table found")

        w.setdefaultbutton(w.browsetablebutton)

        w.tocurrentfont = W.Button((hmargin, -120, buttonwidth, 16),
                                   "Copy to current font",
                                   self.copytocurrentfont)
        w.fromcurrentfont = W.Button((hmargin, -96, buttonwidth, 16),
                                     "Copy from current font",
                                     self.copyfromcurrentfont)
        w.saveflat = W.Button((hmargin, -72, buttonwidth, 16),
                              "Save as flat fileŠ", self.saveflat)
        w.savesuitcasebutton = W.Button((hmargin, -48, buttonwidth, 16),
                                        "Save as suitcaseŠ", self.savesuitcase)
        w.savexmlbutton = W.Button((hmargin, -24, buttonwidth, 16),
                                   "Save as XMLŠ", self.saveXML)

        w.open()
        w.browsetablebutton.enable(0)
Exemple #51
0
import W
w = W.Window((600, 400), "Ha!", minsize=(240, 200))
w.panes = W.HorizontalPanes((8, 8, -30, -8), (0.3, 0.3, 0.4))
w.panes.blah1 = W.EditText(None, "eehhh...")
w.panes.blah2 = W.EditText((8, 8, -8, -8), "xxx nou...")
w.panes.panes = W.VerticalPanes(None, (0.3, 0.4, 0.3))
w.panes.panes.blah1 = W.EditText(None, "eehhh...")
w.panes.panes.blah2 = W.Frame(None)
w.panes.panes.blah2.t = W.EditText((0, 0, 0, 0), "nou...")
w.panes.panes.blah3 = W.List(None, ["eehhh...", 'abc', 'def'])
w.open()

Exemple #52
0
import re
import W
import os
import MacPrefs
import MacOS
import string
import webbrowser
import EasyDialogs

app = W.getapplication()

_titlepat = re.compile('<title>\([^<]*\)</title>')


def sucktitle(path):
    f = open(path)
    text = f.read(1024)  # assume the title is in the first 1024 bytes
    f.close()
    lowertext = text.lower()
    matcher = _titlepat.search(lowertext)
    if matcher:
        return matcher.group(1)
    return path


def verifydocpath(docpath):
    try:
        tut = os.path.join(docpath, "tut")
        lib = os.path.join(docpath, "lib")
        ref = os.path.join(docpath, "ref")
        for path in [tut, lib, ref]:
Exemple #53
0
import W


def listhit(isdbl):
    if isdbl:
        print "double-click in list!"
    else:
        print "click in list."


window = W.Window((200, 400), "Window with List", minsize=(150, 200))

window.list = W.List((-1, 20, 1, -14), [], listhit)

# or (equivalent):
# window.list = W.List((-1, 20, 1, -14), callback = listhit)

window.list.set(range(13213, 13350))
window.open()
Exemple #54
0
 def close(self):
     prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath)
     prefs.docsearchengine = self.getsettings()
Exemple #55
0
import W
def twothird(width, height):
	return (8, 8, width - 8, 2*height/3 - 4)
def onethird(width, height):
	return (8, 2*height/3 + 4, width - 8, height - 22)
def halfbounds1(width, height):
	return (0, 0, width/2 - 4, height)
def halfbounds2(width, height):
	return (width/2 + 4, 0, width, height)
window = W.Window((400, 400), "Sizable window with two lists", minsize = (200, 200))
window.listgroup = W.Group(twothird)
window.listgroup.list1 = W.List(halfbounds1, range(13213, 13310))
window.listgroup.list2 = W.List(halfbounds2, range(800, 830))
window.et = W.EditText(onethird, "Wat nu weer?")
window.open()
Exemple #56
0

def textcallback():
    window.et3.set(window.et1.get())


def cancel():
    import EasyDialogs
    EasyDialogs.Message("Cancel!")


# make a non-sizable window
#window = W.Window((200, 300), "Fixed Size")

#  make a sizable window
window = W.Window((200, 300), "Variable Size!", minsize=(200, 300))

# make some edit text widgets
window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback)
window.et2 = W.EditText((130, 40, 60, 30), "one!")
window.et3 = W.EditText((130, 80, -10, 40), "two?")

# a button
window.button = W.Button((-70, 10, 60, 16), "Close", callback)

# a checkbox
window.ch = W.CheckBox((10, 130, 160, 16), "Check (command \xa4)",
                       checkcallback)

# set of radio buttons (should become easier/nicer)
thebuttons = []
Exemple #57
0
 def click(self, point, modifiers):
     W.SetCursor("watch")
     self.set(self._parentwindow.getclasslist())
     W.PopupWidget.click(self, point, modifiers)