Beispiel #1
0
def test():
    import time

    Message("Testing EasyDialogs.")
    optionlist = (('v', 'Verbose'), ('verbose', 'Verbose as long option'),
                  ('flags=', 'Valued option'), ('f:', 'Short valued option'))
    commandlist = (('start', 'Start something'), ('stop', 'Stop something'))
    argv = GetArgv(optionlist=optionlist,
                   commandlist=commandlist,
                   addoldfile=0)
    Message("Command line: %s" % ' '.join(argv))
    for i in range(len(argv)):
        print 'arg[%d] = %r' % (i, argv[i])
    ok = AskYesNoCancel("Do you want to proceed?")
    ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No")
    if ok > 0:
        s = AskString("Enter your first name", "Joe")
        s2 = AskPassword("Okay %s, tell us your nickname" % s,
                         s,
                         cancel="None")
        if not s2:
            Message("%s has no secret nickname" % s)
        else:
            Message("Hello everybody!!\nThe secret nickname of %s is %s!!!" %
                    (s, s2))
    else:
        s = 'Anonymous'
    rv = AskFileForOpen(message="Gimme a file, %s" % s,
                        wanted=Carbon.File.FSSpec)
    Message("rv: %s" % rv)
    rv = AskFileForSave(wanted=Carbon.File.FSRef, savedFileName="%s.txt" % s)
    Message("rv.as_pathname: %s" % rv.as_pathname())
    rv = AskFolder()
    Message("Folder name: %s" % rv)
    text = ("Working Hard...", "Hardly Working...", "So far, so good!",
            "Keep on truckin'")
    bar = ProgressBar("Progress, progress...", 0, label="Ramping up...")
    try:
        if hasattr(MacOS, 'SchedParams'):
            appsw = MacOS.SchedParams(1, 0)
        for i in xrange(20):
            bar.inc()
            time.sleep(0.05)
        bar.set(0, 100)
        for i in xrange(100):
            bar.set(i)
            time.sleep(0.05)
            if i % 10 == 0:
                bar.label(text[(i / 10) % 4])
        bar.label("Done.")
        time.sleep(1.0)  # give'em a chance to see "Done."
    finally:
        del bar
        if hasattr(MacOS, 'SchedParams'):
            MacOS.SchedParams(*appsw)
 def asyncevents(self, onoff):
     if MacOS.runtimemodel == 'macho':
         raise 'Unsupported in MachoPython'
     old = self._doing_asyncevents
     if old:
         MacOS.SetEventHandler()
         MacOS.SchedParams(*self.schedparams)
     if onoff:
         MacOS.SetEventHandler(self.dispatch)
         doint, dummymask, benice, howoften, bgyield = self.schedparams
         MacOS.SchedParams(doint, everyEvent, benice, howoften, bgyield)
     self._doing_asyncevents = onoff
     return old
Beispiel #3
0
    def mainloop(self, mask = everyEvent, wait = None):
        self.quitting = 0
        if hasattr(MacOS, 'SchedParams'):
            saveparams = MacOS.SchedParams(*self.schedparams)
        try:
            while not self.quitting:
                try:
                    self.do1event(mask, wait)
                except (Application, SystemExit):
                    break

        finally:
            if hasattr(MacOS, 'SchedParams'):
                MacOS.SchedParams(*saveparams)
Beispiel #4
0
 def mainloop(self, mask=everyEvent, wait=None):
     self.quitting = 0
     if hasattr(MacOS, 'SchedParams'):
         saveparams = MacOS.SchedParams(*self.schedparams)
     try:
         while not self.quitting:
             try:
                 self.do1event(mask, wait)
             except (Application, SystemExit):
                 # Note: the raising of "self" is old-fashioned idiom to
                 # exit the mainloop. Calling _quit() is better for new
                 # applications.
                 break
     finally:
         if hasattr(MacOS, 'SchedParams'):
             MacOS.SchedParams(*saveparams)
Beispiel #5
0
 def __init__(self):
     MiniApplication.__init__(self)
     AEServer.__init__(self)
     self.installaehandler('aevt', 'oapp', self.open_app)
     self.installaehandler('aevt', 'quit', self.quit)
     self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
     if debug:
         self.installaehandler('****', '****', self.otherhandler)
     oldparams = MacOS.SchedParams(0, 0)
     self.mainloop()
     apply(MacOS.SchedParams, oldparams)
Beispiel #6
0

add_sibling_path("data_acquisition"
                 )  #look in 'data acquisition' folder for needed routines, too
add_sibling_path(
    "analysis")  #look in 'data acquisition' folder for needed routines, too

import vxi_crate_devices as vxi
import array
import threading
import time
import tagged_data
from dstp_async import DSTPServer, UseNumericArray
try:
    import MacOS
    MacOS.SchedParams(1, 1, 1, 0.1,
                      0.05)  #allow nullEvent handling on Classic/Carbon
