Esempio n. 1
0
def SelectFile(root, kind, edict, pathn, pcode, title, freeze=1):
    top = review.BusyBox(root, 'Busy examining %s files...' % kind)
    # find list of all directories in client region
    sp = 0
    if edict['SETTINGS'].has_key('ShowFilenames'):
        if int(edict['SETTINGS']['ShowFilenames']):
            sp = 1
    c, fl = rawlist.rawlist(pathn, pcode, showpath=sp)
    top.destroy()
    if c == None or len(c) == 0:
        return (None, 0, 0, 0)

    # make selection box of these with cancel, ok options
    sd = SelDlg(root, title, c, edict, freeze)

    sd.Activate()
    #print sd.val,sd.ans,len(c)
    if (sd.val == 'Entire file' or sd.val == 'Partial file'
            or sd.val == 'Partial file with Details') and len(sd.ans):
        for i in range(len(c)):
            #print i,c[i]
            if sd.ans[0] == c[i]:
                if sd.val == 'Partial file':
                    rv = SelectRawRange(root, fl[i], 1, freeze=freeze)
                elif sd.val == 'Partial file with Details':
                    rv = SelectRawRange(root, fl[i], 2, freeze=freeze)
                else:
                    rv = SelectRawRange(root, fl[i], 0, freeze=freeze)
                if rv[0] == None:
                    break
                return rv
    return (None, 0, 0, 0)
Esempio n. 2
0
def SelectRawRange(root, pathname, partial, edict=None, freeze=1):
    "returns pathname,optional start time,optional end time"
    #make up bar with time events and allow mouse selection
    ans = rawlist.rawinfo(pathname)

    if ans[0] == None:
        return (None, 0, 0, 0)  # couldn't open
    if partial:
        data = None
        if partial == 2:
            mom = review.BusyBox(root, 'Busy busy ...')
            data = _getdata(pathname)  # compute data
            mom.destroy()
        lims = get_limits(pathname, ans, root, edict, data, freeze)
        if lims[0] == None:
            return (None, 0, 0, 0)  # aborted
    else:
        lims = [0, ans[0], 0]

    return (pathname, lims[0], lims[1], lims[2])
Esempio n. 3
0
def create_graphics(fr, numtraces, ri, data):
    global gx, pszf, lr

    minutes = (int(ri[0]) + ri[1] - 1) / ri[1] + 2  # rounded up
    bandheight = 200 / numtraces
    bandoffset = 40 / numtraces
    totalheight = numtraces * bandheight + (numtraces + 1) * bandoffset
    #print 'traces=%d bh=%d bo=%d totht=%d' % (numtraces,bandheight,bandoffset,totalheight)
    if data:
        pop = review.BusyBox(fr.myparent, 'Busy Busy busy....')
    gx = Pmw.Blt.Graph(fr, title='', height='2i')  #,width='5i')
    #determine width in units of minutes
    minsc = ri[1] * 60.0  # divide frame number to get minute mark
    gx.axis_configure('x', min=0, max=(ri[0] + ri[1]), showticks=0, hide=1)
    gx.axis_configure('y', min=0, max=totalheight, showticks=0, hide=1)
    gx.axis_configure('x2',
                      min=0,
                      max=(ri[0] + ri[1] + 59) / minsc,
                      showticks=1,
                      title='Minutes',
                      hide=0)
    gx.pack(side='top', expand=YES, fill=BOTH)
    gx.maxwidth = ri[0]

    def setposition(gx, *evnt):
        pos = gx.GrPosit.get()
        wid = gx.GrWidth.get()
        if wid < 0.1:
            wid = 0.1
            gx.GrWidth.set(wid)
        npos = gx.maxwidth * pos / 100.0
        nwid = gx.maxwidth * wid / 100.0
        if npos + nwid > gx.maxwidth:
            npos = gx.maxwidth - nwid
            gx.GrPosit.set(int(100.0 * npos / gx.maxwidth))
        gx.axis_configure('x', min=npos, max=npos + nwid)
        gx.axis_configure('x2', min=npos / minsc, max=(npos + nwid) / minsc)
        ##print gx.maxwidth,pos,wid,npos,nwid,gx.GrPosit.get()

    if 1:
        GrPosit = DoubleVar()
        GrWidth = DoubleVar()
        GrWidth.set(100)
        GrPosit.set(0)
        posit = Scale(fr,
                      orient='horizontal',
                      showvalue=0,
                      variable=GrPosit,
                      command=Command(setposition, gx),
                      label='Start',
                      relief='ridge',
                      background='khaki')
        posit.pack(side='top', expand=YES, fill=BOTH)
        wdth = Scale(fr,
                     orient='horizontal',
                     showvalue=0,
                     variable=GrWidth,
                     command=Command(setposition, gx),
                     label='Width',
                     relief='ridge',
                     background='khaki3')
        wdth.pack(side='top', expand=YES, fill=BOTH)
        gx.GrPosit = GrPosit
        gx.GrWidth = GrWidth
        setposition(gx)
    #gx.grid_configure(mapy='')
    #gx.grid_on()


