Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Adding GUI functionality to TCL script

I have a QuartusII project that can be compiled with a multitude of options set via a vhdl package to make many different products.

Unfortunately it is possible to configure these options in invalid combinations.

I would like to make a tcl script to evaluate the options and report the result back to the user trying to compile the project giving them the option to continue or cancel.

I can assign a script to PRE_FLOW_SCRIPT_FILE which makes the script run before compilation starts, but I would like a message box to appear with OK and Cancel buttons.

So my question is can I (and how) make a message box with buttons appear through a script running on QII?

I tried putting the code into the QII tcl console to make a button appear but it didn't work.

The same code put into QFlow did work.

But the same code in a script produced an error because it didn't recognise the 'button' command.

Any ideas?

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello Steve,

    Do you have 'init_tk' at the start of the code ?

    This is needed to initialise the interpreter.

    jt2
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks jt2,

    Adding init_tk does make it understand the commands.

    But I still don't get a window with buttons open when running it as a script.

    It works in the QII tcl console!

    I'm no tcl/tk expert, as an experiment I am trying to run the following code in the script.

    QII reports that evaluation of the script was successful but I get no window pop up.

    init_tk

    toplevel .window

    button .window.hello -text Hello

    pack .window.hello -padx 20 -pady 20
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Steve

    Try

    load tk84

    at the start of the script - I've found Modelsim needs this - nto sure about Quartus though.

    I also added:

    --- Quote Start ---

    wm state . withdrawn

    --- Quote End ---

    before my toplevel command on my Modelsim scripts. I know you're using Quartus but I had similar problems getting graphical scripts to run in Modelsim.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Steve,

    I think you need to add 'tkwait window .window'

    at the end.

    I ran it (from a file) from the tcl console using:

    quartus_stp -t /tcl/test.tcl

    and it works now.

    jt
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you get something working, would you mind posting the framework? I've occasionally thought of ideas where a GUI would be helpful as a pre-flow script, so it might be useful. (I've done two Tk GUI scripts many years ago, and to be honest, had a decent amount of trouble writing in the Tk syntax and getting it to work. I've heard there are other tools that are better and write out a Tk script. Of course, if you just have a single button it may not be a big deal.)

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    jt, thanks, that does indeed work!

    It also stops the compilation flow until the pop up window is cleared which is exactly what I need.

    Rysc, I need to put all logic in to make it do what I want. But I will post a framework.

    Cheers,

    Steve
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    OK, I have spent a bit of time deciding how to proceed on this and have a rough framework for my pre-flow interactive script.

    To make the script run pre-flow you need to add the following line to your projects .qsf file

    ********************** project.qsf **********************

     
    set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:first.tcl"
    
    ********************** project.qsf **********************

    ********************** first.tcl **********************

     #  Create a standard Yes/No message box dialog passing in the #  dialog title and text.
    proc CreateDialog {title text} {
       tk_messageBox 
          -type yesno 
          -title $title 
          -default yes 
          -message $text 
          -icon question
    }
     #  Do this when user clicks Yes
    proc Yes {} {
       post_message -type info "User request to continue compiling."
    }
     #  Do this when user clicks No
    proc No {} {
       post_message -type error "User request to stop compiling."
    }
     # #################  Program Start# # ################
    init_tk
    set dialogTitle "My Message Box"
    set dialogText "Are you sure you want to continue compiling?"
     
    if { == yes} {
       Yes
    } else {
       No
    }
    
    ********************** first.tcl **********************

    Notes:

    * The puts command seems to do nothing, but post_message prints out to the processing tab of the Messages utility window. This is how I stop the compilation in the No process by causing a error message.

    * This is an example of an interactive script, but any script could be used. If you ever plan to to do script driven batch compilations interactive script will obviously disrupt the process.

    * I managed to inadvertently avoid the need for the tkwait command by using a standard dialog.

    Comments, corrections, or improvements welcome.

    Steve
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hello thanks for this thread is very usefull.

    my problem is:

    to execute this first.tcl file i put quartus_sh -t first.tcl in the tcl windows and execute it well.

    but when i want to introduce another actions from others packages (like quartus_pgm -m JTAG -op;DPD.sof) in the proc yes (for example) the tcl command says:

    invalid command name "quartus_pgm"

    while executing

    "unknown_original quartus_pgm -m JTAG -op"

    how i can use diferent packages (like quartus_stp and quartus_sh) in a single tcl file?

    it is posible?

    thanks

    i hope you understand my cuestion.

    bye.