How to make a GUI open file dialog with SKILL?

Discussion in 'Cadence' started by Reotaro Hashemoto, May 8, 2008.

  1. Hi,

    I need to let the user select file through browsing from a regular
    linux-like open file dialog, i wonder if there's an already existing
    SKILL function to do that? Or i need to somehow implement it from
    scratch? (for IC5033 version)

    Thanks a lot and best regards,
    Ahmad
     
    Reotaro Hashemoto, May 8, 2008
    #1
  2. Hello guys,

    I appreciate any help. I do really need it please. I am pretty sure
    that at least one has a solution and even more, would you please help
    me?

    Thanks and regards,
    Ahmad
     
    Reotaro Hashemoto, May 9, 2008
    #2
  3. Reotaro Hashemoto

    S. Badel Guest

    Ahmad,

    in the 24 hours you have been waiting for a solution, you could have written this file open dialog !

    there are simple solutions to this.

    1/ upgrade to IC6+ and use hiDisplayFileDialog() and friends

    2/ launch an external program such as kdialog or zenity. There is an example using xdialog here :
    http://groups.google.com/group/comp...read/thread/840d2005155362ec/90744b3e6b7c6061

    3/ there is code already available on this group, see
    http://groups.google.com/group/comp...read/thread/689390428ab8a64f/ea82ce34f892d87c

    4/ i have an old piece of code written by Andrew Beckett for this purpose, but I can't remember
    where I got it from. You may want to try and ask CCS for a file named abSelectFile.il

    cheers,
    Stéphane
     
    S. Badel, May 9, 2008
    #3
  4. S. Badel wrote, on 05/09/08 15:49:
    In fact I posted it earlier today - doesn't seem to have shown up yet on google
    groups - hopefully it will later...

    Andrew.
     
    Andrew Beckett, May 9, 2008
    #4
  5. Reotaro Hashemoto

    Riad KACED Guest

    Hi Andrew,

    I think it is worth re-posting it again. The original one seems to end
    in a black hole I'm afraid ;-)

    Riad.
     
    Riad KACED, May 12, 2008
    #5
  6. Riad KACED wrote, on 05/12/08 02:14:
    Rather than attaching, I'll paste in the code. I'll do this in two posts. First
    the main code which does the work.

    /* abSelectFile.il

    Author A.D.Beckett
    Group Custom IC, Cadence Design Systems Ltd
    Machine SUN
    Date Dec 07, 1993
    Modified Jan 21, 2000
    By A.D.Beckett

    File/Directory Browser

    In order to use this, you need to do three things:

    1. Have a button on your form which synchronises your form to
    the select file form. This is done by having a callback
    on the button which invokes:

    (abSyncWithSelectFile yourForm 'yourField [t])

    The optional t indicates that it should just browse directories.

    2. The field being sync'd needs a callback so that values typed
    in the field will be passed to the browser when up. That
    callback should be:

    (abUpdateSelectFile)

    3. When your form completes (i.e. on the form callback), you should
    end the sync with the form by invoking:

    (abEndSyncWithSelectFile)

    Ideally this should be done on both the OK and Cancel callbacks
    for the form. This ensures that the select file form is withdrawn
    when the form is ended.

    ***************************************************
    SCCS Info: @(#) abSelectFile.il 08/07/01.15:31:08 1.3

    */

    /* initialisation - make sure they're bound */
    (setq abSelectFileSyncForm nil)
    (setq abSelectFileSyncField nil)
    (setq abSelectFileDirOnly nil)
    (setq abSelectFileShowHidden nil)

    /*******************************************************************
    * *
    * (abSimplifyFilename fileName) *
    * *
    * Get round the inconsistency of simplifyFilename which means that *
    * it sometimes ends in /, and sometimes doesn't *
    * *
    *******************************************************************/

    (procedure (abSimplifyFilename fileName)
    (let (newFileName)
    (unless (equal (substring (setq newFileName (simplifyFilename fileName)) -1) "/")
    (setq newFileName (strcat newFileName "/")))
    newFileName))

    /*************************************************************************
    * *
    * (abGetDirAssoc @key (dirName ".") (dirOnly nil) (showHidden nil)) *
    * *
    * Generate an assoc list of directory entries. The assoc list contains *
    * the normal "ls -F" style suffixes on each name. Note that this doesn't *
    * check that the directory exists - that is the job of the calling *
    * function. Setting dirOnly to t filters out everything that isn't *
    * a directory. Setting showHidden to t stops dot files being filtered. *
    * *
    *************************************************************************/

    (procedure (abGetDirAssoc @key (dirName ".") (dirOnly nil) (showHidden nil))
    (let (dirList dirAssoc entryPlusType fullEntry simplifiedDir newDir
    simplifiedNewDir simplifiedDotDotDir)
    (setq dirList (reverse (sort (getDirFiles dirName) 'alphalessp)))
    /* used for checking links */
    (setq simplifiedDir (abSimplifyFilename dirName))
    (foreach entry dirList
    (setq fullEntry (strcat simplifiedDir entry))
    /* if dirOnly t, only include directories */
    (when (and (or (null dirOnly) (isDir fullEntry)) (nequal entry "."))
    /* process up directory differently */
    (if (equal entry "..")
    (progn
    (setq newDir (car (abDirAndFile dirName)))
    (setq simplifiedNewDir (abSimplifyFilename newDir))
    (setq simplifiedDotDotDir (abSimplifyFilename (strcat dirName "/..")))
    (if (equal simplifiedNewDir simplifiedDotDotDir)
    (setq dirAssoc (cons (list ".. (Go up 1 directory level)" newDir) dirAssoc))
    (progn
    (setq dirAssoc (cons (list ".. (Go up 1 directory level)" simplifiedDotDotDir) dirAssoc))
    (setq dirAssoc (cons (list ".. (Go up 1 directory level via link)" newDir) dirAssoc))
    )))
    (when (or showHidden (nequal (getchar entry 1) '\.))
    /* append file type characters on end of string in file list */
    (setq entryPlusType
    (strcat entry
    (cond
    ((isDir fullEntry) "/")
    ((isExecutable fullEntry) "*")
    ((nequal fullEntry (simplifyFilename fullEntry)) "@")
    (t ""))))
    /* only stick a / in the middle if it doesn't already end in a / */
    (if (equal (substring dirName -1) "/")
    (setq dirAssoc (cons (list entryPlusType (strcat dirName entry)) dirAssoc))
    (setq dirAssoc (cons (list entryPlusType (strcat dirName "/" entry)) dirAssoc))))
    )))
    dirAssoc))

    /***************************************************************
    * *
    * (abDirAndFile fileName) *
    * *
    * Tries to split a fileName up into directory *
    * and file parts *
    * *
    ***************************************************************/

    (procedure (abDirAndFile fileName)
    (let (compList dir file dirAndFile)
    (setq compList (parseString fileName "/"))
    /* fiddle for filenames beginning with / */
    (when (equal (substring fileName 1 1) "/")
    (setq compList (cons "" compList)))
    (if (onep (length compList))
    /* if it's a directory without any slashes in */
    (if (isDir fileName)
    (if (equal fileName "/")
    (progn
    (setq dir "/")
    (setq file nil))
    (progn
    /* if it can't be reduced, try to use simplifyFileName */
    (setq dirAndFile (abDirAndFile (simplifyFilename fileName)))
    (setq dir (car dirAndFile))
    (setq file (cadr dirAndFile))))
    (progn
    (setq dir ".")
    (setq file fileName)))
    (progn
    (when (equal
    (setq dir (buildString (reverse (cdr (reverse compList))) "/"))
    "")
    (setq dir "/"))
    (setq file (car (reverse compList)))))
    (list dir file)))

    /***************************************************************
    * *
    * (abCreateSelectFileForm) *
    * *
    * Create the form used to display the list in *
    * Better than using a list box, because it is easier *
    * to update (simply change the choices field of the *
    * list box). *
    * *
    ***************************************************************/

    (procedure (abCreateSelectFileForm)
    (let (fileList)
    (setq fileList
    (hiCreateListBoxField
    ?name 'fileList
    ?choices '("")
    ?doubleClickCB "(abSelectFileDC)"
    ))
    (setq abSelectFileForm
    (hiCreateAppForm
    ?name 'abSelectFileForm
    ?fields (list
    (list fileList 0:0 300:350))
    ?formTitle "."
    ?buttonLayout '(OKCancel (Hidden\ Files abToggleHiddenFiles))
    ?callback '(abSelectFileCB abSelectFileCancel)))))


    /***************************************************************
    * *
    * (abCreateSelectFileList @key (fileName ".") (dirOnly nil) *
    * (showHidden nil)) *
    * *
    * Create the select file list, and set the form contents *
    * appropriately. Make sure the form is displayed. *
    * *
    ***************************************************************/

    (procedure (abCreateSelectFileList @key (fileName ".") (dirOnly nil)
    (showHidden nil))
    (let (dirAssoc dirAndFile dir file value)
    (if (isDir fileName)
    (progn
    (setq dir fileName)
    (setq file nil))
    (progn
    (setq dirAndFile (abDirAndFile fileName))
    (setq dir (car dirAndFile))
    (setq file (cadr dirAndFile))))
    (if (isDir dir)
    (progn
    (setq dirAssoc (abGetDirAssoc ?dirName dir ?dirOnly dirOnly
    ?showHidden showHidden))
    (if file
    (setq value (cdr (assoc (strcat dir "/" file) (mapcar 'reverse dirAssoc))))
    (setq value nil))
    (unless (boundp 'abSelectFileForm)
    (abCreateSelectFileForm))
    (putpropq (getq abSelectFileForm fileList) (mapcar 'car dirAssoc) choices)
    (putpropq (getq abSelectFileForm fileList) value value)
    (putpropq (getq abSelectFileForm fileList) dirAssoc dirAssoc)
    (hiChangeFormTitle abSelectFileForm dir)
    (hiDisplayForm abSelectFileForm)
    t)
    (progn
    (hiDisplayAppDBox
    ?name 'abSFinvalidDirectory
    ?dboxBanner "Invalid Directory"
    ?dboxText "Specified Directory is Invalid"
    ?dialogType hicErrorDialog
    ?buttonLayout 'Close)
    nil
    )
    )
    ))

    /***************************************************************
    * *
    * (abSyncWithSelectFile form field @optional (dirOnly nil)) *
    * *
    * Synchronise the user form with the select file form. *
    * *
    ***************************************************************/

    (procedure (abSyncWithSelectFile form field @optional (dirOnly nil) (showHidden nil))
    (setq abSelectFileSyncForm form)
    (setq abSelectFileSyncField field)
    (setq abSelectFileNewFileName nil)
    (setq abSelectFileDirOnly dirOnly)
    (setq abSelectFileShowHidden showHidden)
    (abUpdateSelectFile))

    /***************************************************************
    * *
    * (abEndSyncWithSelectFile) *
    * *
    * End the synchronisation with the form. *
    * *
    ***************************************************************/

    (procedure (abEndSyncWithSelectFile)
    (when (and
    (boundp 'abSelectFileForm)
    (hiIsForm abSelectFileForm)
    (hiIsFormDisplayed abSelectFileForm)
    )
    (hiFormCancel abSelectFileForm)
    )
    (setq abSelectFileSyncForm nil)
    (setq abSelectFileSyncField nil)
    )

    /***************************************************************
    * *
    * (abUpdateSelectFile) *
    * *
    * callback procedure for the field which is synchronised to *
    * the select file form. *
    * *
    ***************************************************************/

    (procedure (abUpdateSelectFile)
    (let (fileName)
    (when abSelectFileSyncForm
    (setq fileName (getq (get abSelectFileSyncForm abSelectFileSyncField) value))
    (if (equal fileName "")
    (progn
    (setq fileName ".")
    (putpropq (get abSelectFileSyncForm abSelectFileSyncField) fileName value))
    (abCreateSelectFileList ?fileName fileName ?dirOnly abSelectFileDirOnly ?showHidden abSelectFileShowHidden)))))

    /***************************************************************
    * *
    * (abToggleHiddenFiles form) *
    * *
    * Callback for "Hidden Files" button which toggles whether *
    * hidden (i.e. dot) files are displayed or not. *
    * *
    ***************************************************************/

    (procedure (abToggleHiddenFiles form)
    (setq abSelectFileShowHidden (null abSelectFileShowHidden))
    (abUpdateSelectFile))

    /***************************************************************
    * *
    * (abSelectFileCB form) *
    * *
    * Callback used when OK or apply is hit *
    * *
    ***************************************************************/

    (procedure (abSelectFileCB form)
    (let (fileName syncForm)
    (setq fileName (cadr (assoc
    (car (getq (getq abSelectFileForm fileList) value))
    (getq (getq abSelectFileForm fileList) dirAssoc))))
    (setq syncForm abSelectFileSyncForm)
    (setq abSelectFileSyncForm nil)
    (when fileName
    (putpropq (get syncForm abSelectFileSyncField) fileName value))
    ))

    /***************************************************************
    * *
    * (abSelectFileCancel form) *
    * *
    * Callback for cancelling select file form. Used to disconnect *
    * select file from original form. *
    * *
    ***************************************************************/

    (procedure (abSelectFileCancel form)
    (setq abSelectFileSyncForm nil))

    /***************************************************************
    * *
    * (abSelectFileDC) *
    * *
    * Callback used when file is double clicked *
    * *
    ***************************************************************/

    (procedure (abSelectFileDC)
    (let (fileName)
    (setq fileName (cadr (assoc
    (car (getq (getq abSelectFileForm fileList) value))
    (getq (getq abSelectFileForm fileList) dirAssoc))))
    (if (isDir fileName)
    (putpropq (get abSelectFileSyncForm abSelectFileSyncField) fileName value)
    (hiFormDone abSelectFileForm))
    ))
     
    Andrew Beckett, May 14, 2008
    #6
  7. Riad KACED wrote, on 05/12/08 02:14:
    And secondly the example of using it:

    /* abSelectFileExample.il

    Author A.D.Beckett
    Group Custom IC (UK), Cadence Design Systems Ltd.
    Language SKILL
    Date Feb 15, 2008
    Modified
    By

    An example of using abSelectFile.il

    The main entry point is abSelectFileExample()

    ***************************************************

    SCCS Info: @(#) abSelectFileExample.il 02/15/08.10:25:18 1.1

    */

    /***************************************************************
    * *
    * abSelectFileExampleCreateForm() *
    * *
    * Create the example form. *
    * *
    ***************************************************************/

    procedure(abSelectFileExampleCreateForm()
    let((fileName selectFile)
    fileName=hiCreateStringField(
    ?name 'fileName
    ?prompt "File Name"
    ?callback "(abUpdateSelectFile)"
    )
    selectFile=hiCreateButton(
    ?name 'selectFile
    ?buttonText "Select File"
    ?callback "(abSelectFileExampleSyncWithSelectFile)"
    )
    hiCreateAppForm(
    ?name 'abSelectFileExampleForm
    ?formTitle "Choose filename"
    ?fields
    list(
    list(fileName 0:0 405:35 105)
    list(selectFile 105:35 95:30)
    )
    ?callback list('abSelectFileExampleCB 'abSelectFileExampleCancelCB)
    )
    ))

    /***************************************************************
    * *
    * abSelectFileExampleSyncWithSelectFile() *
    * *
    * Callback for the button on the form. Sets up the link with *
    * the select file browser. *
    * *
    ***************************************************************/

    procedure(abSelectFileExampleSyncWithSelectFile()
    abSyncWithSelectFile(
    abSelectFileExampleForm
    'fileName
    nil)
    )

    /***************************************************************
    * *
    * abSelectFileExampleCB(form) *
    * *
    * Callback for form. Views the specified file. *
    * *
    ***************************************************************/

    procedure(abSelectFileExampleCB(form)
    abEndSyncWithSelectFile()
    if(isFile(form->fileName->value) then
    view(form->fileName->value)
    else
    warn("Invalid file: %s\n" form->fileName->value)
    )
    )

    /***************************************************************
    * *
    * abSelectFileExampleCancelCB(form) *
    * *
    * Callback for when form is cancelled. Breaks link with select *
    * file browser *
    * *
    ***************************************************************/

    procedure(abSelectFileExampleCancelCB(_form)
    abEndSyncWithSelectFile()
    )

    /***************************************************************
    * *
    * abSelectFileExample() *
    * *
    * Create the form if it doesn't exist, and display it *
    * *
    ***************************************************************/

    procedure(abSelectFileExample()
    unless(boundp('abSelectFileExampleForm)
    abSelectFileExampleCreateForm()
    )
    hiDisplayForm(abSelectFileExampleForm)
    )
     
    Andrew Beckett, May 14, 2008
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.