except:
    MacOS = None  #in case we want to check later


class voltmeter(vxi.scanning_voltmeter
                ):  #almost like those, just use a different range!
    idn_head = "HEWLETT-PACKARD,E1326B"
    device_loop_sleep = 0.5
    initial_config_string = ":conf:volt:dc 10.0,(@100:107);"

    def get_data(self):
        vxi.scanning_voltmeter.get_data(self)
        data.volts = [v.loop_count, v.scan]

    def monitor(self):
Beispiel #7
0
url = url1

import rma
engine = rma.CreateEngine()
player = engine.CreatePlayer()
x1 = player.SetStatusListener(PrintRMListener())
print 'SetStatusListener returned', x1
x2 = player.OpenURL(url)
print 'OpenURL(%s) returned' % url, hex(x2)
x3 = player.Begin()
print 'Begin returned', hex(x3)

if os.name == 'mac':
    import MacOS, Evt, Events

    # Disable event processing
    oldparms = MacOS.SchedParams(0, 0)
    while not player.IsDone():
        ok, evt = Evt.WaitNextEvent(-1, 0)  # No timeout, immedeate return
        if evt[0] == Events.keyDown:  # Stop on any key
            break
        engine.EventOccurred(evt)
    apply(MacOS.SchedParams, oldparms)
    print 'press return to exit-'
    sys.stdin.readline()
# for console apps, enter message loop
#import sys
#if sys.platform=='win32':
#       import win32ui
#       win32ui.GetApp().RunLoop(win32ui.GetWin32Sdk().GetDesktopWindow())
Beispiel #8
0
    del sys.argv[1]
    print '** Verbose **'
    quietconsole=None
else:
    import quietconsole
    quietconsole.install()

if len(sys.path) == 2:
    del sys.path[0]
    print 'sys.path', sys.path
    print 'sys.argv[0]', sys.argv[0]

# Workaround for a strange KeyboardInterrupt bug under Carbon
import MacOS
if MacOS.runtimemodel == 'carbon':
    MacOS.SchedParams(0)

ID_SPLASH_DIALOG=513
# XXXX Debugging code: assure the resource file is available
from Carbon import Res
try:
    Res.GetResource('DLOG', ID_SPLASH_DIALOG)
except:
    Res.FSpOpenResFile(':player.rsrc', 0)
    Res.FSpOpenResFile(':playercontrols.rsrc', 0)
    Res.FSpOpenResFile(':common.rsrc', 0)
    Res.FSpOpenResFile(':playerballoons.rsrc', 0)
Res.GetResource('DLOG', ID_SPLASH_DIALOG)

# Now time for real work.
import os
Beispiel #9
0
"A sort of application framework for the Mac"
Beispiel #10
0
"""PythonCGISlave.py
This program can be used in two ways:
- As a Python CGI script server for web servers supporting "Actions", like WebStar.
- As a wrapper for a single Python CGI script, for any "compliant" Mac web server.
See CGI_README.txt for more details.
"""
#
# Written by Just van Rossum, but partly stolen from example code by Jack.
#

LONG_RUNNING = 1  # If true, don't quit after each request.

import MacOS
MacOS.SchedParams(0, 0)
from MiniAEFrame import AEServer, MiniApplication
import os
import string
import cStringIO
import sys
import traceback
import mimetools
__version__ = '3.2'

slave_dir = os.getcwd()

# log file for errors
sys.stderr = open(sys.argv[0] + ".errors", "a+")
def convertFSSpec(fss):
	return fss.as_pathname()