##    if numtraces > 2:
##        numtraces=2
    for tr in range(numtraces):
        yend = totalheight - bandoffset - (tr +
                                           1) * (bandheight) - tr * bandoffset
        ybeg = yend + bandheight
        ctr = yend + bandheight / 2
        #print tr,yend,ybeg,ctr
        if data:
            # create line
            xord = [x for x in range(0, len(data[tr]), 1)]
            gx.line_create('linectr%d' % tr,
                           xdata=(xord[0], xord[-1]),
                           ydata=(ctr, ctr),
                           symbol='',
                           label='',
                           color='gray40')
            yval = []
            for n in xord:
                y = data[tr][n]
                yv = ctr - y
                ##if yv > yend:
                ##    yv=yend
                yval.append(yv)
                if 0:
                    if len(yval) < 30:
                        print n, y, yv
            gx.line_create('line%d' % tr,
                           xdata=tuple(xord),
                           ydata=tuple(yval),
                           symbol='',
                           label='')
            gx.marker_create('polygon',
                             name='doing%d' % tr,
                             hide=0,
                             fill='wheat',
                             coords=(0, yend, ri[0], yend, ri[0], ybeg, 0,
                                     ybeg),
                             under=1)

        else:
            gx.marker_create('polygon',
                             name='doing%d' % tr,
                             hide=0,
                             fill='wheat',
                             coords=(0, yend, ri[0], yend, ri[0], ybeg, 0,
                                     ybeg))
    lr[1] = ri[0]
    lr[3] = ri[0]
    # compute polygon size factor
    pszf = ri[0] / totalheight / numtraces

    period = 1
    bg = None
    for nix in range(2, len(ri)):
        # draw various things
        itm = ri[nix]
        if itm[0] == 16:
            #draw a 'line'
            gx.line_create(nix,
                           symbol='',
                           data=(itm[1], 0, itm[1], totalheight),
                           label='')
            bg = itm[1]
        elif itm[0] == 17:
            #draw a 'line'
            gx.line_create(nix,
                           symbol='',
                           data=(itm[1], 0, itm[1], totalheight),
                           label='')
            if bg:
                mid = (itm[1] - bg) / 2 + bg
                xx = '%d' % period
                gx.marker_create('text',
                                 text=xx,
                                 coords=(mid, totalheight - bandoffset),
                                 hide=0)
                period += 1
                bg = None
        elif itm[0] == 18:
            #just a marker
            gx.marker_create('polygon',
                             linewidth=1,
                             element='',
                             coords=(itm[1] - pszf, 0, itm[1],
                                     totalheight / 10, itm[1] + pszf, 0),
                             fill='white')
        elif itm[0] == 19 or itm[0] == 0:
            if itm[1] != 0 and itm[2] != "":
                try:
                    # marker with comment
                    gx.marker_create('polygon',
                                     linewidth=1,
                                     element='',
                                     coords=(itm[1] - pszf, 0, itm[1],
                                             totalheight / 10, itm[1] + pszf,
                                             0),
                                     fill='black')
                    xx = 't%d' % nix
                    gx.marker_create('text',
                                     coords=(itm[1], 3),
                                     text=itm[2],
                                     hide=0,
                                     name=xx)
                except:
                    #print itm,pszf
                    #raise
                    pass

    gx.marker_create('line',
                     name='ch',
                     linewidth=1,
                     outline='red',
                     coords=(0, 0, 10, 0))
    gx.marker_create('text',
                     coords=(2, totalheight - bandoffset),
                     text='',
                     name='chp',
                     anchor='nw')

    # Normally we want to bind the crosshairs to the mouse like this:
    #gx.crosshairs_on()
    def mouseMove(event):
        global gx, pszf
        x = event.x
        y = event.y
        co = gx.invtransform(x, y)
        gx.marker_configure('ch', coords=(co[0], 1, co[0], totalheight - 5))
        # turn on/off any message text
        nms = gx.marker_names('t*')
        dif = 0
        for anm in nms:
            cvs = string.split(gx.marker_cget(anm, 'coords'))
            cv = (float(cvs[0]), float(cvs[1]))
            dif = abs(int(cv[0]) - int(co[0]))
            #print '>%4d %6d'%(pszf,dif),cv,co,type(co),type(cv)
            if dif > pszf:
                gx.marker_configure(anm, hide=1)
            else:
                gx.marker_configure(anm, hide=0)
        #gx.marker_configure('chp',text='%3d %3d %d'%(co[0],co[1],dif))
        #pos = "@" +str(event.x) +"," +str(event.y)
        #gx.crosshairs_configure(position = pos)

    def mouseLeft(event):
        mouseXX(0, event)

    def mouseRight(event):
        mouseXX(1, event)

    gx.bind("<Motion>", mouseMove)
    gx.bind("<Button-1>", mouseLeft)
    gx.bind("<Button-3>", mouseRight)
    if data:
        pop.destroy()
