flatscript not working when running from command line in headless mode - fixed for next version

Issue #566 new
nerdunio created an issue

Hi

I modified the isolate_gerber.FlatScript example script to test the --shellfile command and I get warnings.

# #####################################################################################
# DESCRIPTION:
# Will isolate copper features in a Gerber file by creating surrounding paths around
# #####################################################################################

puts "\n**************** RUNNING an EXAMPLE SCRIPT = Isolate a Gerber file *******************\n"

# ----------- START: This is needed only for the examples ----------------
# first set the default location where to search for the files to be open and store it to the ROOT_FOLDER variable
set ROOT_FOLDER  [get_sys root_folder_path]

# calculate the resources path for the examples we need to run and store it inside the PATH varaible
set PATH ${ROOT_FOLDER}/assets/examples/files
# ----------- END: This is needed only for the examples ----------------

# set the working path to the path that holds the files we are going to work with
set_path $PATH

# load the GERBER file
open_gerber test.gbr -outname gerber_file

# ncc the Gerber file
ncc gerber_file -overlap 62 -tooldia 0.33 -method standard -connect 1 -margin 0 -all -outname top_ncc

cncjob top_ncc -dia 0.1 -z_cut -0.04 -z_move 2 -feedrate 120 -outname top_ncc_cnc

write_gcode top_ncc_cnc  ${ROOT_FOLDER}/assets/examples/output.nc

I executed the script with

python .\FlatCAM.py --shellfile=".\assets\examples\ncc_gerber.FlatScript"

And everything works perfectly.

If I execute in headless mode

python .\FlatCAM.py --shellfile=".\assets\examples\ncc_gerber.FlatScript" --headless=1

I get this warning

...
[DEBUG][MainThread] CNCJobObject.build_ui()
[DEBUG][MainThread] build_ui--> FlatCAMObj.build_ui()
[DEBUG][MainThread] CNCJobObject.build_ui()
[DEBUG][MainThread] TCL command 'TclCommandWriteGCode' executed.
WARNING: QWidget::setMaximumSize: (/_ExpandableTextEdit) Negative sizes (16777215,-28) are not possible

and the application blocks.

By the way, it it possible to run FlatCam with debug mode disabled?

Regards

Comments (9)

  1. Marius Stanciu

    Hello Manuel,

    The headless mode is not a priority for me and it is possible that I will remove it soon since I see FlatCAM Evo (beta) as a GUI application.

    By the way, it it possible to run FlatCam with debug mode disabled?

    Yes, you can unset the Verbose log checkbox in the Menu → Edit → Preferences → General → Parameters>
    Or if you want to do it from command line:

    set_sys global_log_verbose 0
    save_sys
    

    I mean that the log will no longer spit messages into the Tcl shell box.

  2. Marius Stanciu

    Actually I just changed the behavior for the verbose logging.
    Now it can take 3 values: 0, 1, 2 each meaning a different level of logging:

    0: logging disabled (ahem… mostly)
    1: logging is done only in console
    2: logging is now done verbose and printed in the Tcl Shell box

  3. nerdunio reporter

    Thank you Marius!

    About removing the headless mode. Will scripting still be available? Will --shellfile be available?

  4. Marius Stanciu

    No, scripting stays since it is just a level of automating some tasks although it will not have all the features that are in GUI, due of inherent limitations.

    It's just that the headless mode may get removed, the attribute.

  5. quelimane

    Hello, i would to know if someone solved this probleme ? because i get the same error with the same ‘'negative size’' (Negative sizes (16777215,-28)) on my own project.

    the error below

    ...
    [DEBUG][MainThread] set_ui --> FlatCAMObj.to_form()
    [DEBUG][MainThread] build_ui--> FlatCAMObj.build_ui()
    [DEBUG][MainThread] TCL command 'TclCommandWriteGCode' executed.
    WARNING: QWidget::setMaximumSize: (/_ExpandableTextEdit) Negative sizes (16777215,-28) are not possible
    (The program stuck here)
    

    Moreover, it tell me

    [DEBUG][MainThread] TCL command 'TclCommandWriteGCode' executed.
    

    without creating my file containing gcode.

    WIthout headless mode, the script is executed, the file containing gcode is created but the console inside flatcam is blocked (but not the GUI still reactive). I cannot write command inside but log are still displayed.

    So, if someone can help ? Let me know !

    Best regards,

    Antoine

  6. quelimane

    I think i solve my problem :

    By deleting the line 95 of Flatcam.py (Yes, the last one!)

    (Flatcam.py:95).

    sys.exit(app.exec_())
    

    flatcam produce the gcode file and finish properly by itself without self looping. But it stills displays the error with negative size.

    I follow the execution of flatcam trought the dubbuger pdb, and i finally find that the loop was during the execution of app.exec() function. Since the gcode was already generated and export during the initialisation time, i remove the call of the exec method and it works.

    In headless mode, theexec is not needed so perhaps we can add a global variable for headless mode and don’t execute app.exec() in that case ?

    Best regards,

    Antoine

  7. Marius Stanciu

    Hi,
    You are deleting the GUI loop through that which is not recommended.
    As I wrote above, this version of FlatCAM is a GUI based one, and it is not seriously intended to be run in headless mode. I may actually remove this mode since it is a burden that had to be carried along.

  8. quelimane

    Hi,

    i agree with you, but now, if someone really want to script and export some gcode in a file, it cans. i really happy that flatcam finally do what i want. is spend some hour to understand why the method doest not work. It is a good and powerful tool, with a gui or not (and better if you can choose). Its clear that it could be nice to make another branch or a main class specific to the headless mode (without all the gui stuff that is not needed).

  9. Log in to comment