Beispiel #11
0
"""Easy to use dialogs.
Beispiel #12
0
# look in 'data acquisition' folder for needed routines, too
add_sibling_path("data_acquisition")
# look in 'data acquisition' folder for needed routines, too
add_sibling_path("analysis")

import vxi_crate_devices as vxi
import array
import threading
import time
import tagged_data
from dstp_async import DSTPServer, UseNumericArray
try:
    import MacOS
    # allow nullEvent handling on Classic/Carbon
    MacOS.SchedParams(1, 1, 1, 0.1, 0.05)
except:
    MacOS = None  # in case we want to check later


# almost like those, just use a different range!
class voltmeter(vxi.scanning_voltmeter):
    idn_head = "HEWLETT-PACKARD,E1326B"
    device_loop_sleep = 0.5
    initial_config_string = ":conf:volt:dc 10.0,(@100:107);"

    def get_data(self):
        vxi.scanning_voltmeter.get_data(self)
        data.volts = [v.loop_count, v.scan]

    def monitor(self):
Beispiel #13
0
"""'echo' -- an AppleEvent handler which handles all events the same.
Beispiel #14
0
"""AEservertest - Test AppleEvent server interface
Beispiel #15
0
"""cgitest - A minimal CGI applet. Echos parameters back to the client.
Beispiel #16
0
#
Beispiel #17
0
def GetArgv(optionlist=None,
            commandlist=None,
            addoldfile=1,
            addnewfile=1,
            addfolder=1,
            id=ARGV_ID):
    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)'
        return
    else:
        if optionlist:
            _setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist)
            _selectoption(d, optionlist, 0)
        else:
            d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl()
        if commandlist:
            _setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist)
            if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1:
                help = commandlist[0][-1]
                h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
                Dlg.SetDialogItemText(h, help)
        else:
            d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl()
        if not addoldfile:
            d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl()
        if not addnewfile:
            d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl()
        if not addfolder:
            d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl()
        d.SetDialogDefaultItem(ARGV_ITEM_OK)
        d.SetDialogCancelItem(ARGV_ITEM_CANCEL)
        d.GetDialogWindow().ShowWindow()
        d.DrawDialog()
        if hasattr(MacOS, 'SchedParams'):
            appsw = MacOS.SchedParams(1, 0)
        try:
            while 1:
                stringstoadd = []
                n = ModalDialog(None)
                if n == ARGV_ITEM_OK:
                    break
                elif n == ARGV_ITEM_CANCEL:
                    raise SystemExit
                elif n == ARGV_OPTION_GROUP:
                    idx = d.GetDialogItemAsControl(
                        ARGV_OPTION_GROUP).GetControlValue() - 1
                    _selectoption(d, optionlist, idx)
                elif n == ARGV_OPTION_VALUE:
                    pass
                elif n == ARGV_OPTION_ADD:
                    idx = d.GetDialogItemAsControl(
                        ARGV_OPTION_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(optionlist):
                        option = optionlist[idx]
                        if type(option) == type(()):
                            option = option[0]
                        if option[-1] == '=' or option[-1] == ':':
                            option = option[:-1]
                            h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
                            value = Dlg.GetDialogItemText(h)
                        else:
                            value = ''
                        if len(option) == 1:
                            stringtoadd = '-' + option
                        else:
                            stringtoadd = '--' + option
                        stringstoadd = [stringtoadd]
                        if value:
                            stringstoadd.append(value)
                    else:
                        MacOS.SysBeep()
                elif n == ARGV_COMMAND_GROUP:
                    idx = d.GetDialogItemAsControl(
                        ARGV_COMMAND_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(commandlist) and type(
                            commandlist[idx]) == type(
                                ()) and len(commandlist[idx]) > 1:
                        help = commandlist[idx][-1]
                        h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
                        Dlg.SetDialogItemText(h, help)
                elif n == ARGV_COMMAND_ADD:
                    idx = d.GetDialogItemAsControl(
                        ARGV_COMMAND_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(commandlist):
                        command = commandlist[idx]
                        if type(command) == type(()):
                            command = command[0]
                        stringstoadd = [command]
                    else:
                        MacOS.SysBeep()
                elif n == ARGV_ADD_OLDFILE:
                    pathname = AskFileForOpen()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_ADD_NEWFILE:
                    pathname = AskFileForSave()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_ADD_FOLDER:
                    pathname = AskFolder()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_CMDLINE_DATA:
                    pass
                else:
                    raise RuntimeError, 'Unknown dialog item %d' % n
                for stringtoadd in stringstoadd:
                    if '"' in stringtoadd or "'" in stringtoadd or ' ' in stringtoadd:
                        stringtoadd = repr(stringtoadd)
                    h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
                    oldstr = GetDialogItemText(h)
                    if oldstr and oldstr[-1] != ' ':
                        oldstr = oldstr + ' '
                    oldstr = oldstr + stringtoadd
                    if oldstr[-1] != ' ':
                        oldstr = oldstr + ' '
                    SetDialogItemText(h, oldstr)
                    d.SelectDialogItemText(ARGV_CMDLINE_DATA, 32767, 32767)

            h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
            oldstr = GetDialogItemText(h)
            tmplist = string.split(oldstr)
            newlist = []
            while tmplist:
                item = tmplist[0]
                del tmplist[0]
                if item[0] == '"':
                    while item[-1] != '"':
                        if not tmplist:
                            raise RuntimeError, 'Unterminated quoted argument'
                        item = item + ' ' + tmplist[0]
                        del tmplist[0]

                    item = item[1:-1]
                if item[0] == "'":
                    while item[-1] != "'":
                        if not tmplist:
                            raise RuntimeError, 'Unterminated quoted argument'
                        item = item + ' ' + tmplist[0]
                        del tmplist[0]

                    item = item[1:-1]
                newlist.append(item)

            return newlist
        finally:
            if hasattr(MacOS, 'SchedParams'):
                MacOS.SchedParams(*appsw)
            del d

        return
Beispiel #18
0
"""Edit the Python Preferences file."""