Esempio n. 4
0
def SelectArchiveClient(root, protoflag, edict=None, nonew=1):
    "Select a client"
    global localedict
    global _sd, _ans, _val

    if edict:
        localedict = edict
    try:
        hmode = localedict['SETTINGS']['HipSelect']
    except:
        hmode = 'All'

    pathn = localedict['ARCHIVES'] + '\\*.zip'
    if bbox:
        top = BusyBox.BusyBox(root, 'Busy examining client files...')
    else:
        top = review.BusyBox(root, 'Busy examining client files...')

    # find list of all directories in client region
    plist = glob.glob(pathn)
    cl = []
    plist.sort()
    for d in plist:
        try:
            zf = zipfile.ZipFile(d, 'r', zipfile.ZIP_DEFLATED)
        except:
            #print 'no zipfile',d
            continue
        dir, bn = os.path.split(d)
        for cname in ('client.', 'CLIENT.', 'client', 'CLIENT'):
            rd = None
            try:
                rd = zf.read(bn[:-4] + '/' + cname)
            except:
                pass
            if rd:
                break
        zf.close()
        del zf
        if not rd:
            continue
        cdict = IniAid.LoadConfigString(rd)
        if cdict:
            cl.append('%-32s  %s' %
                      (cdict['client.clientid'], HIPAA(cdict, hmode)))
    cl.sort(_igsort)

    top.destroy()

    # make selection box of these with cancel, new client, ok options
    _sd = None
    _ans = ''
    _val = ''

    def _execute(result):
        global _sd, _ans, _val
        _val = result
        _ans = _sd.getcurselection()
        _sd.deactivate()

    def _sayok():
        global _sd, _ans, _val
        _val = 'OK'
        _ans = _sd.getcurselection()
        _sd.deactivate()

    if 1:  #nonew:
        blist = ['OK', 'Cancel']
    else:
        blist = ['OK', 'Cancel', 'Create new client']
    _sd=Pmw.SelectionDialog(root,title='Select client',command=_execute,\
            buttons=blist,\
            scrolledlist_items=cl)
    _sd.component('scrolledlist').configure(dblclickcommand=_sayok)
    _sd.component('scrolledlist').component('listbox').configure(
        width=80, font=edict['FIXFONT'])
    gpos = '=%dx%d+0+%d' % (root.maxw, root.maxh - 90, 25)
    hull = _sd.component('hull')
    hull.wm_geometry(gpos)
    hull.update()
    hull.transient(root)

    def _freeze_window(tp, geom, event, *args):
        if tp.wm_geometry() != geom:
            tp.wm_geometry(geom)

    hull.bind('<Configure>', Command(_freeze_window, hull, hull.wm_geometry()))
    _sd.activate()
    if _val == 'OK' and len(_ans):
        vl = string.split(_ans[0])
        client = {}
        client['client.clientid'] = vl[0].strip()
        return client
    return None
Esempio n. 5
0
def makeCDlist(root, edict, pathn=None, live=1):
    "Create selection list of existing clients, perhaps from *-terminated pathname"
    global localedict

    if root:
        if bbox:
            top = BusyBox.BusyBox(root, 'Busy examining client files...')
        else:
            top = review.BusyBox(root, 'Busy examining client files...')

    # find list of all directories in client region
    if pathn == None:
        pathn = edict['DATAPATH'] + '\\*'  # that single * is IMPORTANT
    plist = glob.glob(pathn)
    cl = []
    for d in plist:
        if not os.path.isdir(d):
            continue
        # now see about study subjects
        ans = win32api.GetFileAttributes(d)
        #print live,ans,d
        if live:
            if ans & 6:  # either FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM
                continue
        else:
            if not (ans & 6):
                continue  # want ONLY those marked
        cl.append(string.lower(os.path.basename(d)))
    cl.sort()
    cdict = {}
    for p in cl:
        # get name fullname protocols
        client = GetClientFile(pathn[:-1] + p)
        if not client:
            continue
        if string.lower(client['client.clientid']) != p:
            #raise DataError,'ClientID mismatch'
            ##print 'mismatched client'
            if live:
                continue
        id = client['client.clientid']
        full = client['client.fullname']
        try:
            guid = client['client.xguid']
        except:
            guid = None
        v = pathn[:-1] + p
        if guid == None:
            # fix things up
            _updateGUIDentry(v + '\\Client.', edict)  #rewrites the client file
            client = GetClientFile(v)
            guid = client.get('client.xguid', 'Unknown')
        plist = []
        for look in vals:
            gl = glob.glob(v + '\\' + look + '\\Stages.*')
            if len(gl):
                plist.append(look)
        cdict[id] = (id, full, guid, plist)
    if root:
        top.destroy()
    try:
        gc.collect(
        )  # garbage collect all those lost fd in ConfigParser and IniAid
    except:
        pass
    return cdict